root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / gui / TOC.java @ 7304
History | View | Annotate | Download (28.2 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.project.documents.view.toc.gui; |
48 |
|
49 |
import java.awt.BorderLayout; |
50 |
import java.awt.Dimension; |
51 |
import java.awt.Point; |
52 |
import java.awt.Rectangle; |
53 |
import java.awt.event.ActionEvent; |
54 |
import java.awt.event.ActionListener; |
55 |
import java.awt.event.ComponentEvent; |
56 |
import java.awt.event.ComponentListener; |
57 |
import java.awt.event.InputEvent; |
58 |
import java.awt.event.MouseAdapter; |
59 |
import java.awt.event.MouseEvent; |
60 |
import java.util.Enumeration; |
61 |
import java.util.HashMap; |
62 |
|
63 |
import javax.swing.BorderFactory; |
64 |
import javax.swing.JColorChooser; |
65 |
import javax.swing.JComponent; |
66 |
import javax.swing.JDialog; |
67 |
import javax.swing.JScrollPane; |
68 |
import javax.swing.JTree; |
69 |
import javax.swing.SwingUtilities; |
70 |
import javax.swing.UIManager; |
71 |
import javax.swing.event.TreeExpansionEvent; |
72 |
import javax.swing.event.TreeExpansionListener; |
73 |
import javax.swing.tree.DefaultMutableTreeNode; |
74 |
import javax.swing.tree.DefaultTreeModel; |
75 |
import javax.swing.tree.TreePath; |
76 |
import javax.swing.tree.TreeSelectionModel; |
77 |
|
78 |
import com.iver.andami.PluginServices; |
79 |
import com.iver.cit.gvsig.fmap.AtomicEvent; |
80 |
import com.iver.cit.gvsig.fmap.AtomicEventListener; |
81 |
import com.iver.cit.gvsig.fmap.DriverException; |
82 |
import com.iver.cit.gvsig.fmap.MapContext; |
83 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
84 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
85 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
86 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
87 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
88 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
89 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
90 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
91 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
92 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
93 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection; |
94 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
95 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
96 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
97 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
98 |
import com.iver.cit.gvsig.project.documents.view.toc.DnDJTree; |
99 |
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
100 |
import com.iver.cit.gvsig.project.documents.view.toc.ITocOrderListener; |
101 |
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch; |
102 |
import com.iver.cit.gvsig.project.documents.view.toc.TocItemLeaf; |
103 |
|
104 |
|
105 |
/**
|
106 |
* DOCUMENT ME!
|
107 |
*
|
108 |
* @author fjp To change the template for this generated type comment go to
|
109 |
* Window>Preferences>Java>Code Generation>Code and
|
110 |
* Comments
|
111 |
*/
|
112 |
public class TOC extends JComponent implements ITocOrderListener, |
113 |
LegendListener, LayerCollectionListener, TreeExpansionListener,
|
114 |
ComponentListener {
|
115 |
private MapContext mapContext;
|
116 |
private DnDJTree m_Tree;
|
117 |
private DefaultTreeModel m_TreeModel; |
118 |
private DefaultMutableTreeNode m_Root; |
119 |
private TOCRenderer m_TocRenderer;
|
120 |
private JScrollPane m_Scroller; |
121 |
|
122 |
//private ArrayList m_Listeners;
|
123 |
private HashMap m_ItemsExpanded = new HashMap(); |
124 |
private NodeSelectionListener nodeSelectionListener = null; |
125 |
|
126 |
/**
|
127 |
* Crea un nuevo TOC.
|
128 |
*/
|
129 |
public TOC() {
|
130 |
this.setName("TOC"); |
131 |
this.setLayout(new BorderLayout()); |
132 |
this.setMinimumSize(new Dimension(100, 80)); |
133 |
this.setPreferredSize(new Dimension(100, 80)); |
134 |
|
135 |
//Construct the tree.
|
136 |
m_Root = new DefaultMutableTreeNode(java.lang.Object.class); |
137 |
m_TreeModel = new DefaultTreeModel(m_Root); |
138 |
m_Tree = new DnDJTree(m_TreeModel);
|
139 |
|
140 |
m_TocRenderer = new TOCRenderer();
|
141 |
m_Tree.setCellRenderer(m_TocRenderer); |
142 |
|
143 |
m_Tree.setRootVisible(false);
|
144 |
|
145 |
// m_Tree.setExpandsSelectedPaths(true);
|
146 |
// m_Tree.setAutoscrolls(true);
|
147 |
m_Tree.setShowsRootHandles(true);
|
148 |
|
149 |
//Posibilidad de seleccionar de forma aleatoria nodos de la leyenda.
|
150 |
m_Tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
|
151 |
nodeSelectionListener=new NodeSelectionListener(m_Tree);
|
152 |
m_Tree.addMouseListener(nodeSelectionListener); |
153 |
m_Tree.setBackground(UIManager.getColor("Button.background")); |
154 |
m_Tree.setBorder(BorderFactory.createEtchedBorder());
|
155 |
|
156 |
this.addComponentListener(this); |
157 |
|
158 |
m_Tree.addTreeExpansionListener(this);
|
159 |
|
160 |
m_Tree.addOrderListener(this);
|
161 |
|
162 |
m_Tree.setRowHeight(0); // Para que lo determine el renderer |
163 |
|
164 |
m_Scroller = new JScrollPane(m_Tree); |
165 |
m_Scroller.setBorder(BorderFactory.createEmptyBorder());
|
166 |
|
167 |
// scrollPane.setPreferredSize(new Dimension(80,80));
|
168 |
//Add everything to this panel.
|
169 |
/* GridBagLayout gridbag = new GridBagLayout();
|
170 |
GridBagConstraints c = new GridBagConstraints();
|
171 |
setLayout(gridbag);
|
172 |
c.fill = GridBagConstraints.BOTH;
|
173 |
c.weightx = 1.0;
|
174 |
gridbag.setConstraints(check,c); */
|
175 |
add(m_Scroller); //, BorderLayout.WEST);
|
176 |
|
177 |
// refresh();
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Elimina los listeners que actuan sobre el TOC, lo ?nico que deja hacer
|
182 |
* es desplegar la leyenda de las capas.
|
183 |
*/
|
184 |
public void removeListeners() { |
185 |
m_Tree.removeMouseListener(nodeSelectionListener); |
186 |
m_Tree.invalidateListeners(); |
187 |
} |
188 |
|
189 |
/**
|
190 |
* Inserta el FMap.
|
191 |
*
|
192 |
* @param mc FMap.
|
193 |
*/
|
194 |
public void setMapContext(MapContext mc) { |
195 |
mapContext = mc; |
196 |
mapContext.addAtomicEventListener(new AtomicEventListener() {
|
197 |
/**
|
198 |
* @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
|
199 |
*/
|
200 |
public void atomicEvent(AtomicEvent e) { |
201 |
if ((e.getLayerCollectionEvents().length > 0) || |
202 |
(e.getLegendEvents().length > 0)) {
|
203 |
SwingUtilities.invokeLater(new Runnable() { |
204 |
public void run() { |
205 |
refresh(); |
206 |
} |
207 |
}); |
208 |
} |
209 |
|
210 |
if (e.getLayerEvents().length > 0) { |
211 |
repaint(); |
212 |
} |
213 |
|
214 |
if (e.getExtentEvents().length > 0) { |
215 |
repaint(); |
216 |
} |
217 |
} |
218 |
}); |
219 |
|
220 |
SwingUtilities.invokeLater(new Runnable() { |
221 |
public void run() { |
222 |
refresh(); |
223 |
} |
224 |
}); |
225 |
} |
226 |
|
227 |
/**
|
228 |
* DOCUMENT ME!
|
229 |
*/
|
230 |
private void setExpandedNodes() { |
231 |
//int i = 0;
|
232 |
// Las claves sobrantes de m_ItemsExpanded (provocadas
|
233 |
// por layerRemove, se quitan en el evento layerRemoved
|
234 |
// de este TOC
|
235 |
DefaultMutableTreeNode n;
|
236 |
Enumeration enumeration = m_Root.children();
|
237 |
|
238 |
while (enumeration.hasMoreElements()) {
|
239 |
n = (DefaultMutableTreeNode) enumeration.nextElement();
|
240 |
|
241 |
TreePath path = new TreePath(m_TreeModel.getPathToRoot(n)); |
242 |
ITocItem item = (ITocItem) n.getUserObject(); |
243 |
Boolean b = (Boolean) m_ItemsExpanded.get(item.getLabel()); |
244 |
|
245 |
if (b == null) // No estaba en el hash todav?a: valor por defecto |
246 |
{ |
247 |
// System.out.println("Primera expansi?n de " + item.getLabel());
|
248 |
m_Tree.expandPath(path); |
249 |
|
250 |
return;
|
251 |
} |
252 |
|
253 |
if (b.booleanValue()) {
|
254 |
// System.out.println("Expansi?n de " + item.getLabel());
|
255 |
m_Tree.expandPath(path); |
256 |
} else {
|
257 |
// System.out.println("Colapso de " + item.getLabel());
|
258 |
m_Tree.collapsePath(path); |
259 |
} |
260 |
} |
261 |
} |
262 |
|
263 |
/* (non-Javadoc)
|
264 |
* @see com.iver.cit.opensig.gui.IToc#refresh()
|
265 |
*/
|
266 |
public void refresh() { |
267 |
LayerCollection theLayers = mapContext.getLayers(); |
268 |
m_Root.removeAllChildren(); |
269 |
m_Root.setAllowsChildren(true);
|
270 |
System.out.println("Refresh del toc"); |
271 |
doRefresh(theLayers, m_Root); |
272 |
|
273 |
m_TreeModel.reload(); |
274 |
|
275 |
setExpandedNodes(); |
276 |
} |
277 |
|
278 |
/**
|
279 |
* DOCUMENT ME!
|
280 |
*
|
281 |
* @param theLayers DOCUMENT ME!
|
282 |
* @param parentNode DOCUMENT ME!
|
283 |
*/
|
284 |
private void doRefresh(LayerCollection theLayers, |
285 |
DefaultMutableTreeNode parentNode) {
|
286 |
Dimension sizeLeaf = new Dimension(m_Tree.getWidth(), 15); |
287 |
Dimension sizeBranch = new Dimension(m_Tree.getWidth(), 25); |
288 |
|
289 |
for (int i = theLayers.getLayersCount() - 1; i >= 0; i--) { |
290 |
FLayer lyr = theLayers.getLayer(i); |
291 |
if (!lyr.isInTOC())
|
292 |
continue;
|
293 |
TocItemBranch elTema = new TocItemBranch(lyr);
|
294 |
elTema.setSize(sizeBranch); |
295 |
|
296 |
DefaultMutableTreeNode nodeLayer = new DefaultMutableTreeNode(elTema); |
297 |
|
298 |
m_TreeModel.insertNodeInto(nodeLayer, parentNode, |
299 |
parentNode.getChildCount()); |
300 |
|
301 |
//TreePath path = new TreePath(m_TreeModel.getPathToRoot(nodeLayer));
|
302 |
// m_Tree.makeVisible(path);
|
303 |
if (lyr instanceof LayerCollection) { |
304 |
LayerCollection group = (LayerCollection) lyr; |
305 |
doRefresh(group, nodeLayer); |
306 |
} else {
|
307 |
if (lyr instanceof Classifiable && !(lyr instanceof FLyrAnnotation)) { |
308 |
|
309 |
Classifiable aux = (Classifiable) lyr; |
310 |
Legend legendInfo = aux.getLegend(); |
311 |
|
312 |
try {
|
313 |
if (legendInfo instanceof ClassifiedLegendInfo) { |
314 |
ClassifiedLegendInfo cl = (ClassifiedLegendInfo) legendInfo; |
315 |
String[] descriptions = cl.getDescriptions(); |
316 |
FSymbol[] symbols = cl.getSymbols();
|
317 |
|
318 |
for (int j = 0; j < descriptions.length; j++) { |
319 |
TocItemLeaf itemLeaf; |
320 |
itemLeaf = new TocItemLeaf(symbols[j],
|
321 |
descriptions[j], aux.getShapeType()); |
322 |
itemLeaf.setSize(sizeLeaf); |
323 |
|
324 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf); |
325 |
m_TreeModel.insertNodeInto(nodeValue, |
326 |
nodeLayer, nodeLayer.getChildCount()); |
327 |
|
328 |
//TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot(
|
329 |
// nodeValue));
|
330 |
// m_Tree.makeVisible(pathSymbol);
|
331 |
} |
332 |
} |
333 |
|
334 |
if (legendInfo instanceof SingleSymbolLegend && |
335 |
(legendInfo.getDefaultSymbol() != null)) {
|
336 |
TocItemLeaf itemLeaf; |
337 |
itemLeaf = new TocItemLeaf(legendInfo.getDefaultSymbol(),
|
338 |
"Default", aux.getShapeType());
|
339 |
itemLeaf.setSize(sizeLeaf); |
340 |
|
341 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf); |
342 |
m_TreeModel.insertNodeInto(nodeValue, nodeLayer, |
343 |
nodeLayer.getChildCount()); |
344 |
|
345 |
//TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot(
|
346 |
// nodeValue));
|
347 |
// m_Tree.makeVisible(pathSymbol);
|
348 |
} |
349 |
} catch (DriverException e) {
|
350 |
// TODO Auto-generated catch block
|
351 |
e.printStackTrace(); |
352 |
} |
353 |
} |
354 |
} // if instanceof layers
|
355 |
} |
356 |
} |
357 |
|
358 |
/**
|
359 |
* @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int,
|
360 |
* int)
|
361 |
*/
|
362 |
public void orderChanged(int oldPos, int newPos, FLayers lpd) { |
363 |
//LayerCollection layers = mapContext.getLayers();
|
364 |
// El orden es el contrario, hay que traducir.
|
365 |
// El orden es el contrario, hay que traducir.
|
366 |
///oldPos = layers.getLayersCount() - 1 - oldPos;
|
367 |
///newPos = layers.getLayersCount() - 1 - newPos;
|
368 |
try {
|
369 |
lpd.moveTo(oldPos, newPos); |
370 |
} catch (CancelationException e) {
|
371 |
// TODO Auto-generated catch block
|
372 |
e.printStackTrace(); |
373 |
} |
374 |
|
375 |
// No hace falta un refresh, lo hace mediante eventos.
|
376 |
//refresh();
|
377 |
mapContext.invalidate(); |
378 |
} |
379 |
|
380 |
/**
|
381 |
* DOCUMENT ME!
|
382 |
*
|
383 |
* @param lpo DOCUMENT ME!
|
384 |
* @param lpd DOCUMENT ME!
|
385 |
* @param ls DOCUMENT ME!
|
386 |
*/
|
387 |
public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) { |
388 |
lpo.removeLayer(ls); |
389 |
lpd.addLayer(ls); |
390 |
|
391 |
/*if (lpo.getLayersCount()==0){
|
392 |
lpo.getParentLayer().removeLayer(lpo);
|
393 |
}*/
|
394 |
mapContext.invalidate(); |
395 |
} |
396 |
|
397 |
/* (non-Javadoc)
|
398 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
|
399 |
*/
|
400 |
public void componentHidden(ComponentEvent e) { |
401 |
} |
402 |
|
403 |
/* (non-Javadoc)
|
404 |
* @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
|
405 |
*/
|
406 |
public void componentMoved(ComponentEvent e) { |
407 |
} |
408 |
|
409 |
/* (non-Javadoc)
|
410 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
|
411 |
*/
|
412 |
public void componentResized(ComponentEvent e) { |
413 |
System.out.println("Cambiando tama?o."); |
414 |
|
415 |
int i = 0; |
416 |
DefaultMutableTreeNode n;
|
417 |
Enumeration enumeration = m_Root.children();
|
418 |
|
419 |
while (enumeration.hasMoreElements()) {
|
420 |
n = (DefaultMutableTreeNode) enumeration.nextElement();
|
421 |
|
422 |
if (n.getUserObject() instanceof TocItemBranch) { |
423 |
ITocItem item = (ITocItem) n.getUserObject(); |
424 |
Dimension szAnt = item.getSize();
|
425 |
item.setSize(new Dimension(this.getWidth() - 40, szAnt.height)); |
426 |
} |
427 |
|
428 |
} |
429 |
|
430 |
// m_Tree.setSize(this.getSize());
|
431 |
System.out.println("Ancho del tree=" + m_Tree.getWidth() + " " + |
432 |
m_Tree.getComponentCount()); |
433 |
System.out.println("Ancho del TOC=" + this.getWidth()); |
434 |
|
435 |
// m_Tree.repaint();
|
436 |
} |
437 |
|
438 |
/* (non-Javadoc)
|
439 |
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
|
440 |
*/
|
441 |
public void componentShown(ComponentEvent e) { |
442 |
} |
443 |
|
444 |
/* (non-Javadoc)
|
445 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent)
|
446 |
*/
|
447 |
public void legendChanged(LegendChangedEvent e) { |
448 |
System.out.println("Refrescando TOC"); |
449 |
refresh(); |
450 |
} |
451 |
|
452 |
/* (non-Javadoc)
|
453 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
454 |
*/
|
455 |
public void layerAdded(LayerCollectionEvent e) { |
456 |
refresh(); |
457 |
} |
458 |
|
459 |
/* (non-Javadoc)
|
460 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
461 |
*/
|
462 |
public void layerMoved(LayerPositionEvent e) { |
463 |
refresh(); |
464 |
} |
465 |
|
466 |
/* (non-Javadoc)
|
467 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
468 |
*/
|
469 |
public void layerRemoved(LayerCollectionEvent e) { |
470 |
m_ItemsExpanded.remove(e.getAffectedLayer().getName()); |
471 |
refresh(); |
472 |
} |
473 |
|
474 |
/* (non-Javadoc)
|
475 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
476 |
*/
|
477 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
478 |
} |
479 |
|
480 |
/* (non-Javadoc)
|
481 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
482 |
*/
|
483 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
484 |
} |
485 |
|
486 |
/* (non-Javadoc)
|
487 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
488 |
*/
|
489 |
public void layerRemoving(LayerCollectionEvent e) |
490 |
throws CancelationException {
|
491 |
} |
492 |
|
493 |
/* (non-Javadoc)
|
494 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
495 |
*/
|
496 |
public void activationChanged(LayerCollectionEvent e) |
497 |
throws CancelationException {
|
498 |
repaint(); |
499 |
} |
500 |
|
501 |
/* (non-Javadoc)
|
502 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
503 |
*/
|
504 |
public void visibilityChanged(LayerCollectionEvent e) |
505 |
throws CancelationException {
|
506 |
repaint(); |
507 |
} |
508 |
|
509 |
/* (non-Javadoc)
|
510 |
* @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
|
511 |
*/
|
512 |
public void treeCollapsed(TreeExpansionEvent event) { |
513 |
TreePath path = event.getPath();
|
514 |
DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent(); |
515 |
|
516 |
if (n.getUserObject() instanceof ITocItem) { |
517 |
ITocItem item = (ITocItem) n.getUserObject(); |
518 |
Boolean b = Boolean.FALSE; |
519 |
|
520 |
// System.out.println("Collapsed: " + item.getLabel());
|
521 |
m_ItemsExpanded.put(item.getLabel(), b); |
522 |
} |
523 |
} |
524 |
|
525 |
/* (non-Javadoc)
|
526 |
* @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
|
527 |
*/
|
528 |
public void treeExpanded(TreeExpansionEvent event) { |
529 |
TreePath path = event.getPath();
|
530 |
DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent(); |
531 |
|
532 |
if (n.getUserObject() instanceof ITocItem) { |
533 |
ITocItem item = (ITocItem) n.getUserObject(); |
534 |
Boolean b = Boolean.TRUE; |
535 |
|
536 |
// System.out.println("Expanded: " + item.getLabel());
|
537 |
m_ItemsExpanded.put(item.getLabel(), b); |
538 |
} |
539 |
} |
540 |
|
541 |
/**
|
542 |
* Obtiene el JScrollPane que contiene el TOC
|
543 |
*
|
544 |
* @return JScrollPane que contiene el TOC
|
545 |
*/
|
546 |
public JScrollPane getJScrollPane() { |
547 |
return this.m_Scroller; |
548 |
} |
549 |
|
550 |
/**
|
551 |
* DOCUMENT ME!
|
552 |
*
|
553 |
* @return DOCUMENT ME!
|
554 |
*/
|
555 |
public DnDJTree getTree() {
|
556 |
return m_Tree;
|
557 |
} |
558 |
|
559 |
/**
|
560 |
* Clase Listener que reacciona al pulsar sobre el checkbox de un nodo y
|
561 |
* crea un popupmenu al pulsar el bot?n derecho.
|
562 |
*/
|
563 |
class NodeSelectionListener extends MouseAdapter implements ActionListener { |
564 |
JTree tree;
|
565 |
JDialog dlg;
|
566 |
JColorChooser colorChooser;
|
567 |
FPopupMenu popmenu = null;
|
568 |
|
569 |
/**
|
570 |
* Crea un nuevo NodeSelectionListener.
|
571 |
*
|
572 |
* @param tree DOCUMENT ME!
|
573 |
*/
|
574 |
NodeSelectionListener(JTree tree) {
|
575 |
this.tree = tree;
|
576 |
} |
577 |
|
578 |
/**
|
579 |
* DOCUMENT ME!
|
580 |
*
|
581 |
* @param e DOCUMENT ME!
|
582 |
*/
|
583 |
public void mouseClicked(MouseEvent e) { |
584 |
int x = e.getX();
|
585 |
int y = e.getY();
|
586 |
int row = tree.getRowForLocation(x, y);
|
587 |
TreePath path = tree.getPathForRow(row);
|
588 |
LayerCollection layers = mapContext.getLayers(); |
589 |
|
590 |
// System.out.println(e.getSource());
|
591 |
if (path != null) { |
592 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path |
593 |
.getLastPathComponent(); |
594 |
|
595 |
// System.out.println("Evento de rat?n originado por " +
|
596 |
// e.getSource().getClass().toString());
|
597 |
if (node.getUserObject() instanceof TocItemBranch) { |
598 |
TocItemBranch elTema = (TocItemBranch) node.getUserObject(); |
599 |
FLayer lyr = elTema.getLayer(); |
600 |
lyr.getMapContext().beginAtomicEvent(); |
601 |
|
602 |
if (((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) |
603 |
&& (e.getButton() == MouseEvent.BUTTON1)) {
|
604 |
FLayer[] activeLayers = layers.getActives();
|
605 |
if (activeLayers.length > 0) { |
606 |
selectInterval(layers,lyr); |
607 |
} else {
|
608 |
updateActive(lyr, !lyr.isActive()); |
609 |
} |
610 |
|
611 |
} else {
|
612 |
if (!((e.getModifiers() & InputEvent.CTRL_MASK) != 0) |
613 |
&& (e.getButton() == MouseEvent.BUTTON1)) {
|
614 |
layers.setAllActives(false);
|
615 |
} |
616 |
if (e.getButton() == MouseEvent.BUTTON1) { |
617 |
// lyr.setActive(true);
|
618 |
updateActive(lyr, !lyr.isActive()); |
619 |
} |
620 |
} |
621 |
// Si pertenece a un grupo, lo ponemos activo tambi?n.
|
622 |
// FLayer parentLayer = lyr.getParentLayer();
|
623 |
|
624 |
/*
|
625 |
* if (parentLayer != null) { parentLayer.setActive(true); }
|
626 |
*/
|
627 |
Point layerNodeLocation = tree.getUI().getPathBounds(tree,
|
628 |
path).getLocation(); |
629 |
|
630 |
// Rect?ngulo que representa el checkbox
|
631 |
Rectangle checkBoxBounds = m_TocRenderer
|
632 |
.getCheckBoxBounds(); |
633 |
checkBoxBounds.translate((int) layerNodeLocation.getX(),
|
634 |
(int) layerNodeLocation.getY());
|
635 |
|
636 |
if (checkBoxBounds.contains(e.getPoint())) {
|
637 |
updateVisible(lyr); |
638 |
} |
639 |
|
640 |
// }
|
641 |
if (e.getButton() == MouseEvent.BUTTON3) { |
642 |
// Boton derecho sobre un nodo del arbol
|
643 |
// if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
|
644 |
popmenu = new FPopupMenu(mapContext, node);
|
645 |
tree.add(popmenu); |
646 |
|
647 |
// System.out.println("boton derecho");
|
648 |
popmenu.show(e.getComponent(), e.getX(), e.getY()); |
649 |
|
650 |
// }
|
651 |
} |
652 |
|
653 |
lyr.getMapContext().endAtomicEvent(); |
654 |
} |
655 |
|
656 |
if (node.getUserObject() instanceof TocItemLeaf) { |
657 |
// Boton derecho sobre un Simbolo
|
658 |
// TocItemLeaf auxLeaf = (TocItemLeaf) node.getUserObject();
|
659 |
// FSymbol theSym = auxLeaf.getSymbol();
|
660 |
if ((e.getModifiers() & InputEvent.META_MASK) != 0) { |
661 |
popmenu = new FPopupMenu(mapContext, node);
|
662 |
tree.add(popmenu); |
663 |
popmenu.show(e.getComponent(), e.getX(), e.getY()); |
664 |
} |
665 |
} |
666 |
|
667 |
((DefaultTreeModel) tree.getModel()).nodeChanged(node);
|
668 |
|
669 |
if (row == 0) { |
670 |
tree.revalidate(); |
671 |
tree.repaint(); |
672 |
} |
673 |
|
674 |
if (PluginServices.getMainFrame() != null) { |
675 |
PluginServices.getMainFrame().enableControls(); |
676 |
} |
677 |
} else {
|
678 |
if (e.getButton() == MouseEvent.BUTTON3) { |
679 |
popmenu = new FPopupMenu(mapContext, null); |
680 |
tree.add(popmenu); |
681 |
popmenu.show(e.getComponent(), e.getX(), e.getY()); |
682 |
} |
683 |
|
684 |
} |
685 |
|
686 |
} |
687 |
|
688 |
private void selectInterval(LayerCollection layers, FLayer lyr) { |
689 |
FLayer[] activeLayers = layers.getActives();
|
690 |
//if (activeLayers[0].getParentLayer() instanceof FLayers && activeLayers[0].getParentLayer().getParentLayer()!=null) {
|
691 |
// selectInterval((LayerCollection)activeLayers[0].getParentLayer(),lyr);
|
692 |
//}
|
693 |
for (int j = 0; j < layers.getLayersCount(); j++) { |
694 |
FLayer layerAux=layers.getLayer(j); |
695 |
//Si se cumple esta condici?n es porque la primera capa que nos encontramos en el TOC es la que estaba activa
|
696 |
if (activeLayers[0].equals(layerAux)) { |
697 |
boolean isSelected = false; |
698 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
699 |
FLayer layer = layers.getLayer(i); |
700 |
if (!isSelected)
|
701 |
isSelected = layer.isActive(); |
702 |
else {
|
703 |
updateActive(layer, true);
|
704 |
if (lyr.equals(layer)) {
|
705 |
isSelected = false;
|
706 |
} |
707 |
} |
708 |
} |
709 |
break;
|
710 |
} else
|
711 |
//Si se cumple esta condici?n es porque la primera capa que nos encontramos en el TOC es la que acabamos de seleccionar
|
712 |
if (lyr.equals(layerAux)) {
|
713 |
boolean isSelected = false; |
714 |
for (int i = layers.getLayersCount() - 1; i >= 0; i--) { |
715 |
FLayer layer = layers.getLayer(i); |
716 |
if (!isSelected)
|
717 |
isSelected = layer.isActive(); |
718 |
else {
|
719 |
updateActive(layer, true);
|
720 |
if (lyr.equals(layer)) {
|
721 |
isSelected = false;
|
722 |
} |
723 |
} |
724 |
} |
725 |
break;
|
726 |
} |
727 |
} |
728 |
|
729 |
} |
730 |
|
731 |
/**
|
732 |
* DOCUMENT ME!
|
733 |
*
|
734 |
* @param lyr
|
735 |
* DOCUMENT ME!
|
736 |
* @param active
|
737 |
* DOCUMENT ME!
|
738 |
*/
|
739 |
private void updateActive(FLayer lyr, boolean active) { |
740 |
lyr.setActive(active); |
741 |
updateActiveChild(lyr); |
742 |
} |
743 |
|
744 |
/**
|
745 |
* DOCUMENT ME!
|
746 |
*
|
747 |
* @param lyr
|
748 |
* DOCUMENT ME!
|
749 |
*/
|
750 |
private void updateActiveChild(FLayer lyr) { |
751 |
if (lyr instanceof FLayers) { // Es la raiz de una rama o |
752 |
// cualquier nodo intermedio.
|
753 |
|
754 |
FLayers layergroup = (FLayers) lyr; |
755 |
|
756 |
for (int i = 0; i < layergroup.getLayersCount(); i++) { |
757 |
layergroup.getLayer(i).setActive(lyr.isActive()); |
758 |
updateActiveChild(layergroup.getLayer(i)); |
759 |
} |
760 |
} |
761 |
} |
762 |
|
763 |
/**
|
764 |
* Actualiza la visibilidad de la capas.
|
765 |
*
|
766 |
* @param lyr
|
767 |
* Capa sobre la que se est? clickando.
|
768 |
*/
|
769 |
private void updateVisible(FLayer lyr) { |
770 |
if (lyr.isAvailable()) {
|
771 |
lyr.setVisible(!lyr.visibleRequired()); |
772 |
updateVisibleChild(lyr); |
773 |
updateVisibleParent(lyr); |
774 |
} |
775 |
} |
776 |
|
777 |
/**
|
778 |
* Actualiza de forma recursiva la visibilidad de los hijos de la capa
|
779 |
* que se pasa como par?metro.
|
780 |
*
|
781 |
* @param lyr
|
782 |
* Capa a actualizar.
|
783 |
*/
|
784 |
private void updateVisibleChild(FLayer lyr) { |
785 |
if (lyr instanceof FLayers) { //Es la raiz de una rama o cualquier nodo intermedio. |
786 |
|
787 |
FLayers layergroup = (FLayers) lyr; |
788 |
|
789 |
for (int i = 0; i < layergroup.getLayersCount(); i++) { |
790 |
layergroup.getLayer(i).setVisible(lyr.visibleRequired()); |
791 |
updateVisibleChild(layergroup.getLayer(i)); |
792 |
} |
793 |
} |
794 |
} |
795 |
|
796 |
/**
|
797 |
* Actualiza de forma recursiva la visibilidad del padre de la capa que
|
798 |
* se pasa como par?metro.
|
799 |
*
|
800 |
* @param lyr Capa a actualizar.
|
801 |
*/
|
802 |
private void updateVisibleParent(FLayer lyr) { |
803 |
FLayers parent = (FLayers) lyr.getParentLayer(); |
804 |
|
805 |
if (parent != null) { |
806 |
boolean parentVisible = false; |
807 |
|
808 |
for (int i = 0; i < parent.getLayersCount(); i++) { |
809 |
if (parent.getLayer(i).visibleRequired()) {
|
810 |
parentVisible = true;
|
811 |
} |
812 |
} |
813 |
|
814 |
parent.setVisible(parentVisible); |
815 |
updateVisibleParent(parent); |
816 |
} |
817 |
} |
818 |
|
819 |
/**
|
820 |
* DOCUMENT ME!
|
821 |
*
|
822 |
* @param arg0 DOCUMENT ME!
|
823 |
*/
|
824 |
public void actionPerformed(ActionEvent arg0) { |
825 |
} |
826 |
|
827 |
/**
|
828 |
* DOCUMENT ME!
|
829 |
*
|
830 |
* @param arg0 DOCUMENT ME!
|
831 |
*/
|
832 |
public void mouseReleased(MouseEvent arg0) { |
833 |
super.mouseReleased(arg0);
|
834 |
} |
835 |
|
836 |
/**
|
837 |
* DOCUMENT ME!
|
838 |
*
|
839 |
* @param arg0 DOCUMENT ME!
|
840 |
*/
|
841 |
public void mouseEntered(MouseEvent arg0) { |
842 |
// TODO Auto-generated method stub
|
843 |
super.mouseEntered(arg0);
|
844 |
|
845 |
// FJP: COMENTO ESTO.
|
846 |
// LO CORRECTO CREO QUE ES IMPLEMENTAR CORRECTAMENTE
|
847 |
// LOS METODOS DE DRAG AND DROP
|
848 |
|
849 |
/* if (m_Root.getChildCount()==0){
|
850 |
m_Tree.dropRoot(m_Root);
|
851 |
}*/
|
852 |
} |
853 |
} |
854 |
|
855 |
} |