root / trunk / extensions / extHyperlink / src / org / gvsig / hyperlink / actions / TxtPanel.java @ 28132
History | View | Annotate | Download (2.01 KB)
1 |
package org.gvsig.hyperlink.actions; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.io.IOException; |
5 |
import java.net.MalformedURLException; |
6 |
import java.net.URI; |
7 |
import java.net.URL; |
8 |
|
9 |
import javax.swing.JTextPane; |
10 |
import javax.swing.event.HyperlinkEvent; |
11 |
|
12 |
import org.gvsig.hyperlink.AbstractHyperLinkPanel; |
13 |
|
14 |
import com.iver.andami.PluginServices; |
15 |
import com.iver.andami.messages.NotificationManager; |
16 |
import com.iver.utiles.BrowserControl; |
17 |
|
18 |
|
19 |
/**
|
20 |
* This class extends AbstractHyperLinkPanel. And provides support to open txt files and
|
21 |
* WWW. Implements methods from IExtensionBuilder to make it extending.
|
22 |
*
|
23 |
*/
|
24 |
public class TxtPanel extends AbstractHyperLinkPanel{ |
25 |
private static final long serialVersionUID = 1408583183372898110L; |
26 |
private JTextPane textPane; |
27 |
|
28 |
/**
|
29 |
* Default constructor.
|
30 |
*/
|
31 |
public TxtPanel(URI doc){ |
32 |
super(doc);
|
33 |
initialize(); |
34 |
} |
35 |
|
36 |
/**
|
37 |
* Initializes this panel.
|
38 |
*/
|
39 |
void initialize(){
|
40 |
this.setLayout(new BorderLayout()); |
41 |
showDocument(); |
42 |
} |
43 |
|
44 |
|
45 |
/**
|
46 |
* Implements the necessary code to show the content of the URI in this panel. The
|
47 |
* content of the URI is a TXT or a WWW.
|
48 |
* @param URI
|
49 |
*/
|
50 |
protected void showDocument() { |
51 |
textPane = new JTextPane(); |
52 |
textPane.setEditable(false);
|
53 |
|
54 |
if (!checkAndNormalizeURI()) {
|
55 |
return;
|
56 |
} |
57 |
|
58 |
URL url=null; |
59 |
try {
|
60 |
url=document.normalize().toURL(); |
61 |
} catch (MalformedURLException e1) { |
62 |
NotificationManager.addWarning(PluginServices.getText(this, "Hyperlink_linked_field_doesnot_exist"), e1); |
63 |
return;
|
64 |
} |
65 |
try {
|
66 |
textPane.setPage(url); |
67 |
textPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
|
68 |
public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent e) { |
69 |
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
70 |
System.out.println("hyperlinkUpdate()"); |
71 |
BrowserControl.displayURL(e.getURL().toString()); |
72 |
} |
73 |
} |
74 |
}); |
75 |
} catch (IOException e) { |
76 |
NotificationManager.addWarning(PluginServices.getText(this, "Hyperlink_linked_field_doesnot_exist"), e); |
77 |
return;
|
78 |
} |
79 |
this.add(textPane, BorderLayout.CENTER); |
80 |
} |
81 |
} |