Example usage for javax.swing.event HyperlinkListener HyperlinkListener

List of usage examples for javax.swing.event HyperlinkListener HyperlinkListener

Introduction

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

Prototype

HyperlinkListener

Source Link

Usage

From source file:nz.govt.natlib.ndha.manualdeposit.HelpWindow.java

/** Creates new form HelpWindow */
public HelpWindow(final String title, final URL hlpURL, final String settingsPath) {
    super(title);
    try {/*from w ww.  ja  v  a  2s . c  o  m*/
        frmControl = new FormControl(this, settingsPath);
    } catch (Exception ex) {
        LOG.error("Error loading form parameters", ex);
    }
    helpURL = hlpURL;
    editorpane = new JEditorPane();
    editorpane.setEditable(false);
    try {
        editorpane.setPage(helpURL);
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
    }
    // anonymous inner listener
    editorpane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(final HyperlinkEvent ev) {
            try {
                if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    editorpane.setPage(ev.getURL());
                }
            } catch (IOException ex) {
                // put message in window
                LOG.error(ex.getMessage(), ex);
            }
        }
    });
    getContentPane().add(new JScrollPane(editorpane));
    addButtons();
    // no need for listener just dispose
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setVisible(true);
}

From source file:org.apache.airavata.xbaya.ui.dialogs.monitor.MonitorWindow.java

private void init() {
    this.timeTextField = new XBayaTextField();
    this.timeTextField.setEditable(false);
    XBayaLabel timeLabel = new XBayaLabel(EventDataRepository.Column.TIME.getName(), this.timeTextField);

    this.idTextField = new XBayaTextField();
    this.idTextField.setEditable(false);
    XBayaLabel idLabel = new XBayaLabel(EventDataRepository.Column.ID.getName(), this.idTextField);

    this.statusTextField = new XBayaTextField();
    this.statusTextField.setEditable(false);
    XBayaLabel statusLabel = new XBayaLabel(EventDataRepository.Column.STATUS.getName(), this.statusTextField);

    this.messageTextArea = new JEditorPane(XmlConstants.CONTENT_TYPE_HTML, "");
    this.messageTextArea.setSize(500, 500);
    this.messageTextArea.setEditable(false);
    messageTextArea.setBackground(Color.WHITE);
    messageTextArea.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent event) {
            if (event.getEventType() == EventType.ACTIVATED) {
                URL url = event.getURL();
                try {
                    BrowserLauncher.openURL(url.toString());
                } catch (Exception e) {
                    MonitorWindow.this.xbayaGUI.getErrorWindow().error(MonitorWindow.this.dialog.getDialog(),
                            e.getMessage(), e);
                }/* www.j  av a  2 s  . c  o  m*/
            }
        }
    });
    JScrollPane pane = new JScrollPane(messageTextArea);
    pane.setSize(500, 500);
    XBayaLabel messageLabel = new XBayaLabel(EventDataRepository.Column.MESSAGE.getName(), pane);

    GridPanel infoPanel = new GridPanel();
    infoPanel.add(timeLabel);
    infoPanel.add(this.timeTextField);
    infoPanel.add(idLabel);
    infoPanel.add(this.idTextField);
    infoPanel.add(statusLabel);
    infoPanel.add(this.statusTextField);
    infoPanel.add(messageLabel);
    infoPanel.add(pane);
    infoPanel.layout(4, 2, 3, 1);

    JButton okButton = new JButton("OK");
    okButton.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            hide();
        }
    });
    JButton copyButton = new JButton("Copy to Clipboard");
    copyButton.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(messageText),
                    null);
        }
    });
    JPanel buttonPanel = new JPanel();
    buttonPanel.add(okButton);
    buttonPanel.add(copyButton);

    this.dialog = new XBayaDialog(this.xbayaGUI, "Notification", infoPanel, buttonPanel);
    this.dialog.setDefaultButton(okButton);
}

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Activates itself as a viewer by configuring Size, and location of itself,
 * and configures the default Tabbed Pane elements with the correct layout,
 * table columns, and sets itself viewable.
 */// w  ww .  ja v a  2 s . c  o  m
public void activateViewer() {
    LoggerRepository repo = LogManager.getLoggerRepository();
    if (repo instanceof LoggerRepositoryEx) {
        this.pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry();
    }
    initGUI();

    initPrefModelListeners();

    /**
     * We add a simple appender to the MessageCenter logger
     * so that each message is displayed in the Status bar
     */
    MessageCenter.getInstance().getLogger().addAppender(new AppenderSkeleton() {
        protected void append(LoggingEvent event) {
            getStatusBar().setMessage(event.getMessage().toString());
        }

        public void close() {
        }

        public boolean requiresLayout() {
            return false;
        }
    });

    initSocketConnectionListener();

    if (pluginRegistry.getPlugins(Receiver.class).size() == 0) {
        noReceiversDefined = true;
    }

    getFilterableColumns().add(ChainsawConstants.LEVEL_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.LOGGER_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.THREAD_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.NDC_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.PROPERTIES_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.CLASS_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.METHOD_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.FILE_COL_NAME);
    getFilterableColumns().add(ChainsawConstants.NONE_COL_NAME);

    JPanel panePanel = new JPanel();
    panePanel.setLayout(new BorderLayout(2, 2));

    getContentPane().setLayout(new BorderLayout());

    getTabbedPane().addChangeListener(getToolBarAndMenus());
    getTabbedPane().addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            LogPanel thisLogPanel = getCurrentLogPanel();
            if (thisLogPanel != null) {
                thisLogPanel.updateStatusBar();
            }
        }
    });

    KeyStroke ksRight = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    KeyStroke ksLeft = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    KeyStroke ksGotoLine = KeyStroke.getKeyStroke(KeyEvent.VK_G,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());

    getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksRight, "MoveRight");
    getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksLeft, "MoveLeft");
    getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ksGotoLine, "GotoLine");

    Action moveRight = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            int temp = getTabbedPane().getSelectedIndex();
            ++temp;

            if (temp != getTabbedPane().getTabCount()) {
                getTabbedPane().setSelectedTab(temp);
            }
        }
    };

    Action moveLeft = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            int temp = getTabbedPane().getSelectedIndex();
            --temp;

            if (temp > -1) {
                getTabbedPane().setSelectedTab(temp);
            }
        }
    };

    Action gotoLine = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            String inputLine = JOptionPane.showInputDialog(LogUI.this, "Enter the line number to go:",
                    "Goto Line", -1);
            try {
                int lineNumber = Integer.parseInt(inputLine);
                int row = getCurrentLogPanel().setSelectedEvent(lineNumber);
                if (row == -1) {
                    JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number",
                            "Error", 0);
                }
            } catch (NumberFormatException nfe) {
                JOptionPane.showMessageDialog(LogUI.this, "You have entered an invalid line number", "Error",
                        0);
            }
        }
    };

    getTabbedPane().getActionMap().put("MoveRight", moveRight);
    getTabbedPane().getActionMap().put("MoveLeft", moveLeft);
    getTabbedPane().getActionMap().put("GotoLine", gotoLine);

    /**
         * We listen for double clicks, and auto-undock currently selected Tab if
         * the mouse event location matches the currently selected tab
         */
    getTabbedPane().addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);

            if ((e.getClickCount() > 1) && ((e.getModifiers() & InputEvent.BUTTON1_MASK) > 0)) {
                int tabIndex = getTabbedPane().getSelectedIndex();

                if ((tabIndex != -1) && (tabIndex == getTabbedPane().getSelectedIndex())) {
                    LogPanel logPanel = getCurrentLogPanel();

                    if (logPanel != null) {
                        logPanel.undock();
                    }
                }
            }
        }
    });

    panePanel.add(getTabbedPane());
    addWelcomePanel();

    getContentPane().add(toolbar, BorderLayout.NORTH);
    getContentPane().add(statusBar, BorderLayout.SOUTH);

    mainReceiverSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panePanel, receiversPanel);
    dividerSize = mainReceiverSplitPane.getDividerSize();
    mainReceiverSplitPane.setDividerLocation(-1);

    getContentPane().add(mainReceiverSplitPane, BorderLayout.CENTER);

    /**
     * We need to make sure that all the internal GUI components have been added to the
     * JFrame so that any plugns that get activated during initPlugins(...) method
     * have access to inject menus  
     */
    initPlugins(pluginRegistry);

    mainReceiverSplitPane.setResizeWeight(1.0);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            exit();
        }
    });
    preferencesFrame.setTitle("'Application-wide Preferences");
    preferencesFrame.setIconImage(((ImageIcon) ChainsawIcons.ICON_PREFERENCES).getImage());
    preferencesFrame.getContentPane().add(applicationPreferenceModelPanel);

    preferencesFrame.setSize(750, 520);

    Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
    preferencesFrame.setLocation(new Point((screenDimension.width / 2) - (preferencesFrame.getSize().width / 2),
            (screenDimension.height / 2) - (preferencesFrame.getSize().height / 2)));

    pack();

    final JPopupMenu tabPopup = new JPopupMenu();
    final Action hideCurrentTabAction = new AbstractAction("Hide") {
        public void actionPerformed(ActionEvent e) {
            Component selectedComp = getTabbedPane().getSelectedComponent();
            if (selectedComp instanceof LogPanel) {
                displayPanel(getCurrentLogPanel().getIdentifier(), false);
                tbms.stateChange();
            } else {
                getTabbedPane().remove(selectedComp);
            }
        }
    };

    final Action hideOtherTabsAction = new AbstractAction("Hide Others") {
        public void actionPerformed(ActionEvent e) {
            Component selectedComp = getTabbedPane().getSelectedComponent();
            String currentName;
            if (selectedComp instanceof LogPanel) {
                currentName = getCurrentLogPanel().getIdentifier();
            } else if (selectedComp instanceof WelcomePanel) {
                currentName = ChainsawTabbedPane.WELCOME_TAB;
            } else {
                currentName = ChainsawTabbedPane.ZEROCONF;
            }

            int count = getTabbedPane().getTabCount();
            int index = 0;

            for (int i = 0; i < count; i++) {
                String name = getTabbedPane().getTitleAt(index);

                if (getPanelMap().keySet().contains(name) && !name.equals(currentName)) {
                    displayPanel(name, false);
                    tbms.stateChange();
                } else {
                    index++;
                }
            }
        }
    };

    Action showHiddenTabsAction = new AbstractAction("Show All Hidden") {
        public void actionPerformed(ActionEvent e) {
            for (Iterator iter = getPanels().entrySet().iterator(); iter.hasNext();) {
                Map.Entry entry = (Map.Entry) iter.next();
                Boolean docked = (Boolean) entry.getValue();
                if (docked.booleanValue()) {
                    String identifier = (String) entry.getKey();
                    int count = getTabbedPane().getTabCount();
                    boolean found = false;

                    for (int i = 0; i < count; i++) {
                        String name = getTabbedPane().getTitleAt(i);

                        if (name.equals(identifier)) {
                            found = true;

                            break;
                        }
                    }

                    if (!found) {
                        displayPanel(identifier, true);
                        tbms.stateChange();
                    }
                }
            }
        }
    };

    tabPopup.add(hideCurrentTabAction);
    tabPopup.add(hideOtherTabsAction);
    tabPopup.addSeparator();
    tabPopup.add(showHiddenTabsAction);

    final PopupListener tabPopupListener = new PopupListener(tabPopup);
    getTabbedPane().addMouseListener(tabPopupListener);

    this.handler.addPropertyChangeListener("dataRate", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            double dataRate = ((Double) evt.getNewValue()).doubleValue();
            statusBar.setDataRate(dataRate);
        }
    });

    getSettingsManager().addSettingsListener(this);
    getSettingsManager().addSettingsListener(MRUFileListPreferenceSaver.getInstance());
    getSettingsManager().addSettingsListener(receiversPanel);
    try {
        //if an uncaught exception is thrown, allow the UI to continue to load
        getSettingsManager().loadSettings();
    } catch (Exception e) {
        e.printStackTrace();
    }
    //app preferences have already been loaded (and configuration url possibly set to blank if being overridden)
    //but we need a listener so the settings will be saved on exit (added after loadsettings was called)
    getSettingsManager().addSettingsListener(new ApplicationPreferenceModelSaver(applicationPreferenceModel));

    setVisible(true);

    if (applicationPreferenceModel.isReceivers()) {
        showReceiverPanel();
    } else {
        hideReceiverPanel();
    }

    removeSplash();

    synchronized (initializationLock) {
        isGUIFullyInitialized = true;
        initializationLock.notifyAll();
    }

    if (noReceiversDefined && applicationPreferenceModel.isShowNoReceiverWarning()) {
        SwingHelper.invokeOnEDT(new Runnable() {
            public void run() {
                showReceiverConfigurationPanel();
            }
        });
    }

    Container container = tutorialFrame.getContentPane();
    final JEditorPane tutorialArea = new JEditorPane();
    tutorialArea.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    tutorialArea.setEditable(false);
    container.setLayout(new BorderLayout());

    try {
        tutorialArea.setPage(ChainsawConstants.TUTORIAL_URL);
        JTextComponentFormatter.applySystemFontAndSize(tutorialArea);

        container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER);
    } catch (Exception e) {
        MessageCenter.getInstance().getLogger().error("Error occurred loading the Tutorial", e);
    }

    tutorialFrame.setIconImage(new ImageIcon(ChainsawIcons.HELP).getImage());
    tutorialFrame.setSize(new Dimension(640, 480));

    final Action startTutorial = new AbstractAction("Start Tutorial",
            new ImageIcon(ChainsawIcons.ICON_RESUME_RECEIVER)) {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(null,
                    "This will start 3 \"Generator\" receivers for use in the Tutorial.  Is that ok?",
                    "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                new Thread(new Tutorial()).start();
                putValue("TutorialStarted", Boolean.TRUE);
            } else {
                putValue("TutorialStarted", Boolean.FALSE);
            }
        }
    };

    final Action stopTutorial = new AbstractAction("Stop Tutorial",
            new ImageIcon(ChainsawIcons.ICON_STOP_RECEIVER)) {
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(null,
                    "This will stop all of the \"Generator\" receivers used in the Tutorial, but leave any other Receiver untouched.  Is that ok?",
                    "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                new Thread(new Runnable() {
                    public void run() {
                        LoggerRepository repo = LogManager.getLoggerRepository();
                        if (repo instanceof LoggerRepositoryEx) {
                            PluginRegistry pluginRegistry = ((LoggerRepositoryEx) repo).getPluginRegistry();
                            List list = pluginRegistry.getPlugins(Generator.class);

                            for (Iterator iter = list.iterator(); iter.hasNext();) {
                                Plugin plugin = (Plugin) iter.next();
                                pluginRegistry.stopPlugin(plugin.getName());
                            }
                        }
                    }
                }).start();
                setEnabled(false);
                startTutorial.putValue("TutorialStarted", Boolean.FALSE);
            }
        }
    };

    stopTutorial.putValue(Action.SHORT_DESCRIPTION,
            "Removes all of the Tutorials Generator Receivers, leaving all other Receivers untouched");
    startTutorial.putValue(Action.SHORT_DESCRIPTION,
            "Begins the Tutorial, starting up some Generator Receivers so you can see Chainsaw in action");
    stopTutorial.setEnabled(false);

    final SmallToggleButton startButton = new SmallToggleButton(startTutorial);
    PropertyChangeListener pcl = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            stopTutorial.setEnabled(((Boolean) startTutorial.getValue("TutorialStarted")).equals(Boolean.TRUE));
            startButton.setSelected(stopTutorial.isEnabled());
        }
    };

    startTutorial.addPropertyChangeListener(pcl);
    stopTutorial.addPropertyChangeListener(pcl);

    pluginRegistry.addPluginListener(new PluginListener() {
        public void pluginStarted(PluginEvent e) {
        }

        public void pluginStopped(PluginEvent e) {
            List list = pluginRegistry.getPlugins(Generator.class);

            if (list.size() == 0) {
                startTutorial.putValue("TutorialStarted", Boolean.FALSE);
            }
        }
    });

    final SmallButton stopButton = new SmallButton(stopTutorial);

    final JToolBar tutorialToolbar = new JToolBar();
    tutorialToolbar.setFloatable(false);
    tutorialToolbar.add(startButton);
    tutorialToolbar.add(stopButton);
    container.add(tutorialToolbar, BorderLayout.NORTH);
    tutorialArea.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e.getDescription().equals("StartTutorial")) {
                    startTutorial.actionPerformed(null);
                } else if (e.getDescription().equals("StopTutorial")) {
                    stopTutorial.actionPerformed(null);
                } else {
                    try {
                        tutorialArea.setPage(e.getURL());
                    } catch (IOException e1) {
                        MessageCenter.getInstance().getLogger()
                                .error("Failed to change the URL for the Tutorial", e1);
                    }
                }
            }
        }
    });

    /**
     * loads the saved tab settings and if there are hidden tabs,
     * hide those tabs out of currently loaded tabs..
     */

    if (!getTabbedPane().tabSetting.isWelcome()) {
        displayPanel(ChainsawTabbedPane.WELCOME_TAB, false);
    }
    if (!getTabbedPane().tabSetting.isZeroconf()) {
        displayPanel(ChainsawTabbedPane.ZEROCONF, false);
    }
    tbms.stateChange();

}

From source file:org.echocat.velma.dialogs.AboutDialog.java

protected void createIntroduction(@Nonnull Resources resources) {
    final URL iconUrl = resources.getIconUrl(48);

    final StringBuilder body = new StringBuilder();
    body.append("<html>");
    body.append("<head><style>" + "td { margin-right: 10px; }" + "</style></head>");
    body.append("<body style='font-family: sans; font-size: 1em'><table><tr>");
    body.append("<td valign='top'><img src='").append(iconUrl).append("' /></td>");
    body.append("<td valign='top'>");
    body.append("<h2>").append(escapeHtml4(resources.getApplicationName()));
    final String version = resources.getVersion();
    if (!isEmpty(version)) {
        body.append("<br/><span style='font-size: 0.6em'>")
                .append(resources.formatEscaped("versionText", version)).append("</span>");
    }/*from   w  w  w  .j  a va  2  s . c  om*/
    body.append("</h2>");

    body.append("<p>Copyright 2011-2012 <a href='https://echocat.org'>echocat</a></p>");
    body.append("<p><a href='http://mozilla.org/MPL/2.0/'>")
            .append(resources.formatEscaped("licensedUnder", "MPL 2.0")).append("</a></p>");

    body.append("<p><table cellpadding='0' cellspacing='0'>");
    body.append("<tr><td>").append(resources.formatEscaped("xHomepage", "echocat"))
            .append(":</td><td><a href='https://echocat.org'>echocat.org</a></td></tr>");
    body.append("<tr><td>").append(resources.formatEscaped("xHomepage", "Velma"))
            .append(":</td><td><a href='https://velma.echocat.org'>velma.echocat.org</a></td></tr>");
    body.append("</table></p>");

    body.append("<h4>").append(resources.formatEscaped("developers"))
            .append("</h4><table cellpadding='0' cellspacing='0'>");
    body.append(
            "<tr><td>Gregor Noczinski</td><td><a href='mailto:gregor@noczinski.eu'>gregor@noczinski.eu</a></td><td><a href='https://github.com/blaubaer'>github.com/blaubaer</a></td></tr>");
    body.append("</table>");

    body.append("</td>");
    body.append("</tr></table></body></html>");

    final JTextPane text = new JTextPane();
    text.setMargin(new Insets(0, 0, 0, 0));
    text.setContentType("text/html");
    text.setText(body.toString());
    text.setFont(new Font(DIALOG, PLAIN, 12));
    text.setBackground(new Color(255, 255, 255, 0));
    text.setEditable(false);
    text.addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == ACTIVATED && isDesktopSupported()) {
                final Desktop desktop = getDesktop();
                if (desktop.isSupported(BROWSE)) {
                    try {
                        desktop.browse(e.getURL().toURI());
                    } catch (IOException | URISyntaxException exception) {
                        LOG.error("Could not open " + e.getURL() + " because of an exception.", exception);
                    }
                } else {
                    LOG.error("Could not open " + e.getURL() + " because browse is not supported by desktop.");
                }
            }
            repaint();
        }
    });
    text.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            repaint();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            repaint();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            repaint();
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            repaint();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            repaint();
        }
    });
    add(text, new CC().spanX(2).growX().minWidth("10px"));
}

From source file:org.languagetool.gui.Tools.java

static void addHyperlinkListener(JTextPane pane) {
    pane.addHyperlinkListener(new HyperlinkListener() {
        @Override//from  www  .  j  av a  2 s. c om
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                Tools.openURL(e.getURL());
            }
        }
    });
}

From source file:org.nuclos.client.main.MainController.java

public void cmdShowAboutDialog() {
    try {/*from  w  w  w .  ja v a  2 s.c  om*/
        final MainFrameTab internalFrame = newMainFrameTab(null, "Info");
        String html = IOUtils.readFromTextStream(
                getClass().getClassLoader().getResourceAsStream("org/nuclos/client/help/about/about.html"),
                null);

        Pair<String, String> clientLogFile = StartUp.getLogFile();
        String logDir = "";
        String logFilename = clientLogFile.x;
        String logDatePattern = clientLogFile.y;
        try {
            // try to extract dir and filename...
            logDir = clientLogFile.x.substring(0, clientLogFile.x.lastIndexOf("/"));
            logFilename = clientLogFile.x.substring(clientLogFile.x.lastIndexOf("/") + 1)
                    + logDatePattern.replace("'", "");
        } catch (Exception ex) {
            // do nothing
        }

        HtmlPanel htmlPanel = new HtmlPanel(
                String.format(html, ApplicationProperties.getInstance().getCurrentVersion(), // %1$s
                        getUserName(), // %2$s
                        getNuclosServerName(), // %3$s
                        System.getProperty("java.version"), // %4$s
                        logDir, // %5$s
                        logFilename // %6$s
                ));
        htmlPanel.btnClose.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ev) {
                internalFrame.dispose();
            }
        });
        htmlPanel.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(HyperlinkEvent e) {
                if (e.getEventType() == EventType.ACTIVATED) {
                    try {
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (IOException e1) {
                        LOG.warn("cmdShowAboutDialog " + e1 + ": " + e1, e1);
                    } catch (URISyntaxException e1) {
                        LOG.warn("cmdShowAboutDialog " + e1 + ": " + e1, e1);
                    }
                }
            }
        });
        internalFrame.setLayeredComponent(htmlPanel);
        Main.getInstance().getMainFrame().getHomePane().add(internalFrame);
        internalFrame.setVisible(true);
    } catch (Exception e) {
        Errors.getInstance().showExceptionDialog(Main.getInstance().getMainFrame(), getSpringLocaleDelegate()
                .getMessage("MainController.26", "Die Infos k\u00f6nnen nicht angezeigt werden."), e);
    }
}

From source file:org.openpythia.aboutdialog.AboutController.java

public AboutController(JFrame owner) {
    view = new AboutView(owner);
    view.getEditorPaneAbout().setContentType("text/html");

    String aboutText = "";

    try {/* w w  w .  j a  v a  2 s.  c o  m*/
        InputStream inputStream = this.getClass().getResourceAsStream(ABOUT_HTML);
        aboutText = String.format(IOUtils.toString(inputStream), FileResourceUtility.getVersion());
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

    view.getEditorPaneAbout().setText(aboutText);

    view.getEditorPaneAbout().addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop.getDesktop().browse(evt.getURL().toURI());
                } catch (Exception e) {
                    // If we can't open the URL we just ignore it (no error
                    // message)
                }
            }
        }
    });

    view.getEditorPaneAbout().setCaretPosition(0);

    view.getBtnOK().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            view.dispose();
        }
    });

    view.getRootPane().setDefaultButton(view.getBtnOK());
    view.getBtnOK().requestFocus();

    view.setSize(600, 400);
    view.setVisible(true);
}

From source file:org.openpythia.dbconnection.MissingJDBCDriverController.java

private void prepareTextArea() {
    view.getEditorPaneMissingJDBCDriver().setContentType("text/html");

    String missingJDBCdriverText = "";

    try {/*w w w  .  j  av a2  s  .  c o m*/
        InputStream inputStream = this.getClass().getResourceAsStream(MISSING_JDBCDRIVER_HTML);
        missingJDBCdriverText = IOUtils.toString(inputStream);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

    view.getEditorPaneMissingJDBCDriver().setText(missingJDBCdriverText);

    view.getEditorPaneMissingJDBCDriver().addHyperlinkListener(new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    Desktop.getDesktop().browse(evt.getURL().toURI());
                } catch (Exception e) {
                    // If we can't open the URL - for what reason
                    // ever - we ignore it
                }
            }
        }
    });
}

From source file:org.uecide.About.java

public About(Editor e) {
    editor = e;/* w  ww  .  ja  v  a2s .  c  om*/
    frame = new JDialog(editor, JDialog.ModalityType.APPLICATION_MODAL);
    mainContainer = new JPanel();
    mainContainer.setLayout(new BorderLayout());
    frame.add(mainContainer);

    int imageWidth = 0;

    try {
        URL loc = About.class.getResource("/org/uecide/icons/about.png");
        image = ImageIO.read(loc);
        imageWidth = image.getWidth();
        JLabel picLabel = new JLabel(new ImageIcon(image));

        mainContainer.add(picLabel, BorderLayout.NORTH);
    } catch (Exception ex) {
        Base.error(ex);
    }

    infoScroll = new JScrollPane();
    infoScroll.setPreferredSize(new Dimension(imageWidth, 150));

    info = new JTextPane();
    info.setContentType("text/html");
    infoScroll.setViewportView(info);

    info.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    info.setEditable(false);
    info.setBackground(new Color(0, 0, 0));
    info.setForeground(new Color(0, 255, 0));
    Font f = info.getFont();

    info.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if (e.getDescription().equals("uecide://close")) {
                    frame.dispose();
                    return;
                }
                Base.openURL(e.getURL().toString());
            }
        }
    });

    HTMLEditorKit kit = new HTMLEditorKit();
    info.setEditorKit(kit);
    StyleSheet css = kit.getStyleSheet();

    css.addRule("body {color: #88ff88; font-family: Arial,Helvetica,Sans-Serif;}");
    css.addRule("a {color: #88ffff;}");
    css.addRule("a:visited {color: #00aaaa;}");
    Document doc = kit.createDefaultDocument();
    info.setDocument(doc);

    info.setText(generateInfoData());

    info.setCaretPosition(0);
    mainContainer.add(infoScroll, BorderLayout.CENTER);

    frame.pack();

    Dimension mySize = frame.getSize();

    Dimension eSize = editor.getSize();
    Point ePos = editor.getLocation();
    frame.setLocation(new Point(ePos.x + (eSize.width / 2) - mySize.width / 2,
            ePos.y + (eSize.height / 2) - mySize.height / 2));

    frame.addKeyListener(new KeyListener() {
        public void keyTyped(KeyEvent ev) {
        }

        public void keyPressed(KeyEvent ev) {
            if (ev.getKeyCode() == KeyEvent.VK_ESCAPE) {
                frame.dispose();
            }
        }

        public void keyReleased(KeyEvent ev) {
        }
    });

    frame.setVisible(true);
}

From source file:pl.kotcrab.arget.gui.MainWindow.java

private void createAndShowGUI() {
    setTitle(App.APP_NAME);//from w  ww  .j ava 2s .com
    setBounds(100, 100, 800, 700);
    setMinimumSize(new Dimension(500, 250));
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setIconImage(App.loadImage("/data/icon/icon.png"));

    sessionWindowManager = new SessionWindowManager(this);

    if (profile.mainWindowBounds != null
            && GraphicsUtils.isRectangleDisplayableOnScreen(profile.mainWindowBounds))
        setBounds(profile.mainWindowBounds);

    createMenuBars();

    contactsPanel = new ContactsPanel(profile, this);

    statusPane = new JTextPane();
    statusPane.setBorder(new EmptyBorder(1, 3, 2, 0));
    statusPane.setContentType("text/html");
    statusPane.setBackground(null);
    statusPane.setHighlighter(null);
    statusPane.setEditable(false);
    statusPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
    statusPane.setFont(new Font("Tahoma", Font.PLAIN, 13));

    statusPane.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
                String desc = e.getDescription();

                if (desc.startsWith("version-mismatch")) {
                    desc = desc.substring(desc.indexOf("://") + 3);
                    String[] versionInfo = desc.split("!");
                    new VersionMismatchDialog(MainWindow.instance, versionInfo[0],
                            Integer.valueOf(versionInfo[1]));
                }
            }
        }
    });

    JPanel bottomPanel = new JPanel(new BorderLayout(0, 0));

    getContentPane().add(bottomPanel, BorderLayout.SOUTH);

    scrollLockToggle = new WebToggleButton();
    scrollLockToggle.setToolTipText("Scroll lock");
    scrollLockToggle.setRolloverDecoratedOnly(true);
    scrollLockToggle.setDrawFocus(false);
    scrollLockToggle.setIcon(App.loadImageIcon("/data/scrolllock.png"));
    scrollLockToggle.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            postScrollLockUpdate();
        }
    });

    bottomPanel.add(statusPane);
    bottomPanel.add(scrollLockToggle, BorderLayout.EAST);

    splitPane = new JSplitPane();
    splitPane.setBorder(new BottomSplitPaneBorder());
    splitPane.setResizeWeight(0);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);
    getContentPane().add(splitPane, BorderLayout.CENTER);

    homePanel = new HomePanel(profile.fileName);
    logPanel = new LoggerPanel();

    errorStatusPanel = new ErrorStatusPanel();

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(contactsPanel, BorderLayout.CENTER);
    leftPanel.add(errorStatusPanel, BorderLayout.SOUTH);

    splitPane.setLeftComponent(leftPanel);
    splitPane.setRightComponent(null);
    setCenterScreenTo(homePanel);

    addWindowFocusListener(new WindowAdapter() {
        @Override
        public void windowGainedFocus(WindowEvent e) {
            instance.validate();
            instance.revalidate();
            instance.repaint();

            getCenterScreen().onShow();
        }

        @Override
        public void windowLostFocus(WindowEvent e) {
            getCenterScreen().onHide();
        }

    });

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            ExitCleaner.forceExit();
        }
    });

    setVisible(true);
}