Example usage for javax.swing JEditorPane JEditorPane

List of usage examples for javax.swing JEditorPane JEditorPane

Introduction

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

Prototype

public JEditorPane(String url) throws IOException 

Source Link

Document

Creates a JEditorPane based on a string containing a URL specification.

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  w w  w .  ja  v a2  s  .  co  m
        JEditorPane editorPane = new JEditorPane("http://www.java2s.com");
        editorPane.setEditable(false);
        AccessibleContext context = editorPane.getAccessibleContext();

        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(final String args[]) {
    JFrame frame = new JFrame("EditorPane Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    try {/*from  w w  w  .j  a va2s  .c  o  m*/
        JEditorPane editorPane = new JEditorPane(new URL("http://www.java2s.com"));
        editorPane.setEditable(false);

        HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(editorPane);
        editorPane.addHyperlinkListener(hyperlinkListener);

        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(final String args[]) {
    JFrame frame = new JFrame("EditorPane Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    try {/*  w w w  . j a va 2 s.co m*/
        JEditorPane editorPane = new JEditorPane("http://www.java2s.com");
        editorPane.setEditable(false);

        HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(editorPane);
        editorPane.addHyperlinkListener(hyperlinkListener);

        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:EditorPaneSample.java

public static void main(String args[]) throws IOException {
    JFrame frame = new JFrame("EditorPane Example");
    Container content = frame.getContentPane();

    JEditorPane editorPane = new JEditorPane("http://www.apress.com");
    editorPane.setEditable(false);/*  ww w.  jav  a 2  s .  c o m*/

    HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(frame, editorPane);
    editorPane.addHyperlinkListener(hyperlinkListener);

    JScrollPane scrollPane = new JScrollPane(editorPane);
    content.add(scrollPane);

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

From source file:ShowHTMLViews.java

public static void main(String[] args) {
    try {/*from w w  w .  ja v  a 2s . com*/
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception evt) {
    }

    try {
        JFrame f = new JFrame("HTML Document View Structure");
        final JEditorPane ep = new JEditorPane(args[0]);
        ep.setEditable(false);
        f.getContentPane().add(new JScrollPane(ep));
        f.setSize(400, 300);
        f.setVisible(true);

        ep.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("page")) {
                    System.out.println("Document:\n");
                    HTMLDocDisplay.displayModel(ep, System.out);
                    System.out.println("\n\nViews:\n");
                    HTMLViewDisplayer.displayViews(ep, System.out);
                }
            }
        });
    } catch (Exception e) {
        System.out.println(e);
        System.exit(1);
    }
}

From source file:ActivatedHyperlinkListener.java

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

    try {/*from w  w  w. j a  v  a2 s .  c  o  m*/
        JEditorPane editorPane = new JEditorPane("http://www.google.com");
        editorPane.setEditable(false);

        HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(editorPane);
        editorPane.addHyperlinkListener(hyperlinkListener);
        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:MainClass.java

MainClass() throws IOException {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    view = new JEditorPane("http://www.java2s.com");
    view.setEditable(false);//w w  w  .  j a va 2  s.  com
    view.setPreferredSize(new Dimension(400, 400));
    view.addHyperlinkListener(this);

    getContentPane().add(new JScrollPane(view), BorderLayout.CENTER);

    pack();
    setVisible(true);
}

From source file:SimpleHelp.java

public SimpleHelp(String windowName, String helpIndexFileName) {
    super(windowName + " Help Window");
    cp = getContentPane();//from ww  w.  ja  va 2s . c  om
    getAccessibleContext().setAccessibleName(windowName + " Help Window");
    getAccessibleContext().setAccessibleDescription(
            "A window for viewing the help for " + windowName + ", which is somewhat hyperlinked.");

    try {
        URL url = new File(helpIndexFileName).toURL();
        // Only create the window once.
        if (help == null) {
            // System.out.println("Creat-ing help window for " + url);
            help = new JEditorPane(url);
            // System.out.println("Done!");
            help.setEditable(false);
            help.addHyperlinkListener(this);
            JScrollPane scroller = new JScrollPane();
            scroller.setBorder(BorderFactory.createTitledBorder(windowName + " Help"));
            scroller.getViewport().add(help);
            cp.add(BorderLayout.CENTER, scroller);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    SimpleHelp.this.setVisible(false);
                    SimpleHelp.this.dispose();
                }
            });
            setSize(500, 400);
        } else {
            System.out.println("Re-using help window!");
        }
    } catch (MalformedURLException e) {
        System.out.println("Malformed URL: " + e);
    } catch (IOException e) {
        System.out.println("IOException: " + e);
    }
}

From source file:edu.ku.brc.specify.config.init.secwiz.DatabasePanel.java

/**
 * @param bgColor/*from  w w  w .  ja v a 2s  .c  o  m*/
 * @param htmlFileName
 * @return
 */
public static JComponent createHelpPanel(final Color bgColor, final String htmlFileName) {
    Locale currLocale = Locale.getDefault();

    String helpMasterPath = (new File(".")).getAbsolutePath() + File.separator + "../" + "help/securitywiz/"
            + htmlFileName;
    String fullHelpMasterPath = UIHelper.createLocaleName(currLocale, helpMasterPath, "html");

    JEditorPane htmlPane = null;
    try {
        File file = new File(fullHelpMasterPath);
        if (!file.exists()) // for testing
        {
            helpMasterPath = (new File(".")).getAbsolutePath() + File.separator + "help/securitywiz/"
                    + htmlFileName;
            fullHelpMasterPath = UIHelper.createLocaleName(currLocale, helpMasterPath, "html");
            file = new File(fullHelpMasterPath);
            System.out.println(file.getCanonicalPath());
        }
        URI url = file.toURI();

        htmlPane = new JEditorPane(url.toURL()); //$NON-NLS-1$
        htmlPane.setEditable(false);
        htmlPane.setBackground(bgColor);

    } catch (IOException ex) {
        File file = new File(fullHelpMasterPath);
        String htmlDesc = "";
        try {
            htmlDesc = "Error loading help: " + file.getCanonicalPath();
        } catch (IOException e) {
            e.printStackTrace();
        }
        htmlPane = new JEditorPane("text/plain", htmlDesc); //$NON-NLS-1$
    }

    JScrollPane scrollPane = UIHelper.createScrollPane(htmlPane, true);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    scrollPane.getViewport().setPreferredSize(new Dimension(400, 400));

    return scrollPane;
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * //  w  ww  . ja va 2s  .  com
 */
public void checkForBadAttachments() {
    int count = getNumberofBadAttachments();
    if (count == 0) {
        AppPreferences.getGlobalPrefs().putBoolean("CHECK_ATTCH_ERR", false);
        return;
    }

    URL url = null;
    JEditorPane htmlPane;
    try {
        url = new URL("http://files.specifysoftware.org/attachment_recovery.html");
        htmlPane = new JEditorPane(url);
    } catch (Exception e) {
        e.printStackTrace();
        htmlPane = new JEditorPane("text/html", //$NON-NLS-1$
                "<html><body><h1>Network Error - You must have a network conneciton to get the instructions.</H1></body>");
    }
    JScrollPane scrollPane = UIHelper.createScrollPane(htmlPane);
    htmlPane.setEditable(false);
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
    CustomDialog infoDlg = new CustomDialog((Dialog) null, "Recovery Information", true, CustomDialog.OKCANCEL,
            panel);

    infoDlg.setCancelLabel("Close");
    infoDlg.setOkLabel("Print in Browser");
    infoDlg.createUI();
    infoDlg.setSize(1024, 600);
    try {
        hookupAction(infoDlg.getOkBtn(), url != null ? url.toURI() : null);
        infoDlg.setVisible(true);

    } catch (Exception ex) {

    }

    final String CNT = "CNT";
    final SwingWorker<Integer, Integer> worker = new SwingWorker<Integer, Integer>() {
        int totalFiles = 0;

        HashMap<Integer, Vector<Object[]>> resultsHashMap = new HashMap<Integer, Vector<Object[]>>();
        HashMap<Integer, String> tblTypeHash = new HashMap<Integer, String>();
        HashMap<Integer, String> agentHash = new HashMap<Integer, String>();
        HashMap<Integer, AttchTableModel> tableHash = new HashMap<Integer, AttchTableModel>();
        ArrayList<JTable> tableList = new ArrayList<JTable>();
        ArrayList<Integer> tableIdList = new ArrayList<Integer>();

        @Override
        protected Integer doInBackground() throws Exception {
            DataProviderSessionIFace session = null;

            try {
                // This doesn't need to include the new attachments
                int[] tableIds = { AccessionAttachment.getClassTableId(), AgentAttachment.getClassTableId(),
                        CollectingEventAttachment.getClassTableId(),
                        CollectionObjectAttachment.getClassTableId(),
                        ConservDescriptionAttachment.getClassTableId(),
                        ConservEventAttachment.getClassTableId(), DNASequencingRunAttachment.getClassTableId(),
                        FieldNotebookAttachment.getClassTableId(),
                        FieldNotebookPageAttachment.getClassTableId(),
                        FieldNotebookPageSetAttachment.getClassTableId(), LoanAttachment.getClassTableId(),
                        LocalityAttachment.getClassTableId(), PermitAttachment.getClassTableId(),
                        PreparationAttachment.getClassTableId(),
                        RepositoryAgreementAttachment.getClassTableId(), TaxonAttachment.getClassTableId() };

                Agent userAgent = AppContextMgr.getInstance().getClassObject(Agent.class);

                int totFiles = 0;
                firePropertyChange(CNT, 0, 0);
                int cnt = 0;
                for (int tableId : tableIds) {
                    Vector<Object[]> results = getImageData(userAgent.getId(), tableId, tblTypeHash);
                    if (results != null && results.size() > 0) {
                        resultsHashMap.put(tableId, results);
                        totFiles += results.size();
                        //System.out.println(tableId+"  ->  "+results.size());
                    }
                    firePropertyChange(CNT, 0, (int) ((double) cnt / (double) tableIds.length * 100.0));
                    cnt++;
                }

                if (resultsHashMap.size() == 0) // Shouldn't happen
                {
                    return null;
                }

                session = DataProviderFactory.getInstance().createSession();

                firePropertyChange(CNT, 0, 0);
                int i = 1;
                for (int tblId : resultsHashMap.keySet()) {
                    DBTableInfo ti = DBTableIdMgr.getInstance().getInfoById(tblId);

                    Vector<Object[]> dataRows = new Vector<Object[]>();
                    Vector<Object[]> results = resultsHashMap.get(tblId);
                    for (Object[] row : results) {
                        Integer agentId = (Integer) row[3];
                        String userName = agentHash.get(agentId);
                        if (userName == null) {
                            userName = BasicSQLUtils.querySingleObj(
                                    "SELECT su.Name FROM agent a INNER JOIN specifyuser su ON a.SpecifyUserID = su.SpecifyUserID WHERE a.AgentID = "
                                            + row[3]);
                            agentHash.put(agentId, userName);
                        }
                        //userName = i == 1 ? "bill.johnson" : "joe.smith";

                        int attachJoinID = (Integer) row[4];
                        String identTitle = getIdentityTitle(session, ti, attachJoinID);

                        String fullPath = (String) row[2];
                        //fullPath = StringUtils.replace(fullPath, "darwin\\", "darwin2\\");

                        //boolean doesExist = (new File(fullPath)).exists() && i != 1;
                        boolean doesExist = (new File(fullPath)).exists();
                        //String str        = i != 1 ? "/Users/joe/Desktop/xxx.png" : "/Users/bill/Desktop/xxx.png";
                        //String fullPath   = FilenameUtils.getFullPath(str) + String.format("DSC_%05d.png", i);

                        Object[] rowObjs = new Object[8];
                        rowObjs[0] = StringUtils.isEmpty(identTitle) ? ""
                                : (identTitle.length() > 30 ? identTitle.substring(0, 30) + "..." : identTitle);
                        rowObjs[1] = FilenameUtils.getName(fullPath);
                        rowObjs[2] = fullPath;
                        rowObjs[3] = userName;
                        rowObjs[4] = doesExist;
                        rowObjs[5] = Boolean.FALSE;
                        rowObjs[6] = row[0];
                        rowObjs[7] = attachJoinID;

                        dataRows.add(rowObjs);

                        if (doesExist) {
                            totalFiles++;
                        }
                        firePropertyChange(CNT, 0, (int) ((double) i / (double) totFiles * 100.0));
                        i++;
                    }
                    AttchTableModel model = new AttchTableModel(dataRows);
                    JTable table = new JTable(model);
                    tableHash.put(tblId, model);
                    tableList.add(table);
                    tableIdList.add(tblId);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                session.close();
            }

            return null;
        }

        @Override
        protected void done() {
            UIRegistry.clearSimpleGlassPaneMsg();

            if (tableList.size() > 0) {
                displayBadAttachments(tableList, tableIdList, resultsHashMap, tblTypeHash, tableHash,
                        totalFiles);
            }
            super.done();
        }
    };

    final SimpleGlassPane glassPane = UIRegistry
            .writeSimpleGlassPaneMsg("Verifying attachments in the repository...", 24);
    glassPane.setProgress(0);

    worker.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            if (CNT.equals(evt.getPropertyName())) {
                glassPane.setProgress((Integer) evt.getNewValue());
            }
        }
    });

    worker.execute();
}