commons.java subversion repository

sventon subversion web client - http://www.sventon.org
[show recent changes]
 
  Help
HEAD
Rev: 669 - https://secure.bioinfweb.info/Code/svn/commons.java / trunk / main / info.bioinfweb.commons.swing / src / info / bioinfweb / commons / swing / SystemBrowserHyperlinkListener.java
Show File - SystemBrowserHyperlinkListener.java  [show properties]
spinner
/*
 * bioinfweb.commons.java - Shared components of bioinfweb projects made available in a Java library
 * Copyright (C) 2008-2011, 2013-2018  Ben Stöver, Sarah Wiechers
 * <http://commons.bioinfweb.info/Java>
 * 
 * This file is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
10   * 
11   * This file is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   * GNU Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with this program. If not, see <http://www.gnu.org/licenses/>.
18   */
19  package info.bioinfweb.commons.swing;
20 
21 
22  import java.awt.Component;
23  import java.awt.Desktop;
24 
25  import javax.swing.JOptionPane;
26  import javax.swing.event.HyperlinkEvent;
27  import javax.swing.event.HyperlinkListener;
28 
29 
30 
31  /**
32   * An implementation of {@link HyperlinkListener} that opens URLs in the system browser.
33   *
34   * @author Ben St&ouml;ver
35   * @since 3.3.0
36   */
37  public class SystemBrowserHyperlinkListener implements HyperlinkListener {
38      private Component owner;
39 
40 
41      public SystemBrowserHyperlinkListener(Component owner) {
42          super();
43          this.owner = owner;
44      }
45 
46 
47      public SystemBrowserHyperlinkListener() {
48          this(null);
49      }
50 
51 
52      public void hyperlinkUpdate(HyperlinkEvent e) {
53          if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
54              try {
55                  Desktop.getDesktop().browse(e.getURL().toURI());
56              }
57              catch (Exception ex) {
58                  JOptionPane.showMessageDialog(owner, "An error occurred when trying open the selected link.", 
59                          "Navigation failed,", JOptionPane.ERROR_MESSAGE);
60              }
61          }
62      }
63  }


feed icon

sventon 2.5.1

bioinfweb RSS feed bioinfweb on twitter bioinfweb.commons.java on GitHub
bioinfweb - Biology & Informatics Website