public void ulActionB_actionPerformed(ActionEvent e) { String parentname = document .getParagraphElement(editor.getCaretPosition()) .getParentElement() .getName(); HTML.Tag parentTag = HTML.getTag(parentname); HTMLEditorKit.InsertHTMLTextAction ulAction = new HTMLEditorKit.InsertHTMLTextAction( "insertUL", "<ul><li></li></ul>", parentTag, HTML.Tag.UL); ulAction.actionPerformed(e); }
public void actionPerformed(ActionEvent e) { String elName = document .getParagraphElement(editor.getCaretPosition()) .getName(); /* * if ((elName.toUpperCase().equals("PRE")) || * (elName.toUpperCase().equals("P-IMPLIED"))) { * editor.replaceSelection("\r"); return; */ HTML.Tag tag = HTML.getTag(elName); if (elName.toUpperCase().equals("P-IMPLIED")) tag = HTML.Tag.IMPLIED; HTMLEditorKit.InsertHTMLTextAction hta = new HTMLEditorKit.InsertHTMLTextAction( "insertBR", "<br>", tag, HTML.Tag.BR); hta.actionPerformed(e); //insertHTML("<br>",editor.getCaretPosition()); }
private void postInitComponents () { this.jLabel2.setVisible(false); this.platformHome.setVisible(false); final Collection installFolders = platform.getInstallFolderURLs(); if (platform.getInstallFolders().isEmpty() && installFolders.size() > 0) { this.jLabel2.setVisible(true); this.platformHome.setVisible(true); this.platformHome.setForeground(new Color (164,0,0)); this.platformHome.setText (Utilities.toFile(URI.create(((URL)installFolders.iterator().next()).toExternalForm())).getAbsolutePath()); } HTMLEditorKit htmlkit = new HTMLEditorKit(); StyleSheet css = htmlkit.getStyleSheet(); if (css.getStyleSheets() == null) { StyleSheet css2 = new StyleSheet(); Font f = jLabel2.getFont(); css2.addRule(new StringBuffer("body { font-size: ").append(f.getSize()) // NOI18N .append("; font-family: ").append(f.getName()).append("; }").toString()); // NOI18N css2.addStyleSheet(css); htmlkit.setStyleSheet(css2); } jTextPane1.setEditorKit(htmlkit); jTextPane1.setText(NbBundle.getMessage(BrokenPlatformCustomizer.class,"MSG_BrokenProject")); }
@Messages("LBL_TemplatesPanel_PleaseWait=Please wait...") private void postInitComponents () { Mnemonics.setLocalizedText(jLabel1, this.firer.getCategoriesName()); Mnemonics.setLocalizedText(jLabel2, this.firer.getTemplatesName()); this.description.setEditorKit(new HTMLEditorKit()); description.putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE ); // please wait node, see issue 52900 pleaseWait = new AbstractNode (Children.LEAF) { @Override public Image getIcon (int ignore) { return PLEASE_WAIT_ICON; } }; pleaseWait.setName(LBL_TemplatesPanel_PleaseWait()); Children ch = new Children.Array (); ch.add (new Node[] {pleaseWait}); final Node root = new AbstractNode (ch); SwingUtilities.invokeLater (new Runnable () { @Override public void run() { ((ExplorerProviderPanel)categoriesPanel).setRootNode (root); } }); ((ExplorerProviderPanel)projectsPanel).addDefaultActionListener( firer ); description.addHyperlinkListener(new ClickHyperlinks()); }
public ExtendedHTMLEditorKit() { styleSheet = new StyleSheet(); try { InputStream is = HTMLEditorKit.class.getResourceAsStream(DEFAULT_CSS); Reader r = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); styleSheet.loadRules(r, null); r.close(); } catch (Exception e) { // LogService.getRoot().log(Level.WARNING, "Cannot install stylesheet: "+e, e); LogService.getRoot().log( Level.WARNING, I18N.getMessage(LogService.getRoot().getResourceBundle(), "com.rapidminer.gui.tools.ExtendedHTMLEditorKit.installing_stylesheet_error", e), e); // on error we simply have no styles... the html // will look mighty wrong but still function. } }
public AbstractLinkButton(final Action action, Color linkTextColor) { super("text/html", makeHTML(action)); this.action = action; if (action == null) { throw new IllegalArgumentException("action must not be null!"); } installDefaultStylesheet(); setEditable(false); setOpaque(false); setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); HTMLEditorKit htmlKit = (HTMLEditorKit) getEditorKit(); String hexColor = String.format(SwingTools.getColorHexValue(linkTextColor)); htmlKit.getStyleSheet().addRule("a {color:" + hexColor + ";}"); makeHyperLinkListener(action); }
/** * Creates the main text representation of this result. * * @param text * @return */ private Component makeMainLabel(String text) { JEditorPane label = new ExtendedHTMLJEditorPane("text/html", text); StyleSheet css = ((HTMLEditorKit) label.getEditorKit()).getStyleSheet(); css.addRule("body {font-family:Sans;font-size:11pt}"); css.addRule("h3 {margin:0; padding:0}"); css.addRule("h4 {margin-bottom:0; margin-top:1ex; padding:0}"); css.addRule("p {margin-top:0; margin-bottom:1ex; padding:0}"); css.addRule("ul {margin-top:0; margin-bottom:1ex; list-style-image: url(" + getClass().getResource("/com/rapidminer/resources/icons/modern/help/circle.png") + ")}"); css.addRule("ul li {padding-bottom: 2px}"); css.addRule("li.outPorts {padding-bottom: 0px}"); css.addRule("ul li ul {margin-top:0; margin-bottom:1ex; list-style-image: url(" + getClass().getResource("/com/rapidminer/resources/icons/modern/help/line.png") + ")"); css.addRule("li ul li {padding-bottom:0}"); label.setEditable(false); JScrollPane pane = new JScrollPane(label); pane.setOpaque(false); pane.setBackground(null); pane.setBorder(null); return pane; }
public void olActionB_actionPerformed(ActionEvent e) { String parentname = document .getParagraphElement(editor.getCaretPosition()) .getParentElement() .getName(); HTML.Tag parentTag = HTML.getTag(parentname); HTMLEditorKit.InsertHTMLTextAction olAction = new HTMLEditorKit.InsertHTMLTextAction( "insertOL", "<ol><li></li></ol>", parentTag, HTML.Tag.OL); olAction.actionPerformed(e); //removeIfEmpty(document.getParagraphElement(editor.getCaretPosition()-1)); list = true; }
protected void insertDocument(String msg) { try { HTMLEditorKit kit = (HTMLEditorKit) historyWidget.getEditorKit(); HTMLDocument doc = (HTMLDocument) historyWidget.getDocument(); // historyWidget.getDocument().insertString(len - offset, // trimMsg(msg), null); // Element root = doc.getDefaultRootElement(); // Element body = root.getElement(1); // doc.insertBeforeEnd(body, msg); int pos = historyWidget.getCaretPosition(); kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null); historyWidget.setCaretPosition(scrollLock ? pos : doc.getLength()); } catch (Exception e) { e.printStackTrace(); } }
public PreviewView(ReportEditorView reportEditorView) { this.reportEditorView = reportEditorView; JScrollPane pane = new JScrollPane(editorPane); HTMLEditorKit kit = new HTMLEditorKit() { /** * */ private static final long serialVersionUID = -8040272164224951314L; @Override public Document createDefaultDocument() { Document document = super.createDefaultDocument(); document.putProperty("IgnoreCharsetDirective", true); return document; } }; editorPane.setEditorKit(kit); editorPane.setEditable(false); this.add(pane, BorderLayout.CENTER); }
public static void main(String[] args) { String htmlDoc = "<pre><p> </pre>"; try { HTMLEditorKit kit = new HTMLEditorKit(); Class c = Class.forName( "javax.swing.text.html.parser.ParserDelegator"); HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance(); HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument(); HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0); parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true); htmlReader.flush(); CharArrayWriter writer = new CharArrayWriter(1000); kit.write(writer, doc, 0, doc.getLength()); writer.flush(); } catch (Exception ex) { throw new RuntimeException("Test Failed " + ex); } }
private void createUIComponents() { final Font font = UIManager.getFont("Label.font"); final String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }"; informationEditorPane = new JEditorPane(); informationEditorPane.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) informationEditorPane.getDocument()).getStyleSheet().addRule(bodyRule); cvsEditorPane = new JEditorPane(); cvsEditorPane.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) cvsEditorPane.getDocument()).getStyleSheet().addRule(bodyRule); jrebelEditorPane = new JEditorPane(); jrebelEditorPane.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) jrebelEditorPane.getDocument()).getStyleSheet().addRule(bodyRule); jiraEditorPane = new JEditorPane(); jiraEditorPane.setEditorKit(new HTMLEditorKit()); ((HTMLDocument) jiraEditorPane.getDocument()).getStyleSheet().addRule(bodyRule); jiraEditorPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE); }
@Override public JComponent createTaskInfoPanel(Project project) { myTaskTextPane = new JTextPane(); final JBScrollPane scrollPane = new JBScrollPane(myTaskTextPane); myTaskTextPane.setContentType(new HTMLEditorKit().getContentType()); final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme(); int fontSize = editorColorsScheme.getEditorFontSize(); final String fontName = editorColorsScheme.getEditorFontName(); final Font font = new Font(fontName, Font.PLAIN, fontSize); String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }" + "pre {font-family: Courier; display: inline; ine-height: 50px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}" + "code {font-family: Courier; display: flex; float: left; background-color:" + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}"; ((HTMLDocument)myTaskTextPane.getDocument()).getStyleSheet().addRule(bodyRule); myTaskTextPane.setEditable(false); if (!UIUtil.isUnderDarcula()) { myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()); } myTaskTextPane.setBorder(new EmptyBorder(20, 20, 0, 10)); myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE); return scrollPane; }
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); } }
private static void createAndShowGUI(String text) throws Exception { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception ex) { throw new RuntimeException(ex); } frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); editorPane = new JEditorPane(); HTMLEditorKit editorKit = new HTMLEditorKit(); editorPane.setEditorKit(editorKit); editorPane.setText(text); editorPane.setCaretPosition(1); frame.add(editorPane); frame.setSize(200, 200); frame.setVisible(true); } }); }
private static void createAndShowGUI() { try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception ex) { throw new RuntimeException(ex); } JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane editorPane = new JEditorPane(); HTMLEditorKit editorKit = new HTMLEditorKit(); editorPane.setEditorKit(editorKit); editorPane.setText(text); frame.add(editorPane); frame.setVisible(true); }
public static void main(String[] args) throws Exception { int N = 10; for (int i = 0; i < N; i++) { HTMLEditorKit kit = new HTMLEditorKit(); Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator"); HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance(); HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument(); HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0); parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true); htmlReader.flush(); CharArrayWriter writer = new CharArrayWriter(1000); kit.write(writer, doc, 0, doc.getLength()); writer.flush(); String result = writer.toString(); if (!result.contains("<tt><a")) { throw new RuntimeException("The <a> and <tt> tags are swapped"); } } }
public static void main(String[] args) throws Exception { ParserCB cb = new ParserCB(); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); htmlDoc.getParser().parse(new StringReader(text), cb, true); synchronized (lock) { if (!isCallbackInvoked) { lock.wait(5000); } } if (!isCallbackInvoked) { throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text); } if (exception != null) { throw exception; } }
private static void createAndShowGUI() { try { UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (Exception ex) { throw new RuntimeException(ex); } JFrame frame = new JFrame("bug8058120"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane editorPane = new JEditorPane(); editorPane.setContentType("text/html"); editorPane.setEditorKit(new HTMLEditorKit()); document = (HTMLDocument) editorPane.getDocument(); editorPane.setText(text); frame.add(editorPane); frame.setSize(200, 200); frame.setVisible(true); }
private static void checkImages() throws Exception { SwingUtilities.invokeAndWait(new Runnable() { public void run() { HTMLEditorKit c = new HTMLEditorKit(); HTMLDocument doc = new HTMLDocument(); try { c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0); } catch (Exception e) { throw new RuntimeException("The test failed", e); } Element elem = doc.getElement("test"); ImageView iv = new ImageView(elem); if (iv.getLoadingImageIcon() == null) { throw new RuntimeException("getLoadingImageIcon returns null"); } if (iv.getNoImageIcon() == null) { throw new RuntimeException("getNoImageIcon returns null"); } } }); }
public static void main(String[] args) throws IOException, InvocationTargetException, InterruptedException { SwingUtilities.invokeAndWait(() -> { MyParser cb = new MyParser(); HTMLEditorKit htmlKit = new HTMLEditorKit(); HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument(); FileReader reader = null; try { reader = new FileReader(getDirURL() + "test.html"); htmlDoc.getParser().parse(reader, cb, true); if(failed) { throw new RuntimeException("Test failed"); } } catch (IOException e) { throw new RuntimeException(e); } }); }
public void olActionB_actionPerformed(ActionEvent e) { String parentname = document .getParagraphElement(editor.getCaretPosition()) .getParentElement() .getName(); HTML.Tag parentTag = HTML.getTag(parentname); HTMLEditorKit.InsertHTMLTextAction olAction = new HTMLEditorKit.InsertHTMLTextAction( "insertOL", "<ol><li></li></ol>", parentTag, HTML.Tag.OL); olAction.actionPerformed(e); }
public void lAlignActionB_actionPerformed(ActionEvent e) { HTMLEditorKit.AlignmentAction aa = new HTMLEditorKit.AlignmentAction( "leftAlign", StyleConstants.ALIGN_LEFT); aa.actionPerformed(e); }
public void cAlignActionB_actionPerformed(ActionEvent e) { HTMLEditorKit.AlignmentAction aa = new HTMLEditorKit.AlignmentAction( "centerAlign", StyleConstants.ALIGN_CENTER); aa.actionPerformed(e); }
public void rAlignActionB_actionPerformed(ActionEvent e) { HTMLEditorKit.AlignmentAction aa = new HTMLEditorKit.AlignmentAction( "rightAlign", StyleConstants.ALIGN_RIGHT); aa.actionPerformed(e); }
public void insertHTML(String html, int location) { //assumes editor is already set to "text/html" type try { HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit(); Document doc = editor.getDocument(); StringReader reader = new StringReader(html); kit.read(reader, doc, location); } catch (Exception ex) { ex.printStackTrace(); } }
/** Creates new form AddPropertyDialog */ public AddPropertyDialog(NbMavenProjectImpl prj, String goalsText) { initComponents(); manager = new ExplorerManager(); //project can be null when invoked from Tools/Options project = prj; okbutton = new JButton(NbBundle.getMessage(AddPropertyDialog.class, "BTN_OK")); manager.setRootContext(Node.EMPTY); tpDesc.setEditorKit(new HTMLEditorKit()); tpDesc.putClientProperty( JTextPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE ); manager.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { Node[] nds = getExplorerManager().getSelectedNodes(); if (nds.length != 1) { okbutton.setEnabled(false); } else { PluginIndexManager.ParameterDetail plg = nds[0].getLookup().lookup(PluginIndexManager.ParameterDetail.class); if (plg != null) { okbutton.setEnabled(true); tpDesc.setText(plg.getHtmlDetails(false)); } else { okbutton.setEnabled(false); tpDesc.setText(""); } } } }); ((BeanTreeView)tvExpressions).setRootVisible(false); ((BeanTreeView)tvExpressions).setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.goalsText = goalsText; RequestProcessor.getDefault().post(new Loader()); }
/** 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 (); }