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:FileTableHTML.java

public static void main(String[] args) throws IOException {
    // Get the name of the directory to display
    String dirname = (args.length > 0) ? args[0] : System.getProperty("user.home");

    // Create something to display it in.
    final JEditorPane editor = new JEditorPane();
    editor.setEditable(false); // we're browsing not editing
    editor.setContentType("text/html"); // must specify HTML text
    editor.setText(makeHTMLTable(dirname)); // specify the text to display

    // Set up the JEditorPane to handle clicks on hyperlinks
    editor.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            // Handle clicks; ignore mouseovers and other link-related events
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                // Get the HREF of the link and display it.
                editor.setText(makeHTMLTable(e.getDescription()));
            }//from  w  w w. j  a v  a2s  .c  o m
        }
    });

    // Put the JEditorPane in a scrolling window and display it.
    JFrame frame = new JFrame("FileTableHTML");
    frame.getContentPane().add(new JScrollPane(editor));
    frame.setSize(650, 500);
    frame.setVisible(true);
}

From source file:Main.java

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

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent he) {
    HyperlinkEvent.EventType type = he.getEventType();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println(he.getURL().toString());
    } else if (type == HyperlinkEvent.EventType.EXITED) {
        System.out.println("exit");
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        if (he instanceof HTMLFrameHyperlinkEvent) {
            HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) he;
            HTMLDocument doc = (HTMLDocument) pane.getDocument();
            doc.processHTMLFrameHyperlinkEvent(evt);
        } else {/*from   www .j a v a 2s . com*/
            try {
                pane.setPage(he.getURL());
                System.out.println(he.getURL().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent he) {
    HyperlinkEvent.EventType type = he.getEventType();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println(he.getURL().toString());
    } else if (type == HyperlinkEvent.EventType.EXITED) {
        System.out.println("Exited");
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        if (he instanceof HTMLFrameHyperlinkEvent) {
            HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) he;
            HTMLDocument doc = (HTMLDocument) pane.getDocument();
            doc.processHTMLFrameHyperlinkEvent(evt);
        } else {//  w  w w  . java2s . c om
            try {
                pane.setPage(he.getURL());
                System.out.println(he.getURL().toString());
            } catch (FileNotFoundException fnfe) {
                pane.setText("Could not open file: <tt>" + he.getURL() + "</tt>.<hr>");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:WebBrowserBasedOnJEditorPane.java

public void hyperlinkUpdate(HyperlinkEvent hle) {
    HyperlinkEvent.EventType evtype = hle.getEventType();
    if (evtype == HyperlinkEvent.EventType.ENTERED)
        lblStatus.setText(hle.getURL().toString());
    else if (evtype == HyperlinkEvent.EventType.EXITED)
        lblStatus.setText(" ");
}

From source file:Main.java

private Box getEditPaneBox() {
    editorPane.setEditable(false);//w  w  w.  j  a va 2s.  c  o m
    Box editorBox = Box.createHorizontalBox();
    editorBox.add(new JScrollPane(editorPane));

    editorPane.addHyperlinkListener((HyperlinkEvent event) -> {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            go(event.getURL());
        } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) {
            System.out.println("click this link");
        } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) {
            System.out.println("Ready");
        }
    });

    editorPane.addPropertyChangeListener((PropertyChangeEvent e) -> {
        String propertyName = e.getPropertyName();
        if (propertyName.equalsIgnoreCase("page")) {
            URL url = editorPane.getPage();
            System.out.println(url.toExternalForm());
        }
    });

    return editorBox;
}

From source file:ActivatedHyperlinkListener.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");

        Document doc = editorPane.getDocument();
        try {//from w w  w.  j a va 2s.  c o  m
            editorPane.setPage(url);
        } catch (IOException ioException) {
            System.out.println("Error following link, Invalid link");
            editorPane.setDocument(doc);
        }
    }
}

From source file:Main.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");
        Document doc = editorPane.getDocument();
        try {//from ww  w .j a va 2 s.c  o m
            editorPane.setPage(url);
        } catch (IOException ioException) {
            System.out.println("Error following link");
            editorPane.setDocument(doc);
        }
    }
}

From source file:EditorPaneSample.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");
        Runnable runner = new Runnable() {
            public void run() {
                // Retain reference to original
                Document doc = editorPane.getDocument();
                try {
                    editorPane.setPage(url);
                } catch (IOException ioException) {
                    JOptionPane.showMessageDialog(frame, "Error following link", "Invalid link",
                            JOptionPane.ERROR_MESSAGE);
                    editorPane.setDocument(doc);
                }//from  ww w. jav a  2  s. co  m
            }
        };
        SwingUtilities.invokeLater(runner);
    }
}

From source file:de.mendelson.comm.as2.client.HTMLPanel.java

/**Listen to be a HyperlinkListener*/
@Override// ww  w. j a v a2 s.  co m
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        try {
            URI uri = new URI(e.getURL().toExternalForm());
            Desktop.getDesktop().browse(uri);
        } catch (Exception ex) {
            //nop
        }
    }
    if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
        jEditorPane.setCursor(new Cursor(Cursor.HAND_CURSOR));
    }
    if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
        jEditorPane.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}