Example usage for javax.swing JEditorPane getFont

List of usage examples for javax.swing JEditorPane getFont

Introduction

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

Prototype

@Transient
public Font getFont() 

Source Link

Document

Gets the font of this component.

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;
            }//from  w w  w  .  j a va  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;
            }//from   w ww.  j a va 2  s  .c om

            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();
}