Example usage for javax.swing.event HyperlinkEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent evt) {
    if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        JEditorPane pane = (JEditorPane) evt.getSource();
        try {//from w w  w .j a  v a2s  .  co  m
            // Show the new page in the editor pane.
            pane.setPage(evt.getURL());
        } catch (IOException e) {
        }
    }
}

From source file:util.ui.UiUtilities.java

/**
 * Creates a Html EditorPane that holds a HTML-Help Text
 *
 * Links will be displayed and are clickable
 *
 * @param html//  w ww .  j  a v a2s . co m
 *          HTML-Text to display
 * @param background The color for the background.
 * @return EditorPane that holds a Help Text
 * @since 2.7.2
 */
public static JEditorPane createHtmlHelpTextArea(String html, Color background) {
    return createHtmlHelpTextArea(html, new HyperlinkListener() {
        private String mTooltip;

        public void hyperlinkUpdate(HyperlinkEvent evt) {
            JEditorPane pane = (JEditorPane) evt.getSource();
            if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                mTooltip = pane.getToolTipText();
                pane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                if (evt.getURL() != null) {
                    pane.setToolTipText(evt.getURL().toExternalForm());
                }
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(Cursor.getDefaultCursor());
                pane.setToolTipText(mTooltip);
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                URL url = evt.getURL();
                if (url != null) {
                    Launch.openURL(url.toString());
                }
            }
        }
    }, background);
}