root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / TOC.java @ 2078
History | View | Annotate | Download (20.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 13-may-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.gui.toc; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.AtomicEvent; |
52 |
import com.iver.cit.gvsig.fmap.AtomicEventListener; |
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.FMap; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
56 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
59 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
60 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
61 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
62 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
64 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection; |
65 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
66 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
67 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
68 |
|
69 |
import java.awt.BorderLayout; |
70 |
import java.awt.Dimension; |
71 |
import java.awt.Point; |
72 |
import java.awt.Rectangle; |
73 |
import java.awt.event.ActionEvent; |
74 |
import java.awt.event.ActionListener; |
75 |
import java.awt.event.ComponentEvent; |
76 |
import java.awt.event.ComponentListener; |
77 |
import java.awt.event.InputEvent; |
78 |
import java.awt.event.MouseAdapter; |
79 |
import java.awt.event.MouseEvent; |
80 |
|
81 |
import java.util.ArrayList; |
82 |
import java.util.Enumeration; |
83 |
import java.util.HashMap; |
84 |
|
85 |
import javax.swing.BorderFactory; |
86 |
import javax.swing.JColorChooser; |
87 |
import javax.swing.JComponent; |
88 |
import javax.swing.JDialog; |
89 |
import javax.swing.JScrollPane; |
90 |
import javax.swing.JTree; |
91 |
import javax.swing.SwingUtilities; |
92 |
import javax.swing.UIManager; |
93 |
import javax.swing.event.TreeExpansionEvent; |
94 |
import javax.swing.event.TreeExpansionListener; |
95 |
import javax.swing.tree.DefaultMutableTreeNode; |
96 |
import javax.swing.tree.DefaultTreeModel; |
97 |
import javax.swing.tree.TreePath; |
98 |
import javax.swing.tree.TreeSelectionModel; |
99 |
|
100 |
|
101 |
/**
|
102 |
* DOCUMENT ME!
|
103 |
*
|
104 |
* @author fjp To change the template for this generated type comment go to
|
105 |
* Window>Preferences>Java>Code Generation>Code and
|
106 |
* Comments
|
107 |
*/
|
108 |
public class TOC extends JComponent implements ITocOrderListener, |
109 |
LegendListener, LayerCollectionListener, TreeExpansionListener,
|
110 |
ComponentListener {
|
111 |
private FMap mapContext;
|
112 |
private DnDJTree m_Tree;
|
113 |
private DefaultTreeModel m_TreeModel; |
114 |
private DefaultMutableTreeNode m_Root; |
115 |
private TOCRenderer m_TocRenderer;
|
116 |
private JScrollPane m_Scroller; |
117 |
private ArrayList m_Listeners; |
118 |
private HashMap m_ItemsExpanded = new HashMap(); |
119 |
|
120 |
/**
|
121 |
* Crea un nuevo TOC.
|
122 |
*/
|
123 |
public TOC() {
|
124 |
this.setLayout(new BorderLayout()); |
125 |
this.setMinimumSize(new Dimension(100, 80)); |
126 |
this.setPreferredSize(new Dimension(100, 80)); |
127 |
|
128 |
//Construct the tree.
|
129 |
m_Root = new DefaultMutableTreeNode(java.lang.Object.class); |
130 |
m_TreeModel = new DefaultTreeModel(m_Root); |
131 |
m_Tree = new DnDJTree(m_TreeModel);
|
132 |
|
133 |
m_TocRenderer = new TOCRenderer();
|
134 |
m_Tree.setCellRenderer(m_TocRenderer); |
135 |
|
136 |
m_Tree.setRootVisible(false);
|
137 |
|
138 |
// m_Tree.setExpandsSelectedPaths(true);
|
139 |
// m_Tree.setAutoscrolls(true);
|
140 |
m_Tree.setShowsRootHandles(true);
|
141 |
|
142 |
//Posibilidad de seleccionar de forma aleatoria nodos de la leyenda.
|
143 |
m_Tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
|
144 |
m_Tree.addMouseListener(new NodeSelectionListener(m_Tree));
|
145 |
m_Tree.setBackground(UIManager.getColor("Button.background")); |
146 |
m_Tree.setBorder(BorderFactory.createEtchedBorder());
|
147 |
|
148 |
this.addComponentListener(this); |
149 |
|
150 |
m_Tree.addTreeExpansionListener(this);
|
151 |
|
152 |
m_Tree.addOrderListener(this);
|
153 |
|
154 |
m_Tree.setRowHeight(0); // Para que lo determine el renderer |
155 |
|
156 |
m_Scroller = new JScrollPane(m_Tree); |
157 |
m_Scroller.setBorder(BorderFactory.createEmptyBorder());
|
158 |
|
159 |
// scrollPane.setPreferredSize(new Dimension(80,80));
|
160 |
//Add everything to this panel.
|
161 |
/* GridBagLayout gridbag = new GridBagLayout();
|
162 |
GridBagConstraints c = new GridBagConstraints();
|
163 |
setLayout(gridbag);
|
164 |
c.fill = GridBagConstraints.BOTH;
|
165 |
c.weightx = 1.0;
|
166 |
gridbag.setConstraints(check,c); */
|
167 |
add(m_Scroller); //, BorderLayout.WEST);
|
168 |
|
169 |
// refresh();
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* DOCUMENT ME!
|
174 |
*
|
175 |
* @param mc DOCUMENT ME!
|
176 |
*/
|
177 |
public void setMapContext(FMap mc) { |
178 |
mapContext = mc; |
179 |
mapContext.addAtomicEventListener(new AtomicEventListener() {
|
180 |
/**
|
181 |
* @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
|
182 |
*/
|
183 |
public void atomicEvent(AtomicEvent e) { |
184 |
if ((e.getLayerCollectionEvents().length > 0) || |
185 |
(e.getLegendEvents().length > 0)) {
|
186 |
SwingUtilities.invokeLater(new Runnable() { |
187 |
public void run() { |
188 |
refresh(); |
189 |
} |
190 |
}); |
191 |
} |
192 |
|
193 |
if (e.getLayerEvents().length > 0) { |
194 |
repaint(); |
195 |
} |
196 |
|
197 |
if (e.getExtentEvents().length > 0) { |
198 |
repaint(); |
199 |
} |
200 |
} |
201 |
}); |
202 |
|
203 |
SwingUtilities.invokeLater(new Runnable() { |
204 |
public void run() { |
205 |
refresh(); |
206 |
} |
207 |
}); |
208 |
} |
209 |
|
210 |
/**
|
211 |
* DOCUMENT ME!
|
212 |
*/
|
213 |
private void setExpandedNodes() { |
214 |
int i = 0; |
215 |
|
216 |
// Las claves sobrantes de m_ItemsExpanded (provocadas
|
217 |
// por layerRemove, se quitan en el evento layerRemoved
|
218 |
// de este TOC
|
219 |
DefaultMutableTreeNode n;
|
220 |
Enumeration enumeration = m_Root.children();
|
221 |
|
222 |
while (enumeration.hasMoreElements()) {
|
223 |
n = (DefaultMutableTreeNode) enumeration.nextElement();
|
224 |
|
225 |
TreePath path = new TreePath(m_TreeModel.getPathToRoot(n)); |
226 |
ITocItem item = (ITocItem) n.getUserObject(); |
227 |
Boolean b = (Boolean) m_ItemsExpanded.get(item.getLabel()); |
228 |
|
229 |
if (b == null) // No estaba en el hash todav?a: valor por defecto |
230 |
{ |
231 |
// System.out.println("Primera expansi?n de " + item.getLabel());
|
232 |
m_Tree.expandPath(path); |
233 |
|
234 |
return;
|
235 |
} |
236 |
|
237 |
if (b.booleanValue()) {
|
238 |
// System.out.println("Expansi?n de " + item.getLabel());
|
239 |
m_Tree.expandPath(path); |
240 |
} else {
|
241 |
// System.out.println("Colapso de " + item.getLabel());
|
242 |
m_Tree.collapsePath(path); |
243 |
} |
244 |
} |
245 |
} |
246 |
|
247 |
/* (non-Javadoc)
|
248 |
* @see com.iver.cit.opensig.gui.IToc#refresh()
|
249 |
*/
|
250 |
public void refresh() { |
251 |
LayerCollection theLayers = mapContext.getLayers(); |
252 |
m_Root.removeAllChildren(); |
253 |
m_Root.setAllowsChildren(true);
|
254 |
System.out.println("Refresh del toc"); |
255 |
doRefresh(theLayers, m_Root); |
256 |
|
257 |
m_TreeModel.reload(); |
258 |
|
259 |
setExpandedNodes(); |
260 |
} |
261 |
|
262 |
/**
|
263 |
* DOCUMENT ME!
|
264 |
*
|
265 |
* @param theLayers DOCUMENT ME!
|
266 |
* @param parentNode DOCUMENT ME!
|
267 |
*/
|
268 |
private void doRefresh(LayerCollection theLayers, |
269 |
DefaultMutableTreeNode parentNode) {
|
270 |
Dimension sizeLeaf = new Dimension(m_Tree.getWidth(), 15); |
271 |
Dimension sizeBranch = new Dimension(m_Tree.getWidth(), 25); |
272 |
|
273 |
for (int i = theLayers.getLayersCount() - 1; i >= 0; i--) { |
274 |
FLayer lyr = theLayers.getLayer(i); |
275 |
TocItemBranch elTema = new TocItemBranch(lyr);
|
276 |
elTema.setSize(sizeBranch); |
277 |
|
278 |
DefaultMutableTreeNode nodeLayer = new DefaultMutableTreeNode(elTema); |
279 |
|
280 |
m_TreeModel.insertNodeInto(nodeLayer, parentNode, |
281 |
parentNode.getChildCount()); |
282 |
|
283 |
TreePath path = new TreePath(m_TreeModel.getPathToRoot(nodeLayer)); |
284 |
|
285 |
// m_Tree.makeVisible(path);
|
286 |
if (lyr instanceof LayerCollection) { |
287 |
LayerCollection group = (LayerCollection) lyr; |
288 |
doRefresh(group, nodeLayer); |
289 |
} else {
|
290 |
if (lyr instanceof Classifiable) { |
291 |
Classifiable aux = (Classifiable) lyr; |
292 |
Legend legendInfo = aux.getLegend(); |
293 |
|
294 |
try {
|
295 |
if (legendInfo instanceof ClassifiedLegendInfo) { |
296 |
ClassifiedLegendInfo cl = (ClassifiedLegendInfo) legendInfo; |
297 |
String[] descriptions = cl.getDescriptions(); |
298 |
FSymbol[] symbols = cl.getSymbols();
|
299 |
|
300 |
for (int j = 0; j < descriptions.length; j++) { |
301 |
TocItemLeaf itemLeaf; |
302 |
itemLeaf = new TocItemLeaf(symbols[j],
|
303 |
descriptions[j], aux.getShapeType()); |
304 |
itemLeaf.setSize(sizeLeaf); |
305 |
|
306 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf); |
307 |
m_TreeModel.insertNodeInto(nodeValue, |
308 |
nodeLayer, nodeLayer.getChildCount()); |
309 |
|
310 |
TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot( |
311 |
nodeValue)); |
312 |
|
313 |
// m_Tree.makeVisible(pathSymbol);
|
314 |
} |
315 |
} |
316 |
|
317 |
if (legendInfo.getDefaultSymbol() != null) { |
318 |
TocItemLeaf itemLeaf; |
319 |
itemLeaf = new TocItemLeaf(legendInfo.getDefaultSymbol(),
|
320 |
"Default", aux.getShapeType());
|
321 |
itemLeaf.setSize(sizeLeaf); |
322 |
|
323 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf); |
324 |
m_TreeModel.insertNodeInto(nodeValue, nodeLayer, |
325 |
nodeLayer.getChildCount()); |
326 |
|
327 |
TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot( |
328 |
nodeValue)); |
329 |
|
330 |
// m_Tree.makeVisible(pathSymbol);
|
331 |
} |
332 |
} catch (DriverException e) {
|
333 |
// TODO Auto-generated catch block
|
334 |
e.printStackTrace(); |
335 |
} |
336 |
} |
337 |
} // if instanceof layers
|
338 |
} |
339 |
} |
340 |
|
341 |
/**
|
342 |
* @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int,
|
343 |
* int)
|
344 |
*/
|
345 |
public void orderChanged(int oldPos, int newPos,FLayers lpd) { |
346 |
LayerCollection layers = mapContext.getLayers(); |
347 |
|
348 |
// El orden es el contrario, hay que traducir.
|
349 |
// El orden es el contrario, hay que traducir.
|
350 |
///oldPos = layers.getLayersCount() - 1 - oldPos;
|
351 |
///newPos = layers.getLayersCount() - 1 - newPos;
|
352 |
|
353 |
try {
|
354 |
lpd.moveTo(oldPos, newPos); |
355 |
} catch (CancelationException e) {
|
356 |
// TODO Auto-generated catch block
|
357 |
e.printStackTrace(); |
358 |
} |
359 |
|
360 |
// No hace falta un refresh, lo hace mediante eventos.
|
361 |
// refresh();
|
362 |
} |
363 |
|
364 |
public void parentChanged(FLayers lpo,FLayers lpd,FLayer ls){ |
365 |
lpo.removeLayer(ls); |
366 |
lpd.addLayer(ls); |
367 |
/*if (lpo.getLayersCount()==0){
|
368 |
lpo.getParentLayer().removeLayer(lpo);
|
369 |
}*/
|
370 |
} |
371 |
/* (non-Javadoc)
|
372 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
373 |
*/
|
374 |
public void componentHidden(ComponentEvent e) { |
375 |
} |
376 |
|
377 |
/* (non-Javadoc)
|
378 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
379 |
*/
|
380 |
public void componentMoved(ComponentEvent e) { |
381 |
} |
382 |
|
383 |
/* (non-Javadoc)
|
384 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
385 |
*/
|
386 |
public void componentResized(ComponentEvent e) { |
387 |
System.out.println("Cambiando tama?o."); |
388 |
|
389 |
int i = 0; |
390 |
DefaultMutableTreeNode n;
|
391 |
Enumeration enumeration = m_Root.children();
|
392 |
|
393 |
while (enumeration.hasMoreElements()) {
|
394 |
n = (DefaultMutableTreeNode) enumeration.nextElement();
|
395 |
|
396 |
if (n.getUserObject() instanceof TocItemBranch) { |
397 |
ITocItem item = (ITocItem) n.getUserObject(); |
398 |
Dimension szAnt = item.getSize();
|
399 |
item.setSize(new Dimension(this.getWidth() - 40, szAnt.height)); |
400 |
} |
401 |
|
402 |
System.out.println("i=" + i++); |
403 |
} |
404 |
|
405 |
// m_Tree.setSize(this.getSize());
|
406 |
System.out.println("Ancho del tree=" + m_Tree.getWidth() + " " + |
407 |
m_Tree.getComponentCount()); |
408 |
System.out.println("Ancho del TOC=" + this.getWidth()); |
409 |
|
410 |
// m_Tree.repaint();
|
411 |
} |
412 |
|
413 |
/* (non-Javadoc)
|
414 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
415 |
*/
|
416 |
public void componentShown(ComponentEvent e) { |
417 |
} |
418 |
|
419 |
/* (non-Javadoc)
|
420 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent)
|
421 |
*/
|
422 |
public void legendChanged(LegendChangedEvent e) { |
423 |
System.out.println("Refrescando TOC"); |
424 |
refresh(); |
425 |
} |
426 |
|
427 |
/* (non-Javadoc)
|
428 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
429 |
*/
|
430 |
public void layerAdded(LayerCollectionEvent e) { |
431 |
refresh(); |
432 |
} |
433 |
|
434 |
/* (non-Javadoc)
|
435 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
436 |
*/
|
437 |
public void layerMoved(LayerPositionEvent e) { |
438 |
refresh(); |
439 |
} |
440 |
|
441 |
/* (non-Javadoc)
|
442 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
443 |
*/
|
444 |
public void layerRemoved(LayerCollectionEvent e) { |
445 |
m_ItemsExpanded.remove(e.getAffectedLayer().getName()); |
446 |
refresh(); |
447 |
} |
448 |
|
449 |
/* (non-Javadoc)
|
450 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
451 |
*/
|
452 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
453 |
} |
454 |
|
455 |
/* (non-Javadoc)
|
456 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
457 |
*/
|
458 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
459 |
} |
460 |
|
461 |
/* (non-Javadoc)
|
462 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
463 |
*/
|
464 |
public void layerRemoving(LayerCollectionEvent e) |
465 |
throws CancelationException {
|
466 |
} |
467 |
|
468 |
/* (non-Javadoc)
|
469 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
470 |
*/
|
471 |
public void activationChanged(LayerCollectionEvent e) |
472 |
throws CancelationException {
|
473 |
repaint(); |
474 |
} |
475 |
|
476 |
/* (non-Javadoc)
|
477 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
478 |
*/
|
479 |
public void visibilityChanged(LayerCollectionEvent e) |
480 |
throws CancelationException {
|
481 |
repaint(); |
482 |
} |
483 |
|
484 |
/* (non-Javadoc)
|
485 |
* @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
|
486 |
*/
|
487 |
public void treeCollapsed(TreeExpansionEvent event) { |
488 |
TreePath path = event.getPath();
|
489 |
DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent(); |
490 |
|
491 |
if (n.getUserObject() instanceof ITocItem) { |
492 |
ITocItem item = (ITocItem) n.getUserObject(); |
493 |
Boolean b = Boolean.FALSE; |
494 |
|
495 |
// System.out.println("Collapsed: " + item.getLabel());
|
496 |
m_ItemsExpanded.put(item.getLabel(), b); |
497 |
} |
498 |
} |
499 |
|
500 |
/* (non-Javadoc)
|
501 |
* @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
|
502 |
*/
|
503 |
public void treeExpanded(TreeExpansionEvent event) { |
504 |
TreePath path = event.getPath();
|
505 |
DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent(); |
506 |
|
507 |
if (n.getUserObject() instanceof ITocItem) { |
508 |
ITocItem item = (ITocItem) n.getUserObject(); |
509 |
Boolean b = Boolean.TRUE; |
510 |
|
511 |
// System.out.println("Expanded: " + item.getLabel());
|
512 |
m_ItemsExpanded.put(item.getLabel(), b); |
513 |
} |
514 |
} |
515 |
|
516 |
/**
|
517 |
* Clase Listener que reacciona al pulsar sobre el checkbox de un nodo y
|
518 |
* crea un popupmenu al pulsar el bot?n derecho.
|
519 |
*/
|
520 |
class NodeSelectionListener extends MouseAdapter implements ActionListener { |
521 |
JTree tree;
|
522 |
JDialog dlg;
|
523 |
JColorChooser colorChooser;
|
524 |
FPopupMenu popmenu = null;
|
525 |
|
526 |
/**
|
527 |
* Crea un nuevo NodeSelectionListener.
|
528 |
*
|
529 |
* @param tree DOCUMENT ME!
|
530 |
*/
|
531 |
NodeSelectionListener(JTree tree) {
|
532 |
this.tree = tree;
|
533 |
} |
534 |
|
535 |
/**
|
536 |
* DOCUMENT ME!
|
537 |
*
|
538 |
* @param e DOCUMENT ME!
|
539 |
*/
|
540 |
public void mouseClicked(MouseEvent e) { |
541 |
int x = e.getX();
|
542 |
int y = e.getY();
|
543 |
int row = tree.getRowForLocation(x, y);
|
544 |
TreePath path = tree.getPathForRow(row);
|
545 |
LayerCollection layers = mapContext.getLayers(); |
546 |
|
547 |
// System.out.println(e.getSource());
|
548 |
if (path != null) { |
549 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); |
550 |
|
551 |
// System.out.println("Evento de rat?n originado por " + e.getSource().getClass().toString());
|
552 |
if (node.getUserObject() instanceof TocItemBranch) { |
553 |
|
554 |
TocItemBranch elTema = (TocItemBranch) node.getUserObject(); |
555 |
FLayer lyr = elTema.getLayer(); |
556 |
lyr.getFMap().beginAtomicEvent(); |
557 |
//if (e.getButton()==MouseEvent.BUTTON1){
|
558 |
// Si tenemos may?sculas apretadas es que queremos activar m?s temas.
|
559 |
// Si no, primero desactivamos temas
|
560 |
if (!((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) && e.getButton()==MouseEvent.BUTTON1) { |
561 |
layers.setAllActives(false);
|
562 |
} |
563 |
|
564 |
if (e.getButton()==MouseEvent.BUTTON1){ |
565 |
//lyr.setActive(true);
|
566 |
updateActive(lyr,!lyr.isActive()); |
567 |
}else{
|
568 |
updateActive(lyr,true);
|
569 |
} |
570 |
// Si pertenece a un grupo, lo ponemos activo tambi?n.
|
571 |
FLayer parentLayer = lyr.getParentLayer(); |
572 |
|
573 |
/*if (parentLayer != null) {
|
574 |
parentLayer.setActive(true);
|
575 |
}*/
|
576 |
|
577 |
Point layerNodeLocation = tree.getUI()
|
578 |
.getPathBounds(tree, path) |
579 |
.getLocation(); |
580 |
|
581 |
//Rect?ngulo que representa el checkbox
|
582 |
Rectangle checkBoxBounds = m_TocRenderer.getCheckBoxBounds();
|
583 |
checkBoxBounds.translate((int) layerNodeLocation.getX(),
|
584 |
(int) layerNodeLocation.getY());
|
585 |
|
586 |
if (checkBoxBounds.contains(e.getPoint())) {
|
587 |
updateVisible(lyr); |
588 |
} |
589 |
//}
|
590 |
if (e.getButton()==MouseEvent.BUTTON3 && layers.getActives().length>0){ |
591 |
//Boton derecho sobre un nodo del arbol
|
592 |
//if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
|
593 |
popmenu = new FPopupMenu(mapContext, node);
|
594 |
tree.add(popmenu); |
595 |
|
596 |
//System.out.println("boton derecho");
|
597 |
popmenu.show(e.getComponent(), e.getX(), e.getY()); |
598 |
//}
|
599 |
} |
600 |
lyr.getFMap().endAtomicEvent(); |
601 |
} |
602 |
|
603 |
if (node.getUserObject() instanceof TocItemLeaf) { |
604 |
//Boton derecho sobre un Simbolo
|
605 |
TocItemLeaf auxLeaf = (TocItemLeaf) node.getUserObject(); |
606 |
FSymbol theSym = auxLeaf.getSymbol(); |
607 |
|
608 |
if ((e.getModifiers() & InputEvent.META_MASK) != 0) { |
609 |
popmenu = new FPopupMenu(mapContext, node);
|
610 |
tree.add(popmenu); |
611 |
popmenu.show(e.getComponent(), e.getX(), e.getY()); |
612 |
} |
613 |
} |
614 |
|
615 |
((DefaultTreeModel) tree.getModel()).nodeChanged(node);
|
616 |
|
617 |
if (row == 0) { |
618 |
tree.revalidate(); |
619 |
tree.repaint(); |
620 |
} |
621 |
|
622 |
if (PluginServices.getMainFrame() != null) { |
623 |
PluginServices.getMainFrame().enableControls(); |
624 |
} |
625 |
} |
626 |
|
627 |
} |
628 |
|
629 |
private void updateActive(FLayer lyr,boolean active) { |
630 |
lyr.setActive(active); |
631 |
updateActiveChild(lyr); |
632 |
} |
633 |
|
634 |
private void updateActiveChild(FLayer lyr) { |
635 |
if (lyr instanceof FLayers) { //Es la raiz de una rama o cualquier nodo intermedio. |
636 |
FLayers layergroup = (FLayers) lyr; |
637 |
|
638 |
for (int i = 0; i < layergroup.getLayersCount(); i++) { |
639 |
layergroup.getLayer(i).setActive(lyr.isActive()); |
640 |
updateActiveChild(layergroup.getLayer(i)); |
641 |
} |
642 |
} |
643 |
} |
644 |
|
645 |
/**
|
646 |
* Actualiza la visibilidad de la capas.
|
647 |
*
|
648 |
* @param lyr Capa sobre la que se est? clickando.
|
649 |
*/
|
650 |
private void updateVisible(FLayer lyr) { |
651 |
lyr.setVisible(!lyr.isVisible()); |
652 |
updateVisibleChild(lyr); |
653 |
updateVisibleParent(lyr); |
654 |
} |
655 |
|
656 |
/**
|
657 |
* Actualiza de forma recursiva la visibilidad de los hijos de la capa que se pasa como par?metro.
|
658 |
*
|
659 |
* @param lyr Capa a actualizar.
|
660 |
*/
|
661 |
private void updateVisibleChild(FLayer lyr) { |
662 |
if (lyr instanceof FLayers) { //Es la raiz de una rama o cualquier nodo intermedio. |
663 |
|
664 |
FLayers layergroup = (FLayers) lyr; |
665 |
|
666 |
for (int i = 0; i < layergroup.getLayersCount(); i++) { |
667 |
layergroup.getLayer(i).setVisible(lyr.isVisible()); |
668 |
updateVisibleChild(layergroup.getLayer(i)); |
669 |
} |
670 |
} |
671 |
} |
672 |
|
673 |
/**
|
674 |
* Actualiza de forma recursiva la visibilidad del padre de la capa que se pasa como par?metro.
|
675 |
*
|
676 |
* @param lyr Capa a actualizar.
|
677 |
*/
|
678 |
private void updateVisibleParent(FLayer lyr) { |
679 |
FLayers parent = (FLayers) lyr.getParentLayer(); |
680 |
|
681 |
if (parent != null) { |
682 |
boolean parentVisible = false; |
683 |
|
684 |
for (int i = 0; i < parent.getLayersCount(); i++) { |
685 |
if (parent.getLayer(i).isVisible()) {
|
686 |
parentVisible = true;
|
687 |
} |
688 |
} |
689 |
|
690 |
parent.setVisible(parentVisible); |
691 |
updateVisibleParent(parent); |
692 |
} |
693 |
} |
694 |
|
695 |
/**
|
696 |
* DOCUMENT ME!
|
697 |
*
|
698 |
* @param arg0 DOCUMENT ME!
|
699 |
*/
|
700 |
public void actionPerformed(ActionEvent arg0) { |
701 |
} |
702 |
} |
703 |
} |