Java Code Examples for javax.swing.text.html.HTMLEditorKit#getStyleSheet()

The following examples show how to use javax.swing.text.html.HTMLEditorKit#getStyleSheet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonTipsDialog.java    From WePush with MIT License 5 votes vote down vote up
public void setHtmlText(String htmlText) {
    textPane1.setContentType("text/html; charset=utf-8");
    HTMLEditorKit kit = new HTMLEditorKit();
    textPane1.setEditorKit(kit);
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("h2{color:#FBC87A;}");
    styleSheet.addRule("body{font-family:" + buttonOK.getFont().getName() + ";font-size:" + buttonOK.getFont().getSize() + ";}");
    textPane1.setText(htmlText);
}
 
Example 2
Source File: UpdateInfoDialog.java    From WePush with MIT License 5 votes vote down vote up
public void setHtmlText(String htmlText) {
    textPane1.setContentType("text/html; charset=utf-8");
    HTMLEditorKit kit = new HTMLEditorKit();
    textPane1.setEditorKit(kit);
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("h2{color:#FBC87A;}");
    styleSheet.addRule("body{font-family:" + buttonOK.getFont().getName() + ";font-size:" + buttonOK.getFont().getSize() + ";}");
    textPane1.setText(htmlText);
    textPane1.setCaretPosition(0);
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static JEditorPane makeEditorPane(HTMLEditorKit kit, String text) {
  JEditorPane editor = new JEditorPane();
  editor.setEditable(false);
  editor.setContentType("text/html");
  editor.setEditorKit(kit);
  editor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
  editor.setText(text);
  StyleSheet style = kit.getStyleSheet();
  style.addRule("span {color: orange;}");
  style.addRule("img {align: middle; valign: middle; vertical-align: middle;}");
  return editor;
}
 
Example 4
Source File: PanelBodyContainer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates new form InstallPanelContainer */
public PanelBodyContainer (String heading, String msg, JPanel bodyPanel) {
    head = heading;
    message = msg;
    this.bodyPanel = bodyPanel;
    initComponents ();
    
    HTMLEditorKit htmlkit = new HTMLEditorKitEx();
    // override the Swing default CSS to make the HTMLEditorKit use the
    // same font as the rest of the UI.

    // XXX the style sheet is shared by all HTMLEditorKits.  We must
    // detect if it has been tweaked by ourselves or someone else
    // (code completion javadoc popup for example) and avoid doing the
    // same thing again

    StyleSheet css = htmlkit.getStyleSheet();

    if (css.getStyleSheets() == null) {
        StyleSheet css2 = new StyleSheet();
        Font f = new JList().getFont();
        int size = f.getSize();
        css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
                .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
        css2.addStyleSheet(css);
        htmlkit.setStyleSheet(css2);
    }
    
    tpPanelHeader.setEditorKit(htmlkit);
    tpPanelHeader.putClientProperty( JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE );
    writeToHeader (head, message);
    initBodyPanel ();
}
 
Example 5
Source File: BrowserSwing.java    From Rel with Apache License 2.0 5 votes vote down vote up
private void setEnhancedOutputStyle(JTextPane pane) {
	pane.setContentType("text/html");
	pane.setEditable(false);
	pane.setEnabled(true);
	HTMLEditorKit editorKit = new HTMLEditorKit();
	HTMLDocument defaultDocument = (HTMLDocument) editorKit.createDefaultDocument();
	pane.setEditorKit(editorKit);
	pane.setDocument(defaultDocument);
	StyleSheet css = editorKit.getStyleSheet();
	for (String entry : style.getFormattedStyle())
		css.addRule(entry);
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private MainPanel() {
  super(new GridLayout(3, 1));
  add(makeUrlPanel("Default", HREF));

  // Customize detault html link color in java swing - Stack Overflow
  // https://stackoverflow.com/questions/26749495/customize-detault-html-link-color-in-java-swing
  HTMLEditorKit kit = new HTMLEditorKit();
  StyleSheet styleSheet = kit.getStyleSheet();
  styleSheet.addRule("a{color:#FF0000;}");
  add(makeUrlPanel("styleSheet.addRule(\"a{color:#FF0000;}\")", HREF));

  add(makeUrlPanel("<a style='color:#00FF00'...", String.format("<html><a style='color:#00FF00' href='%s'>%s</a>", MYSITE, MYSITE)));

  setPreferredSize(new Dimension(320, 240));
}
 
Example 7
Source File: AboutAction.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
private JComponent createPanel() {
	System.setProperty("awt.useSystemAAFontSettings", "on");
	final JEditorPane editorPane = new JEditorPane();    	
	HTMLEditorKit kit = new HTMLEditorKit();
	editorPane.setEditorKit(kit);
    editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
    editorPane.setFont(new Font("Arial", Font.PLAIN, 12));
    editorPane.setPreferredSize(new Dimension(350, 180));
    editorPane.setEditable(false);
    editorPane.setContentType("text/html");
    editorPane.setBackground(new Color(234, 241, 248));        
    // add some styles to the html
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule(".firstCol {margin-left: 25px; }");
    styleSheet.addRule(".secondCol {color: blue; }");
    Document doc = kit.createDefaultDocument();
    editorPane.setDocument(doc);
    editorPane.setText(
            "<html>" +
            "<body>" +
            "<table border='0px' BGCOLOR=\"#EAF1F8\">" +
            "<tr><td colspan=2>" +
            "<img src='" + ImageUtil.getImageURL("logo").toExternalForm() + "'>" +
            "</td></tr>" +
            "<tr><td class=\"firstCol\"><b>" + VERSION + "</b></td><td class=\"secondCol\">" + 
            	VERSION_NO + 
            "</td></tr>" +
            "<tr><td class=\"firstCol\"><b>" + BUILD + "</b></td><td class=\"secondCol\">" + 
            	ReleaseInfo.getBuildNumber() + " (" + BUILD_DATE + ")" + 
            "</td></tr>" +
            "<tr><td class=\"firstCol\"><b>" + SITE + "</b></td><td class=\"secondCol\">"+ 
            	"<a href=\"" + SITE_VALUE + "\">" + SITE_SMALL_VALUE + 
            "</a></td></tr>" +
            "<tr><td class=\"firstCol\"><b>" + COPYRIGHT + "</b></td><td class=\"secondCol\">" + 
            	DEVELOPER + 
            "</td></tr>" +
            "</table>" +
            "</body>" +
            "</html>"
    );

    // Add Hyperlink listener to process hyperlinks
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(final HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                        editorPane.setToolTipText(e.getURL().toExternalForm());
                    }
                });
            } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
                EventQueue.invokeLater(new Runnable() {
                    public void run() {                            
                        SwingUtilities.getWindowAncestor(editorPane).setCursor(Cursor.getDefaultCursor());
                        editorPane.setToolTipText(null);
                    }
                });
            } else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {       
            	    FileUtil.openUrl(e.getURL().toString(), AboutAction.class);                       
            }
        }
    });        
    editorPane.addMouseListener(mouseListener);
    JScrollPane sp = new JScrollPane(editorPane);       
    return sp;
}
 
Example 8
Source File: ArtARDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JPanel getComponent(int width, int height) throws IOException {
	final JPanel container = new JPanel();
	container.setSize(width, height);
	container.setPreferredSize(container.getSize());

	final OverlayLayout overlay = new OverlayLayout(container);
	container.setLayout(overlay);

	labelField = new JEditorPane();
	labelField.setOpaque(false);
	labelField.setSize(640 - 50, 480 - 50);
	labelField.setPreferredSize(labelField.getSize());
	labelField.setMaximumSize(labelField.getSize());
	labelField.setContentType("text/html");

	// add a HTMLEditorKit to the editor pane
	final HTMLEditorKit kit = new HTMLEditorKit();
	labelField.setEditorKit(kit);

	final StyleSheet styleSheet = kit.getStyleSheet();
	styleSheet.addRule("body {color:#FF00FF; font-family:courier;}");
	styleSheet.addRule("h1 {font-size: 60pt}");
	styleSheet.addRule("h2 {font-size: 50pt }");

	final Document doc = kit.createDefaultDocument();
	labelField.setDocument(doc);

	// final GridBagConstraints gbc = new GridBagConstraints();
	// gbc.gridy = 1;
	// panel.add(labelField, gbc);
	container.add(labelField);
	// labelField.setAlignmentX(0.5f);
	// labelField.setAlignmentY(0.5f);

	final JPanel panel = super.getComponent(width, height);
	container.add(panel);

	vc.getDisplay().addVideoListener(this);

	isRunning = true;
	new Thread(this).start();

	return container;
}
 
Example 9
Source File: SimpleGUI.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * This method displays the about box.
 */
public Runner doAbout() {
    if (wrap)
        return wrapMe();

    // Old about message
    // OurDialog.showmsg("About Alloy Analyzer " + Version.version(), OurUtil.loadIcon("images/logo.gif"), "Alloy Analyzer " + Version.version(), "Build date: " + " git: " + Version.commit, " ", "Lead developer: Felix Chang", "Engine developer: Emina Torlak", "Graphic design: Julie Pelaez", "Project lead: Daniel Jackson", " ", "Please post comments and questions to the Alloy Community Forum at http://alloy.mit.edu/", " ", "Thanks to: Ilya Shlyakhter, Manu Sridharan, Derek Rayside, Jonathan Edwards, Gregory Dennis,", "Robert Seater, Edmond Lau, Vincent Yeung, Sam Daitch, Andrew Yip, Jongmin Baek, Ning Song,", "Arturo Arizpe, Li-kuo (Brian) Lin, Joseph Cohen, Jesse Pavel, Ian Schechter, and Uriel Schafer.");

    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet styleSheet = kit.getStyleSheet();
    styleSheet.addRule("body {color:#000; font-family:Verdana, Trebuchet MS,Geneva, sans-serif; font-size: 10px; margin: 4px; }");
    styleSheet.addRule("h1 {color: blue;}");
    styleSheet.addRule("h2 {color: #ff0000;}");
    styleSheet.addRule("pre {font : 10px monaco; color : black; background-color: #C0C0C0; padding: 4px; margin: 4px; }");
    styleSheet.addRule("th {text-align:left;}");

    JTextPane ta = new JTextPane();
    ta.setEditorKit(kit);
    ta.setContentType("text/html");
    ta.setBackground(null);
    ta.setBorder(null);
    ta.setFont(new JLabel().getFont());
    // @formatter:off
    ta.setText("<html><h1>Alloy Analyzer " + Version.getShortversion() + "</h1>"
    + "<br/>"
    + "<html>"
    + "<tr><th>Project Lead</th><td>Daniel Jackson</td></tr>"
    + "<tr><th>Chief Developer</th><td>Aleksandar Milicevic</td></tr>"
    + "<tr><th>Kodkod Engine</th><td>Emina Torlak</td></tr>"
    + "<tr><th>Open Source</th><td>Peter Kriens</td></tr>"
    + "</table><br/>"
    + "<p>For more information about Alloy, <a href='http://alloytools.org'>http://alloytools.org</a></p>"
    + "<p>Questions and comments about Alloy are welcome at the community forum:</p>"
    + "<p>Alloy Community Forum: <a href='https://groups.google.com/forum/#!forum/alloytools'>https://groups.google.com/forum/#!forum/alloytools</a></p>"
    + "<p>Alloy experts also respond to <a href='https://stackoverflow.com/questions/tagged/alloy'>https://stackoverflow.com</a> questions tagged <code>alloy</code>.</p>"
    + "<p>Major contributions to earlier versions of Alloy were made by: Felix Chang (v4);<br/>"
    + "Jonathan Edwards, Eunsuk Kang, Joe Near, Robert Seater, Derek Rayside, Greg Dennis,<br/>"
    + "Ilya Shlyakhter, Mana Taghdiri, Mandana Vaziri, Sarfraz Khurshid (v3); Manu Sridharan<br/>"
    + "(v2); Edmond Lau, Vincent Yeung, Sam Daitch, Andrew Yip, Jongmin Baek, Ning Song,<br/>"
    + "Arturo Arizpe, Li-kuo (Brian) Lin, Joseph Cohen, Jesse Pavel, Ian Schechter, Uriel<br/>"
    + "Schafer (v1).</p>"
    + "<p>The development of Alloy was funded by part by the National Science Foundation under<br/>"
    + "Grant Nos. 0325283, 0541183, 0438897 and 0707612; by the Air Force Research Laboratory<br/>"
    + "(AFRL/IF) and the Disruptive Technology Office (DTO) in the National Intelligence<br/>"
    + "Community Information Assurance Research (NICIAR) Program; and by the Nokia<br/>"
    + "Corporation as part of a collaboration between Nokia Research and MIT CSAIL.</p>"
    + "<br/><pre>"
    + "Build Date: " + Version.buildDate() + "<br/>"
    + "Git Commit: " + Version.commit
    + "</pre>");
    // @formatter:on
    ta.setEditable(false);
    ta.addHyperlinkListener((e) -> {
        if (e.getEventType() == EventType.ACTIVATED) {
            if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (IOException | URISyntaxException e1) {
                    // ignore
                }
            }
        }
    });
    OurDialog.showmsg("About Alloy Analyzer " + Version.version(), ta);

    return null;
}
 
Example 10
Source File: DetailsPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DetailsPanel() {
    initComponents2();
    HTMLEditorKit htmlkit = new HTMLEditorKitEx();
    // override the Swing default CSS to make the HTMLEditorKit use the
    // same font as the rest of the UI.
    
    // XXX the style sheet is shared by all HTMLEditorKits.  We must
    // detect if it has been tweaked by ourselves or someone else
    // (code completion javadoc popup for example) and avoid doing the
    // same thing again
    
    StyleSheet css = htmlkit.getStyleSheet();
    
    if (css.getStyleSheets() == null) {
        StyleSheet css2 = new StyleSheet();
        Font f = new JList().getFont();
        int size = f.getSize();
        css2.addRule(new StringBuffer("body { font-size: ").append(size) // NOI18N
                .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N
        css2.addStyleSheet(css);
        htmlkit.setStyleSheet(css2);
    }
    
    setEditorKit(htmlkit);
    addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent hlevt) {
            if (EventType.ACTIVATED == hlevt.getEventType()) {
                if (hlevt.getURL () != null) {
                    Utilities.showURL(hlevt.getURL());
                }
            }
        }
    });
    setEditable(false);
    setPreferredSize(new Dimension(300, 80));
    RP.post(new Runnable() {

        @Override
        public void run() {
            getAccessibleContext ().setAccessibleName (
                    NbBundle.getMessage (DetailsPanel.class, "ACN_DetailsPanel")); // NOI18N
        }
    });

    putClientProperty( JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE );
}
 
Example 11
Source File: Browser.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
public Browser(String currentHref) {
    super();

    this.currentHref = currentHref;


    try {
        if (Bither.getMainFrame() != null) {
            Bither.getMainFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        }
        addHyperlinkListener(new ActivatedHyperlinkListener(Bither.getMainFrame(), this));

        loadingMessage = LocaliserUtils.getString("browser.loadingMessage");

        setEditable(false);
        setBackground(Themes.currentTheme.detailPanelBackground());

        String fontName = null;
        if (fontName == null || "".equals(fontName)) {
            fontName = ColorAndFontConstants.BITHER_DEFAULT_FONT_NAME;
        }
        // Add in san-serif as a fallback.
        fontName = fontName + ", san-serif";

        int fontSize = ColorAndFontConstants.BITHER_DEFAULT_FONT_SIZE;
        boolean isItalic = false;
        boolean isBold = false;
        Font adjustedFont = FontSizer.INSTANCE.getAdjustedDefaultFont();
        if (adjustedFont != null) {
            setFont(adjustedFont);
            fontSize = adjustedFont.getSize();
            isItalic = adjustedFont.isItalic();
            isBold = adjustedFont.isBold();
        }

        String fontCSS = "font-size:" + fontSize + "pt; font-family:" + fontName + ";";
        if (isItalic) {
            fontCSS = fontCSS + "font-style:italic;";
        } else {
            fontCSS = fontCSS + "font-style:normal;";
        }
        if (isBold) {
            fontCSS = fontCSS + "font-weight:bold;";
        } else {
            fontCSS = fontCSS + "font-weight:normal;";
        }

        HTMLEditorKit kit = new HTMLEditorKit();
        setEditorKit(kit);
        javax.swing.text.html.StyleSheet styleSheet = kit.getStyleSheet();
        styleSheet.addRule("body {" + fontCSS + "}");
        Document doc = kit.createDefaultDocument();
        setDocument(doc);

        log.debug("Trying to load '" + currentHref + "'...");
    } catch (Exception ex) {
        showUnableToLoadMessage(ex.getClass().getCanonicalName() + " " + ex.getMessage());
    }
}
 
Example 12
Source File: bug6938813.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 13
Source File: bug6938813.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 14
Source File: bug6938813.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 15
Source File: bug6938813.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 16
Source File: bug6938813.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 17
Source File: bug6938813.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 18
Source File: bug6938813.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 19
Source File: bug6938813.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}
 
Example 20
Source File: bug6938813.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
private static void validate() throws Exception {
    AppContext appContext = AppContext.getAppContext();

    assertTrue(DTD.getDTD(DTD_KEY).getName().equals(DTD_KEY), "DTD.getDTD() mixed AppContexts");

    // Spoil hash value
    DTD invalidDtd = DTD.getDTD("invalid DTD");

    DTD.putDTDHash(DTD_KEY, invalidDtd);

    assertTrue(DTD.getDTD(DTD_KEY) == invalidDtd, "Something wrong with DTD.getDTD()");

    Object dtdKey = getParserDelegator_DTD_KEY();

    assertTrue(appContext.get(dtdKey) == null, "ParserDelegator mixed AppContexts");

    // Init default DTD
    new ParserDelegator();

    Object dtdValue = appContext.get(dtdKey);

    assertTrue(dtdValue != null, "ParserDelegator.defaultDTD isn't initialized");

    // Try reinit default DTD
    new ParserDelegator();

    assertTrue(dtdValue == appContext.get(dtdKey), "ParserDelegator.defaultDTD created a duplicate");

    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    if (styleSheet == null) {
        // First AppContext
        styleSheet = htmlEditorKit.getStyleSheet();

        assertTrue(styleSheet != null, "htmlEditorKit.getStyleSheet() returns null");
        assertTrue(htmlEditorKit.getStyleSheet() == styleSheet, "Something wrong with htmlEditorKit.getStyleSheet()");
    } else {
        assertTrue(htmlEditorKit.getStyleSheet() != styleSheet, "HtmlEditorKit.getStyleSheet() mixed AppContexts");
    }
}