svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.about / org.gvsig.about.impl / src / main / java / org / gvsig / htmlBrowser / SimpleHtmlBrowserPanel.java @ 42024
History | View | Annotate | Download (2.89 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program 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 General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.htmlBrowser; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.io.IOException; |
26 |
import java.net.URL; |
27 |
|
28 |
import javax.swing.JEditorPane; |
29 |
import javax.swing.JScrollPane; |
30 |
import javax.swing.event.HyperlinkEvent; |
31 |
import javax.swing.event.HyperlinkListener; |
32 |
|
33 |
import org.slf4j.Logger; |
34 |
import org.slf4j.LoggerFactory; |
35 |
|
36 |
/**
|
37 |
* @author gvSIG Team
|
38 |
* @version $Id$
|
39 |
*
|
40 |
*/
|
41 |
public class SimpleHtmlBrowserPanel extends HtmlBrowserPanel implements |
42 |
HyperlinkListener {
|
43 |
|
44 |
private static final long serialVersionUID = 2222495134882233629L; |
45 |
private static final Logger LOG = LoggerFactory |
46 |
.getLogger(SimpleHtmlBrowserPanel.class); |
47 |
|
48 |
public JEditorPane htmlPane; |
49 |
public JScrollPane scroll; |
50 |
|
51 |
public SimpleHtmlBrowserPanel() {
|
52 |
setLayout(new BorderLayout()); |
53 |
|
54 |
this.htmlPane = new JEditorPane(); |
55 |
this.htmlPane.setContentType("text/html"); |
56 |
this.htmlPane.setEditable(false); |
57 |
|
58 |
this.scroll = new JScrollPane(htmlPane); |
59 |
// htmlPane.addHyperlinkListener(this);
|
60 |
|
61 |
add(scroll, BorderLayout.CENTER);
|
62 |
} |
63 |
|
64 |
@Override
|
65 |
public void navigate(URL url) { |
66 |
try {
|
67 |
this.htmlPane.setPage(url);
|
68 |
} catch (IOException e) { |
69 |
this.htmlPane.setText("Error reading html content"); |
70 |
LOG.error("Error reading html content from URL: " + url, e);
|
71 |
} |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public void setText(String text) { |
76 |
this.htmlPane.setText(text);
|
77 |
this.htmlPane.setCaretPosition(0); |
78 |
} |
79 |
|
80 |
public void hyperlinkUpdate(HyperlinkEvent event) { |
81 |
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
82 |
try {
|
83 |
htmlPane.setPage(event.getURL()); |
84 |
} catch (IOException ioe) { |
85 |
this.htmlPane.setText("Error reading html content"); |
86 |
LOG.error( |
87 |
"Error reading html content from URL: " + event.getURL(),
|
88 |
ioe); |
89 |
} |
90 |
} |
91 |
} |
92 |
|
93 |
public JEditorPane getJEditorPane() { |
94 |
return htmlPane;
|
95 |
} |
96 |
|
97 |
} |