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:com.gele.tools.wow.wdbearmanager.WDBearManager.java

public void actionPerformed(ActionEvent arg0) {
    JMenuItem source = (JMenuItem) (arg0.getSource());

    if (source.getText().equals(MENU_ABOUT)) {
        JOptionPane.showMessageDialog(this, WDBearManager.VERSION_INFO + "\n" + "by kizura\n"
                + WDBearManager.EMAIL + "\n\n" + "\n" + "Supports any WDB version\n" + "\n" + "Thanks to:\n"
                + "DarkMan for testing,\n" + "John for the 1.10 specs, Annunaki for helping with the header,\n"
                + "Andrikos for the 1.6.x WDB specs, Pyro's WDBViewer, WDDG Forum,\n"
                + "blizzhackers, etc etc\n\n" + "This program uses: \n"
                + "JGoodies from http://www.jgoodies.com/\n" + "Hypersonic SQL database 1.7.3\n"
                + "Apache Log4J, Xerces\n" + "Jakarta Commons Logging and CLI\n" + "Castor from ExoLab\n"
                + "MySQL JDBC connector 3.1.7\n" + "HTTPUNIT from Russell Gold\n" + "Jython 2.1\n"
                + "Refer to directory 'licenses' for more details about the software used\n" + "PLEASE:\n"
                + "If you like this program and find it usefull:\n"
                + "Please donate money to a charity oranization of your choice.\n"
                + "I recommend any organization that fights cancer.\n\n" + "License:\n"
                + "WDBearMgr is placed under the GNU GPL. \n" + "For further information, see the page :\n"
                + "http://www.gnu.org/copyleft/gpl.html.\n" + "See licenses/GPL_license.html\n" + "\n"
                + "For a different license please contact the author.", "Info " + VERSION_INFO,
                JOptionPane.INFORMATION_MESSAGE);
        return;/*w w w  .  java  2  s.co m*/
    } else if (source.getText().equals(MENU_HELP)) {
        JFrame myFrame = new JFrame("doc/html/index.html");
        //myFrame.setFont(   );
        URL urlHTML = null;
        try {
            JEditorPane htmlPane = new JEditorPane();
            //htmlPane.setFont(sourceFont);
            // .out.println("/scripts/"+source.getName()+".py");
            File scriptFile = new File("doc/html/index.html");
            urlHTML = scriptFile.toURL();//this.getClass().getResource("/scripts/"+source.getName()+".py");
            //          .out.println( urlHTML );
            //          .out.println( urlHTML.toExternalForm() );
            htmlPane.setPage(urlHTML);
            htmlPane.setEditable(false);
            JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane);
            htmlPane.addHyperlinkListener(myJEPHL);
            myFrame.getContentPane().add(new JScrollPane(htmlPane));
            myFrame.pack();
            myFrame.setSize(640, 480);
            myFrame.show();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                            + "Could not open 'doc/html/index.html'",
                    "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
        }
    } else if (source.getText().equals(MENU_JDOCS)) {
        JFrame myFrame = new JFrame("doc/javadoc/index.html");
        //myFrame.setFont(   );
        URL urlHTML = null;
        try {
            JEditorPane htmlPane = new JEditorPane();
            //htmlPane.setFont(sourceFont);
            // .out.println("/scripts/"+source.getName()+".py");
            File scriptFile = new File("doc/javadoc/index.html");
            urlHTML = scriptFile.toURL();
            htmlPane.setPage(urlHTML);
            htmlPane.setEditable(false);
            JEPyperlinkListener myJEPHL = new JEPyperlinkListener(htmlPane);
            htmlPane.addHyperlinkListener(myJEPHL);
            myFrame.getContentPane().add(new JScrollPane(htmlPane));
            myFrame.pack();
            myFrame.setSize(640, 480);
            myFrame.show();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this,
                    VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                            + "Could not open 'doc/javadoc/index.html'",
                    "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
        }
    } else if (source.getText().equals(MENU_CHECKUPDATE)) {
        Properties dbProps = null;
        String filName = PROPS_CHECK_UPDATE;
        try {
            dbProps = ReadPropertiesFile.readProperties(filName);
            String updFile = dbProps.getProperty(KEY_UPD_FILE);
            if (updFile == null) {
                JOptionPane.showMessageDialog(this,
                        VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                                + "Could not find update information",
                        "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
                return;
            }
            String updSite = dbProps.getProperty(KEY_WDBMGR_SITE);
            if (updFile == null) {
                JOptionPane.showMessageDialog(this,
                        VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                                + "Could not find SITE information",
                        "Warning " + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
                return;
            }

            URL urlUpdScript = new URL(updFile);
            BufferedReader in = new BufferedReader(new InputStreamReader(urlUpdScript.openStream()));

            String versionTXT = in.readLine();
            String downloadName = in.readLine();
            in.close();

            if (versionTXT.equals(WDBearManager.VERSION_INFO)) {
                JOptionPane.showMessageDialog(this,
                        VERSION_INFO + "\n" + "by kizura\n" + WDBearManager.EMAIL + "\n\n"
                                + "You are using the latest version, no updates available",
                        "Info " + VERSION_INFO, JOptionPane.INFORMATION_MESSAGE);
                return;
            } else {
                // Read version.txt
                String versionInfo = (String) dbProps.getProperty(KEY_VERSION_INFO);
                URL urlversionInfo = new URL(versionInfo);
                BufferedReader brVInfo = new BufferedReader(new InputStreamReader(urlversionInfo.openStream()));
                StringBuffer sbuVInfo = new StringBuffer();
                String strLine = "";
                boolean foundStart = false;
                while ((strLine = brVInfo.readLine()) != null) {
                    if (strLine.startsWith("---")) {
                        break;
                    }
                    if (foundStart == true) {
                        sbuVInfo.append(strLine);
                        sbuVInfo.append("\n");
                        continue;
                    }
                    if (strLine.startsWith(versionTXT)) {
                        foundStart = true;
                        continue;
                    }
                }
                brVInfo.close();

                int n = JOptionPane.showConfirmDialog(this,
                        "New version available - Please visit " + updSite + "\n\n" + versionTXT + "\n" + "\n"
                                + "You are using version:\n" + WDBearManager.VERSION_INFO + "\n" + "\n"
                                + "Do you want to download this version?\n\n" + "Version information:\n"
                                + sbuVInfo.toString(),
                        VERSION_INFO + "by kizura", JOptionPane.YES_NO_OPTION);
                //          JOptionPane.showMessageDialog(this, VERSION_INFO + "\n"
                //              + "by kizura\n" + WDBManager.EMAIL + "\n\n"
                //              + "New version available - Please visit " + updSite,
                //              "Warning "
                //              + VERSION_INFO, JOptionPane.WARNING_MESSAGE);
                if (n == 0) {
                    JFileChooser chooser = new JFileChooser(new File("."));
                    chooser.setDialogTitle("Please select download location");
                    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

                    int returnVal = chooser.showOpenDialog(this);
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        try {
                            URL urlUpd = new URL(downloadName);
                            BufferedInputStream bin = new BufferedInputStream(urlUpd.openStream());
                            System.out.println(
                                    new File(chooser.getSelectedFile(), urlUpd.getFile()).getAbsolutePath());
                            File thisFile = new File(chooser.getSelectedFile(), urlUpd.getFile());
                            BufferedOutputStream bout = new BufferedOutputStream(
                                    new FileOutputStream(thisFile));

                            byte[] bufFile = new byte[102400];
                            int bytesRead = 0;
                            while ((bytesRead = bin.read(bufFile)) != -1) {
                                bout.write(bufFile, 0, bytesRead);
                            }
                            bin.close();
                            bout.close();

                            JOptionPane.showMessageDialog(this,
                                    "Update downloaded successfully" + "\n" + "Please check '"
                                            + thisFile.getAbsolutePath() + "'",
                                    "Success " + WDBearManager.VERSION_INFO, JOptionPane.INFORMATION_MESSAGE);
                            //String msg = WriteCSV.writeCSV(chooser.getSelectedFile(), this.items);
                        } catch (Exception ex) {
                            String msg = ex.getMessage();
                            JOptionPane.showMessageDialog(this, msg + "\n" + "Error downloading update",
                                    "Error " + WDBearManager.VERSION_INFO, JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } // user selected "download"
                return;
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } else {
        System.exit(0);
    }

}

From source file:mondrian.gui.Workbench.java

private void aboutMenuItemActionPerformed(ActionEvent evt) {
    try {//ww w  .  j  a v  a  2s  .co  m
        JEditorPane jEditorPane = new JEditorPane(
                myClassLoader.getResource(getResourceConverter().getGUIReference("version")).toString());
        jEditorPane.setEditable(false);
        JScrollPane jScrollPane = new JScrollPane(jEditorPane);
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new java.awt.BorderLayout());
        jPanel.add(jScrollPane, java.awt.BorderLayout.CENTER);

        JInternalFrame jf = new JInternalFrame();
        jf.setTitle("About");
        jf.getContentPane().add(jPanel);

        Dimension screenSize = this.getSize();
        int aboutW = 400;
        int aboutH = 300;
        int width = (screenSize.width / 2) - (aboutW / 2);
        int height = (screenSize.height / 2) - (aboutH / 2) - 100;
        jf.setBounds(width, height, aboutW, aboutH);
        jf.setClosable(true);

        desktopPane.add(jf);

        jf.setVisible(true);
        jf.show();
    } catch (Exception ex) {
        LOGGER.error("aboutMenuItemActionPerformed", ex);
    }
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

/**
* 
* @param html String of valid HTML./*from www .jav a 2s .  c o m*/
* @return a 
*/
private JTextComponent createHyperlinkListenableJEditorPane(String html) {
    final JEditorPane bottomText = new JEditorPane();
    bottomText.setContentType("text/html");
    bottomText.setEditable(false);
    bottomText.setText(html);
    bottomText.setOpaque(false);
    final HyperlinkListener hyperlinkListener = new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
            if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(hyperlinkEvent.getURL().toURI());
                    } catch (IOException | URISyntaxException exception) {
                        // FIXME Auto-generated catch block
                        exception.printStackTrace();
                    }
                }

            }
        }
    };
    bottomText.addHyperlinkListener(hyperlinkListener);
    return bottomText;
}

From source file:com.microsoft.tfs.client.common.ui.controls.generic.CompatibleBrowser.java

public CompatibleBrowser(final Composite parent, final int style) {
    super(parent, style);

    Check.notNull(parent, "parent"); //$NON-NLS-1$

    final GridLayout gridLayout = new GridLayout(1, true);
    gridLayout.marginHeight = 0;//w  ww.ja  v a  2s  .  c o  m
    gridLayout.marginWidth = 0;

    setLayout(gridLayout);

    if (isNativeBrowserAvailable()) {
        log.info(MessageFormat.format("{0} using SWT Browser", CompatibleBrowser.class.getName())); //$NON-NLS-1$

        final GridData gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
        gd.grabExcessVerticalSpace = true;
        gd.verticalAlignment = SWT.FILL;

        browser = new Browser(this, style);
        browser.setLayoutData(gd);

        editorPane = null;
    } else {
        log.info(MessageFormat.format("{0} using JEditorPane", CompatibleBrowser.class.getName())); //$NON-NLS-1$

        browser = null;

        JEditorPane tempEditorPane = null;
        CompatibilityLinkControl tempErrorLabel = null;

        /*
         * Embedded AWT widgets must be in a Composite with SWT.EMBEDDED
         * set, so create one.
         */
        final Composite embeddableComposite = new Composite(this, SWT.EMBEDDED);

        final GridData compositeGridData = new GridData();
        compositeGridData.grabExcessHorizontalSpace = true;
        compositeGridData.horizontalAlignment = SWT.FILL;
        compositeGridData.grabExcessVerticalSpace = true;
        compositeGridData.verticalAlignment = SWT.FILL;

        embeddableComposite.setLayoutData(compositeGridData);

        /*
         * We have to skip trying AWT entirely some places.
         */
        boolean loadedAWTBrowser = false;
        if (CompatibleBrowser.isAWTDangerousHere() == false) {
            try {
                /*
                 * Create a Frame in the SWT Composite as the top-level
                 * element.
                 */
                final Frame browserFrame = SWT_AWT.new_Frame(embeddableComposite);

                /*
                 * Create a panel with a simple BorderLayout to hold
                 * contents.
                 */
                final Panel panel = new Panel(new BorderLayout());
                browserFrame.add(panel);

                /*
                 * Create an JEditorPane with an HTML document.
                 */
                final String pageContents = "<html><body></body></html>"; //$NON-NLS-1$
                tempEditorPane = new JEditorPane("text/html", pageContents); //$NON-NLS-1$
                tempEditorPane.setEditable(false);

                /*
                 * Put the HTML viewer in a scroll pane and parent the
                 * scroll pane in the panel.
                 */
                final JScrollPane scrollPane = new JScrollPane(tempEditorPane);
                panel.add(scrollPane);

                loadedAWTBrowser = true;
            } catch (final Throwable t) {
                log.warn("Error embedding AWT frame for JEditorPane", t); //$NON-NLS-1$
            }
        }

        if (loadedAWTBrowser == false) {
            /*
             * We don't need the embeddable composite because AWT embedding
             * failed, and we can't put normal (error label) things in it,
             * so hide it.
             */
            compositeGridData.widthHint = 0;
            compositeGridData.heightHint = 0;

            tempErrorLabel = CompatibilityLinkFactory.createLink(this, SWT.NONE);

            tempErrorLabel.setText(
                    MessageFormat.format(Messages.getString("CompatibleBrowser.CouldNotLoadSWTBrowserFormat"), //$NON-NLS-1$
                            AWT_TOOLKIT_ENV_VAR_NAME, XTOOLKIT_ENV_VAR_VALUE));

            final GridData labelGridData = new GridData();
            labelGridData.grabExcessHorizontalSpace = true;
            labelGridData.horizontalAlignment = SWT.FILL;
            labelGridData.grabExcessVerticalSpace = true;
            labelGridData.verticalAlignment = SWT.FILL;

            tempErrorLabel.getControl().setLayoutData(labelGridData);
        }

        editorPane = tempEditorPane;
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * add a tree listener for enabling/disabling menu and toolbar ICONS.
 *
 * @param tree JTree//  w ww.  j  a va2s. c o  m
 */
private void addTreeListener(JTree tree) {
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        ViewScrollPane emptyView = null;

        public void valueChanged(TreeSelectionEvent e) {
            getMainMenu().getCloseMenuItem().setEnabled(e.getPath() != null);
            if (getMainMenu().getCloseToolBarButton() != null) {
                getMainMenu().getCloseToolBarButton().setEnabled(e.getPath() != null);
            }
            // reset right pane of the top view:

            if (emptyView == null) {
                JEditorPane emptyPane = new JEditorPane("text/html",
                        "<html><body bgcolor=\"ffffff\"></body></html>");
                emptyPane.setEditable(false);
                emptyPane.setSize(Const.EMPTY_DIMENSION);

                emptyView = new ViewScrollPane(emptyPane, runningAsVisualVMPlugin);
            }

            if (e.getPath() == null || !(((DefaultMutableTreeNode) e.getPath().getLastPathComponent())
                    .getUserObject() instanceof Category)) {
                resetPane();
            }
        }

        private void resetPane() {
            final Rectangle bounds = topSplitPane.getBounds();
            final int width = bounds.width;
            int dividerLocation = topSplitPane.getDividerLocation();
            if (width - dividerLocation < Const.MIN_RIGHT_PANE_SIZE
                    && width - Const.MIN_RIGHT_PANE_SIZE > 300) {
                dividerLocation = width - Const.MIN_RIGHT_PANE_SIZE;
            }
            topSplitPane.setRightComponent(emptyView);
            topSplitPane.setDividerLocation(dividerLocation);
        }

    });
}

From source file:com.pironet.tda.TDA.java

/**
 * initializes tda panel//  w  ww.  j  a  v  a  2s.  c  om
 *
 * @param asJConsolePlugin specifies if tda is running as plugin
 */
public void init(boolean asJConsolePlugin, boolean asVisualVMPlugin) {
    // init everything
    tree = new JTree();
    addTreeListener(tree);
    runningAsJConsolePlugin = asJConsolePlugin;
    runningAsVisualVMPlugin = asVisualVMPlugin;

    //Create the HTML viewing pane.
    if (!this.runningAsVisualVMPlugin && !this.runningAsJConsolePlugin) {
        InputStream is = TDA.class.getResourceAsStream("/doc/welcome.html");

        htmlPane = new JEditorPane();

        String welcomeText = parseWelcomeURL(is);
        htmlPane.setContentType("text/html");
        htmlPane.setText(welcomeText);
    } else if (asJConsolePlugin) {
        htmlPane = new JEditorPane("text/html",
                "<html><body bgcolor=\"ffffff\"><i>Press Button above to request a thread dump.</i></body></html>");

    } else {
        htmlPane = new JEditorPane("text/html", "<html><body bgcolor=\"ffffff\"></body></html>");
    }
    htmlPane.putClientProperty(Const.AA_TEXT_INFO_PROPERTY_KEY, Boolean.TRUE);
    htmlPane.setEditable(false);

    if (!asJConsolePlugin && !asVisualVMPlugin) {
        hdt = new DropTarget(htmlPane, new FileDropTargetListener());
    }

    JEditorPane emptyPane = new JEditorPane("text/html", "");
    emptyPane.setEditable(false);

    htmlPane.addHyperlinkListener(evt -> {
        // if a link was clicked
        if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            if (evt.getDescription().startsWith("monitor")) {
                navigateToMonitor(evt.getDescription());
            } else if (evt.getDescription().startsWith("dump")) {
                navigateToDump();
            } else if (evt.getDescription().startsWith("wait")) {
                navigateToChild("Threads waiting");
            } else if (evt.getDescription().startsWith("sleep")) {
                navigateToChild("Threads sleeping");
            } else if (evt.getDescription().startsWith("dead")) {
                navigateToChild("Deadlocks");
            } else if (evt.getDescription().startsWith("threaddump")) {
                addMXBeanDump();
            } else if (evt.getDescription().startsWith("openlogfile") && !evt.getDescription().endsWith("//")) {
                File[] files = { new File(evt.getDescription().substring(14)) };
                openFiles(files, false);
            } else if (evt.getDescription().startsWith("openlogfile")) {
                chooseFile();
            } else if (evt.getDescription().startsWith("opensession") && !evt.getDescription().endsWith("//")) {
                File file = new File(evt.getDescription().substring(14));
                openSession(file, true);
            } else if (evt.getDescription().startsWith("opensession")) {
                openSession();
            } else if (evt.getDescription().startsWith("preferences")) {
                showPreferencesDialog();
            } else if (evt.getDescription().startsWith("filters")) {
                showFilterDialog();
            } else if (evt.getDescription().startsWith("categories")) {
                showCategoriesDialog();
            } else if (evt.getDescription().startsWith("overview")) {
                showHelp();
            } else if (evt.getURL() != null) {
                try {
                    // launch a browser with the appropriate URL
                    Browser.open(evt.getURL().toString());
                } catch (InterruptedException e) {
                    System.out.println("Error launching external browser.");
                } catch (IOException e) {
                    System.out.println("I/O error launching external browser." + e.getMessage());
                    e.printStackTrace();
                }
            }
        }
    });

    htmlView = new ViewScrollPane(htmlPane, runningAsVisualVMPlugin);
    ViewScrollPane emptyView = new ViewScrollPane(emptyPane, runningAsVisualVMPlugin);

    // create the top split pane
    topSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    topSplitPane.setLeftComponent(emptyView);
    topSplitPane.setDividerSize(Const.DIVIDER_SIZE);
    topSplitPane.setContinuousLayout(true);

    //Add the scroll panes to a split pane.
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setBottomComponent(htmlView);
    splitPane.setTopComponent(topSplitPane);
    splitPane.setDividerSize(Const.DIVIDER_SIZE);
    splitPane.setContinuousLayout(true);

    if (this.runningAsVisualVMPlugin) {
        setOpaque(true);
        setBackground(Color.WHITE);
        setBorder(BorderFactory.createEmptyBorder(6, 0, 3, 0));
        topSplitPane.setBorder(BorderFactory.createEmptyBorder());
        topSplitPane.setOpaque(false);
        topSplitPane.setBackground(Color.WHITE);
        htmlPane.setBorder(BorderFactory.createEmptyBorder());
        htmlPane.setOpaque(false);
        htmlPane.setBackground(Color.WHITE);
        splitPane.setBorder(BorderFactory.createEmptyBorder());
        splitPane.setOpaque(false);
        splitPane.setBackground(Color.WHITE);
    }

    Dimension minimumSize = new Dimension(200, 50);
    htmlView.setMinimumSize(minimumSize);
    emptyView.setMinimumSize(minimumSize);

    //Add the split pane to this panel.
    add(htmlView, BorderLayout.CENTER);

    statusBar = new StatusBar(!(asJConsolePlugin || asVisualVMPlugin));
    add(statusBar, BorderLayout.SOUTH);

    firstFile = true;
    setFileOpen(false);

    if (!runningAsVisualVMPlugin) {
        setShowToolbar(PrefManager.get().getShowToolbar());
    }

    if (firstFile && runningAsVisualVMPlugin) {
        // init filechooser
        fc = new JFileChooser();
        fc.setMultiSelectionEnabled(true);
        fc.setCurrentDirectory(PrefManager.get().getSelectedPath());
    }
}

From source file:Main.Interface_Main.java

private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed

    // for copying style
    JLabel label = new JLabel();
    Font font = label.getFont();//from w  ww  . ja  v a2s. c om

    // create some css from the label's font
    StringBuffer style = new StringBuffer("font-family:" + font.getFamily() + ";");
    style.append("font-weight:" + (font.isBold() ? "bold" : "normal") + ";");
    style.append("font-size:" + font.getSize() + "pt;");

    // html content
    JEditorPane ep = new JEditorPane("text/html", "<html><body style=\"" + style + "\">" //
            + "This application was designed by <A HREF=http://www.friedcircuits.us>FriedCircuits</A> for the USB Tester." //
            + "<br><br><center>App Version: " + appVersion + "<br>FW Version: " + FW_VERSION
            + "</center><br><br>*Connect once to get FW version.</body></html>");

    // handle link events
    ep.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                java.awt.Desktop desktop = java.awt.Desktop.getDesktop();

                URI uri;
                try {
                    uri = new java.net.URI("www.friedcircuits.us");
                    if (desktop.isSupported(Desktop.Action.BROWSE)) {
                        try {
                            desktop.browse(uri);
                        } catch (IOException ex) {
                            Logger.getLogger(Interface_Main.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } catch (URISyntaxException ex) {
                    Logger.getLogger(Interface_Main.class.getName()).log(Level.SEVERE, null, ex);
                }

            } // roll your own link launcher or use Desktop if J6+
        }
    });
    Color bgColor = label.getBackground();
    UIDefaults defaults = new UIDefaults();
    defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
    ep.putClientProperty("Nimbus.Overrides", defaults);
    ep.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
    ep.setEditable(false);
    ep.setBackground(bgColor);

    // show
    ImageIcon myCustomIcon = new ImageIcon(getClass().getResource("/faviconbot2edit.png"));
    JOptionPane.showMessageDialog(plCurrent, ep, "About", JOptionPane.INFORMATION_MESSAGE, myCustomIcon);
}

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * Create if needed and return the editorpane for the description tab
 *
 * @return description view// w w w  .  j  a v  a 2 s .  c  o m
 */
private JEditorPane getHtmlView() {
    if (htmlView == null) {
        JEditorPane tmp = new JEditorPane();
        tmp.setContentType("text/html");
        tmp.setPreferredSize(new Dimension(300, 400));
        tmp.setEditable(false);
        tmp.setText(" ");
        htmlView = tmp;
    }
    return htmlView;

}

From source file:userinterface.properties.GUIGraphHandler.java

public void plotNewFunction() {

    JDialog dialog;//from w  w  w .  j a v  a2s  .  c  o  m
    JRadioButton radio2d, radio3d, newGraph, existingGraph;
    JTextField functionField, seriesName;
    JButton ok, cancel;
    JComboBox<String> chartOptions;
    JLabel example;

    //init all the fields of the dialog
    dialog = new JDialog(GUIPrism.getGUI());
    radio2d = new JRadioButton("2D");
    radio3d = new JRadioButton("3D");
    newGraph = new JRadioButton("New Graph");
    existingGraph = new JRadioButton("Exisiting");
    chartOptions = new JComboBox<String>();
    functionField = new JTextField();
    ok = new JButton("Plot");
    cancel = new JButton("Cancel");
    seriesName = new JTextField();
    example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
    example.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.HAND_CURSOR));
            example.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            example.setForeground(Color.BLACK);
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {

                if (radio2d.isSelected()) {
                    functionField.setText("x/2 + 5");
                } else {
                    functionField.setText("x+y+5");
                }

                functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
                functionField.setForeground(Color.BLACK);

            }
        }

    });

    //set dialog properties
    dialog.setSize(400, 350);
    dialog.setTitle("Plot a new function");
    dialog.setModal(true);
    dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    dialog.setLocationRelativeTo(GUIPrism.getGUI());

    //add every component to their dedicated panels
    JPanel graphTypePanel = new JPanel(new FlowLayout());
    graphTypePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type"));
    graphTypePanel.add(radio2d);
    graphTypePanel.add(radio3d);

    JPanel functionFieldPanel = new JPanel(new BorderLayout());
    functionFieldPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function"));
    functionFieldPanel.add(functionField, BorderLayout.CENTER);
    functionFieldPanel.add(example, BorderLayout.SOUTH);

    JPanel chartSelectPanel = new JPanel();
    chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS));
    chartSelectPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to"));
    JPanel radioPlotPanel = new JPanel(new FlowLayout());
    radioPlotPanel.add(newGraph);
    radioPlotPanel.add(existingGraph);
    JPanel chartOptionsPanel = new JPanel(new FlowLayout());
    chartOptionsPanel.add(chartOptions);
    chartSelectPanel.add(radioPlotPanel);
    chartSelectPanel.add(chartOptionsPanel);

    JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bottomControlPanel.add(ok);
    bottomControlPanel.add(cancel);

    JPanel seriesNamePanel = new JPanel(new BorderLayout());
    seriesNamePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name"));
    seriesNamePanel.add(seriesName, BorderLayout.CENTER);

    // add all the panels to the dialog

    dialog.add(graphTypePanel);
    dialog.add(functionFieldPanel);
    dialog.add(chartSelectPanel);
    dialog.add(seriesNamePanel);
    dialog.add(bottomControlPanel);

    // do all the enables and set properties

    radio2d.setSelected(true);
    newGraph.setSelected(true);
    chartOptions.setEnabled(false);
    functionField.setText("Add function expression here....");
    functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
    functionField.setForeground(Color.GRAY);
    seriesName.setText("New function");
    ok.setMnemonic('P');
    cancel.setMnemonic('C');
    example.setToolTipText("click to try out");

    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
    ok.getActionMap().put("ok", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok.doClick();
        }
    });

    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    cancel.getActionMap().put("cancel", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel.doClick();
        }
    });

    boolean found = false;

    for (int i = 0; i < theTabs.getTabCount(); i++) {

        if (theTabs.getComponentAt(i) instanceof Graph) {
            chartOptions.addItem(getGraphName(i));
            found = true;
        }
    }

    if (!found) {

        existingGraph.setEnabled(false);
        chartOptions.setEnabled(false);
    }

    //add all the action listeners

    radio2d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio2d.isSelected()) {

                radio3d.setSelected(false);

                if (chartOptions.getItemCount() > 0) {
                    existingGraph.setEnabled(true);
                    chartOptions.setEnabled(true);
                }

                example.setText(
                        "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
            }
        }
    });

    radio3d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio3d.isSelected()) {

                radio2d.setSelected(false);
                newGraph.setSelected(true);
                existingGraph.setEnabled(false);
                chartOptions.setEnabled(false);
                example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>");

            }

        }
    });

    newGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (newGraph.isSelected()) {
                existingGraph.setSelected(false);
                chartOptions.setEnabled(false);
            }
        }
    });

    existingGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (existingGraph.isSelected()) {

                newGraph.setSelected(false);
                chartOptions.setEnabled(true);
            }
        }
    });

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            String function = functionField.getText();

            Expression expr = null;

            try {

                expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function);
                expr = (Expression) expr.accept(new ASTTraverseModify() {

                    @Override
                    public Object visit(ExpressionIdent e) throws PrismLangException {
                        return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                    }

                });

                expr.typeCheck();
                expr.semanticCheck();

            } catch (PrismLangException e1) {

                // for copying style
                JLabel label = new JLabel();

                // html content in our case the error we want to show
                JEditorPane ep = new JEditorPane("text/html",
                        "<html> There was an error parsing the function. To read about what built-in"
                                + " functions are supported <br>and some more information on the functions, visit "
                                + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>."
                                + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>");

                // handle link events
                ep.addHyperlinkListener(new HyperlinkListener() {
                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                            try {
                                Desktop.getDesktop().browse(e.getURL().toURI());
                            } catch (IOException | URISyntaxException e1) {

                                e1.printStackTrace();
                            }
                        }
                    }
                });
                ep.setEditable(false);
                ep.setBackground(label.getBackground());

                // show the error dialog
                JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (radio2d.isSelected()) {

                ParametricGraph graph = null;

                if (newGraph.isSelected()) {

                    graph = new ParametricGraph("");
                } else {

                    for (int i = 0; i < theTabs.getComponentCount(); i++) {

                        if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) {

                            graph = (ParametricGraph) theTabs.getComponent(i);
                        }
                    }

                }

                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true);

            } else if (radio3d.isSelected()) {

                try {

                    expr = (Expression) expr.accept(new ASTTraverseModify() {
                        @Override
                        public Object visit(ExpressionIdent e) throws PrismLangException {
                            return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                        }

                    });

                    expr.semanticCheck();
                    expr.typeCheck();

                } catch (PrismLangException e1) {
                    e1.printStackTrace();
                }

                if (expr.getAllConstants().size() < 2) {

                    JOptionPane.showMessageDialog(dialog,
                            "There are not enough variables in the function to plot a 3D chart!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                // its always a new graph
                ParametricGraph3D graph = new ParametricGraph3D(expr);
                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false);
            }

            dialog.dispose();
        }
    });

    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    // we will show info about the function when field is out of focus
    functionField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

            if (!functionField.getText().equals("")) {
                return;
            }

            functionField.setText("Add function expression here....");
            functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
            functionField.setForeground(Color.GRAY);
        }

        @Override
        public void focusGained(FocusEvent e) {

            if (!functionField.getText().equals("Add function expression here....")) {
                return;
            }

            functionField.setForeground(Color.BLACK);
            functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
            functionField.setText("");
        }
    });

    // show the dialog
    dialog.setVisible(true);
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Shows the About dialog./*from  ww w  . j  a va 2 s .  c om*/
 */
public void doAbout() {
    AppContextMgr acm = AppContextMgr.getInstance();
    boolean showDetailedAbout = acm.hasContext() && acm.getClassObject(Division.class) != null
            && acm.getClassObject(Discipline.class) != null && acm.getClassObject(Collection.class) != null;

    int baseNumRows = 14;
    String serverName = AppPreferences.getLocalPrefs().get("login.servers_selected", null);
    if (serverName != null) {
        baseNumRows++;
    }

    CellConstraints cc = new CellConstraints();
    PanelBuilder infoPB = new PanelBuilder(new FormLayout("p,6px,f:p:g",
            "p,4px,p,4px," + UIHelper.createDuplicateJGoodiesDef("p", "2px", baseNumRows)));

    JLabel iconLabel = new JLabel(IconManager.getIcon("SpecifyLargeIcon"), SwingConstants.CENTER); //$NON-NLS-1$
    PanelBuilder iconPB = new PanelBuilder(new FormLayout("p", "20px,t:p,f:p:g"));
    iconPB.add(iconLabel, cc.xy(1, 2));

    if (showDetailedAbout) {
        final ArrayList<String> values = new ArrayList<String>();

        DBTableIdMgr tableMgr = DBTableIdMgr.getInstance();
        boolean hasReged = !RegisterSpecify.isAnonymous() && RegisterSpecify.hasInstitutionRegistered();

        int y = 1;
        infoPB.addSeparator(getResourceString("Specify.SYS_INFO"), cc.xyw(1, y, 3));
        y += 2;

        JLabel lbl = UIHelper.createLabel(databaseName);
        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.DB"), cc.xy(1, y));
        addLabel(values, infoPB, lbl, cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openLocalPrefs();
                }
            }
        });

        int instId = Institution.getClassTableId();
        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(instId)), cc.xy(1, y));
        addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Institution.class).getName()),
                cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(instId)), cc.xy(1, y));

        String noGUID = "<No GUID>";
        String guidStr = acm.getClassObject(Institution.class).getGuid();
        addLabel(values, infoPB, lbl = UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y));
        y += 2;

        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openRemotePrefs();
                }
            }
        });
        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Division.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, lbl = UIHelper.createLabel(acm.getClassObject(Division.class).getName()),
                cc.xy(3, y));
        y += 2;
        lbl.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    openGlobalPrefs();
                }
            }
        });

        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Discipline.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Discipline.class).getName()),
                cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createFormLabel(tableMgr.getTitleForId(Collection.getClassTableId())),
                cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(acm.getClassObject(Collection.class).getCollectionName()),
                cc.xy(3, y));
        y += 2;
        addLabel(values, infoPB, UIHelper.createFormLabel(getGUIDTitle(Collection.getClassTableId())),
                cc.xy(1, y));

        guidStr = acm.getClassObject(Collection.class).getGuid();
        addLabel(values, infoPB, UIHelper.createLabel(guidStr != null ? guidStr : noGUID), cc.xy(3, y));
        y += 2;
        //addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        //addLabel(values, infoPB, UIHelper.createLabel(appBuildVersion),cc.xy(3, y)); y += 2;

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD"), cc.xy(1, y));
        UIRegistry.loadAndPushResourceBundle("bld");
        addLabel(values, infoPB, UIHelper.createLabel(getResourceString("build")), cc.xy(3, y));
        y += 2;

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.BLD_TM"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(getResourceString("buildtime")), cc.xy(3, y));
        y += 2;
        UIRegistry.popResourceBundle();

        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.REG"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createI18NLabel(hasReged ? "Specify.HASREG" : "Specify.NOTREG"),
                cc.xy(3, y));
        y += 2;

        String isaNumber = RegisterSpecify.getISANumber();
        addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.ISANUM"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(isaNumber) ? isaNumber : ""),
                cc.xy(3, y));
        y += 2;

        if (serverName != null) {
            addLabel(values, infoPB, UIHelper.createI18NFormLabel("Specify.SERVER"), cc.xy(1, y));
            addLabel(values, infoPB, UIHelper.createLabel(StringUtils.isNotEmpty(serverName) ? serverName : ""),
                    cc.xy(3, y));
            y += 2;
        }

        if (StringUtils.contains(DBConnection.getInstance().getConnectionStr(), "mysql")) {
            Vector<Object[]> list = BasicSQLUtils.query("select version() as ve");
            if (list != null && list.size() > 0) {
                addLabel(values, infoPB, UIHelper.createFormLabel("MySQL Version"), cc.xy(1, y));
                addLabel(values, infoPB, UIHelper.createLabel(list.get(0)[0].toString()), cc.xy(3, y));
                y += 2;
            }
        }

        addLabel(values, infoPB, UIHelper.createFormLabel("Java Version"), cc.xy(1, y));
        addLabel(values, infoPB, UIHelper.createLabel(System.getProperty("java.version")), cc.xy(3, y));
        y += 2;

        JButton copyCBBtn = createIconBtn("ClipboardCopy", IconManager.IconSize.Std24, "Specify.CPY_ABT_TO_TT",
                null);
        //copyCBBtn.setBackground(Color.WHITE);
        //copyCBBtn.setOpaque(true);
        //copyCBBtn.setBorder(BorderFactory.createEtchedBorder());

        copyCBBtn.setEnabled(true);

        PanelBuilder cbPB = new PanelBuilder(new FormLayout("f:p:g,p", "p"));
        cbPB.add(copyCBBtn, cc.xy(2, 1));
        copyCBBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // Copy to Clipboard
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < values.size(); i++) {
                    sb.append(String.format("%s = %s\n", values.get(i), values.get(i + 1)));
                    i++;
                }
                UIHelper.setTextToClipboard(sb.toString());
                UIRegistry.displayInfoMsgDlgLocalized("Specify.CPY_ABT_TO_MSG");
            }
        });
        infoPB.add(cbPB.getPanel(), cc.xy(3, y));
        y += 2;
    }

    String txt = getAboutText(appName, appVersion);
    JLabel txtLbl = createLabel(txt);
    txtLbl.setFont(UIRegistry.getDefaultFont());

    final JEditorPane txtPane = new JEditorPane("text/html", txt);
    txtPane.setEditable(false);
    txtPane.setBackground(new JPanel().getBackground());

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,20px,f:min(400px;p):g,10px,8px,10px,p:g", "f:p:g"));

    pb.add(iconPB.getPanel(), cc.xy(1, 1));
    pb.add(txtPane, cc.xy(3, 1));
    Color bg = getBackground();

    if (showDetailedAbout) {
        pb.add(new VerticalSeparator(bg.darker(), bg.brighter()), cc.xy(5, 1));
        pb.add(infoPB.getPanel(), cc.xy(7, 1));
    }

    pb.setDefaultDialogBorder();

    String title = getResourceString("Specify.ABOUT");//$NON-NLS-1$
    CustomDialog aboutDlg = new CustomDialog(topFrame, title + " " + appName, true, CustomDialog.OK_BTN, //$NON-NLS-1$
            pb.getPanel());
    String okLabel = getResourceString("Specify.CLOSE");//$NON-NLS-1$
    aboutDlg.setOkLabel(okLabel);

    aboutDlg.createUI();
    aboutDlg.pack();

    // for some strange reason I can't get the dialog to size itself correctly
    Dimension size = aboutDlg.getSize();
    size.height += 120;
    aboutDlg.setSize(size);

    txtPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    AttachmentUtils.openURI(event.getURL().toURI());

                } catch (Exception e) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                }
            }
        }
    });

    UIHelper.centerAndShow(aboutDlg);
}