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