Example usage for javax.swing JEditorPane setText

List of usage examples for javax.swing JEditorPane setText

Introduction

In this page you can find the example usage for javax.swing JEditorPane setText.

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified content, which is expected to be in the format of the content type of this editor.

Usage

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Formats the text and displays it in a {@link JEditorPane}.
 * /*from   w w  w . j  a  v  a2s .  c  o m*/
 * @param text   The text to display.
 * @return See above.
 */
public static JEditorPane buildTextEditorPane(String text) {
    if (text == null)
        text = "";
    JEditorPane textPane = new JEditorPane();
    textPane.setContentType("text/html");
    textPane.setText(text);
    textPane.setOpaque(false);
    textPane.setEditable(false);
    textPane.setFocusable(false);
    return textPane;
}

From source file:org.pentaho.reporting.engine.classic.demo.util.CompoundDemoFrame.java

protected JComponent createDescriptionTextPane(final URL url) {
    final JEditorPane editorPane = new JEditorPane();
    editorPane.setEditable(false);// w w  w  .  j  ava  2 s . com
    editorPane.setPreferredSize(new Dimension(400, 200));
    if (url != null) {
        try {
            editorPane.setPage(url);
        } catch (IOException e) {
            logger.error("Failed to load demo description", e);
            editorPane.setText("Unable to load the demo description. Error: " + e.getMessage());
        }
    } else {
        editorPane.setText("Unable to load the demo description. No such resource.");
    }

    return new JScrollPane(editorPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
}

From source file:org.squidy.designer.knowledgebase.RepositoryItem.java

private void initPane() {
    // Add Zoomable Component
    new Thread(new Runnable() {
        public void run() {

            // ProgressIndicator indicator = new
            // ProgressIndicator(InformationShape.this);

            if (information == null || "".equals(information)) {
                return;
            }/*  ww w .j a  v a  2s  .c o  m*/

            URL url = null;
            try {
                try {
                    if (information.endsWith(".pdf")) {
                        url = InformationShape.class.getResource(information);
                    } else if (information.endsWith(".html")) {
                        try {
                            url = new URL(information);
                        } catch (Exception e) {
                            url = InformationShape.class.getResource(information);
                        }
                    } else {
                        url = new URL(information);
                    }
                } catch (Exception e) {
                    // do nothing
                }

                PNode cropNode;
                // PDF
                if (information.endsWith(".pdf")) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Display information as PDF.");
                    }
                    cropNode = new PDFPane(url.getFile());
                }
                // HTML
                else {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Display information as HTML.");
                    }

                    JEditorPane editorPane = new JEditorPane();
                    editorPane.setFont(internalFont.deriveFont(10f));

                    FontMetrics fm = editorPane.getFontMetrics(editorPane.getFont());
                    int editorWidth = 400;
                    editorPane.setPreferredSize(new Dimension(editorWidth,
                            FontUtils.getLineCount(information, editorWidth) * fm.getHeight()));

                    cropNode = JComponentWrapper.create(editorPane);
                    editorPane.setEditable(false);

                    if (information.endsWith(".html")) {
                        HTMLEditorKit editorKit = new HTMLEditorKit();
                        editorPane.setEditorKit(editorKit);
                        editorPane.setPage(url);
                        editorPane.setPreferredSize(new Dimension(800, 2000));
                    } else {
                        editorPane.setText(information);
                    }

                    // Prepare HTML Kit
                    // HTMLParser editorKit = new HTMLParser();
                    // HTMLParserCallback callback = new
                    // HTMLParserCallback();
                    // getComponentEditorPane().setEditorKit(editorKit);
                    // //Open connection
                    // InputStreamReader reader = new
                    // InputStreamReader(url.openStream());
                    // //Start parse process
                    // editorKit.getParser().parse(reader, callback, true);
                    // Wait until parsing process has finished
                    // try {
                    // Thread.sleep(2000);
                    // }
                    // catch (InterruptedException e) {
                    // if (LOG.isErrorEnabled()) {
                    // LOG.error("Error in " +
                    // InformationShape.class.getName() + ".", e);
                    // }
                    // }
                }

                cropScroll = new CropScroll(cropNode, new Dimension(1000, 700), 0.2);
                cropScroll.setOffset(
                        getBoundsReference().getCenterX() - cropScroll.getBoundsReference().getCenterX(), 250);
                addChild(cropScroll);
                invalidateFullBounds();
                invalidateLayout();
                invalidatePaint();
            } catch (MalformedURLException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Could not parse URL from input string: " + e.getMessage() + " in "
                            + RepositoryItem.class.getName() + ".\nInput was: " + information);
                }
            } catch (IOException e) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Could not create HTMLPane in " + RepositoryItem.class.getName(), e);
                }
            }

            // indicator.done();
        }
    }).start();
}

From source file:org.squidy.designer.zoom.impl.InformationShape.java

private void initPane() {
    // Add Zoomable Component
    new Thread(new Runnable() {
        public void run() {

            // ProgressIndicator indicator = new
            // ProgressIndicator(InformationShape.this);

            if (informationSource == null || "".equals(informationSource)) {
                return;
            }/*  ww w . ja  va2s  .  c  o  m*/

            try {
                if (informationSource.endsWith(".pdf")) {
                    url = InformationShape.class.getResource(informationSource);
                } else if (informationSource.endsWith(".html")) {
                    try {
                        url = new URL(informationSource);
                    } catch (Exception e) {
                        url = InformationShape.class.getResource(informationSource);
                    }
                } else {
                    url = new URL(informationSource);
                }
            } catch (Exception e) {
                // do nothing
            }

            PNode cropNode;
            // PDF
            if (informationSource.endsWith(".pdf")) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Display information as PDF.");
                }
                cropNode = new PDFPane(url.getFile());
            }
            // HTML
            else {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Display information as HTML.");
                }

                if (informationSource.startsWith("http") || informationSource.endsWith(".html")) {

                    XHTMLPanel xhtmlPanel = new XHTMLPanel();
                    try {
                        xhtmlPanel.setDocument(url.toURI().toString());
                    } catch (URISyntaxException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    xhtmlPanel.setPreferredSize(new Dimension(800, 800));
                    //                  xhtmlPanel.addPropertyChangeListener("preferredSize", new PropertyChangeListener() {
                    //                     
                    //                     public void propertyChange(PropertyChangeEvent evt) {
                    //                        cropScroll.updateScroller();
                    //                        cropNode.
                    //                     }
                    //                  });
                    cropNode = JComponentWrapper.create(xhtmlPanel);
                } else {
                    JEditorPane editorPane = new JEditorPane();
                    editorPane.setFont(internalFont.deriveFont(10f));

                    FontMetrics fm = editorPane.getFontMetrics(editorPane.getFont());
                    int editorWidth = 400;
                    editorPane.setPreferredSize(new Dimension(editorWidth,
                            FontUtils.getLineCount(informationSource, editorWidth) * fm.getHeight()));

                    cropNode = JComponentWrapper.create(editorPane);
                    editorPane.setEditable(false);

                    editorPane.setText(informationSource);
                }

                // Prepare HTML Kit
                // HTMLParser editorKit = new HTMLParser();
                // HTMLParserCallback callback = new
                // HTMLParserCallback();
                // getComponentEditorPane().setEditorKit(editorKit);
                // //Open connection
                // InputStreamReader reader = new
                // InputStreamReader(url.openStream());
                // //Start parse process
                // editorKit.getParser().parse(reader, callback, true);
                // Wait until parsing process has finished
                // try {
                // Thread.sleep(2000);
                // }
                // catch (InterruptedException e) {
                // if (LOG.isErrorEnabled()) {
                // LOG.error("Error in " +
                // InformationShape.class.getName() + ".", e);
                // }
                // }
            }

            cropScroll = new CropScroll(cropNode, new Dimension(1000, 700), 0.2);
            cropScroll.setOffset(
                    getBoundsReference().getCenterX() - cropScroll.getBoundsReference().getCenterX(), 250);
            addChild(cropScroll);
            invalidateFullBounds();
            invalidateLayout();
            invalidatePaint();

            // indicator.done();
        }
    }).start();
}

From source file:tvbrowser.ui.settings.channel.ChannelGroupInfoDialog.java

/**
 * Create the GUI/* w  w w .j ava  2s  . c om*/
 */
private void initGui() {
    UiUtilities.registerForClosing(this);
    JPanel panel = (JPanel) getContentPane();
    panel.setBorder(Borders.DLU4_BORDER);
    panel.setLayout(new FormLayout("fill:default:grow, default", "fill:default:grow, 3dlu, default"));

    CellConstraints cc = new CellConstraints();

    final JEditorPane infoPanel = new JEditorPane();

    infoPanel.setEditorKit(new ExtendedHTMLEditorKit());

    ExtendedHTMLDocument doc = (ExtendedHTMLDocument) infoPanel.getDocument();

    infoPanel.setEditable(false);
    infoPanel.setText(generateHtml(doc));

    infoPanel.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                URL url = evt.getURL();
                if (url != null) {
                    Launch.openURL(url.toString());
                }
            }
        }
    });

    final JScrollPane scrollPane = new JScrollPane(infoPanel);
    panel.add(scrollPane, cc.xyw(1, 1, 2));

    JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));

    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            infoPanel.scrollRectToVisible(new Rectangle(0, 0));
        }
    });

    panel.add(ok, cc.xy(2, 3));

    setSize(500, 350);
}

From source file:tvbrowser.ui.settings.PluginInfoDialog.java

/**
 * Create the GUI//from   ww  w  . j  a  v a 2  s  .com
 */
private void initGui() {

    JPanel panel = (JPanel) getContentPane();
    panel.setBorder(Borders.DLU4_BORDER);
    panel.setLayout(new FormLayout("fill:default:grow, default", "fill:default:grow, 3dlu, default"));

    CellConstraints cc = new CellConstraints();

    JEditorPane infoPanel = new JEditorPane();

    infoPanel.setEditorKit(new ExtendedHTMLEditorKit());

    ExtendedHTMLDocument doc = (ExtendedHTMLDocument) infoPanel.getDocument();

    infoPanel.setEditable(false);
    infoPanel.setText(generateHtml(doc));

    infoPanel.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                URL url = evt.getURL();
                if (url != null) {
                    Launch.openURL(url.toString());
                }
            }
        }
    });

    panel.add(new JScrollPane(infoPanel), cc.xyw(1, 1, 2));

    JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK));

    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            close();
        }
    });

    panel.add(ok, cc.xy(2, 3));

    Settings.layoutWindow("pluginInfoDialog", this, new Dimension(700, 500));

    UiUtilities.registerForClosing(this);
}

From source file:uk.ac.ucl.cs.cmic.giftcloud.uploadapp.GiftCloudDialogs.java

public void showMessage(final String message) throws HeadlessException {

    final JPanel messagePanel = new JPanel(new GridBagLayout());
    final JEditorPane textField = new JEditorPane();
    textField.setContentType("text/html");
    textField.setText(message);
    textField.setEditable(false);/*from  www  . j ava  2 s.  co m*/
    textField.setBackground(null);
    textField.setBorder(null);
    textField.setEditable(false);
    textField.setForeground(UIManager.getColor("Label.foreground"));
    textField.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    textField.setFont(UIManager.getFont("Label.font"));
    textField.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        // Ignore failure to launch URL
                    } catch (URISyntaxException e1) {
                        // Ignore failure to launch URL
                    }
                }
            }
        }
    });

    messagePanel.add(textField);
    textField.setAlignmentX(SwingConstants.CENTER);

    JOptionPane.showMessageDialog(mainFrame.getContainer(), messagePanel, applicationName,
            JOptionPane.INFORMATION_MESSAGE, icon);
}