Java Code Examples for javax.swing.event.HyperlinkEvent#EventType

The following examples show how to use javax.swing.event.HyperlinkEvent#EventType . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HyperlinkEventProcessor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    url = hyperlinkEvent.getURL();
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    if (type == HyperlinkEvent.EventType.ENTERED) {
      isInsideHyperlink = true;
      pane.setToolTipText(getURLExternalForm()); // #176141
    }
    else if (type == HyperlinkEvent.EventType.ACTIVATED) {
      isInsideHyperlink = false;
      pane.setToolTipText(null);
    }
    else if (type == HyperlinkEvent.EventType.EXITED) {
      isInsideHyperlink = false;
      pane.setToolTipText(null);
    }
    else {
      Installer.log.log(Level.SEVERE, "Unknown hyperlinkEvent: " +
                                       hyperlinkEvent);
    }
}
 
Example 2
Source File: ColopediaPanel.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
    HyperlinkEvent.EventType type = e.getEventType();
    if (type == HyperlinkEvent.EventType.ACTIVATED) {
        String[] path = e.getURL().getPath().split("/");
        if (null != path[1]) {
            switch (path[1]) {
            case FreeColObject.ID_ATTRIBUTE_TAG:
                select(path[2]);
                break;
            case "action":
                getFreeColClient().getActionManager()
                    .getFreeColAction(path[2]).actionPerformed(null);
                break;
            default:
                break;
            }
        }
    }
}
 
Example 3
Source File: GuiActions.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate (HyperlinkEvent event)
{
    HyperlinkEvent.EventType type = event.getEventType();
    final URL url = event.getURL();

    if (type == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            //System.out.println("Activated URL " + url);
            URI uri = new URI(url.toString());
            WebBrowser.getBrowser().launch(uri);
        } catch (URISyntaxException ex) {
            logger.warn("Illegal URI " + url, ex);
        }
    }
}
 
Example 4
Source File: HTMLPanel.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent event) {
    JEditorPane descriptionPane = (JEditorPane) event.getSource();
    HyperlinkEvent.EventType type = event.getEventType();
    if (type == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            DemoUtilities.browse(event.getURL().toURI());
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e);
        }

    } else if (type == HyperlinkEvent.EventType.ENTERED) {
        defaultCursor = descriptionPane.getCursor();
        descriptionPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    } else if (type == HyperlinkEvent.EventType.EXITED) {
        descriptionPane.setCursor(defaultCursor);
    }
}
 
Example 5
Source File: HTMLPanel.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent event) {
    JEditorPane descriptionPane = (JEditorPane) event.getSource();
    HyperlinkEvent.EventType type = event.getEventType();
    if (type == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            DemoUtilities.browse(event.getURL().toURI());
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e);
        }

    } else if (type == HyperlinkEvent.EventType.ENTERED) {
        defaultCursor = descriptionPane.getCursor();
        descriptionPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    } else if (type == HyperlinkEvent.EventType.EXITED) {
        descriptionPane.setCursor(defaultCursor);
    }
}
 
Example 6
Source File: AboutBox.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
private void jEditorPane1HyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {//GEN-FIRST:event_jEditorPane1HyperlinkUpdate
    // retrieve the event type, e.g. if a link was clicked by the user
    HyperlinkEvent.EventType typ = evt.getEventType();
    // get the description, to check whether we have a file or a hyperlink to a website
    String linktype = evt.getDescription();
    // if the link was clicked, proceed
    if (typ==HyperlinkEvent.EventType.ACTIVATED) {
        try {
            // if the string contains "http://", we assume we have a webpage
            if (linktype.contains("http://") || linktype.contains("https://")) {
                Desktop.getDesktop().browse(new URI(evt.getURL().toString()));
            }
            // if the string contains "http://", we assume we have a webpage
            else if (linktype.contains("mailto:")) {
                Desktop.getDesktop().mail(new URI(evt.getURL().toString()));
            }
            else if (linktype.startsWith("#")) {
                jEditorPane1.scrollToReference(linktype.substring(1));
            }
        }
        catch (IOException | URISyntaxException e) {
            Constants.zknlogger.log(Level.WARNING,e.getLocalizedMessage());
        }
    }
}
 
Example 7
Source File: GuiActions.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate (HyperlinkEvent event)
{
    HyperlinkEvent.EventType type = event.getEventType();
    final URL url = event.getURL();

    if (type == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            //System.out.println("Activated URL " + url);
            URI uri = new URI(url.toString());
            WebBrowser.getBrowser()
                    .launch(uri);
        } catch (URISyntaxException ex) {
            logger.warn("Illegal URI " + url, ex);
        }
    }
}
 
Example 8
Source File: HTMLPanel.java    From Darcula with Apache License 2.0 6 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent event) {
    JEditorPane descriptionPane = (JEditorPane) event.getSource();
    HyperlinkEvent.EventType type = event.getEventType();
    if (type == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            DemoUtilities.browse(event.getURL().toURI());
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(e);
        }

    } else if (type == HyperlinkEvent.EventType.ENTERED) {
        defaultCursor = descriptionPane.getCursor();
        descriptionPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    } else if (type == HyperlinkEvent.EventType.EXITED) {
        descriptionPane.setCursor(defaultCursor);
    }
}
 
Example 9
Source File: ActivatedHyperlinkListener.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
    public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
        HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
        final URL url = hyperlinkEvent.getURL();
        if (type == HyperlinkEvent.EventType.ENTERED) {
//            Message message = new Message(url.toString(), true);
//            message.setShowInMessagesTab(false);
//            MessageManager.INSTANCE.addMessage(message);
            if (browser.isLoading()) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    }
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                    }
                });
            }
        } else if (type == HyperlinkEvent.EventType.EXITED) {
//            Message message = new Message(SPACER, true);
//            message.setShowInMessagesTab(false);
//            MessageManager.INSTANCE.addMessage(message);
            if (browser.isLoading()) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    }
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    }
                });
            }
        } else if (type == HyperlinkEvent.EventType.ACTIVATED) {

        }
    }
 
Example 10
Source File: SearchResultsFrame.java    From Zettelkasten with GNU General Public License v3.0 4 votes vote down vote up
private void openAttachment(javax.swing.event.HyperlinkEvent evt) {
    // retrieve the event type, e.g. if a link was clicked by the user
    HyperlinkEvent.EventType typ = evt.getEventType();
    // get the description, to check whether we have a file or a hyperlink to a website
    String linktype = evt.getDescription();
    // if the link was clicked, proceed
    if (typ==HyperlinkEvent.EventType.ACTIVATED) {
        // call method that handles the hyperlink-click
        String returnValue = Tools.openHyperlink(linktype, this, Constants.FRAME_SEARCH, dataObj, bibtexObj, settingsObj, jEditorPaneSearchEntry, Integer.parseInt(jTableResults.getValueAt(jTableResults.getSelectedRow(), 0).toString()));
        // check whether we have a return value. this might be the case either when the user clicked on
        // a footenote, or on the rating-stars
        if (returnValue!=null) {
            // here we have a reference to another entry
            if (returnValue.startsWith("#z_") || returnValue.startsWith("#cr_")) {
                // show entry
                mainframe.showEntry(dataObj.getCurrentZettelPos());
            }
            // edit cross references
            else if (returnValue.equalsIgnoreCase("#crt")) {
                mainframe.editManualLinks();
            }
            // check whether a rating was requested
            else if (returnValue.startsWith("#rateentry")) {
                try {
                    // retrieve entry-number
                    int entrynr = Integer.parseInt(linktype.substring(10));
                    // open rating-dialog
                    if (null == rateEntryDlg) {
                        rateEntryDlg = new CRateEntry(this,dataObj,entrynr);
                        rateEntryDlg.setLocationRelativeTo(this);
                    }
                    ZettelkastenApp.getApplication().show(rateEntryDlg);
                    // check whether dialog was cancelled or not
                    if (!rateEntryDlg.isCancelled()) {
                        // update display
                        displayZettelContent(entrynr, null);
                    }
                    rateEntryDlg.dispose();
                    rateEntryDlg=null;
                    // try to motivate garbage collector
                    System.gc();
                }
                catch (NumberFormatException ex) {
                    // log error
                    Constants.zknlogger.log(Level.WARNING,ex.getLocalizedMessage());
                    Constants.zknlogger.log(Level.WARNING, "Could not rate entry. Link-text was {0}", linktype);
                }

            }
        }
    }
}
 
Example 11
Source File: ActivatedHyperlinkListener.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
    public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
        HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
        final URL url = hyperlinkEvent.getURL();
        if (type == HyperlinkEvent.EventType.ENTERED) {
//            Message message = new Message(url.toString(), true);
//            message.setShowInMessagesTab(false);
//            MessageManager.INSTANCE.addMessage(message);
            if (browser.isLoading()) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    }
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                    }
                });
            }
        } else if (type == HyperlinkEvent.EventType.EXITED) {
//            Message message = new Message(SPACER, true);
//            message.setShowInMessagesTab(false);
//            MessageManager.INSTANCE.addMessage(message);
            if (browser.isLoading()) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    }
                });
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        browser.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                    }
                });
            }
        } else if (type == HyperlinkEvent.EventType.ACTIVATED) {

        }
    }