23 |
23 |
package org.gvsig.hyperlink.app.extension.actions;
|
24 |
24 |
|
25 |
25 |
import java.awt.BorderLayout;
|
26 |
|
import java.awt.Color;
|
27 |
26 |
import java.awt.Dimension;
|
28 |
|
import java.io.IOException;
|
29 |
27 |
import java.net.MalformedURLException;
|
30 |
28 |
import java.net.URI;
|
31 |
29 |
import java.net.URL;
|
32 |
|
import javax.swing.JScrollPane;
|
33 |
30 |
|
34 |
31 |
import javax.swing.JTextPane;
|
35 |
|
import javax.swing.event.HyperlinkEvent;
|
36 |
32 |
|
37 |
33 |
import org.gvsig.andami.PluginServices;
|
38 |
34 |
import org.gvsig.andami.messages.NotificationManager;
|
39 |
35 |
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
|
40 |
|
import org.gvsig.utils.BrowserControl;
|
|
36 |
import org.gvsig.webbrowser.WebBrowserFactory;
|
|
37 |
import org.gvsig.webbrowser.WebBrowserPanel;
|
41 |
38 |
|
42 |
39 |
/**
|
43 |
40 |
* This class extends AbstractHyperLinkPanel. And provides support to open txt
|
... | ... | |
48 |
45 |
public class TxtPanel extends AbstractHyperLinkPanel {
|
49 |
46 |
|
50 |
47 |
private static final long serialVersionUID = 1408583183372898110L;
|
51 |
|
private JTextPane textPane;
|
52 |
48 |
|
53 |
49 |
/**
|
54 |
50 |
* Default constructor.
|
... | ... | |
68 |
64 |
|
69 |
65 |
/**
|
70 |
66 |
* Implements the necessary code to show the content of the URI in this
|
71 |
|
* panel. The
|
72 |
|
* content of the URI is a TXT or a WWW.
|
73 |
|
*
|
74 |
|
* @param URI
|
|
67 |
* panel. The content of the URI is a TXT or a WWW.
|
75 |
68 |
*/
|
76 |
69 |
protected void showDocument() {
|
77 |
|
textPane = new JTextPane();
|
78 |
|
textPane.setEditable(false);
|
79 |
|
textPane.setCaretPosition(0);
|
80 |
|
|
81 |
|
JScrollPane scrollPane = new JScrollPane(textPane);
|
82 |
|
scrollPane.setPreferredSize(new Dimension(400, 220));
|
|
70 |
WebBrowserPanel webbrowser = WebBrowserFactory.createWebBrowserPanel();
|
|
71 |
webbrowser.asJComponent().setPreferredSize(new Dimension(400, 220));
|
83 |
72 |
|
84 |
73 |
if (!checkAndNormalizeURI()) {
|
85 |
74 |
return;
|
... | ... | |
93 |
82 |
"Hyperlink_linked_field_doesnot_exist"), e1);
|
94 |
83 |
return;
|
95 |
84 |
}
|
96 |
|
try {
|
97 |
|
textPane.setPage(url);
|
98 |
|
textPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
|
99 |
|
|
100 |
|
public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent e) {
|
101 |
|
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
|
102 |
|
BrowserControl.displayURL(e.getURL().toString());
|
103 |
|
}
|
104 |
|
}
|
105 |
|
});
|
106 |
|
} catch (IOException e) {
|
107 |
|
NotificationManager.addWarning(PluginServices.getText(this,
|
108 |
|
"Hyperlink_linked_field_doesnot_exist"), e);
|
109 |
|
return;
|
110 |
|
}
|
111 |
|
this.add(scrollPane, BorderLayout.CENTER);
|
|
85 |
webbrowser.setPage(url);
|
|
86 |
this.add(webbrowser.asJComponent(), BorderLayout.CENTER);
|
112 |
87 |
}
|
113 |
88 |
}
|