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);
}
}
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");
}
}
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;
}
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) {
}
}
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) {
}
}
Aggregations