01: package org.enhydra.jawe;
02:
03: import java.net.URL;
04:
05: import javax.swing.event.HyperlinkEvent;
06: import javax.swing.event.HyperlinkListener;
07:
08: public class Hyperactive implements HyperlinkListener {
09: private String hoveredURLStr;
10:
11: public void hyperlinkUpdate(HyperlinkEvent e) {
12: if (e.getEventType() == HyperlinkEvent.EventType.ENTERED) {
13: URL url = e.getURL();
14: if (url != null) {
15: hoveredURLStr = url.toExternalForm();
16: } else {
17: // error case
18: hoveredURLStr = null;
19: }
20:
21: } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED) {
22: hoveredURLStr = null;
23: } else if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED
24: && hoveredURLStr != null) {
25: String startCommand = System.getProperty("path.to.start");
26: String url = hoveredURLStr;
27: if (null != startCommand) {
28: if (System.getProperty("path.separator").equals(";")) {
29: url = "\"" + url + "\"";
30: }
31: } else {
32: if (System.getProperty("path.separator").equals(":")) {
33: startCommand = "kfmclient exec";
34: } else {
35: startCommand = "cmd /c start";
36: url = "\"" + url + "\"" + " \"" + url + "\"";
37: }
38: }
39: try {
40: Runtime.getRuntime().exec(startCommand + " " + url);
41: } catch (Throwable t) {
42: t.printStackTrace();
43: }
44: }
45: }
46: }
|