svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / LinkPanel.java @ 6483
History | View | Annotate | Download (7.07 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.panels; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.io.File; |
45 |
import java.io.IOException; |
46 |
import java.net.MalformedURLException; |
47 |
import java.net.URL; |
48 |
|
49 |
import javax.swing.ImageIcon; |
50 |
import javax.swing.JButton; |
51 |
import javax.swing.JDialog; |
52 |
import javax.swing.JEditorPane; |
53 |
import javax.swing.JLabel; |
54 |
import javax.swing.JPanel; |
55 |
import javax.swing.JScrollPane; |
56 |
import javax.swing.event.HyperlinkEvent; |
57 |
|
58 |
import org.apache.log4j.Logger; |
59 |
|
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.andami.ui.mdiManager.View; |
62 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
63 |
|
64 |
|
65 |
/**
|
66 |
* Vista donde mostrar el fichero del hiperlink.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
*
|
70 |
*/
|
71 |
public class LinkPanel extends JPanel implements View { |
72 |
private static Logger logger = Logger.getLogger(LinkPanel.class.getName()); |
73 |
private JPanel jPane = null; |
74 |
private JScrollPane jScrollPane = null; |
75 |
private JEditorPane jEditorPane1 = null; |
76 |
private JPanel jPanel = null; // @jve:decl-index=0:visual-constraint="220,10" |
77 |
private JButton jButton = null; |
78 |
private String field; |
79 |
private String value; |
80 |
private String ext=""; |
81 |
private int type=0; |
82 |
/**
|
83 |
* This is the default constructor
|
84 |
*/
|
85 |
public LinkPanel(String f,String v,String e,int t) { |
86 |
super();
|
87 |
field=f; |
88 |
value=v; |
89 |
ext=e; |
90 |
type=t; |
91 |
initialize(); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* This method initializes this
|
96 |
*/
|
97 |
private void initialize() { |
98 |
this.setLayout(new BorderLayout()); |
99 |
this.setSize(600, 450); |
100 |
this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
|
101 |
this.add(getJPanel(), java.awt.BorderLayout.SOUTH);
|
102 |
} |
103 |
|
104 |
|
105 |
/**
|
106 |
* This method initializes jScrollPane
|
107 |
*
|
108 |
* @return javax.swing.JScrollPane
|
109 |
*/
|
110 |
private JScrollPane getJScrollPane() { |
111 |
if (jScrollPane == null) { |
112 |
jScrollPane = new JScrollPane(); |
113 |
jScrollPane.setPreferredSize(new java.awt.Dimension(300, 400)); |
114 |
jScrollPane.setViewportView(getJPane()); |
115 |
} |
116 |
|
117 |
return jScrollPane;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* This method initializes jEditorPane1
|
122 |
*
|
123 |
* @return javax.swing.JEditorPane
|
124 |
*/
|
125 |
private JPanel getJPane() { |
126 |
|
127 |
if (jPane == null) { |
128 |
jPane=new JPanel(); |
129 |
|
130 |
//if (ext.equals(".htm") || ext.equals(".HTM") || ext.equals(".html") || ext.equals(".HTML") || ext.equals(".xml") || ext.equals(".XML") || ext.equals(".txt") || ext.equals(".TXT")){
|
131 |
if (type==1){ |
132 |
JEditorPane jEditorPane = new JEditorPane(); |
133 |
jEditorPane.setAutoscrolls(true);
|
134 |
jEditorPane.setEditable(false);
|
135 |
jEditorPane.setContentType("text/html");
|
136 |
//jEditorPane.setPreferredSize(new java.awt.Dimension(300, 200));
|
137 |
String auxext=""; |
138 |
if (!ext.equals("")){ |
139 |
auxext="."+ext;
|
140 |
} |
141 |
//URL url = LinkPanel.class.getResource(("/"+value+auxext));
|
142 |
URL url=null; |
143 |
File file =new File(value+auxext); |
144 |
try {
|
145 |
url = file.toURL(); |
146 |
} catch (MalformedURLException e1) { |
147 |
e1.printStackTrace(); |
148 |
} |
149 |
if (url != null) { |
150 |
try {
|
151 |
jEditorPane.setPage(url); |
152 |
jEditorPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
|
153 |
public void hyperlinkUpdate( |
154 |
javax.swing.event.HyperlinkEvent e) { |
155 |
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { |
156 |
JEditorPane pane = (JEditorPane) e.getSource(); |
157 |
System.out.println("hyperlinkUpdate()"); |
158 |
BrowserControl.displayURL(e.getURL() |
159 |
.toString()); |
160 |
|
161 |
} |
162 |
} |
163 |
}); |
164 |
} catch (IOException e) { |
165 |
System.err.println("Attempted to read a bad URL: " + |
166 |
url); |
167 |
} |
168 |
jPane.add(jEditorPane); |
169 |
} else {
|
170 |
System.err.println("Couldn't find file: " + value+auxext); |
171 |
} |
172 |
}else if (type==0){ |
173 |
String auxext=""; |
174 |
if (!ext.equals("")){ |
175 |
auxext="."+ext;
|
176 |
} |
177 |
//java.net.URL url = LinkPanel.class.getResource(("/" + value + auxext));
|
178 |
URL url=null; |
179 |
File file =new File(value+auxext); |
180 |
try {
|
181 |
url = file.toURL(); |
182 |
} catch (MalformedURLException e1) { |
183 |
e1.printStackTrace(); |
184 |
} |
185 |
ImageIcon image = null; |
186 |
|
187 |
if (url == null) { |
188 |
System.err.println("Couldn't find file: " + value+auxext); |
189 |
} else {
|
190 |
image = new ImageIcon(url); |
191 |
} |
192 |
JLabel label = new JLabel(image); |
193 |
jPane.add(label); |
194 |
|
195 |
jPane.setVisible(true);
|
196 |
|
197 |
} |
198 |
} |
199 |
|
200 |
return jPane;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* This method initializes jPanel
|
205 |
*
|
206 |
* @return javax.swing.JPanel
|
207 |
*/
|
208 |
private JPanel getJPanel() { |
209 |
if (jPanel == null) { |
210 |
JLabel name = new JLabel(); |
211 |
jPanel = new JPanel(); |
212 |
jPanel.setLayout(null);
|
213 |
jPanel.setPreferredSize(new java.awt.Dimension(10, 50)); |
214 |
jPanel.setSize(411, 50); |
215 |
name.setBounds(31, 20, 172, 17); |
216 |
String auxext=""; |
217 |
if (!ext.equals("")){ |
218 |
auxext="."+ext;
|
219 |
} |
220 |
name.setText(field + " : " + value+auxext);
|
221 |
jPanel.add(getJButton(), null);
|
222 |
jPanel.add(name, null);
|
223 |
} |
224 |
|
225 |
return jPanel;
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* This method initializes jButton
|
230 |
*
|
231 |
* @return javax.swing.JButton
|
232 |
*/
|
233 |
private JButton getJButton() { |
234 |
if (jButton == null) { |
235 |
jButton = new JButton(); |
236 |
jButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); |
237 |
jButton.setText(PluginServices.getText(this,"Cerrar")); |
238 |
jButton.setBounds(266, 12, 94, 25); |
239 |
jButton.addActionListener(new java.awt.event.ActionListener() {
|
240 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
241 |
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
242 |
|
243 |
if (PluginServices.getMainFrame() != null) { |
244 |
PluginServices.getMDIManager().closeView(LinkPanel.this); |
245 |
} else {
|
246 |
((JDialog) (getParent().getParent().getParent()
|
247 |
.getParent())).dispose(); |
248 |
} |
249 |
} |
250 |
}); |
251 |
} |
252 |
|
253 |
return jButton;
|
254 |
} |
255 |
|
256 |
/* (non-Javadoc)
|
257 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
258 |
*/
|
259 |
public ViewInfo getViewInfo() {
|
260 |
ViewInfo m_ViewInfo = new ViewInfo(ViewInfo.MODALDIALOG |
|
261 |
ViewInfo.RESIZABLE); |
262 |
m_ViewInfo.setTitle("HiperLink");
|
263 |
|
264 |
return m_ViewInfo;
|
265 |
} |
266 |
|
267 |
/* (non-Javadoc)
|
268 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
269 |
*/
|
270 |
public void viewActivated() { |
271 |
// TODO Auto-generated method stub
|
272 |
} |
273 |
} // @jve:decl-index=0:visual-constraint="10,10"
|