Example usage for javax.swing JEditorPane setEditorKit

List of usage examples for javax.swing JEditorPane setEditorKit

Introduction

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

Prototype

@BeanProperty(expert = true, description = "the currently installed kit for handling content")
public void setEditorKit(EditorKit kit) 

Source Link

Document

Sets the currently installed kit for handling content.

Usage

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;
            }/*  w  w  w  .  j av a2 s. 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:tvbrowser.ui.settings.channel.ChannelGroupInfoDialog.java

/**
 * Create the GUI//from   w w w .j ava2  s . c  o m
 */
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/* w w  w. j  a va  2 s.co m*/
 */
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);
}