Search in sources :

Example 36 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project jdk8u_jdk by JetBrains.

the class bug4492274 method createAndShowGUI.

private static void createAndShowGUI() {
    try {
        File file = new File(System.getProperty("test.src", "."), "test.html");
        page = file.toURI().toURL();
        JFrame f = new JFrame();
        jep = new JEditorPane();
        jep.setEditorKit(new HTMLEditorKit());
        jep.setEditable(false);
        jep.setPage(page);
        JScrollPane sp = new JScrollPane(jep);
        f.getContentPane().add(sp);
        f.setSize(500, 500);
        f.setVisible(true);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) File(java.io.File)

Example 37 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project jdk8u_jdk by JetBrains.

the class bug6938813 method validate.

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");
    }
}
Also used : ParserDelegator(javax.swing.text.html.parser.ParserDelegator) DTD(javax.swing.text.html.parser.DTD) AppContext(sun.awt.AppContext) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

Example 38 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project beast-mcmc by beast-dev.

the class TextUtil method createHTMLScrollPane.

public static JScrollPane createHTMLScrollPane(String text, Dimension dimension) {
    JEditorPane jEditorPane = new JEditorPane();
    jEditorPane.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(jEditorPane);
    HTMLEditorKit kit = new HTMLEditorKit();
    jEditorPane.setEditorKit(kit);
    // create a document, set it on the jeditorpane, then add the html
    Document doc = kit.createDefaultDocument();
    jEditorPane.setDocument(doc);
    jEditorPane.setText(text);
    // to make html auto wrap
    jEditorPane.setPreferredSize(dimension);
    return scrollPane;
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Document(javax.swing.text.Document)

Example 39 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project megameklab by MegaMek.

the class UnitUtil method showBVCalculations.

public static void showBVCalculations(String bvText, JFrame frame) {
    HTMLEditorKit kit = new HTMLEditorKit();
    JEditorPane textPane = new JEditorPane("text/html", "");
    JScrollPane scroll = new JScrollPane();
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    textPane.setEditorKit(kit);
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    textPane.setText(bvText);
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    Dimension size = new Dimension((int) (CConfig.getIntParam("WINDOWWIDTH") / 1.5), CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    // text.setPreferredSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultCaret(javax.swing.text.DefaultCaret) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog) LocationFullException(megamek.common.LocationFullException)

Example 40 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit in project megameklab by MegaMek.

the class UnitUtil method showUnitSpecs.

public static void showUnitSpecs(Entity unit, JFrame frame) {
    HTMLEditorKit kit = new HTMLEditorKit();
    MechView mechView = null;
    try {
        mechView = new MechView(unit, true);
    } catch (Exception e) {
    // error unit didn't load right. this is bad news.
    }
    StringBuffer unitSpecs = new StringBuffer("<html><body>");
    unitSpecs.append(mechView.getMechReadoutBasic());
    unitSpecs.append(mechView.getMechReadoutLoadout());
    unitSpecs.append("</body></html>");
    // System.err.println(unitSpecs.toString());
    JEditorPane textPane = new JEditorPane("text/html", "");
    JScrollPane scroll = new JScrollPane();
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    textPane.setEditorKit(kit);
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    textPane.setText(unitSpecs.toString());
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    /*
         * if (unit instanceof Mech) { EntityVerifier entityVerifier = new
         * EntityVerifier(new File("data/mechfiles/UnitVerifierOptions.xml"));
         * //$NON-NLS-1$ TestMech test = new TestMech((Mech)unit,
         * entityVerifier.mechOption, null); JEditorPane pane2 = new
         * JEditorPane();
         * pane2.setText(test.printWeightCalculation().toString());
         * jdialog.add(pane2); }
         */
    Dimension size = new Dimension(CConfig.getIntParam("WINDOWWIDTH") / 2, CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    // text.setPreferredSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MechView(megamek.common.MechView) DefaultCaret(javax.swing.text.DefaultCaret) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) LocationFullException(megamek.common.LocationFullException) JDialog(javax.swing.JDialog)

Aggregations

HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)47 HTMLDocument (javax.swing.text.html.HTMLDocument)18 JEditorPane (javax.swing.JEditorPane)10 StyleSheet (javax.swing.text.html.StyleSheet)9 IOException (java.io.IOException)8 JScrollPane (javax.swing.JScrollPane)8 Dimension (java.awt.Dimension)7 URL (java.net.URL)7 Document (javax.swing.text.Document)6 MouseEvent (java.awt.event.MouseEvent)5 StringReader (java.io.StringReader)5 HyperlinkEvent (javax.swing.event.HyperlinkEvent)5 ActionListener (java.awt.event.ActionListener)4 HyperlinkListener (javax.swing.event.HyperlinkListener)4 BorderLayout (java.awt.BorderLayout)3 ActionEvent (java.awt.event.ActionEvent)3 InputStream (java.io.InputStream)3 BadLocationException (javax.swing.text.BadLocationException)3 MouseAdapter (java.awt.event.MouseAdapter)2 InputStreamReader (java.io.InputStreamReader)2