List of usage examples for javax.swing JEditorPane setContentType
@BeanProperty(bound = false, description = "the type of content") public final void setContentType(String type)
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
private void printHtmlParagraphsPdf(Section section, String content, int parentLevel) throws Exception { if (content == null || content.length() == 0) return;/*from w w w . ja v a 2s .co m*/ if (isBase64Encoded(content) || "true".equals(System.getProperty("mdw.designer.force.msword"))) { byte[] docBytes = decodeBase64(content); content = new DocxBuilder(docBytes).toHtml(); content = content.replaceAll(" ", " "); } JEditorPane documentation = new JEditorPane(); documentation.setContentType("text/html"); documentation.setText(content); javax.swing.text.Document swingdoc = documentation.getDocument(); Element[] elements = swingdoc.getRootElements(); boolean useGenerate = true; if (useGenerate) { for (Element e : elements) { Object gen = generateElementHtml(e, 0, normalFont); addSectionContentPdf(section, gen, parentLevel); } } else { // use print for (Element e : elements) { printElementHtml(e, section, 0, normalFont, parentLevel); } } }
From source file:com.marginallyclever.makelangelo.MainGUI.java
/** * * @param html String of valid HTML.//from w w w. java 2 s .c o m * @return a */ private JTextComponent createHyperlinkListenableJEditorPane(String html) { final JEditorPane bottomText = new JEditorPane(); bottomText.setContentType("text/html"); bottomText.setEditable(false); bottomText.setText(html); bottomText.setOpaque(false); final HyperlinkListener hyperlinkListener = new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) { if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().browse(hyperlinkEvent.getURL().toURI()); } catch (IOException | URISyntaxException exception) { // FIXME Auto-generated catch block exception.printStackTrace(); } } } } }; bottomText.addHyperlinkListener(hyperlinkListener); return bottomText; }
From source file:br.com.atmatech.sac.view.ViewPessoa.java
public void DisplayHtml(String urlString) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container con = frame.getContentPane(); JEditorPane jep = new JEditorPane(); JScrollPane jsp = new JScrollPane(jep); con.add(jsp);//from ww w .j a v a2 s . com jep.setContentType("text/html"); try { jep.setPage(urlString); } catch (Exception e) { e.printStackTrace(); } frame.setBounds(50, 50, 600, 800); frame.setVisible(true); }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * Create if needed and return the editorpane for the description tab * * @return description view//from w ww. j av a2s . com */ private JEditorPane getHtmlView() { if (htmlView == null) { JEditorPane tmp = new JEditorPane(); tmp.setContentType("text/html"); tmp.setPreferredSize(new Dimension(300, 400)); tmp.setEditable(false); tmp.setText(" "); htmlView = tmp; } return htmlView; }
From source file:net.yacy.cora.util.Html2Image.java
/** * render a html page with a JEditorPane, which can do html up to html v 3.2. No CSS supported! * @param url//from www .j a v a2 s.co m * @param size * @throws IOException */ public static void writeSwingImage(String url, Dimension size, File destination) throws IOException { // set up a pane for rendering final JEditorPane htmlPane = new JEditorPane(); htmlPane.setSize(size); htmlPane.setEditable(false); final HTMLEditorKit kit = new HTMLEditorKit() { private static final long serialVersionUID = 1L; @Override public Document createDefaultDocument() { HTMLDocument doc = (HTMLDocument) super.createDefaultDocument(); doc.setAsynchronousLoadPriority(-1); return doc; } @Override public ViewFactory getViewFactory() { return new HTMLFactory() { @Override public View create(Element elem) { View view = super.create(elem); if (view instanceof ImageView) { ((ImageView) view).setLoadsSynchronously(true); } return view; } }; } }; htmlPane.setEditorKitForContentType("text/html", kit); htmlPane.setContentType("text/html"); htmlPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { } }); // load the page try { htmlPane.setPage(url); } catch (IOException e) { e.printStackTrace(); } // render the page Dimension prefSize = htmlPane.getPreferredSize(); BufferedImage img = new BufferedImage(prefSize.width, htmlPane.getPreferredSize().height, BufferedImage.TYPE_INT_ARGB); Graphics graphics = img.getGraphics(); htmlPane.setSize(prefSize); htmlPane.paint(graphics); ImageIO.write(img, destination.getName().endsWith("jpg") ? "jpg" : "png", destination); }
From source file:org.apache.tika.gui.TikaGUI.java
private void addWelcomeCard(JPanel panel, String name) { try {/* w ww . jav a 2 s.c om*/ JEditorPane editor = new JEditorPane(TikaGUI.class.getResource("welcome.html")); editor.setContentType("text/html"); editor.setEditable(false); editor.setBackground(Color.WHITE); editor.setTransferHandler(new ParsingTransferHandler(editor.getTransferHandler(), this)); panel.add(new JScrollPane(editor), name); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.apache.tika.gui.TikaGUI.java
private JEditorPane addCard(JPanel panel, String type, String name) { JEditorPane editor = new JTextPane(); editor.setBackground(Color.WHITE); editor.setContentType(type); editor.setTransferHandler(new ParsingTransferHandler(editor.getTransferHandler(), this)); panel.add(new JScrollPane(editor), name); return editor; }
From source file:org.apache.tika.gui.TikaGUI.java
private void textDialog(String title, URL resource) { try {/*from w w w . jav a2 s . c om*/ JDialog dialog = new JDialog(this, title); JEditorPane editor = new JEditorPane(resource); editor.setContentType("text/html"); editor.setEditable(false); editor.setBackground(Color.WHITE); editor.setPreferredSize(new Dimension(400, 250)); editor.addHyperlinkListener(this); dialog.add(editor); dialog.pack(); dialog.setVisible(true); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.docx4all.ui.main.WordMLEditor.java
private JEditorPane createSourceView(WordMLTextPane editorView) { //Create the Source View JEditorPane sourceView = new JEditorPane(); MutableAttributeSet attrs = new SimpleAttributeSet(); StyleConstants.setFontFamily(attrs, FontManager.getInstance().getSourceViewFontFamilyName()); StyleConstants.setFontSize(attrs, FontManager.getInstance().getSourceViewFontSize()); // TODO - only do this if the font is available. Font font = new Font("Arial Unicode MS", Font.PLAIN, 12); System.out.println(font.getFamily()); System.out.println(font.getFontName()); System.out.println(font.getPSName()); sourceView.setFont(font);//from www . j a v a 2s . co m //sourceView.setFont(FontManager.getInstance().getFontInAction(attrs)); sourceView.setContentType("text/xml; charset=UTF-16"); // Instantiate a XMLEditorKit with wrapping enabled. XMLEditorKit kit = new XMLEditorKit(true); // Set the wrapping style. kit.setWrapStyleWord(true); sourceView.setEditorKit(kit); WordMLDocument editorViewDoc = (WordMLDocument) editorView.getDocument(); try { editorViewDoc.readLock(); editorView.getWordMLEditorKit().saveCaretText(); DocumentElement elem = (DocumentElement) editorViewDoc.getDefaultRootElement(); WordprocessingMLPackage wmlPackage = ((DocumentML) elem.getElementML()).getWordprocessingMLPackage(); String filePath = (String) editorView.getDocument().getProperty(WordMLDocument.FILE_PATH_PROPERTY); //Do not include the last paragraph which is an extra paragraph. elem = (DocumentElement) elem.getElement(elem.getElementCount() - 1); ElementML paraML = elem.getElementML(); ElementML bodyML = paraML.getParent(); paraML.delete(); Document doc = DocUtil.read(sourceView, wmlPackage); doc.putProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath); doc.putProperty(WordMLDocument.WML_PACKAGE_PROPERTY, wmlPackage); doc.addDocumentListener(getToolbarStates()); //Below are the properties used by bounce.jar library //See http://www.edankert.com/bounce/xmleditorkit.html doc.putProperty(PlainDocument.tabSizeAttribute, new Integer(4)); doc.putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, Boolean.TRUE); doc.putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, Boolean.TRUE); //Remember to put 'paraML' as last paragraph bodyML.addChild(paraML); } finally { editorViewDoc.readUnlock(); } kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, new Color(255, 0, 0), Font.PLAIN); sourceView.addFocusListener(getToolbarStates()); //sourceView.setDocument(doc); sourceView.putClientProperty(Constants.LOCAL_VIEWS_SYNCHRONIZED_FLAG, Boolean.TRUE); return sourceView; }
From source file:org.fit.cssbox.scriptbox.demo.tester.JavaScriptTesterUIPresenter.java
private JEditorPane addSourceCodeTab() { JScrollPane sourceCodeScrollPane = new JScrollPane(); NEW_COUNTER++;/*w ww. ja va2s. co m*/ sourceCodeTabbedPane.addTab("New " + NEW_COUNTER, null, sourceCodeScrollPane, null); sourceCodeTabbedPane.setSelectedIndex(sourceCodeTabbedPane.getTabCount() - 1); DefaultSyntaxKit.initKit(); final JEditorPane codeEditor = new JEditorPane(); sourceCodeScrollPane.setViewportView(codeEditor); codeEditor.setContentType("text/xhtml"); return codeEditor; }