Example usage for javax.swing JEditorPane setEditable

List of usage examples for javax.swing JEditorPane setEditable

Introduction

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

Prototype

@BeanProperty(description = "specifies if the text can be edited")
public void setEditable(boolean b) 

Source Link

Document

Sets the specified boolean to indicate whether or not this TextComponent should be editable.

Usage

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep5(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final JLabel lbResult = new JLabel();
    final JEditorPane editLog = new JEditorPane();
    final JScrollPane scrollLog = new JScrollPane(editLog);
    final JLabel lbStructureChangeResult = new JLabel(
            localeDelegate.getMessage("dbtransfer.import.step5.1", "\u00c4nderungen am Datenbankschema"));
    final JButton btnSaveStructureChangeScript = new JButton(
            localeDelegate.getMessage("dbtransfer.import.step5.2", "Script speichern") + "...");
    final JButton btnSaveStructureChangeLog = new JButton(
            localeDelegate.getMessage("dbtransfer.import.step5.3", "Log speichern") + "...");

    editLog.setContentType("text/html");
    editLog.setEditable(false);

    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("dbtransfer.import.step5.4", "Ergebnis"), localeDelegate.getMessage(
                    "dbtransfer.import.step5.5", "Hier wird Ihnen das Ergebnis des Imports angezeigt.")) {

        @Override//  w ww.j  av  a  2  s . c o m
        public void prepare() {
            if (!importTransferResult.hasWarnings() && !importTransferResult.hasCriticals()) {
                lbResult.setText(localeDelegate.getMessage("dbtransfer.import.step5.6", "Import erfolgreich!"));
                this.setComplete(true);
            } else {
                lbResult.setText(
                        localeDelegate.getMessage("dbtransfer.import.step5.7", "Ein Problem ist aufgetreten!"));
                blnSaveOfLogRecommend = true;
            }
            StringBuffer sbLog = new StringBuffer();
            sbLog.append("<html><body>");
            if (!importTransferResult.foundReferences.isEmpty()) {
                sbLog.append(localeDelegate.getMessage("dbtransfer.import.step5.8",
                        "Folgende Konfigurationsobjekte sollten entfernt werden, werden aber noch verwendet")
                        + ":<br />");
                for (Pair<String, String> reference : importTransferResult.foundReferences) {
                    sbLog.append(
                            "- " + reference.y + " ("
                                    + localeDelegate.getLabelFromMetaDataVO(
                                            MetaDataClientProvider.getInstance().getEntity(reference.x))
                                    + ")<br />");
                }
                sbLog.append("<br />" + localeDelegate.getMessage("dbtransfer.import.step5.9",
                        "Passen Sie Ihre Konfiguration dahingehend an oder bearbeiten Sie die Daten,\nwelche noch auf die Konfigurationsobjekte verweisen."));
                sbLog.append("<br />");
            }
            sbLog.append("<font color=\"#800000\">" + importTransferObject.result.getCriticals() + "</font>"
                    + (importTransferObject.result.hasCriticals() ? "<br />" : ""));
            sbLog.append(importTransferResult.getWarnings());
            sbLog.append("</body></html>");
            editLog.setText(sbLog.toString());
        }
    };

    utils.initJPanel(step, new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
            TableLayout.FILL }, new double[] { 20, TableLayout.FILL, TableLayout.PREFERRED });

    step.add(lbResult, "0,0,3,0");
    step.add(scrollLog, "0,1,3,1");
    step.add(lbStructureChangeResult, "0,2");
    step.add(btnSaveStructureChangeScript, "1,2");
    step.add(btnSaveStructureChangeLog, "2,2");

    btnSaveStructureChangeScript.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            try {
                UIUtils.showWaitCursorForFrame(ifrm, true);

                final StringBuffer sbSql = new StringBuffer();
                org.apache.commons.collections.CollectionUtils.forAllDo(importTransferResult.script,
                        new Closure() {
                            @Override
                            public void execute(Object element) {
                                sbSql.append("<DDL>" + element + "</DDL>\n\n");
                            }
                        });

                final JFileChooser filechooser = utils.getFileChooser(
                        localeDelegate.getMessage("configuration.transfer.file.sql", "SQL-Dateien"),
                        ".import-sql.txt");
                filechooser.setSelectedFile(new File(tfTransferFile.getText() + ".import-sql.txt"));
                final int iBtn = filechooser.showSaveDialog(step);

                if (iBtn == JFileChooser.APPROVE_OPTION) {
                    final File file = filechooser.getSelectedFile();
                    if (file != null) {
                        String fileName = file.getPath();

                        if (!fileName.toLowerCase().endsWith(".import-sql.txt")) {
                            fileName += ".import-sql.txt";
                        }

                        File outFile = new File(fileName);
                        final Writer out = new BufferedWriter(new FileWriter(outFile));
                        try {
                            out.write(sbSql.toString());
                        } finally {
                            out.close();
                        }
                        if (blnSaveOfScriptRecommend) {
                            step.setComplete(true);
                        }
                    }
                }
            } catch (Exception e) {
                Errors.getInstance().showExceptionDialog(ifrm, e);
            } finally {
                UIUtils.showWaitCursorForFrame(ifrm, false);
            }
        }
    });
    btnSaveStructureChangeLog.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            try {
                UIUtils.showWaitCursorForFrame(ifrm, true);

                final JFileChooser filechooser = utils.getFileChooser(
                        localeDelegate.getMessage("configuration.transfer.file.log", "Log-Dateien"),
                        ".import-log.html");
                filechooser.setSelectedFile(new File(tfTransferFile.getText() + ".import-log.html"));
                final int iBtn = filechooser.showSaveDialog(step);

                if (iBtn == JFileChooser.APPROVE_OPTION) {
                    final File file = filechooser.getSelectedFile();
                    if (file != null) {
                        String fileName = file.getPath();

                        if (!fileName.toLowerCase().endsWith(".import-log.html")) {
                            fileName += ".import-log.html";
                        }

                        File outFile = new File(fileName);
                        final Writer out = new BufferedWriter(new FileWriter(outFile));
                        try {
                            out.write(editLog.getText());
                        } finally {
                            out.close();
                        }
                        if (blnSaveOfLogRecommend) {
                            step.setComplete(true);
                        }
                    }
                }
            } catch (Exception e) {
                Errors.getInstance().showExceptionDialog(ifrm, e);
            } finally {
                UIUtils.showWaitCursorForFrame(ifrm, false);
            }
        }
    });

    return step;
}

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

/**
 * Formats the text and displays it in a {@link JEditorPane}.
 * /* w  w  w .  ja  v a2 s  .  co  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);
    editorPane.setPreferredSize(new Dimension(400, 200));
    if (url != null) {
        try {/*from   ww w  .ja v  a  2s.com*/
            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.sonarlint.intellij.ui.SonarLintRulePanel.java

private JEditorPane createEditor() {
    JEditorPane newEditor = new JEditorPane();
    newEditor.setEditorKit(kit);/*w ww  . j  av  a2  s. c o m*/
    newEditor.setBorder(new EmptyBorder(10, 10, 10, 10));
    newEditor.setEditable(false);
    newEditor.setContentType("text/html");
    newEditor.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(e.getURL().toURI());
            } catch (Exception ex) {
                SonarLintConsole.get(project).error("Error opening browser: " + e.getURL(), ex);
            }
        }
    });

    return newEditor;
}

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 ww  .j av a 2 s. co  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;
            }/*www .  jav a  2s  .co  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  av  a  2 s  .com*/
 */
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/* ww w .  j a  va  2s.c  o 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);
}

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);/*from  www . j  ava  2s  . co m*/
    textField.setEditable(false);
    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);
}

From source file:util.ui.UiUtilities.java

/**
 * Creates a Html EditorPane that holds a HTML-Help Text.
 *
 * Add a Listener if you want to have clickable Links
 *
 * @param html//  w w  w  .j  a  va2s .  c  om
 *          HTML-Text to display
 * @param listener
 *          Link-Listener for this HelpText
 * @param background The color for the background.
 * @return EditorPane that holds a Help Text
 * @since 2.7.2
 */
public static JEditorPane createHtmlHelpTextArea(String html, HyperlinkListener listener, Color background) {
    // Quick "hack". Remove HTML-Code and replace it with Code that includes the
    // correct Font
    if (html.indexOf("<html>") >= 0) {
        html = StringUtils.substringBetween(html, "<html>", "</html>");
    }
    JLabel label = new JLabel();
    Font font = label.getFont();
    html = "<html><div style=\"color:" + UiUtilities.getHTMLColorCode(label.getForeground()) + ";font-family:"
            + font.getName() + "; font-size:" + font.getSize() + ";background-color:rgb(" + background.getRed()
            + "," + background.getGreen() + "," + background.getBlue() + ");\">" + html + "</div></html>";

    final JEditorPane pane = new JEditorPane("text/html", html);
    pane.setBorder(BorderFactory.createEmptyBorder());
    pane.setEditable(false);
    pane.setFont(font);
    pane.setOpaque(false);
    pane.setFocusable(false);

    if (listener != null) {
        pane.addHyperlinkListener(listener);
    }
    return pane;
}