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