Example usage for javax.swing.event HyperlinkEvent getEventType

List of usage examples for javax.swing.event HyperlinkEvent getEventType

Introduction

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

Prototype

public EventType getEventType() 

Source Link

Document

Gets the type of event.

Usage

From source file:esmska.gui.AboutFrame.java

private void licenseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_licenseButtonActionPerformed
    //show licence
    try {/*from ww  w  .  j av  a2s. c  o m*/
        logger.fine("Showing license...");
        String license = IOUtils.toString(getClass().getResourceAsStream(RES + "license.txt"), "UTF-8");
        final String agpl = IOUtils.toString(getClass().getResourceAsStream(RES + "gnu-agpl.txt"), "UTF-8");
        license = MiscUtils.escapeHtml(license);
        license = license.replaceAll("GNU Affero General Public License",
                "<a href=\"agpl\">GNU Affero General Public License</a>");

        final JTextPane tp = new JTextPane();
        tp.setContentType("text/html; charset=UTF-8");
        tp.setText("<html><pre>" + license + "</pre></html>");
        tp.setEditable(false);
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        tp.setPreferredSize(new Dimension((int) d.getWidth() / 2, (int) d.getHeight() / 2)); //reasonable size
        tp.setCaretPosition(0);
        //make links clickable
        tp.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(final HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    logger.fine("Showing GNU AGPL...");
                    tp.setText(null);
                    tp.setContentType("text/plain");
                    tp.setText(agpl);
                    tp.setCaretPosition(0);
                }
            }
        });

        String option = l10n.getString("AboutFrame.Acknowledge");
        JOptionPane op = new JOptionPane(new JScrollPane(tp), JOptionPane.INFORMATION_MESSAGE,
                JOptionPane.DEFAULT_OPTION, null, new Object[] { option }, option);
        JDialog dialog = op.createDialog(this, l10n.getString("AboutFrame.License"));
        dialog.setResizable(true);
        dialog.pack();
        dialog.setVisible(true);
    } catch (IOException ex) {
        logger.log(Level.WARNING, "Could not show license", ex);
    }
}

From source file:esmska.gui.AboutFrame.java

private void creditsButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_creditsButtonActionPerformed
    //show credits
    try {//from  w  ww.j  a  v a  2 s  .c om
        logger.fine("Showing credits...");
        String credits = IOUtils.toString(getClass().getResourceAsStream(RES + "credits.html"), "UTF-8");
        String translators = l10n.getString("Translators");
        if ("translator-credits".equals(translators)) {
            //there are no translators mentioned
            translators = "";
        } else {
            translators = translators.replaceAll("\n", "<br>\n").replaceAll("\n  ", "\n&nbsp;&nbsp;");
            //add hyperlinks to the Launchpad URLs
            translators = translators.replaceAll("(https://[^<]*)", "<a href=\"$1\">$1</a>");
        }

        String document = MessageFormat.format(credits, l10n.getString("Credits.authors"),
                l10n.getString("Credits.contributors"), l10n.getString("Credits.graphics"),
                l10n.getString("Credits.sponsors"), l10n.getString("Credits.translators"), translators,
                Links.DONATORS, l10n.getString("Credits.moreDonators"),
                MessageFormat.format(l10n.getString("Credits.packagers"), Links.DOWNLOAD));

        JTextPane tp = new JTextPane();
        tp.setContentType("text/html; charset=UTF-8");
        tp.setText(document);
        tp.setEditable(false);
        tp.setPreferredSize(new Dimension(450, 400));
        tp.setCaretPosition(0);
        //make links clickable
        tp.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(final HyperlinkEvent e) {
                if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && Desktop.isDesktopSupported()) {
                    try {
                        logger.fine("Browsing URL: " + e.getURL());
                        Desktop.getDesktop().browse(e.getURL().toURI());
                    } catch (Exception ex) {
                        logger.log(Level.SEVERE, "Can't browse hyperlink: " + e.getURL(), ex);
                    }
                }
            }
        });

        String option = l10n.getString("AboutFrame.Thank_you");
        JOptionPane op = new JOptionPane(new JScrollPane(tp), JOptionPane.INFORMATION_MESSAGE,
                JOptionPane.DEFAULT_OPTION, null, new Object[] { option }, option);
        JDialog dialog = op.createDialog(this, l10n.getString("AboutFrame.Credits"));
        dialog.setResizable(true);
        dialog.pack();
        dialog.setVisible(true);
    } catch (IOException e) {
        logger.log(Level.WARNING, "Could not show credits", e);
    }
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Called when something is happened on a hyperlink in the page browser.
 * This is the {@code HyperlinkListener} method.
 *//*from ww  w.j a va 2 s .  c o m*/
public void hyperlinkUpdate(HyperlinkEvent e) {
    URL url = e.getURL();
    EventType type = e.getEventType();

    if (type == EventType.ENTERED) {
        messageArea.setText("Go to " + url);
    } else if (type == EventType.EXITED) {
        messageArea.setText(defaultMessage);
    } else if (type == EventType.ACTIVATED) {
        setPage(url);
        messageArea.setText(defaultMessage);
    }
}

From source file:ja.lingo.application.gui.main.settings.dictionaries.add.AddPanel.java

public AddPanel(JDialog parentDialog, IEngine engine) {
    Arguments.assertNotNull("parentDialog", parentDialog);
    Arguments.assertNotNull("engine", engine);

    this.parentDialog = parentDialog;
    this.engine = engine;

    fileChooser = new FileChooser();

    encodingComboBox = new JComboBox();
    encodingAutoComboBox = new JComboBox(new String[] { resources.text("encoding_auto") });
    encodingAutoComboBox.setEnabled(false);

    encodingCardPanel = new CardPanel();
    encodingCardPanel.add(encodingComboBox);
    encodingCardPanel.add(encodingAutoComboBox);

    readerList = Components//ww  w .  ja  v  a2  s .  c  om
            .list(new StaticListModel<IDictionaryReader>(new ReaderLabelBuilder(), engine.getReaders()));
    readerList.setSelectedIndex(0);

    editorPane = Components.editorPane();
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                Browser.openUrl(e.getURL().toExternalForm());
            }
        }
    });

    continueButton = Buttons.continue1();
    continueButton.setDefaultCapable(true);

    closeButton = Buttons.cancel();

    JPanel buttonPanel = new JPanel(new GridLayout(1, 2, GAP5, GAP5));
    buttonPanel.add(continueButton);
    buttonPanel.add(closeButton);

    JPanel listReaderPanel = new JPanel(new BorderLayout());
    listReaderPanel.add(resources.label("reader"), BorderLayout.NORTH);
    listReaderPanel.add(new JScrollPane(readerList), BorderLayout.CENTER);

    readerList.setPreferredSize(new Dimension(50, 50));
    listReaderPanel.setPreferredSize(new Dimension(100, 100));

    JPanel descriptionReaderPanel = new JPanel(new BorderLayout());
    descriptionReaderPanel.add(resources.label("readerDescription"), BorderLayout.NORTH);
    descriptionReaderPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listReaderPanel, descriptionReaderPanel);
    splitPane.setContinuousLayout(true);
    splitPane.setDividerLocation(130);

    gui = new JPanel(new TableLayout(new double[][] { { TableLayout.PREFERRED, GAP5, TableLayout.FILL },
            { TableLayout.FILL, // 0: reader panel
                    GAP5, TableLayout.PREFERRED, // 2: file
                    GAP5, TableLayout.PREFERRED, // 4: encoding
                    GAP5 * 2, TableLayout.PREFERRED // 6: button panel
            } }));

    gui.add(splitPane, "0, 0, 2, 0");

    gui.add(resources.label("file"), "0, 2");
    gui.add(fileChooser.getGui(), "2, 2");

    gui.add(resources.label("encoding"), "0, 4");
    gui.add(encodingCardPanel.getGui(), "2, 4");

    gui.add(buttonPanel, "0, 6, 2, 6, right, center");

    Gaps.applyBorder7(gui);

    ActionBinder.bind(this);

    if (encodingComboBox.getModel().getSize() > 0) {
        encodingComboBox.setSelectedIndex(0);
    }

    // filters
    for (IDictionaryReader reader : engine.getReaders()) {
        fileChooser.getChooser().addChoosableFileFilter(reader.getFileFilter());
    }

    onReaderSelected();
    onFileFieldEdited();
}

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DViewExtensions.java

@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        try {/*from   w  w  w  .j av  a2  s  . c o m*/
            URL url = e.getURL();
            if (url != null) {
                if (url.getPath().endsWith(".cer") || url.getPath().endsWith(".crt")) {
                    X509Certificate[] certs = downloadCert(url);
                    if (certs != null && certs.length > 0) {
                        DViewCertificate dViewCertificate = new DViewCertificate(this, MessageFormat
                                .format(res.getString("DViewExtensions.ViewCert.Title"), url.toString()), certs,
                                null, DViewCertificate.NONE);
                        dViewCertificate.setLocationRelativeTo(this);
                        dViewCertificate.setVisible(true);
                    }
                } else if (url.getPath().endsWith(".crl")) {
                    X509CRL crl = downloadCrl(url);
                    if (crl != null) {
                        DViewCrl dViewCrl = new DViewCrl(this, MessageFormat
                                .format(res.getString("DViewExtensions.ViewCrl.Title"), url.toString()),
                                ModalityType.DOCUMENT_MODAL, crl);
                        dViewCrl.setLocationRelativeTo(this);
                        dViewCrl.setVisible(true);
                    }
                } else {
                    Desktop.getDesktop().browse(url.toURI());
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:jamel.gui.JamelWindow.java

/**
 * Returns the info panel./*from w w  w .jav a2s .  co  m*/
 * @return the info panel.
 */
private Component getInfoPanel() {
    final JEditorPane editorPane = new JEditorPane("text/html", "<center>" + this.infoString + "</center>");
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
                try {
                    java.awt.Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(null,
                            "<html>" + "Error.<br>" + "Cause: " + e.toString() + ".<br>"
                                    + "Please see server.log for more details.</html>",
                            "Warning", JOptionPane.WARNING_MESSAGE);
                }
        }
    });
    editorPane.setEditable(false);
    final JScrollPane scrollPane = new JScrollPane(editorPane);
    return scrollPane;
}

From source file:net.pms.newgui.LanguageSelection.java

private JComponent buildComponent() {
    // UIManager manages to get the background color wrong for text
    // components on OS X, so we apply the color manually
    Color backgroundColor = UIManager.getColor("Panel.background");
    rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.PAGE_AXIS));

    // It needs to be something in the title text, or the size calculation for the border will be wrong.
    selectionPanelBorder.setTitle(" ");
    selectionPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5),
            BorderFactory.createCompoundBorder(selectionPanelBorder,
                    BorderFactory.createEmptyBorder(10, 5, 10, 5))));
    selectionPanel.setLayout(new BoxLayout(selectionPanel, BoxLayout.PAGE_AXIS));
    descriptionText.setEditable(false);/*from   w  w  w . j a  va  2  s .c  o m*/
    descriptionText.setBackground(backgroundColor);
    descriptionText.setFocusable(false);
    descriptionText.setLineWrap(true);
    descriptionText.setWrapStyleWord(true);
    descriptionText.setBorder(BorderFactory.createEmptyBorder(5, 15, 10, 15));
    selectionPanel.add(descriptionText);

    jLanguage = new JComboBox<>(keyedModel);
    jLanguage.setEditable(false);
    jLanguage.setPreferredSize(new Dimension(50, jLanguage.getPreferredSize().height));
    jLanguage.addActionListener(new LanguageComboBoxActionListener());
    languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.PAGE_AXIS));
    languagePanel.setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
    languagePanel.add(jLanguage);
    selectionPanel.add(languagePanel);

    warningText.setEditable(false);
    warningText.setFocusable(false);
    warningText.setBackground(backgroundColor);
    warningText.setFont(warningText.getFont().deriveFont(Font.BOLD));
    warningText.setLineWrap(true);
    warningText.setWrapStyleWord(true);
    warningText.setBorder(BorderFactory.createEmptyBorder(5, 15, 0, 15));
    selectionPanel.add(warningText);

    // It needs to be something in the title text, or the size calculation for the border will be wrong.
    infoTextBorder.setTitle(" ");
    infoText.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory
                    .createCompoundBorder(infoTextBorder, BorderFactory.createEmptyBorder(15, 20, 20, 20))));
    infoText.setEditable(false);
    infoText.setFocusable(false);
    infoText.setBackground(backgroundColor);
    infoText.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);

    // This exercise is to avoid using the default shared StyleSheet with padding
    CustomHTMLEditorKit editorKit = new CustomHTMLEditorKit();
    StyleSheet styleSheet = new StyleSheet();
    styleSheet.addRule("a { color: #0000EE; text-decoration:underline; }");
    editorKit.setStyleSheet(styleSheet);
    infoText.setEditorKit(editorKit);
    infoText.addHyperlinkListener(new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                boolean error = false;
                if (Desktop.isDesktopSupported()) {
                    try {
                        Desktop.getDesktop().browse(new URI(e.getDescription()));
                    } catch (IOException | URISyntaxException ex) {
                        LOGGER.error("Language selection failed to open translation page hyperlink: ",
                                ex.getMessage());
                        LOGGER.trace("", ex);
                        error = true;
                    }
                } else {
                    LOGGER.warn("Desktop is not supported, the clicked translation page link can't be opened");
                    error = true;
                }
                if (error) {
                    JOptionPane.showOptionDialog(dialog,
                            String.format(buildString("LanguageSelection.6", true), PMS.CROWDIN_LINK),
                            buildString("Dialog.Error"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE,
                            null, null, null);
                }
            }
        }

    });

    rootPanel.add(selectionPanel);
    rootPanel.add(infoText);

    applyButton.addActionListener(new ApplyButtonActionListener());
    applyButton.setActionCommand("apply");

    selectButton.addActionListener(new SelectButtonActionListener());
    selectButton.setActionCommand("select");

    return rootPanel;

}

From source file:com.enderville.enderinstaller.ui.Installer.java

@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
    if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
        return;//from w  w  w. j a  va2s .c  o m
    }
    SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() {

        @Override
        protected Object doInBackground() throws Exception {
            try {
                String url = e.getURL().toExternalForm();
                Desktop.getDesktop().browse(URI.create(url));
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    };
    worker.execute();
}

From source file:dk.dma.epd.common.prototype.gui.notification.MsiNmNotificationPanel.java

/**
 * {@inheritDoc}//from   ww w  .  j a v a  2s  .  co  m
 */
@Override
public void hyperlinkUpdate(HyperlinkEvent hle) {
    if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
        try {
            URL url = hle.getURL();
            if (url.getHost().equals("msinm") && url.getPath().length() > 1) {
                String msinmId = url.getPath().substring(1);

                for (MsiNmNotification notification : notificationPanel.getNotifications()) {
                    if (notification.getSeriesId().equals(msinmId)) {
                        EPD.getInstance().getNotificationCenter().openNotification(NotificationType.MSI_NM,
                                notification.getId(), false);
                        return;
                    }
                    Toolkit.getDefaultToolkit().beep();
                }
            } else {
                Desktop desktop = Desktop.getDesktop();
                desktop.browse(new URI(hle.getURL().toString()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}

From source file:fxts.stations.ui.help.HelpPane.java

/**
 * Inits all components./*  w w w . ja v  a2s.  co  m*/
 */
private void initComponents() {
    //creates history
    mHistory = new HelpContentHistory();
    //Create the text area for contents
    mTabbedPane = new JTabbedPane();

    //creates content tree
    mContentTree = new ContentTree("fxts/stations/trader/resources/help/contents.xml");
    mContentTree.addListener(this);

    //Create the scroll pane and add the tree to it.
    JScrollPane treeView = new JScrollPane(mContentTree.getTree());
    mTabbedPane.addTab(mResMan.getString("IDS_HELP_CONTENTS", "Contents"), treeView);

    //xxx workaround for bug #6424509, memory leak
    JEditorPane.registerEditorKitForContentType("text/html", WeakHTMLEditorKit.class.getName());
    //creates the text area for the showing of the help.
    mHtmlPage = new JEditorPane();
    mHtmlPage.setEditable(false);
    mHtmlPage.putClientProperty("charset", "UTF-16");
    mHtmlPage.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent aEvent) {
            if (aEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    onSelectContentByHyperlink(aEvent.getURL());
                    mHtmlPage.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
                } catch (Exception e) {
                    mLogger.error("Hiperlink not processed!");
                    e.printStackTrace();
                }
            }
        }
    });
    JScrollPane scrollPane = new JScrollPane(mHtmlPage);

    //creates a split pane for the change log and the text area.
    mSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mTabbedPane, scrollPane);
    mSplitPane.setOneTouchExpandable(true);

    //Creates the toolbar area.
    JToolBar toolbar = UIManager.getInst().createToolBar();
    toolbar.setFloatable(false);

    //creates label with left arrow
    UIManager uiMan = UIManager.getInst();
    mBackButton = uiMan.createButton(null, "ID_HELP_LEFT_ARROW", "ID_HELP_LEFT_ARROW_DESC",
            "ID_HELP_LEFT_ARROW_DESC");
    mBackButton.setEnabled(false);
    mBackButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            if (mHistory.hasBackStep()) {
                mIsHistorycalStep = true;
                onSelectContent(mHistory.back());
                mBackButton.setEnabled(mHistory.hasBackStep());
                mForwardButton.setEnabled(mHistory.hasForwardStep());
            }
        }
    });
    toolbar.add(mBackButton);

    //creates label with right arrow
    mForwardButton = uiMan.createButton(null, "ID_HELP_RIGHT_ARROW", "ID_HELP_RIGHT_ARROW_DESC",
            "ID_HELP_RIGHT_ARROW_DESC");
    mForwardButton.setEnabled(false);
    mForwardButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            if (mHistory.hasForwardStep()) {
                mIsHistorycalStep = true;
                onSelectContent(mHistory.forward());
                mBackButton.setEnabled(mHistory.hasBackStep());
                mForwardButton.setEnabled(mHistory.hasForwardStep());
            }
        }
    });
    toolbar.add(mForwardButton);

    //creates label with up arrow
    mUpButton = uiMan.createButton(null, "ID_HELP_UP_ARROW", "ID_HELP_UP_ARROW_DESC", "ID_HELP_UP_ARROW_DESC");
    mUpButton.setEnabled(mContentTree.getIterator().hasPrevious());
    mUpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            mContentsBrowsing = true;
            onSelectContent(mContentTree.getIterator().previous());
            mUpButton.setEnabled(mContentTree.getIterator().hasPrevious());
            mDownButton.setEnabled(mContentTree.getIterator().hasNext());
        }
    });
    toolbar.add(mUpButton);

    //creates label with down arrow
    mDownButton = uiMan.createButton(null, "ID_HELP_DOWN_ARROW", "ID_HELP_DOWN_ARROW_DESC",
            "ID_HELP_DOWN_ARROW_DESC");
    mDownButton.setEnabled(mContentTree.getIterator().hasNext());
    mDownButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            mContentsBrowsing = true;
            onSelectContent(mContentTree.getIterator().next());
            mUpButton.setEnabled(mContentTree.getIterator().hasPrevious());
            mDownButton.setEnabled(mContentTree.getIterator().hasNext());
        }
    });
    toolbar.add(mDownButton);

    //sets layout
    setLayout(new BorderLayout());

    //add the components to the frame.
    add(mSplitPane, BorderLayout.CENTER);
    add(toolbar, BorderLayout.NORTH);

    //sets first page
    onSelectContent(mContentTree.getIterator().toBegin());
}