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