Example usage for javax.swing JEditorPane getText

List of usage examples for javax.swing JEditorPane getText

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the text contained in this TextComponent in terms of the content type of this editor.

Usage

From source file:Main.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("EditorPane Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    try {//from www.  j  a  va  2s . c om
        JEditorPane editorPane = new JEditorPane("http://www.java2s.com");
        editorPane.setEditable(false);
        String b = editorPane.getText();

        JScrollPane scrollPane = new JScrollPane(editorPane);
        frame.add(scrollPane);
    } catch (IOException e) {
        System.err.println("Unable to load: " + e);
    }

    frame.setSize(640, 480);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JEditorPane editPane1 = new JEditorPane("text/html", "Try ty\tping some tabs");
    editPane1.setPreferredSize(new Dimension(400, 300));
    JOptionPane.showMessageDialog(null, new JScrollPane(editPane1));
    JOptionPane.showMessageDialog(null, new JScrollPane(new JEditorPane("text/html", editPane1.getText())));
}

From source file:com.net2plan.utils.HTMLUtils.java

/**
 * <p>Saves an HTML content to a given file. Plain text is automatically 
 * wrapped into HTML.</p>/*ww  w.  j a  v  a2  s  .  c  om*/
 *
 * @param file A valid file
 * @param html HTML content
 */
public static void saveToFile(File file, String html) {
    CustomHTMLEditorKit kit = new CustomHTMLEditorKit();
    JEditorPane editor = new CustomHTMLEditorKit.CustomJEditorPane();
    editor.setEditorKit(kit);
    editor.setContentType("text/html");
    editor.setText(html);
    editor.setText(CustomHTMLEditorKit.includeNet2PlanHeader(editor.getText()));
    CustomHTMLEditorKit.saveToFile(file, editor.getText(), kit.getImages());
}

From source file:emperior.Main.java

public static void copyFile(String filePath, File targetLocation) throws Exception {
    File f = new File(filePath);
    if (f.isFile()) {

        targetLocation.mkdirs();/*ww w  . j a va 2  s  . co m*/

        System.out.println(filePath);

        //         String [] pathElements = filePath.split("/");
        //         String [] pathElements = filePath.split("\\\\|/");
        String[] pathElements = filePath.split("\\\\");

        //         if(pathElements.length > 0){
        //            System.out.println("[test] " + targetLocation + File.separator + filePath.substring(0, filePath.lastIndexOf(System.getProperty("file.separator"))));
        //            targetLocation = new File(targetLocation + File.separator + filePath.substring(0, filePath.lastIndexOf(System.getProperty("file.separator"))));
        //            targetLocation.mkdirs();
        //         }

        JEditorPane editor = mainFrame.editors.get(filePath);

        String copypath = targetLocation + File.separator + pathElements[pathElements.length - 1];

        System.out.println("[test] " + copypath);

        Main.addLineToLogFile("[File] saving to: " + copypath);

        FileWriter fstream = new FileWriter(copypath);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(editor.getText());
        // Close the output stream
        out.close();

    }

}

From source file:io.github.jeddict.jpa.modeler.properties.classmember.ClassMemberPanel.java

private String getCode(String code, String title) {
    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/x-java");
    editorPane.setPreferredSize(new java.awt.Dimension(600, 400));
    editorPane.setText(code);/* ww  w  . j  a  v  a  2 s  .c  om*/
    OptionDialog dialog = new OptionDialog(editorPane, title);
    dialog.setVisible(true);
    if (OK_OPTION == dialog.getDialogResult()) {
        return editorPane.getText();
    } else {
        return code;
    }
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Adds text to the write area editor./*from  w ww  .j  a v  a 2 s.  c om*/
 *
 * @param text The text to add.
 */
public void addTextInWriteArea(String text) {
    JEditorPane editorPane = this.writeMessagePanel.getEditorPane();

    editorPane.setText(editorPane.getText() + text);
}

From source file:org.fit.cssbox.scriptbox.demo.tester.JavaScriptTesterUIPresenter.java

private boolean saveSourceCodeTab(File file) {
    int paneIndex = sourceCodeTabbedPane.getSelectedIndex();
    JEditorPane pane = getSelectedEditorPane();

    try {/*from w ww.  j a v a2  s  .c o m*/
        FileWriter writer = new FileWriter(file);
        String content = pane.getText();
        writer.write(content);

        if (paneIndex > 0) {
            openedFiles.put(paneIndex, file);
        }

        writer.close();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(tester.getWindow(), "Unable to save file with source code.",
                "File I/O error", JOptionPane.ERROR_MESSAGE);
        return false;
    }
}

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);//from  w  w w .  j a  v a 2 s  .c  om

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