Revision 5837 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/Dialogs/FInfoDialog.java
FInfoDialog.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 24-jun-2003 |
|
3 |
* |
|
4 |
* Copyright (c) 2003 |
|
5 |
* Francisco Jos� Pe�arrubia Mart�nez |
|
6 |
* IVER Tecnolog�as de la Informaci�n S.A. |
|
7 |
* Salamanca 50 |
|
8 |
* 46005 Valencia ( SPAIN ) |
|
9 |
* +34 963163400 |
|
10 |
* mailto:fran@iver.es |
|
11 |
* http://www.iver.es |
|
12 |
*/ |
|
13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
14 |
* |
|
15 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
16 |
* |
|
17 |
* This program is free software; you can redistribute it and/or |
|
18 |
* modify it under the terms of the GNU General Public License |
|
19 |
* as published by the Free Software Foundation; either version 2 |
|
20 |
* of the License, or (at your option) any later version. |
|
21 |
* |
|
22 |
* This program is distributed in the hope that it will be useful, |
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
* GNU General Public License for more details. |
|
26 |
* |
|
27 |
* You should have received a copy of the GNU General Public License |
|
28 |
* along with this program; if not, write to the Free Software |
|
29 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
30 |
* |
|
31 |
* For more information, contact: |
|
32 |
* |
|
33 |
* Generalitat Valenciana |
|
34 |
* Conselleria d'Infraestructures i Transport |
|
35 |
* Av. Blasco Ib??ez, 50 |
|
36 |
* 46010 VALENCIA |
|
37 |
* SPAIN |
|
38 |
* |
|
39 |
* +34 963862235 |
|
40 |
* gvsig@gva.es |
|
41 |
* www.gvsig.gva.es |
|
42 |
* |
|
43 |
* or |
|
44 |
* |
|
45 |
* IVER T.I. S.A |
|
46 |
* Salamanca 50 |
|
47 |
* 46005 Valencia |
|
48 |
* Spain |
|
49 |
* |
|
50 |
* +34 963163400 |
|
51 |
* dac@iver.es |
|
52 |
*/ |
|
1 |
|
|
53 | 2 |
package com.iver.cit.gvsig.gui.Dialogs; |
54 | 3 |
|
55 |
import java.awt.BorderLayout; |
|
56 |
import java.awt.Dimension; |
|
57 |
import java.util.ArrayList; |
|
58 |
import java.util.StringTokenizer; |
|
59 |
|
|
60 |
import javax.swing.JPanel; |
|
61 |
import javax.swing.JScrollPane; |
|
62 |
import javax.swing.table.AbstractTableModel; |
|
63 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
64 |
import javax.swing.tree.DefaultTreeModel; |
|
65 |
import javax.swing.tree.TreePath; |
|
66 |
import javax.swing.tree.TreeSelectionModel; |
|
67 |
|
|
68 | 4 |
import com.iver.andami.PluginServices; |
69 |
import com.iver.andami.Utilities; |
|
70 | 5 |
import com.iver.andami.ui.mdiManager.SingletonView; |
71 | 6 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
72 |
import com.iver.cit.gvsig.project.ProjectView;
|
|
7 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
|
|
73 | 8 |
|
74 | 9 |
|
75 | 10 |
/** |
76 |
* DOCUMENT ME! |
|
11 |
* Dialog that contains the generic Feature Info Viewer |
|
12 |
* |
|
13 |
* @author laura |
|
77 | 14 |
* |
78 |
* @author Administrador To change the template for this generated type comment |
|
79 |
* go to Window>Preferences>Java>Code Generation>Code and Comments |
|
80 | 15 |
*/ |
81 |
public final class FInfoDialog extends JPanel implements SingletonView { |
|
82 |
boolean DEBUG=true; |
|
83 |
private ArrayList m_arrayNomTemas; |
|
84 |
private String m_strInfo; |
|
85 |
private ArrayList m_arrayStrings; |
|
86 |
private MyTableModel m_gridModel; |
|
87 |
private int m_itemSelected; |
|
88 |
private int m_subItemSelected; |
|
89 |
private DefaultTreeModel m_treeModel; |
|
90 |
|
|
91 |
// Variables declaration - do not modify |
|
92 |
private javax.swing.JSplitPane jSplitPane1; |
|
93 |
private javax.swing.JTable m_grid; |
|
94 |
private javax.swing.JTree jTree1; |
|
95 |
|
|
96 |
private ProjectView viewModel = null; |
|
16 |
public class FInfoDialog extends InfoToolViewer implements SingletonView { |
|
97 | 17 |
|
18 |
|
|
19 |
public FInfoDialog(){ |
|
20 |
super(); |
|
21 |
} |
|
22 |
|
|
23 |
public FInfoDialog(XMLItem[] layers) { |
|
24 |
super(layers); |
|
25 |
} |
|
26 |
|
|
98 | 27 |
/** |
99 |
* Creates new form FInfoDialog |
|
100 |
* |
|
101 |
* @param parent DOCUMENT ME! |
|
102 |
* @param modal DOCUMENT ME! |
|
103 |
*/ |
|
104 |
public FInfoDialog() { |
|
105 |
//super(parent, modal); |
|
106 |
m_arrayNomTemas = new ArrayList(); |
|
107 |
m_arrayStrings = new ArrayList(); |
|
28 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated() |
|
29 |
*/ |
|
30 |
public void viewActivated() { |
|
31 |
} |
|
108 | 32 |
|
109 |
initComponents(); |
|
110 |
|
|
111 |
this.setSize(300, 235); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* DOCUMENT ME! |
|
116 |
*/ |
|
117 |
public void refresh() { |
|
118 |
setSelected(0, 0); |
|
119 |
refreshLeft(); |
|
120 |
refreshRight(); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* DOCUMENT ME! |
|
125 |
*/ |
|
126 |
public void clearAll() { |
|
127 |
m_arrayStrings.clear(); |
|
128 |
m_arrayNomTemas.clear(); |
|
129 |
m_strInfo = ""; |
|
130 |
jTree1.removeAll(); |
|
131 |
|
|
132 |
|
|
133 |
DefaultMutableTreeNode top = new DefaultMutableTreeNode("root"); |
|
134 |
|
|
135 |
// m_treeModel.setRoot(top); |
|
136 |
m_treeModel = new DefaultTreeModel(top); |
|
137 |
m_gridModel.setData("","",0); |
|
138 |
jTree1.setModel(m_treeModel); |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* DOCUMENT ME! |
|
143 |
*/ |
|
144 |
private void refreshLeft() { |
|
145 |
int i; |
|
146 |
int j; |
|
147 |
|
|
148 |
DefaultMutableTreeNode idRoot = (DefaultMutableTreeNode) m_treeModel.getRoot(); |
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
for (i = 0; i < m_arrayStrings.size(); i++) { |
|
153 |
String strInfo = (String) m_arrayStrings.get(i); |
|
154 |
String nomTema = (String) m_arrayNomTemas.get(i); |
|
155 |
StringTokenizer tkz = new StringTokenizer(strInfo, "\n"); |
|
156 |
String strCampos = tkz.nextToken(); |
|
157 |
|
|
158 |
DefaultMutableTreeNode idTema = new DefaultMutableTreeNode(nomTema); |
|
159 |
m_treeModel.insertNodeInto(idTema, idRoot, i); |
|
160 |
|
|
161 |
j = 0; |
|
162 |
|
|
163 |
while (tkz.hasMoreTokens()) { |
|
164 |
String token = tkz.nextToken(); |
|
165 |
StringTokenizer tkzValores = new StringTokenizer(token, "|"); |
|
166 |
String strID = tkzValores.nextToken(); |
|
167 |
MyTreeItem aux = new MyTreeItem(strID, i, j); |
|
168 |
|
|
169 |
DefaultMutableTreeNode idChild = new DefaultMutableTreeNode(aux); |
|
170 |
m_treeModel.insertNodeInto(idChild, idTema, j); |
|
171 |
|
|
172 |
// jTree1.expandRow(j); |
|
173 |
if ((i == m_itemSelected) && (j == m_subItemSelected)) { |
|
174 |
// TreePath elPath = jTree1.getPathForRow(j); |
|
175 |
TreePath elPath = new TreePath(idChild.getPath()); |
|
176 |
jTree1.expandPath(elPath); |
|
177 |
if (DEBUG) System.out.println("El path = " + elPath); |
|
178 |
jTree1.setSelectionPath(elPath); |
|
179 |
} |
|
180 |
|
|
181 |
// m_tree->Expand(idChild); |
|
182 |
// m_tree->EnsureVisible(idChild); |
|
183 |
j++; |
|
184 |
} |
|
185 |
} |
|
186 |
// for tema |
|
187 |
|
|
188 |
jTree1.stopEditing(); |
|
189 |
jTree1.setRootVisible(false); |
|
190 |
} |
|
191 |
|
|
192 |
/** |
|
193 |
* DOCUMENT ME! |
|
194 |
*/ |
|
195 |
private void refreshRight() { |
|
196 |
m_grid.invalidate(); |
|
197 |
m_grid.repaint(); |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* DOCUMENT ME! |
|
202 |
* |
|
203 |
* @param idItem DOCUMENT ME! |
|
204 |
* @param idSubItem DOCUMENT ME! |
|
205 |
*/ |
|
206 |
private void setSelected(int idItem, int idSubItem) { |
|
207 |
m_itemSelected = idItem; |
|
208 |
m_subItemSelected = idSubItem; |
|
209 |
|
|
210 |
int i; |
|
211 |
int numCols; |
|
212 |
int numRows = 0; |
|
213 |
|
|
214 |
for (i = 0; i < m_arrayStrings.size(); i++) { |
|
215 |
if (i == m_itemSelected) { |
|
216 |
m_strInfo = (String) m_arrayStrings.get(i); |
|
217 |
} |
|
218 |
} |
|
219 |
|
|
220 |
StringTokenizer tkz = new StringTokenizer(m_strInfo, "\n"); |
|
221 |
if (! tkz.hasMoreTokens()) return; |
|
222 |
|
|
223 |
String strCampos = tkz.nextToken(); |
|
224 |
|
|
225 |
StringTokenizer tkzCampos = new StringTokenizer(strCampos, "|"); |
|
226 |
i = 0; |
|
227 |
|
|
228 |
while (tkzCampos.hasMoreTokens()) { |
|
229 |
tkzCampos.nextToken(); |
|
230 |
i++; |
|
231 |
} |
|
232 |
|
|
233 |
numCols = i; |
|
234 |
|
|
235 |
int regSelec = 0; |
|
236 |
String strValores = ""; |
|
237 |
|
|
238 |
while (tkz.hasMoreTokens()) { |
|
239 |
String token = tkz.nextToken(); |
|
240 |
|
|
241 |
if (regSelec == m_subItemSelected) { |
|
242 |
strValores = token; |
|
243 |
} |
|
244 |
|
|
245 |
regSelec++; |
|
246 |
} |
|
247 |
|
|
248 |
if (strValores != "") { |
|
249 |
m_gridModel.setData(strCampos, strValores, numCols); |
|
250 |
} |
|
251 |
|
|
252 |
refreshRight(); |
|
253 |
} |
|
254 |
|
|
255 |
/** |
|
256 |
* This method is called from within the constructor to initialize the |
|
257 |
* form. WARNING: Do NOT modify this code. The content of this method is |
|
258 |
* always regenerated by the Form Editor. |
|
259 |
*/ |
|
260 |
private void initComponents() { |
|
261 |
jSplitPane1 = new javax.swing.JSplitPane(); |
|
262 |
|
|
263 |
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("root"); |
|
264 |
m_treeModel = new DefaultTreeModel(rootNode); |
|
265 |
|
|
266 |
jTree1 = new javax.swing.JTree(m_treeModel); |
|
267 |
jTree1.setEditable(true); |
|
268 |
jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); |
|
269 |
jTree1.setShowsRootHandles(true); |
|
270 |
|
|
271 |
m_grid = new javax.swing.JTable(); |
|
272 |
|
|
273 |
/* addWindowListener(new java.awt.event.WindowAdapter() { |
|
274 |
public void windowClosing(java.awt.event.WindowEvent evt) { |
|
275 |
closeDialog(evt); |
|
276 |
} |
|
277 |
}); |
|
278 |
*/ |
|
279 |
jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { |
|
280 |
public void valueChanged( |
|
281 |
javax.swing.event.TreeSelectionEvent evt) { |
|
282 |
jTree1ValueChanged(evt); |
|
283 |
} |
|
284 |
}); |
|
285 |
|
|
286 |
//Create the scroll pane and add the tree to it. |
|
287 |
JScrollPane treeView = new JScrollPane(jTree1); |
|
288 |
treeView.setPreferredSize((new Dimension(80, 200))); |
|
289 |
//Add the scroll panes to a split pane. |
|
290 |
jSplitPane1.setLeftComponent(treeView); |
|
291 |
|
|
292 |
m_gridModel = new MyTableModel(); |
|
293 |
m_grid.setModel(m_gridModel); |
|
294 |
|
|
295 |
JScrollPane tableView = new JScrollPane(m_grid); |
|
296 |
|
|
297 |
// tableView.setBackground(java.awt.Color.WHITE); |
|
298 |
jSplitPane1.setRightComponent(tableView); |
|
299 |
|
|
300 |
java.awt.Dimension minimumSize = new java.awt.Dimension(100, 50); |
|
301 |
m_grid.setMinimumSize(minimumSize); |
|
302 |
treeView.setMinimumSize(minimumSize); |
|
303 |
|
|
304 |
// splitPane.setDividerLocation(100); //XXX: ignored in some releases |
|
305 |
//of Swing. bug 4101306 |
|
306 |
//workaround for bug 4101306: |
|
307 |
//treeView.setPreferredSize(new Dimension(100, 100)); |
|
308 |
jSplitPane1.setPreferredSize(new java.awt.Dimension(300, 200)); |
|
309 |
|
|
310 |
setLayout(new BorderLayout()); |
|
311 |
add(jSplitPane1, java.awt.BorderLayout.CENTER); |
|
312 |
|
|
313 |
//pack(); |
|
314 |
} |
|
315 |
|
|
316 |
/** |
|
317 |
* DOCUMENT ME! |
|
318 |
* |
|
319 |
* @param evt DOCUMENT ME! |
|
320 |
*/ |
|
321 |
private void jTree1ValueChanged(javax.swing.event.TreeSelectionEvent evt) { |
|
322 |
// Add your handling code here: |
|
323 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree1.getLastSelectedPathComponent(); |
|
324 |
|
|
325 |
if (node == null) { |
|
326 |
return; |
|
327 |
} |
|
328 |
|
|
329 |
Object nodeInfo = node.getUserObject(); |
|
330 |
|
|
331 |
if (node.isLeaf()) { |
|
332 |
MyTreeItem dato = (MyTreeItem) nodeInfo; |
|
333 |
setSelected(dato.m_idNodo, dato.m_idSubNodo); |
|
334 |
} |
|
335 |
|
|
336 |
// System.out.println("El path seleccionado= " + jTree1.getRowForPath(evt.getPath())); |
|
337 |
} |
|
338 |
|
|
339 |
|
|
340 |
/** |
|
341 |
* DOCUMENT ME! |
|
342 |
* |
|
343 |
* @param nomTema DOCUMENT ME! |
|
344 |
* @param strInfo DOCUMENT ME! |
|
345 |
*/ |
|
346 |
public void addLayerInfo(String nomTema, String strInfo) { |
|
347 |
m_arrayNomTemas.add(nomTema); |
|
348 |
m_arrayStrings.add(strInfo); |
|
349 |
} |
|
350 |
|
|
351 |
private class MyTableModel extends AbstractTableModel { |
|
352 |
private String[] columnNames; |
|
353 |
private Object[][] data; |
|
354 |
|
|
355 |
MyTableModel() { |
|
356 |
columnNames = new String[2]; |
|
357 |
columnNames[0] = PluginServices.getText(this,"campo"); |
|
358 |
columnNames[1] = PluginServices.getText(this,"Valor"); |
|
359 |
data = new Object[1][2]; |
|
360 |
} |
|
361 |
|
|
362 |
public int getColumnCount() { |
|
363 |
return columnNames.length; |
|
364 |
} |
|
365 |
|
|
366 |
public int getRowCount() { |
|
367 |
return data.length; |
|
368 |
} |
|
369 |
|
|
370 |
public String getColumnName(int col) { |
|
371 |
return columnNames[col]; |
|
372 |
} |
|
373 |
|
|
374 |
public Object getValueAt(int row, int col) { |
|
375 |
return data[row][col]; |
|
376 |
} |
|
377 |
|
|
378 |
public void setData(String strCampos, String strValores, int numRows) { |
|
379 |
// Fijamos columnNames y data en funci�n de strInfo. |
|
380 |
// strInfo es una cabecera con los nombres de los campos separados |
|
381 |
// por | y despu�s una l�nea por cada registro con los valores |
|
382 |
// de los campos. |
|
383 |
data = new Object[numRows][2]; |
|
384 |
|
|
385 |
if (strCampos == "") return; // Como si borraramos la tabla |
|
386 |
|
|
387 |
int i; |
|
388 |
|
|
389 |
StringTokenizer tkzCampos = new StringTokenizer(strCampos, "|"); |
|
390 |
i = 0; |
|
391 |
|
|
392 |
while (tkzCampos.hasMoreTokens()) { |
|
393 |
data[i][0] = tkzCampos.nextToken(); |
|
394 |
i++; |
|
395 |
} |
|
396 |
|
|
397 |
StringTokenizer tkzValores = new StringTokenizer(strValores, "|"); |
|
398 |
String strID = tkzValores.nextToken(); |
|
399 |
i = 0; |
|
400 |
|
|
401 |
while (tkzValores.hasMoreTokens()) { |
|
402 |
// m_grid->SetCellValue(i,1,tkzValores.GetNextToken()); |
|
403 |
data[i][1] = tkzValores.nextToken(); |
|
404 |
i++; |
|
405 |
} |
|
406 |
} |
|
407 |
} |
|
408 |
// MyTableModel |
|
409 |
|
|
410 |
private final class MyTreeItem { |
|
411 |
public int m_idNodo; |
|
412 |
public int m_idSubNodo; |
|
413 |
private String m_strVal; |
|
414 |
|
|
415 |
public MyTreeItem(String str, int idN, int idSub) { |
|
416 |
m_strVal = str; |
|
417 |
m_idNodo = idN; |
|
418 |
m_idSubNodo = idSub; |
|
419 |
} |
|
420 |
|
|
421 |
public String toString() { |
|
422 |
return m_strVal; |
|
423 |
} |
|
424 |
} |
|
425 | 33 |
/* (non-Javadoc) |
426 | 34 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo() |
427 | 35 |
*/ |
428 | 36 |
public ViewInfo getViewInfo() { |
429 |
ViewInfo m_ViewInfo=new ViewInfo(ViewInfo.MODELESSDIALOG|ViewInfo.RESIZABLE); |
|
430 |
m_ViewInfo.setTitle(PluginServices.getText(this,"Identificar_Resultados")); |
|
431 |
return m_ViewInfo; |
|
432 |
} |
|
37 |
ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODELESSDIALOG | |
|
38 |
ViewInfo.RESIZABLE | ViewInfo.PALETTE); |
|
39 |
m_viewinfo.setWidth(300); |
|
40 |
m_viewinfo.setHeight(235); |
|
41 |
m_viewinfo.setTitle(PluginServices.getText(this, |
|
42 |
"Identificar_Resultados")); |
|
433 | 43 |
|
44 |
return m_viewinfo; |
|
45 |
} |
|
46 |
|
|
434 | 47 |
/** |
435 | 48 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel() |
436 | 49 |
*/ |
437 | 50 |
public Object getViewModel() { |
438 |
return viewModel;
|
|
51 |
return "FInfoDialogXML";
|
|
439 | 52 |
} |
440 |
|
|
441 |
// End of variables declaration |
|
442 |
/** |
|
443 |
* @param view |
|
444 |
*/ |
|
445 |
public void setViewModel(ProjectView view) { |
|
446 |
viewModel = view; |
|
447 |
} |
|
448 |
|
|
449 |
/** |
|
450 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated() |
|
451 |
*/ |
|
452 |
public void viewActivated() { |
|
453 |
} |
|
454 |
|
|
455 | 53 |
} |
Also available in: Unified diff