Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / TOC.java @ 2791

History | View | Annotate | Download (27 KB)

1
/*
2
 * Created on 13-may-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.gui.toc;
48

    
49
import com.iver.andami.PluginServices;
50

    
51
import com.iver.cit.gvsig.fmap.AtomicEvent;
52
import com.iver.cit.gvsig.fmap.AtomicEventListener;
53
import com.iver.cit.gvsig.fmap.DriverException;
54
import com.iver.cit.gvsig.fmap.FMap;
55
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
56
import com.iver.cit.gvsig.fmap.layers.CancelationException;
57
import com.iver.cit.gvsig.fmap.layers.FLayer;
58
import com.iver.cit.gvsig.fmap.layers.FLayers;
59
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
60
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
61
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
62
import com.iver.cit.gvsig.fmap.layers.LegendListener;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection;
65
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
66
import com.iver.cit.gvsig.fmap.rendering.Legend;
67
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
68
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
69

    
70
import java.awt.BorderLayout;
71
import java.awt.Dimension;
72
import java.awt.Point;
73
import java.awt.Rectangle;
74
import java.awt.event.ActionEvent;
75
import java.awt.event.ActionListener;
76
import java.awt.event.ComponentEvent;
77
import java.awt.event.ComponentListener;
78
import java.awt.event.InputEvent;
79
import java.awt.event.MouseAdapter;
80
import java.awt.event.MouseEvent;
81

    
82
import java.util.Enumeration;
83
import java.util.HashMap;
84

    
85
import javax.swing.BorderFactory;
86
import javax.swing.JColorChooser;
87
import javax.swing.JComponent;
88
import javax.swing.JDialog;
89
import javax.swing.JScrollPane;
90
import javax.swing.JTree;
91
import javax.swing.SwingUtilities;
92
import javax.swing.UIManager;
93
import javax.swing.event.TreeExpansionEvent;
94
import javax.swing.event.TreeExpansionListener;
95
import javax.swing.tree.DefaultMutableTreeNode;
96
import javax.swing.tree.DefaultTreeModel;
97
import javax.swing.tree.TreePath;
98
import javax.swing.tree.TreeSelectionModel;
99

    
100

    
101
/**
102
 * DOCUMENT ME!
103
 *
104
 * @author fjp To change the template for this generated type comment go to
105
 *         Window>Preferences>Java>Code Generation>Code and
106
 *         Comments
107
 */
108
public class TOC extends JComponent implements ITocOrderListener,
109
    LegendListener, LayerCollectionListener, TreeExpansionListener,
110
    ComponentListener {
111
    private FMap mapContext;
112
    private DnDJTree m_Tree;
113
    private DefaultTreeModel m_TreeModel;
114
    private DefaultMutableTreeNode m_Root;
115
    private TOCRenderer m_TocRenderer;
116
    private JScrollPane m_Scroller;
117

    
118
    //private ArrayList m_Listeners;
119
    private HashMap m_ItemsExpanded = new HashMap();
120
    private NodeSelectionListener nodeSelectionListener = new NodeSelectionListener(m_Tree);
121

    
122
    /**
123
     * Crea un nuevo TOC.
124
     */
125
    public TOC() {
126
        this.setLayout(new BorderLayout());
127
        this.setMinimumSize(new Dimension(100, 80));
128
        this.setPreferredSize(new Dimension(100, 80));
129

    
130
        //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

    
135
        m_TocRenderer = new TOCRenderer();
136
        m_Tree.setCellRenderer(m_TocRenderer);
137

    
138
        m_Tree.setRootVisible(false);
139

    
140
        // m_Tree.setExpandsSelectedPaths(true);
141
        // m_Tree.setAutoscrolls(true);
142
        m_Tree.setShowsRootHandles(true);
143

    
144
        //Posibilidad de seleccionar de forma aleatoria nodos de la leyenda.
145
        m_Tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
146
        m_Tree.addMouseListener(nodeSelectionListener);
147
        m_Tree.setBackground(UIManager.getColor("Button.background"));
148
        m_Tree.setBorder(BorderFactory.createEtchedBorder());
149

    
150
        this.addComponentListener(this);
151

    
152
        m_Tree.addTreeExpansionListener(this);
153

    
154
        m_Tree.addOrderListener(this);
155

    
156
        m_Tree.setRowHeight(0); // Para que lo determine el renderer
157

    
158
        m_Scroller = new JScrollPane(m_Tree);
159
        m_Scroller.setBorder(BorderFactory.createEmptyBorder());
160

    
161
        // scrollPane.setPreferredSize(new Dimension(80,80));
162
        //Add everything to this panel.
163
        /* GridBagLayout gridbag = new GridBagLayout();
164
           GridBagConstraints c = new GridBagConstraints();
165
           setLayout(gridbag);
166
           c.fill = GridBagConstraints.BOTH;
167
           c.weightx = 1.0;
168
           gridbag.setConstraints(check,c); */
169
        add(m_Scroller); //, BorderLayout.WEST);
170

    
171
        //                refresh();
172
    }
173

    
174
    /**
175
     * Elimina los listeners que actuan sobre el TOC, lo ?nico que deja hacer
176
     * es desplegar la leyenda de las capas.
177
     */
178
    public void removeListeners() {
179
        m_Tree.removeMouseListener(nodeSelectionListener);
180
        m_Tree.invalidateListeners();
181
    }
182

    
183
    /**
184
     * Inserta el FMap.
185
     *
186
     * @param mc FMap.
187
     */
188
    public void setMapContext(FMap mc) {
189
        mapContext = mc;
190
        mapContext.addAtomicEventListener(new AtomicEventListener() {
191
                /**
192
                 * @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
193
                 */
194
                public void atomicEvent(AtomicEvent e) {
195
                    if ((e.getLayerCollectionEvents().length > 0) ||
196
                            (e.getLegendEvents().length > 0)) {
197
                        SwingUtilities.invokeLater(new Runnable() {
198
                                public void run() {
199
                                    refresh();
200
                                }
201
                            });
202
                    }
203

    
204
                    if (e.getLayerEvents().length > 0) {
205
                        repaint();
206
                    }
207

    
208
                    if (e.getExtentEvents().length > 0) {
209
                        repaint();
210
                    }
211
                }
212
            });
213

    
214
        SwingUtilities.invokeLater(new Runnable() {
215
                public void run() {
216
                    refresh();
217
                }
218
            });
219
    }
220

    
221
    /**
222
     * DOCUMENT ME!
223
     */
224
    private void setExpandedNodes() {
225
        //int i = 0;
226
        // Las claves sobrantes de m_ItemsExpanded (provocadas
227
        // por layerRemove, se quitan en el evento layerRemoved
228
        // de este TOC
229
        DefaultMutableTreeNode n;
230
        Enumeration enumeration = m_Root.children();
231

    
232
        while (enumeration.hasMoreElements()) {
233
            n = (DefaultMutableTreeNode) enumeration.nextElement();
234

    
235
            TreePath path = new TreePath(m_TreeModel.getPathToRoot(n));
236
            ITocItem item = (ITocItem) n.getUserObject();
237
            Boolean b = (Boolean) m_ItemsExpanded.get(item.getLabel());
238

    
239
            if (b == null) // No estaba en el hash todav?a: valor por defecto
240
             {
241
                // System.out.println("Primera expansi?n de " + item.getLabel());
242
                m_Tree.expandPath(path);
243

    
244
                return;
245
            }
246

    
247
            if (b.booleanValue()) {
248
                // System.out.println("Expansi?n de " + item.getLabel());
249
                m_Tree.expandPath(path);
250
            } else {
251
                // System.out.println("Colapso de " + item.getLabel());
252
                m_Tree.collapsePath(path);
253
            }
254
        }
255
    }
256

    
257
    /* (non-Javadoc)
258
     * @see com.iver.cit.opensig.gui.IToc#refresh()
259
     */
260
    public void refresh() {
261
        LayerCollection theLayers = mapContext.getLayers();
262
        m_Root.removeAllChildren();
263
        m_Root.setAllowsChildren(true);
264
        System.out.println("Refresh del toc");
265
        doRefresh(theLayers, m_Root);
266

    
267
        m_TreeModel.reload();
268

    
269
        setExpandedNodes();
270
    }
271

    
272
    /**
273
     * DOCUMENT ME!
274
     *
275
     * @param theLayers DOCUMENT ME!
276
     * @param parentNode DOCUMENT ME!
277
     */
278
    private void doRefresh(LayerCollection theLayers,
279
        DefaultMutableTreeNode parentNode) {
280
        Dimension sizeLeaf = new Dimension(m_Tree.getWidth(), 15);
281
        Dimension sizeBranch = new Dimension(m_Tree.getWidth(), 25);
282

    
283
        for (int i = theLayers.getLayersCount() - 1; i >= 0; i--) {
284
            FLayer lyr = theLayers.getLayer(i);
285
            TocItemBranch elTema = new TocItemBranch(lyr);
286
            elTema.setSize(sizeBranch);
287

    
288
            DefaultMutableTreeNode nodeLayer = new DefaultMutableTreeNode(elTema);
289

    
290
            m_TreeModel.insertNodeInto(nodeLayer, parentNode,
291
                parentNode.getChildCount());
292

    
293
            //TreePath path = new TreePath(m_TreeModel.getPathToRoot(nodeLayer));
294
            // m_Tree.makeVisible(path);
295
            if (lyr instanceof LayerCollection) {
296
                LayerCollection group = (LayerCollection) lyr;
297
                doRefresh(group, nodeLayer);
298
            } else {
299
                if (lyr instanceof Classifiable) {
300
                    Classifiable aux = (Classifiable) lyr;
301
                    Legend legendInfo = aux.getLegend();
302

    
303
                    try {
304
                        if (legendInfo instanceof ClassifiedLegendInfo) {
305
                            ClassifiedLegendInfo cl = (ClassifiedLegendInfo) legendInfo;
306
                            String[] descriptions = cl.getDescriptions();
307
                            FSymbol[] symbols = cl.getSymbols();
308

    
309
                            for (int j = 0; j < descriptions.length; j++) {
310
                                TocItemLeaf itemLeaf;
311
                                itemLeaf = new TocItemLeaf(symbols[j],
312
                                        descriptions[j], aux.getShapeType());
313
                                itemLeaf.setSize(sizeLeaf);
314

    
315
                                DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf);
316
                                m_TreeModel.insertNodeInto(nodeValue,
317
                                    nodeLayer, nodeLayer.getChildCount());
318

    
319
                                //TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot(
320
                                //                        nodeValue));
321
                                // m_Tree.makeVisible(pathSymbol);                                                        
322
                            }
323
                        }
324

    
325
                        if (legendInfo instanceof SingleSymbolLegend &&
326
                                (legendInfo.getDefaultSymbol() != null)) {
327
                            TocItemLeaf itemLeaf;
328
                            itemLeaf = new TocItemLeaf(legendInfo.getDefaultSymbol(),
329
                                    "Default", aux.getShapeType());
330
                            itemLeaf.setSize(sizeLeaf);
331

    
332
                            DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf);
333
                            m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
334
                                nodeLayer.getChildCount());
335

    
336
                            //TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot(
337
                            //                        nodeValue));
338
                            // m_Tree.makeVisible(pathSymbol);
339
                        }
340
                    } catch (DriverException e) {
341
                        // TODO Auto-generated catch block
342
                        e.printStackTrace();
343
                    }
344
                }
345
            } // if instanceof layers
346
        }
347
    }
348

    
349
    /**
350
     * @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int,
351
     *      int)
352
     */
353
    public void orderChanged(int oldPos, int newPos, FLayers lpd) {
354
        //LayerCollection layers = mapContext.getLayers();
355
        // El orden es el contrario, hay que traducir.
356
        // El orden es el contrario, hay que traducir.
357
        ///oldPos = layers.getLayersCount() - 1 - oldPos;
358
        ///newPos = layers.getLayersCount() - 1 - newPos;
359
        try {
360
            lpd.moveTo(oldPos, newPos);
361
        } catch (CancelationException e) {
362
            // TODO Auto-generated catch block
363
            e.printStackTrace();
364
        }
365

    
366
        // No hace falta un refresh, lo hace mediante eventos.
367
        //refresh();
368
        mapContext.invalidate();
369
    }
370

    
371
    /**
372
     * DOCUMENT ME!
373
     *
374
     * @param lpo DOCUMENT ME!
375
     * @param lpd DOCUMENT ME!
376
     * @param ls DOCUMENT ME!
377
     */
378
    public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) {
379
        lpo.removeLayer(ls);
380
        lpd.addLayer(ls);
381

    
382
        /*if (lpo.getLayersCount()==0){
383
           lpo.getParentLayer().removeLayer(lpo);
384
           }*/
385
        mapContext.invalidate();
386
    }
387

    
388
    /* (non-Javadoc)
389
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
390
     */
391
    public void componentHidden(ComponentEvent e) {
392
    }
393

    
394
    /* (non-Javadoc)
395
     * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
396
     */
397
    public void componentMoved(ComponentEvent e) {
398
    }
399

    
400
    /* (non-Javadoc)
401
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
402
     */
403
    public void componentResized(ComponentEvent e) {
404
        System.out.println("Cambiando tama?o.");
405

    
406
        int i = 0;
407
        DefaultMutableTreeNode n;
408
        Enumeration enumeration = m_Root.children();
409

    
410
        while (enumeration.hasMoreElements()) {
411
            n = (DefaultMutableTreeNode) enumeration.nextElement();
412

    
413
            if (n.getUserObject() instanceof TocItemBranch) {
414
                ITocItem item = (ITocItem) n.getUserObject();
415
                Dimension szAnt = item.getSize();
416
                item.setSize(new Dimension(this.getWidth() - 40, szAnt.height));
417
            }
418

    
419
            System.out.println("i=" + i++);
420
        }
421

    
422
        // m_Tree.setSize(this.getSize());
423
        System.out.println("Ancho del tree=" + m_Tree.getWidth() + " " +
424
            m_Tree.getComponentCount());
425
        System.out.println("Ancho del TOC=" + this.getWidth());
426

    
427
        // m_Tree.repaint();
428
    }
429

    
430
    /* (non-Javadoc)
431
     * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
432
     */
433
    public void componentShown(ComponentEvent e) {
434
    }
435

    
436
    /* (non-Javadoc)
437
     * @see com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent)
438
     */
439
    public void legendChanged(LegendChangedEvent e) {
440
        System.out.println("Refrescando TOC");
441
        refresh();
442
    }
443

    
444
    /* (non-Javadoc)
445
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
446
     */
447
    public void layerAdded(LayerCollectionEvent e) {
448
        refresh();
449
    }
450

    
451
    /* (non-Javadoc)
452
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
453
     */
454
    public void layerMoved(LayerPositionEvent e) {
455
        refresh();
456
    }
457

    
458
    /* (non-Javadoc)
459
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
460
     */
461
    public void layerRemoved(LayerCollectionEvent e) {
462
        m_ItemsExpanded.remove(e.getAffectedLayer().getName());
463
        refresh();
464
    }
465

    
466
    /* (non-Javadoc)
467
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
468
     */
469
    public void layerAdding(LayerCollectionEvent e) throws CancelationException {
470
    }
471

    
472
    /* (non-Javadoc)
473
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
474
     */
475
    public void layerMoving(LayerPositionEvent e) throws CancelationException {
476
    }
477

    
478
    /* (non-Javadoc)
479
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
480
     */
481
    public void layerRemoving(LayerCollectionEvent e)
482
        throws CancelationException {
483
    }
484

    
485
    /* (non-Javadoc)
486
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
487
     */
488
    public void activationChanged(LayerCollectionEvent e)
489
        throws CancelationException {
490
        repaint();
491
    }
492

    
493
    /* (non-Javadoc)
494
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
495
     */
496
    public void visibilityChanged(LayerCollectionEvent e)
497
        throws CancelationException {
498
        repaint();
499
    }
500

    
501
    /* (non-Javadoc)
502
     * @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
503
     */
504
    public void treeCollapsed(TreeExpansionEvent event) {
505
        TreePath path = event.getPath();
506
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent();
507

    
508
        if (n.getUserObject() instanceof ITocItem) {
509
            ITocItem item = (ITocItem) n.getUserObject();
510
            Boolean b = Boolean.FALSE;
511

    
512
            // System.out.println("Collapsed: " + item.getLabel());
513
            m_ItemsExpanded.put(item.getLabel(), b);
514
        }
515
    }
516

    
517
    /* (non-Javadoc)
518
     * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
519
     */
520
    public void treeExpanded(TreeExpansionEvent event) {
521
        TreePath path = event.getPath();
522
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent();
523

    
524
        if (n.getUserObject() instanceof ITocItem) {
525
            ITocItem item = (ITocItem) n.getUserObject();
526
            Boolean b = Boolean.TRUE;
527

    
528
            // System.out.println("Expanded: " + item.getLabel());
529
            m_ItemsExpanded.put(item.getLabel(), b);
530
        }
531
    }
532

    
533
    /**
534
     * Obtiene el JScrollPane que contiene el TOC
535
     *
536
     * @return JScrollPane que contiene el TOC
537
     */
538
    public JScrollPane getJScrollPane() {
539
        return this.m_Scroller;
540
    }
541

    
542
    /**
543
     * DOCUMENT ME!
544
     *
545
     * @return DOCUMENT ME!
546
     */
547
    public DnDJTree getTree() {
548
        return m_Tree;
549
    }
550

    
551
    /**
552
     * Clase Listener que reacciona al pulsar sobre el checkbox de un nodo y
553
     * crea un popupmenu al pulsar el bot?n derecho.
554
     */
555
    class NodeSelectionListener extends MouseAdapter implements ActionListener {
556
        JTree tree;
557
        JDialog dlg;
558
        JColorChooser colorChooser;
559
        FPopupMenu popmenu = null;
560

    
561
        /**
562
         * Crea un nuevo NodeSelectionListener.
563
         *
564
         * @param tree DOCUMENT ME!
565
         */
566
        NodeSelectionListener(JTree tree) {
567
            this.tree = tree;
568
        }
569

    
570
        /**
571
         * DOCUMENT ME!
572
         *
573
         * @param e DOCUMENT ME!
574
         */
575
        public void mouseClicked(MouseEvent e) {
576
            int x = e.getX();
577
            int y = e.getY();
578
            int row = tree.getRowForLocation(x, y);
579
            TreePath path = tree.getPathForRow(row);
580
            LayerCollection layers = mapContext.getLayers();
581

    
582
            // System.out.println(e.getSource());
583
            if (path != null) {
584
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
585

    
586
                // System.out.println("Evento de rat?n originado por " + e.getSource().getClass().toString());
587
                if (node.getUserObject() instanceof TocItemBranch) {
588
                    TocItemBranch elTema = (TocItemBranch) node.getUserObject();
589
                    FLayer lyr = elTema.getLayer();
590
                    lyr.getFMap().beginAtomicEvent();
591

    
592
                    //if (e.getButton()==MouseEvent.BUTTON1){
593
                    // Si tenemos may?sculas apretadas es que queremos activar m?s temas.
594
                    // Si no, primero desactivamos temas
595
                    if (!((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) &&
596
                            (e.getButton() == MouseEvent.BUTTON1)) {
597
                        layers.setAllActives(false);
598
                    }
599

    
600
                    if (e.getButton() == MouseEvent.BUTTON1) {
601
                        //lyr.setActive(true);
602
                        updateActive(lyr, !lyr.isActive());
603
                    } else {
604
                        /*if (!((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) && e.getButton()==MouseEvent.BUTTON3) {
605
                           layers.setAllActives(false);
606
                           }
607
                           updateActive(lyr,true);
608
                         */
609
                    }
610

    
611
                    // Si pertenece a un grupo, lo ponemos activo tambi?n.
612
                    //FLayer parentLayer = lyr.getParentLayer();
613

    
614
                    /*if (parentLayer != null) {
615
                       parentLayer.setActive(true);
616
                       }*/
617
                    Point layerNodeLocation = tree.getUI()
618
                                                  .getPathBounds(tree, path)
619
                                                  .getLocation();
620

    
621
                    //Rect?ngulo que representa el checkbox
622
                    Rectangle checkBoxBounds = m_TocRenderer.getCheckBoxBounds();
623
                    checkBoxBounds.translate((int) layerNodeLocation.getX(),
624
                        (int) layerNodeLocation.getY());
625

    
626
                    if (checkBoxBounds.contains(e.getPoint())) {
627
                        updateVisible(lyr);
628
                    }
629

    
630
                    //}
631
                    if ((e.getButton() == MouseEvent.BUTTON3) &&
632
                            (layers.getActives().length > 0)) {
633
                        //Boton derecho sobre un nodo del arbol
634
                        //if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
635
                        popmenu = new FPopupMenu(mapContext, node);
636
                        tree.add(popmenu);
637

    
638
                        //System.out.println("boton derecho");
639
                        popmenu.show(e.getComponent(), e.getX(), e.getY());
640

    
641
                        //}
642
                    }
643

    
644
                    lyr.getFMap().endAtomicEvent();
645
                }
646

    
647
                if (node.getUserObject() instanceof TocItemLeaf) {
648
                    //Boton derecho sobre un Simbolo
649
                    //TocItemLeaf auxLeaf = (TocItemLeaf) node.getUserObject();
650
                    //FSymbol theSym = auxLeaf.getSymbol();
651
                    if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
652
                        popmenu = new FPopupMenu(mapContext, node);
653
                        tree.add(popmenu);
654
                        popmenu.show(e.getComponent(), e.getX(), e.getY());
655
                    }
656
                }
657

    
658
                ((DefaultTreeModel) tree.getModel()).nodeChanged(node);
659

    
660
                if (row == 0) {
661
                    tree.revalidate();
662
                    tree.repaint();
663
                }
664

    
665
                if (PluginServices.getMainFrame() != null) {
666
                    PluginServices.getMainFrame().enableControls();
667
                }
668
            }
669
        }
670

    
671
        /**
672
         * DOCUMENT ME!
673
         *
674
         * @param lyr DOCUMENT ME!
675
         * @param active DOCUMENT ME!
676
         */
677
        private void updateActive(FLayer lyr, boolean active) {
678
            lyr.setActive(active);
679
            updateActiveChild(lyr);
680
        }
681

    
682
        /**
683
         * DOCUMENT ME!
684
         *
685
         * @param lyr DOCUMENT ME!
686
         */
687
        private void updateActiveChild(FLayer lyr) {
688
            if (lyr instanceof FLayers) { //Es la raiz de una rama o cualquier nodo intermedio.
689

    
690
                FLayers layergroup = (FLayers) lyr;
691

    
692
                for (int i = 0; i < layergroup.getLayersCount(); i++) {
693
                    layergroup.getLayer(i).setActive(lyr.isActive());
694
                    updateActiveChild(layergroup.getLayer(i));
695
                }
696
            }
697
        }
698

    
699
        /**
700
         * Actualiza la visibilidad de la capas.
701
         *
702
         * @param lyr Capa sobre la que se est? clickando.
703
         */
704
        private void updateVisible(FLayer lyr) {
705
            lyr.setVisible(!lyr.isVisible());
706
            updateVisibleChild(lyr);
707
            updateVisibleParent(lyr);
708
        }
709

    
710
        /**
711
         * Actualiza de forma recursiva la visibilidad de los hijos de la capa
712
         * que se pasa como par?metro.
713
         *
714
         * @param lyr Capa a actualizar.
715
         */
716
        private void updateVisibleChild(FLayer lyr) {
717
            if (lyr instanceof FLayers) { //Es la raiz de una rama o cualquier nodo intermedio.
718

    
719
                FLayers layergroup = (FLayers) lyr;
720

    
721
                for (int i = 0; i < layergroup.getLayersCount(); i++) {
722
                    layergroup.getLayer(i).setVisible(lyr.isVisible());
723
                    updateVisibleChild(layergroup.getLayer(i));
724
                }
725
            }
726
        }
727

    
728
        /**
729
         * Actualiza de forma recursiva la visibilidad del padre de la capa que
730
         * se pasa como par?metro.
731
         *
732
         * @param lyr Capa a actualizar.
733
         */
734
        private void updateVisibleParent(FLayer lyr) {
735
            FLayers parent = (FLayers) lyr.getParentLayer();
736

    
737
            if (parent != null) {
738
                boolean parentVisible = false;
739

    
740
                for (int i = 0; i < parent.getLayersCount(); i++) {
741
                    if (parent.getLayer(i).isVisible()) {
742
                        parentVisible = true;
743
                    }
744
                }
745

    
746
                parent.setVisible(parentVisible);
747
                updateVisibleParent(parent);
748
            }
749
        }
750

    
751
        /**
752
         * DOCUMENT ME!
753
         *
754
         * @param arg0 DOCUMENT ME!
755
         */
756
        public void actionPerformed(ActionEvent arg0) {
757
        }
758

    
759
        /**
760
         * DOCUMENT ME!
761
         *
762
         * @param arg0 DOCUMENT ME!
763
         */
764
        public void mouseReleased(MouseEvent arg0) {
765
            super.mouseReleased(arg0);
766
        }
767

    
768
        /**
769
         * DOCUMENT ME!
770
         *
771
         * @param arg0 DOCUMENT ME!
772
         */
773
        public void mouseEntered(MouseEvent arg0) {
774
            // TODO Auto-generated method stub
775
            super.mouseEntered(arg0);
776

    
777
            // FJP: COMENTO ESTO.
778
            // LO CORRECTO CREO QUE ES IMPLEMENTAR CORRECTAMENTE
779
            // LOS METODOS DE DRAG AND DROP
780

    
781
            /* if (m_Root.getChildCount()==0){
782
               m_Tree.dropRoot(m_Root);
783
               }*/
784
        }
785
    }
786
}