svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / info / gui / InfoToolViewer.java @ 40558
History | View | Annotate | Download (9.88 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.info.gui; |
25 |
|
26 |
import java.awt.Dimension; |
27 |
import java.awt.event.ComponentEvent; |
28 |
import java.awt.event.ComponentListener; |
29 |
import java.util.Vector; |
30 |
|
31 |
import javax.swing.JList; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.event.ListSelectionListener; |
34 |
import javax.swing.tree.DefaultMutableTreeNode; |
35 |
import javax.swing.tree.DefaultTreeModel; |
36 |
import javax.swing.tree.TreePath; |
37 |
|
38 |
import org.gvsig.app.gui.wizards.FormatListModel; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
41 |
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint; |
42 |
import org.gvsig.utils.xmlViewer.XMLContent; |
43 |
import org.xml.sax.ContentHandler; |
44 |
import org.xml.sax.SAXException; |
45 |
|
46 |
/**
|
47 |
* This is the generic Feature Info Viewer
|
48 |
*
|
49 |
* If the feature Info comes from a special layer which has registered
|
50 |
* the way to visualize itself, adds a panel that the layer should provide
|
51 |
* otherwise this viewer will add a panel to visualize HTML or a special
|
52 |
* viewer to show XML.
|
53 |
*
|
54 |
* @author laura
|
55 |
*
|
56 |
*/
|
57 |
public class InfoToolViewer extends JPanel { |
58 |
|
59 |
public static Class XULPanelClass = null; |
60 |
|
61 |
private javax.swing.JScrollPane jScrollPane = null; |
62 |
private JList layerList = null; |
63 |
private javax.swing.JSplitPane jSplitPane1 = null; |
64 |
private javax.swing.JPanel layerListPanel = null; |
65 |
private JPanel infoViewerPanel; |
66 |
private XMLItem[] m_layers; |
67 |
IInfoToolPanel infoPanel = null;
|
68 |
|
69 |
/**
|
70 |
* This is the default constructor
|
71 |
*/
|
72 |
public InfoToolViewer() {
|
73 |
super();
|
74 |
initialize(); |
75 |
this.addComponentListener(new componentListener()); |
76 |
} |
77 |
|
78 |
public InfoToolViewer(XMLItem[] layers) { |
79 |
super();
|
80 |
initialize(); |
81 |
setLayers(layers); |
82 |
} |
83 |
|
84 |
public void setLayers(XMLItem[] layers){ |
85 |
m_layers = layers; |
86 |
initilizeLayerListModel(); |
87 |
updateViewer(0);
|
88 |
// layerList.setSelectedIndex(0);
|
89 |
} |
90 |
|
91 |
|
92 |
/**
|
93 |
* This method initializes this
|
94 |
*/
|
95 |
private void initialize() { |
96 |
this.setLayout(new java.awt.BorderLayout()); |
97 |
this.add(getJSplitPane1(), java.awt.BorderLayout.CENTER);
|
98 |
this.setSize(600, 600); |
99 |
this.setPreferredSize(new Dimension(600, 600)); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* This method initializes jScrollPane
|
104 |
*
|
105 |
* @return javax.swing.JScrollPane
|
106 |
*/
|
107 |
private javax.swing.JScrollPane getJScrollPane() {
|
108 |
if (jScrollPane == null) { |
109 |
jScrollPane = new javax.swing.JScrollPane();
|
110 |
jScrollPane.setSize(new Dimension(600,600)); |
111 |
jScrollPane.setPreferredSize( new Dimension(600,600)); |
112 |
jScrollPane.setViewportView(getLayerListPanel()); |
113 |
} |
114 |
|
115 |
return jScrollPane;
|
116 |
} |
117 |
|
118 |
private void initilizeLayerListModel() { |
119 |
Vector layerNames = new Vector(); |
120 |
if (m_layers != null) |
121 |
{ |
122 |
for (int i = 0; i < m_layers.length; i++) |
123 |
{ |
124 |
layerNames.add(m_layers[i].getLayer().getName()); |
125 |
} |
126 |
} |
127 |
|
128 |
FormatListModel model = new FormatListModel((String[])layerNames.toArray(new String[0])); |
129 |
getJList().setModel(model); |
130 |
} |
131 |
|
132 |
public JList getJList(){ |
133 |
|
134 |
if (layerList == null) { |
135 |
layerList = new JList(); |
136 |
initilizeLayerListModel(); |
137 |
layerList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
138 |
} |
139 |
|
140 |
layerList.addListSelectionListener(new ListSelectionListener() { |
141 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
142 |
int changedIdx = layerList.getSelectedIndex();//e.getFirstIndex(); |
143 |
|
144 |
if (changedIdx == -1) return; |
145 |
updateViewer(changedIdx); |
146 |
} |
147 |
}); |
148 |
return layerList;
|
149 |
} |
150 |
/**
|
151 |
* This method initializes jSplitPane1
|
152 |
*
|
153 |
* @return javax.swing.JSplitPane
|
154 |
*/
|
155 |
private javax.swing.JSplitPane getJSplitPane1() {
|
156 |
if (jSplitPane1 == null) { |
157 |
jSplitPane1 = new javax.swing.JSplitPane();
|
158 |
jSplitPane1.setLeftComponent(getJScrollPane()); |
159 |
jSplitPane1.setRightComponent(getInfoViewerPanel()); |
160 |
jSplitPane1.setDividerSize(4);
|
161 |
jSplitPane1.setDividerLocation(100);
|
162 |
jSplitPane1.setSize( new Dimension(600,600)); |
163 |
jSplitPane1.setPreferredSize( new Dimension(600,600)); |
164 |
} |
165 |
return jSplitPane1;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* This method initializes jPanel
|
170 |
*
|
171 |
* @return javax.swing.JPanel
|
172 |
*/
|
173 |
private javax.swing.JPanel getLayerListPanel() {
|
174 |
if (layerListPanel == null) { |
175 |
layerListPanel = new javax.swing.JPanel();
|
176 |
layerListPanel.setLayout(new java.awt.BorderLayout());
|
177 |
layerListPanel.add(getJList(), java.awt.BorderLayout.CENTER); |
178 |
} |
179 |
|
180 |
return layerListPanel;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* This method initializes jPanel1
|
185 |
*
|
186 |
* @return javax.swing.JPanel
|
187 |
*/
|
188 |
private javax.swing.JPanel getInfoViewerPanel() {
|
189 |
if (infoViewerPanel == null) { |
190 |
infoViewerPanel = new javax.swing.JPanel();
|
191 |
infoViewerPanel.setLayout(new java.awt.BorderLayout());
|
192 |
} |
193 |
validate(); |
194 |
return infoViewerPanel;
|
195 |
} |
196 |
|
197 |
/**
|
198 |
* updates the layer to display
|
199 |
*
|
200 |
*/
|
201 |
private void updateViewer(int changedIdx) |
202 |
{ |
203 |
if((m_layers == null) || (m_layers.length == 0)) return; |
204 |
final XMLItem item = m_layers[changedIdx];
|
205 |
FLayer layer = item.getLayer(); |
206 |
|
207 |
if (layer instanceof InfoByPoint){ |
208 |
FLyrDefault defaultLayer = (FLyrDefault)layer; |
209 |
if ( XULPanelClass!=null && defaultLayer.getProperty("infoTool.XULFile") != null){ |
210 |
try {
|
211 |
IXULInfoToolSupport infoPanel = (IXULInfoToolSupport) XULPanelClass.newInstance(); |
212 |
infoPanel.setXULFile((String)defaultLayer.getProperty("infoTool.XULFile")); |
213 |
infoViewerPanel.removeAll(); |
214 |
infoViewerPanel.add((JPanel)infoPanel);
|
215 |
infoPanel.show(item); |
216 |
infoViewerPanel.setVisible( true );
|
217 |
revalidate(); |
218 |
return;
|
219 |
} catch (Exception e) { |
220 |
// TODO Auto-generated catch block
|
221 |
e.printStackTrace(); |
222 |
} |
223 |
|
224 |
} |
225 |
|
226 |
if (defaultLayer.getProperty("customPanel") != null){ |
227 |
|
228 |
Object o = (Object)defaultLayer.getProperty("customPanel"); |
229 |
if (o instanceof IInfoToolPanel) { |
230 |
infoPanel = (IInfoToolPanel)o; |
231 |
} else {
|
232 |
try {
|
233 |
Class c = (Class)o; |
234 |
infoPanel = (IInfoToolPanel)c.newInstance(); |
235 |
} catch (InstantiationException e1) { |
236 |
e1.printStackTrace(); |
237 |
} catch (IllegalAccessException e1) { |
238 |
e1.printStackTrace(); |
239 |
} |
240 |
} |
241 |
infoViewerPanel.removeAll(); |
242 |
infoViewerPanel.add((JPanel)infoPanel);
|
243 |
infoPanel.show(item); |
244 |
infoViewerPanel.setVisible( true );
|
245 |
revalidate(); |
246 |
|
247 |
} else {
|
248 |
|
249 |
if (item.toString().toLowerCase().endsWith( "</html>"))//if (item.toString().toLowerCase().startsWith( "<html>")) |
250 |
{ |
251 |
//skip the header info
|
252 |
IInfoToolPanel htmlPanel = new HTMLInfoToolPanel();
|
253 |
|
254 |
int idx = item.toString().toLowerCase().indexOf("<html"); |
255 |
if (idx != -1){ |
256 |
htmlPanel.show(item.toString().substring(idx)); |
257 |
}else{
|
258 |
htmlPanel.show(item.toString()); |
259 |
} |
260 |
infoViewerPanel.removeAll(); |
261 |
infoViewerPanel.add((JPanel)htmlPanel);
|
262 |
infoViewerPanel.setVisible( true );
|
263 |
revalidate(); |
264 |
} else {
|
265 |
FInfoDialogXML dlgXML = new FInfoDialogXML();
|
266 |
try {
|
267 |
dlgXML.setModel(new XMLContent() {
|
268 |
private ContentHandler handler; |
269 |
|
270 |
public void setContentHandler(ContentHandler arg0) { |
271 |
handler = arg0; |
272 |
} |
273 |
|
274 |
public void parse() throws SAXException { |
275 |
handler.startDocument(); |
276 |
item.parse( handler); |
277 |
handler.endDocument(); |
278 |
} |
279 |
}); |
280 |
dlgXML.getXmlTree().setRootVisible(false);
|
281 |
DefaultTreeModel treeModel = (DefaultTreeModel) dlgXML |
282 |
.getXmlTree().getModel(); |
283 |
DefaultMutableTreeNode n;
|
284 |
DefaultMutableTreeNode root = (DefaultMutableTreeNode) dlgXML |
285 |
.getXmlTree().getModel().getRoot(); |
286 |
n = root.getFirstLeaf(); |
287 |
TreePath path = new TreePath(treeModel.getPathToRoot(n)); |
288 |
dlgXML.getXmlTree().expandPath(path); |
289 |
dlgXML.getXmlTree().setSelectionPath(path); |
290 |
//dlgXML.
|
291 |
|
292 |
infoViewerPanel.removeAll(); |
293 |
infoViewerPanel.add(dlgXML); |
294 |
infoViewerPanel.setVisible( true );
|
295 |
this.validate();
|
296 |
this.doLayout();
|
297 |
|
298 |
} catch (SAXException e1) {
|
299 |
e1.printStackTrace(); |
300 |
} |
301 |
} |
302 |
} |
303 |
} |
304 |
} |
305 |
|
306 |
class componentListener implements ComponentListener{ |
307 |
|
308 |
public void componentHidden(ComponentEvent e) { |
309 |
// TODO Auto-generated method stub
|
310 |
|
311 |
} |
312 |
|
313 |
public void componentMoved(ComponentEvent e) { |
314 |
// TODO Auto-generated method stub
|
315 |
|
316 |
} |
317 |
|
318 |
public void componentResized(ComponentEvent e) { |
319 |
|
320 |
//if (e.getComponent() == )
|
321 |
if (infoPanel != null){ |
322 |
infoPanel.refreshSize(); |
323 |
} |
324 |
|
325 |
|
326 |
} |
327 |
|
328 |
public void componentShown(ComponentEvent e) { |
329 |
// TODO Auto-generated method stub
|
330 |
|
331 |
} |
332 |
|
333 |
} |
334 |
} |