Java Code Examples for javax.swing.event.HyperlinkEvent#getURL()

The following examples show how to use javax.swing.event.HyperlinkEvent#getURL() . 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: 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 2
Source File: DViewExtensions.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
		try {
			URL url = e.getURL();
			if (url != null) {
				if (url.getPath().endsWith(".cer") || url.getPath().endsWith(".crt")) {
					downloadCert(url);
				} else if (url.getPath().endsWith(".crl")) {
					downloadCrl(url);
				} else {
					Desktop.getDesktop().browse(url.toURI());
				}
			}
		} catch (Exception ex) {
			// TODO proper error message
			ex.printStackTrace();
		}
	}
}
 
Example 3
Source File: BrowserUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static HyperlinkListener createHyperlinkListener() {
    return new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent hlevt) {
            if (HyperlinkEvent.EventType.ACTIVATED == hlevt.getEventType()) {
                final URL url = hlevt.getURL();
                if (url != null) {
                    try {
                        openBrowser(url.toURI());
                    } catch (URISyntaxException e) {
                        LogManager.log(e);
                    }
                }
            }
        }
    };
}
 
Example 4
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 5
Source File: HTMLTextArea.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (!isEnabled()) {
        return;
    }

    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        activeLink = e.getURL();
        showURL(activeLink, e.getInputEvent());
    } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
        activeLink = e.getURL();
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
        activeLink = null;
        setCursor(Cursor.getDefaultCursor());
    }
}
 
Example 6
Source File: HTMLTextArea.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (!isEnabled()) {
        return;
    }

    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        activeLink = e.getURL();
        showURL(activeLink, e.getInputEvent());
    } else if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
        activeLink = e.getURL();
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
        activeLink = null;
        setCursor(Cursor.getDefaultCursor());
    }
}
 
Example 7
Source File: HelpViewer.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Load the link activated. Calls FileNode to handle custom URL resolving and resolves itself if the result is null.  
 */
public void hyperlinkUpdate(HyperlinkEvent arg0) {
	try {
		if (arg0.getEventType().toString().equals("ACTIVATED")) {
			FileNode node = currentNode.resolveURL(arg0.getURL());
			if(node == null){
				node = new ExternalNode(arg0.getURL());
			}
			currentNode = node;
		}
	} catch (Exception e) {
		e.printStackTrace();
		JOptionPane.showMessageDialog(null,
				e.getMessage() + e.getStackTrace(), "ERROR",
				JOptionPane.ERROR_MESSAGE);
	}
}
 
Example 8
Source File: NotificationListener.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void hyperlinkActivated(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) {
  URL url = event.getURL();
  if (url == null) {
    BrowserUtil.browse(event.getDescription());
  }
  else {
    BrowserUtil.browse(url);
  }
  if (myExpireNotification) {
    notification.expire();
  }
}
 
Example 9
Source File: ShowFilePathAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void hyperlinkActivated(@Nonnull Notification notification, @Nonnull HyperlinkEvent e) {
  URL url = e.getURL();
  if (url != null) {
    try {
      openFile(new File(url.toURI()));
    }
    catch (URISyntaxException ex) {
      LOG.warn("invalid URL: " + url, ex);
    }
  }
  notification.expire();
}
 
Example 10
Source File: BrowseUtil.java    From dummydroid with Apache License 2.0 5 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent e) {
	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
		if (e.getURL()==null) {
			// Custom protocols (e.g. market://)
			return;
		}
		if ("file".equals(e.getURL().getProtocol())) {
			try {
				BrowseUtil.openFile(new File(e.getURL().toURI()));
			}
			catch (Exception exp) {
				exp.printStackTrace();
			}
		}
		if ("http".equals(e.getURL().getProtocol())) {
			BrowseUtil.openUrl(e.getURL().toString());
		}
		if ("https".equals(e.getURL().getProtocol())) {
			BrowseUtil.openUrl(e.getURL().toString());
		}
		if ("mailto".equals(e.getURL().getProtocol())) {
			try {
				BrowseUtil.openMail(e.getURL().toURI());
			}
			catch (URISyntaxException e1) {
				e1.printStackTrace();
			}
		}
	}
}
 
Example 11
Source File: AboutDialog.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
static void editorPaneHyperlinkUpdate(HyperlinkEvent evt) {// GEN-FIRST:event_editorPaneHyperlinkUpdate
    try {
        if (evt.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
            URL url = evt.getURL();
            LaunchBrowser.showDocument(url);
        }
    } catch (Exception e) {
    }
}
 
Example 12
Source File: BytecodeSyntaxArea.java    From java-disassembler with GNU General Public License v3.0 5 votes vote down vote up
private void processClick(HyperlinkEvent e) {
    URL url = e.getURL();
    String data = url.getFile();
    switch (url.getProtocol()) {
        case "setcaret":
            setCaretPosition(Integer.parseInt(data));
            break;
    }
}
 
Example 13
Source File: ReportWindow.java    From Rails with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED && ! isStatic ) {
        activateTimeWarp();
        URL url = e.getURL();
        int index = url.getPort();
        gotoIndex(index);
        toFront();
    }
}
 
Example 14
Source File: ProductInformationPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent event) {
    if(HyperlinkEvent.EventType.ENTERED == event.getEventType()) {
        url = event.getURL();
    } else if (HyperlinkEvent.EventType.EXITED == event.getEventType()) {
        url = null;
    }
}
 
Example 15
Source File: Help.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public void hyperlinkUpdate(HyperlinkEvent e)
{
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    {
        URL url = e.getURL();
        String protocol = url.getProtocol();
        if (protocol.equals("jar") || protocol.equals("file"))
        {
            loadURL(url);
            appendHistory(url);
        }
        else
            openExternal(url);
    }
}
 
Example 16
Source File: GHelpHTMLEditorKit.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/** 
 * Tests the URL of the given event.  If the URL is invalid, a new event may be created if
 *  a new, valid URL can be created. Creates a new event with a patched URL if 
 *  the given event's URL is invalid.
 */
private HyperlinkEvent validateURL(HyperlinkEvent event) {
	URL url = event.getURL();
	try {
		url.openStream();// assume that this will fail if the file does not exist
	}
	catch (IOException ioe) {
		// assume this means that the url is invalid
		Msg.trace(this, "URL of link is invalid: " + url.toExternalForm());
		return maybeCreateNewHyperlinkEventWithUpdatedURL(event);
	}

	return event;// url is fine
}
 
Example 17
Source File: TemplatesPanelGUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override void hyperlinkUpdate(HyperlinkEvent evt) {
    if (EventType.ACTIVATED == evt.getEventType() && evt.getURL() != null) {
        HtmlBrowser.URLDisplayer.getDefault().showURL(evt.getURL());
    }
}
 
Example 18
Source File: AboutDialog.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
private void initComponents() {

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setIconImage(MainWin.icon);
		setSize(500, 300);
		setResizable(false);

		setLocationRelativeTo(this.getParent());
		setTitle("About " + AppConfig.appTitle);

		JPanel mainPanel = new JPanel(new BorderLayout());
		add(mainPanel);

		JPanel leftPanel = new JPanel();
		mainPanel.add(leftPanel, BorderLayout.WEST);

		ImageIcon iconImg = new ImageIcon(MainWin.icon);
		iconImg.setImage(iconImg.getImage().getScaledInstance((int) (iconImg.getIconWidth() * 0.5), (int) (iconImg.getIconHeight() * 0.5), Image.SCALE_SMOOTH));
		JLabel iconLabel = new JLabel(iconImg);
		iconLabel.setBorder(BorderFactory.createEmptyBorder(6, 10, 6, 10));
		leftPanel.add(iconLabel);

		HyperlinkListener hlLsnr = new HyperlinkListener() {
			@Override
			public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
					return;
				// 超链接标记中必须带有协议指定,e.getURL()才能得到,否则只能用e.getDescription()得到href的内容。
				// JOptionPane.showMessageDialog(InfoDialog.this, "URL:"+e.getURL()+"\nDesc:"+ e.getDescription());
				URL linkUrl = e.getURL();
				if (linkUrl != null) {
					try {
						Desktop.getDesktop().browse(linkUrl.toURI());
					} catch (Exception e1) {
						e1.printStackTrace();
						JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "无法打开超链接:" + linkUrl + "\n详情:" + e1, JOptionPane.ERROR_MESSAGE);
					}
				} else {
					JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "超链接信息不完整:" + e.getDescription() + "\n请确保链接带有协议信息,如http://,mailto:", JOptionPane.ERROR_MESSAGE);
				}
			}
		};

		JTextPane infoArea = new JTextPane();
		//设置css单位(px/pt)和chrome一致
		infoArea.putClientProperty(JTextPane.W3C_LENGTH_UNITS, true);
		infoArea.addHyperlinkListener(hlLsnr);
		infoArea.setContentType("text/html");
		infoArea.setText(getInfo());
		infoArea.setEditable(false);
		infoArea.setBorder(BorderFactory.createEmptyBorder(2, 10, 6, 10));
		infoArea.setFocusable(false);

		JScrollPane infoAreaScrollPane = new JScrollPane(infoArea);
		infoAreaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		infoAreaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		infoAreaScrollPane.getViewport().setBackground(Color.WHITE);
		mainPanel.add(infoAreaScrollPane, BorderLayout.CENTER);

	}
 
Example 19
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 20
Source File: AboutDialog.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
private void initComponents() {

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		setIconImage(MainWin.icon);
		setSize(500, 300);
		setResizable(false);

		setLocationRelativeTo(this.getParent());
		setTitle("About " + AppConfig.appTitle);

		JPanel mainPanel = new JPanel(new BorderLayout());
		add(mainPanel);

		JPanel leftPanel = new JPanel();
		mainPanel.add(leftPanel, BorderLayout.WEST);

		ImageIcon iconImg = new ImageIcon(MainWin.icon);
		iconImg.setImage(iconImg.getImage().getScaledInstance((int) (iconImg.getIconWidth() * 0.5), (int) (iconImg.getIconHeight() * 0.5), Image.SCALE_SMOOTH));
		JLabel iconLabel = new JLabel(iconImg);
		iconLabel.setBorder(BorderFactory.createEmptyBorder(6, 10, 6, 10));
		leftPanel.add(iconLabel);

		HyperlinkListener hlLsnr = new HyperlinkListener() {
			@Override
			public void hyperlinkUpdate(HyperlinkEvent e) {
				if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
					return;
				// 超链接标记中必须带有协议指定,e.getURL()才能得到,否则只能用e.getDescription()得到href的内容。
				// JOptionPane.showMessageDialog(InfoDialog.this, "URL:"+e.getURL()+"\nDesc:"+ e.getDescription());
				URL linkUrl = e.getURL();
				if (linkUrl != null) {
					try {
						Desktop.getDesktop().browse(linkUrl.toURI());
					} catch (Exception e1) {
						e1.printStackTrace();
						JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "无法打开超链接:" + linkUrl + "\n详情:" + e1, JOptionPane.ERROR_MESSAGE);
					}
				} else {
					JOptionPane.showMessageDialog(AboutDialog.this, "超链接错误", "超链接信息不完整:" + e.getDescription() + "\n请确保链接带有协议信息,如http://,mailto:", JOptionPane.ERROR_MESSAGE);
				}
			}
		};

		JTextPane infoArea = new JTextPane();
		//设置css单位(px/pt)和chrome一致
		infoArea.putClientProperty(JTextPane.W3C_LENGTH_UNITS, true);
		infoArea.addHyperlinkListener(hlLsnr);
		infoArea.setContentType("text/html");
		infoArea.setText(getInfo());
		infoArea.setEditable(false);
		infoArea.setBorder(BorderFactory.createEmptyBorder(2, 10, 6, 10));
		infoArea.setFocusable(false);

		JScrollPane infoAreaScrollPane = new JScrollPane(infoArea);
		infoAreaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		infoAreaScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		infoAreaScrollPane.getViewport().setBackground(Color.WHITE);
		mainPanel.add(infoAreaScrollPane, BorderLayout.CENTER);

	}