Revision 37338

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/gui/IView.java
46 46
 */
47 47
package com.iver.cit.gvsig.project.documents.view.gui;
48 48

  
49
import org.gvsig.fmap.swing.toc.TOC;
50

  
49 51
import com.iver.cit.gvsig.fmap.MapControl;
50
import com.iver.cit.gvsig.project.documents.view.toc.gui.TOC;
51 52

  
52 53
/**
53 54
 * @author FJP
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/gui/BaseView.java
47 47
import javax.swing.JSplitPane;
48 48

  
49 49
import org.cresques.cts.IProjection;
50
import org.gvsig.fmap.swing.toc.TOC;
50 51

  
51 52
import com.iver.andami.PluginServices;
52 53
import com.iver.andami.messages.NotificationManager;
......
59 60
import com.iver.cit.gvsig.project.documents.gui.WindowData;
60 61
import com.iver.cit.gvsig.project.documents.view.IProjectView;
61 62
import com.iver.cit.gvsig.project.documents.view.MapOverview;
62
import com.iver.cit.gvsig.project.documents.view.toc.gui.TOC;
63 63
import com.iver.utiles.exceptionHandling.ExceptionListener;
64 64

  
65 65
//import javax.swing.JSplitPane;
......
287 287
			}
288 288
		}
289 289
		if (m_TOC!=null) {
290
			windowData.set("TOC.Width", Integer.toString(m_TOC.getWidth()));
291
			windowData.set("TOC.Height", Integer.toString(m_TOC.getHeight()));
290
			windowData.set("TOC.Width", Integer.toString(m_TOC.getComponent().getWidth()));
291
			windowData.set("TOC.Height", Integer.toString(m_TOC.getComponent().getHeight()));
292 292
		}
293 293
		if (m_MapControl!=null) {
294 294
			windowData.set("MapControl.Width", Integer.toString(m_MapControl.getWidth()));
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/gui/View.java
50 50

  
51 51
import javax.swing.JSplitPane;
52 52

  
53
import org.gvsig.fmap.swing.toc.TOCLocator;
54
import org.gvsig.tools.service.ServiceException;
55

  
53 56
import com.iver.andami.PluginServices;
57
import com.iver.andami.messages.NotificationManager;
54 58
import com.iver.andami.ui.mdiManager.WindowInfo;
55 59
import com.iver.cit.gvsig.fmap.ColorEvent;
56 60
import com.iver.cit.gvsig.fmap.ExtentEvent;
......
72 76
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
73 77
import com.iver.cit.gvsig.project.documents.view.MapOverview;
74 78
import com.iver.cit.gvsig.project.documents.view.ProjectViewBase;
75
import com.iver.cit.gvsig.project.documents.view.toc.gui.TOC;
76 79
import com.iver.cit.gvsig.project.documents.view.toolListeners.AreaListener;
77 80
import com.iver.cit.gvsig.project.documents.view.toolListeners.InfoListener;
78 81
import com.iver.cit.gvsig.project.documents.view.toolListeners.LinkListener;
......
152 155
     * method, the window will be populated according to this
153 156
     * properties.
154 157
     */
155
    public void initialize() {
158
    public void initialize(MapContext mc) {
156 159
    	super.initialize();
157
    	initComponents();
160
    	initComponents(mc);
158 161
    	hideConsole();
159 162
        getConsolePanel().addResponseListener(consoleResponseAdapter);
160 163
    }
......
178 181

  
179 182
		//Se configura el mapControl
180 183
        m_MapControl.setMapContext(fmap);
181
        m_TOC.setMapContext(fmap);
182
        m_MapControl.getMapContext().getLayers().addLegendListener(m_TOC);
184
        
185
        
186
        // m_TOC.setMapContext(fmap);
187
        
188
        /*
189
        try {
190
            m_TOC = TOCLocator.getInstance(
191
            		).getTOCManager().createTOC(fmap);
192
        } catch (ServiceException se) {
193
        	NotificationManager.addError("While creating TOC. ", se);
194
        }
195
        */
183 196

  
197
        // m_TOC = TocFactory.createPreferredToc();
198
        
199
        // m_MapControl.getMapContext().getLayers().addLegendListener(m_TOC);
200
        // listenerx
201

  
184 202
        m_MapControl.setBackground(new Color(255, 255, 255));
185 203
        if (modelo.getMapOverViewContext()!=null){
186 204
        	m_MapLoc.setModel(modelo.getMapOverViewContext());
......
372 390
    /**
373 391
	 * DOCUMENT ME!
374 392
	 */
375
    protected void initComponents() { // GEN-BEGIN:initComponents
393
    protected void initComponents(MapContext mc) { // GEN-BEGIN:initComponents
376 394
        m_MapControl = new MapControl(); // Default is paintEnabled = false.
377 395
											// Remember to activate it
378 396
              
379 397
        m_MapControl.addExceptionListener(mapControlExceptionListener);
380
        m_TOC = new TOC();
398
        
399
        try {
400
            m_TOC = TOCLocator.getInstance(
401
    		).getTOCManager().createTOC(mc);
402
        } catch (ServiceException se) {
403
        	NotificationManager.addError("While creating TOC. ", se);
404
        }
405
        // m_TOC.setMapContext();
381 406

  
382 407
        // Ponemos el localizador
383 408
        m_MapLoc = new MapOverview(m_MapControl);
......
391 416

  
392 417
		if (!isPalette()){
393 418
			tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
394
			tempSplitToc.setTopComponent(m_TOC);
419
			tempSplitToc.setTopComponent(m_TOC.getComponent());
395 420
			tempSplitToc.setBottomComponent(m_MapLoc);
396 421
			tempSplitToc.setResizeWeight(0.7);
397 422
			tempMainSplit.setLeftComponent(tempSplitToc);
398 423
		}else{
399
			tempMainSplit.setLeftComponent(m_TOC);
424
			tempMainSplit.setLeftComponent(m_TOC.getComponent());
400 425
		}
401
		m_TOC.setVisible(true);
426
		m_TOC.getComponent().setVisible(true);
402 427
		tempMainSplit.setRightComponent(m_MapControl);
403 428
		//split.setBottomComponent(getConsolePanel());
404 429
		//split.setTopComponent(tempMainSplit);
......
543 568
		}
544 569
		hideConsole();
545 570
		JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
546
		tempSplitToc.setTopComponent(m_TOC);
571
		tempSplitToc.setTopComponent(m_TOC.getComponent());
547 572
		tempSplitToc.setBottomComponent(m_MapLoc);
548 573
		tempSplitToc.setResizeWeight(0.7);
549 574
		tempMainSplit.setLeftComponent(tempSplitToc);
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/DnDJTree.java
90 90
import javax.swing.tree.DefaultTreeModel;
91 91
import javax.swing.tree.MutableTreeNode;
92 92
import javax.swing.tree.TreeModel;
93
import javax.swing.tree.TreeNode;
94 93
import javax.swing.tree.TreePath;
95 94

  
96
import com.iver.andami.PluginServices;
97 95
import com.iver.cit.gvsig.fmap.layers.FLayer;
98 96
import com.iver.cit.gvsig.fmap.layers.FLayers;
99
import com.iver.cit.gvsig.project.documents.view.gui.View;
100 97

  
101 98
public class DnDJTree extends JTree
102 99
                  implements TreeSelectionListener,
......
153 150
    //DropTarget dropTarget = new DropTarget(this, this);
154 151
    setDropTarget();
155 152
  }
156
  public void invalidateListeners(){
157
	  removeDropListener();
158
	  removeTreeListener();
159
  }
153
//  public void invalidateListeners(){
154
//	  removeDropListener();
155
//	  removeTreeListener();
156
//  }
160 157
  private void addDropListener(){
161 158
	  dropTarget= new DropTarget(this, this);
162 159
  }
163
  private void removeDropListener(){
164
	  dropTarget=null;
165
  }
160
//  private void removeDropListener(){
161
//	  dropTarget=null;
162
//  }
166 163
  private void addTreeListener(){
167 164
	  addTreeSelectionListener(this);
168 165
  }
169
  private void removeTreeListener(){
170
	  removeTreeSelectionListener(this);
171
  }
166
//  private void removeTreeListener(){
167
//	  removeTreeSelectionListener(this);
168
//  }
172 169
  public void setDropTarget(){
173 170
      // TODO: COMENTADO POR FJP
174 171
	  /* com.iver.andami.ui.mdiManager.View[] views=PluginServices.getMDIManager().getAllViews();
......
186 183
	 ////////// new DropTarget(this, this);
187 184
  }
188 185
  /** Returns The selected node */
189
  public DefaultMutableTreeNode getSelectedNode() {
186
  private DefaultMutableTreeNode getSelectedNode() {
190 187
    return SelectedNode;
191 188
  }
192 189

  
......
406 403
    catch (IOException io) { e.rejectDrop(); }
407 404
    catch (UnsupportedFlavorException ufe) {e.rejectDrop();}
408 405
  } //end of method
406
  
407
  /*
409 408
public void dropRoot(TreeNode tn){
410 409
	int oldPos,newPos;
411 410
	DefaultMutableTreeNode nodoTocado =
......
452 451
		  }
453 452
		  }
454 453
	}
455

  
454
*/
455
  
456 456
  /** DropTaregetListener interface method */
457 457
  public void dragEnter(DropTargetDragEvent e) {
458 458
  }
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/AbstractTocContextMenuAction.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government.
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330,
19
 * Boston, MA  02111-1307, USA.
20
 *
21
 */
1 22
package com.iver.cit.gvsig.project.documents.view.toc;
2 23

  
3 24
import java.util.Map;
......
7 28
import com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction;
8 29
import com.iver.utiles.extensionPoints.IExtensionBuilder;
9 30

  
10
public abstract class AbstractTocContextMenuAction extends AbstractContextMenuAction implements IExtensionBuilder{
11
	private MapContext mapContext;
12
	
13
	public MapContext getMapContext() {
14
		return this.mapContext;
15
	}
16
	
17
	public void setMapContext(MapContext mapContext) {
18
		this.mapContext = mapContext;
19
	}
20
	
21
	/**
22
	 * @deprecated use public boolean isEnabled(ITocItem item, FLayer[] selectedItems)
23
	 */
24
	public boolean isEnabled(Object item, Object[] selectedItems) {
25
		return this.isEnabled((ITocItem)item, (FLayer[])selectedItems);
26
	}
31
public abstract class AbstractTocContextMenuAction extends
32
    AbstractContextMenuAction implements IExtensionBuilder {
27 33

  
28
	/**
29
	 * @deprecated use public boolean isVisible(ITocItem item, FLayer[] selectedItems)
30
	 */
31
	public boolean isVisible(Object item, Object[] selectedItems) {
32
		return this.isVisible((ITocItem)item, (FLayer[])selectedItems);
33
	}
34
    private MapContext mapContext;
34 35

  
35
	/**
36
	 * @deprecated use public void execute(ITocItem item, FLayer[] selectedItems)
37
	 */
38
	public void execute(Object item, Object[] selectedItems) {
39
		this.execute((ITocItem)item, (FLayer[])selectedItems);		
40
	}
36
    public MapContext getMapContext() {
37
        return this.mapContext;
38
    }
41 39

  
42
	public FLayer getNodeLayer(ITocItem node) {
43
		if (isTocItemBranch(node))
44
			return ((TocItemBranch) node).getLayer();
45
		return null;
46
	}
47
	public boolean isTocItemLeaf(ITocItem node) {
48
		return node instanceof TocItemLeaf;
49
	}
50
	
51
	public boolean isTocItemBranch(ITocItem node) {
52
		return node instanceof TocItemBranch;
53
	}
40
    public void setMapContext(MapContext mapContext) {
41
        this.mapContext = mapContext;
42
    }
54 43

  
44
    /**
45
     * @deprecated use public boolean isEnabled(ITocItem item, FLayer[]
46
     *             selectedItems)
47
     */
48
    @Deprecated
49
    @Override
50
    public boolean isEnabled(Object item, Object[] selectedItems) {
51
        return this.isEnabled((ITocItem) item, (FLayer[]) selectedItems);
52
    }
55 53

  
56
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
57
		return true;
58
	}
54
    /**
55
     * @deprecated use public boolean isVisible(ITocItem item, FLayer[]
56
     *             selectedItems)
57
     */
58
    @Deprecated
59
    @Override
60
    public boolean isVisible(Object item, Object[] selectedItems) {
61
        return this.isVisible((ITocItem) item, (FLayer[]) selectedItems);
62
    }
59 63

  
60
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
61
		return true;
62
	}
64
    /**
65
     * @deprecated use public void execute(ITocItem item, FLayer[]
66
     *             selectedItems)
67
     */
68
    @Deprecated
69
    public void execute(Object item, Object[] selectedItems) {
70
        this.execute((ITocItem) item, (FLayer[]) selectedItems);
71
    }
63 72

  
64
	public abstract void execute(ITocItem item, FLayer[] selectedItems);
73
    public FLayer getNodeLayer(ITocItem node) {
74
        if (isTocItemBranch(node)) {
75
            return ((TocItemBranch) node).getLayer();
76
        }
77
        return null;
78
    }
65 79

  
66
	public Object create() {		
67
		return this;
68
	}
80
    public boolean isTocItemLeaf(ITocItem node) {
81
        return node instanceof TocItemLeaf;
82
    }
69 83

  
70
	public Object create(Map args) {
71
		// TODO Auto-generated method stub
72
		return this;
73
	}
84
    public boolean isTocItemBranch(ITocItem node) {
85
        return node instanceof TocItemBranch;
86
    }
74 87

  
75
	public Object create(Object[] args) {
76
		// TODO Auto-generated method stub
77
		return this;
78
	}
88
    public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
89
        return true;
90
    }
79 91

  
92
    public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
93
        return true;
94
    }
95

  
96
    public abstract void execute(ITocItem item, FLayer[] selectedItems);
97

  
98
    public Object create() {
99
        return this;
100
    }
101

  
102
    public Object create(Map args) {
103
        // TODO Auto-generated method stub
104
        return this;
105
    }
106

  
107
    public Object create(Object[] args) {
108
        // TODO Auto-generated method stub
109
        return this;
110
    }
111

  
80 112
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/gui/TOCRenderer.java
1
/*
2
 * Created on 23-feb-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.Color;
50
import java.awt.Component;
51
import java.awt.Dimension;
52
import java.awt.FlowLayout;
53
import java.awt.Font;
54
import java.awt.GridBagConstraints;
55
import java.awt.GridBagLayout;
56
import java.awt.Rectangle;
57

  
58
import javax.swing.BorderFactory;
59
import javax.swing.Icon;
60
import javax.swing.JCheckBox;
61
import javax.swing.JLabel;
62
import javax.swing.JPanel;
63
import javax.swing.JTree;
64
import javax.swing.SpringLayout;
65
import javax.swing.UIManager;
66
import javax.swing.border.Border;
67
import javax.swing.tree.DefaultMutableTreeNode;
68
import javax.swing.tree.TreeCellRenderer;
69

  
70
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
71
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
72
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch;
73

  
74

  
75

  
76
/**
77
 * Renderer que actua sobre el TOC.
78
 *
79
 * @author vcn
80
 */
81
public class TOCRenderer extends JPanel implements TreeCellRenderer {
82
    public Border bordeSeleccionado = BorderFactory.createEtchedBorder();
83

  
84
    /*public Border bordeSeleccionado = BorderFactory.createBevelBorder(BevelBorder.RAISED,
85
            SystemColor.black, SystemColor.lightGray, SystemColor.gray,
86
            SystemColor.lightGray);
87
    */
88
    private Border bordeNormal = BorderFactory.createEmptyBorder();
89
    
90
	private JCheckBox check;
91
	private JLabel label;
92

  
93
	private static final Font BIGGER_FONT = 
94
									  new Font("SansSerif", Font.BOLD, 12);
95

  
96
	GridBagLayout gridbag = new GridBagLayout();
97
	GridBagConstraints c = new GridBagConstraints();
98
    /**
99
     * Creates a new TOCRenderer object.
100
     */
101
    public TOCRenderer() {
102
        this.setBackground(Color.lightGray);
103
        // this.setLayout(new BorderLayout());
104
        this.setLayout(new FlowLayout(FlowLayout.LEADING, 0,0));
105
		check = new JCheckBox();
106
		label = new JLabel();
107
		
108

  
109

  
110
		/* this.setLayout(gridbag);
111

  
112
		c.fill = GridBagConstraints.NONE;
113
		c.weightx = 1.0;
114
		c.anchor = GridBagConstraints.WEST;
115
		// c.weightx = check.getWidth();
116
		gridbag.setConstraints(check,c);
117
		this.add(check);
118
		c.anchor = GridBagConstraints.WEST;
119
		gridbag.setConstraints(colorPanel,c);
120
		// c.weightx = colorPanel.getWidth();
121
		this.add(colorPanel);
122
		c.gridwidth = GridBagConstraints.REMAINDER; //end row
123
		c.fill = GridBagConstraints.HORIZONTAL;		
124
		gridbag.setConstraints(label,c);
125
		this.add(label); */ 
126

  
127

  
128

  
129
		/* this.setLayout(new FlowLayout(FlowLayout.LEFT));
130
		this.add(check);
131
		this.add(colorPanel);
132
		this.add(label); */
133
		
134
		/* this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
135
		this.add(check);
136
		this.add(colorPanel);
137
		this.add(label); */  
138

  
139
		SpringLayout theLayout = new SpringLayout();		 
140
		this.setLayout(theLayout);
141

  
142
		//int rows = 1;
143
		//int cols = 2;
144
				
145
		/* this.setLayout(new BorderLayout());
146
		
147
		this.add(check, BorderLayout.WEST);
148
		this.add(label, BorderLayout.CENTER);
149
		*/ 
150
		/*
151
		GridBagLayout gridbag = new GridBagLayout();
152
        GridBagConstraints c = new GridBagConstraints();
153
        
154
        this.setLayout(gridbag);
155
        this.add(check);
156
        c.gridwidth = GridBagConstraints.REMAINDER;
157
        c.fill = GridBagConstraints.HORIZONTAL;
158
        this.add(label, c);
159
        */
160
		
161
//		Adjust constraints for the text field so it's at
162
//		(<label's right edge> + 5, 5).
163
		this.add(check);
164
		this.add(label);  
165

  
166
		theLayout.putConstraint(SpringLayout.WEST, label,
167
						   5,
168
						   SpringLayout.EAST, check); 
169

  
170
		this.setBorder(bordeSeleccionado);
171

  
172
        check.setBackground(UIManager.getColor("Button.background"));
173
        label.setForeground(UIManager.getColor("Tree.textForeground"));
174
        
175
        
176
    }
177

  
178
    /**
179
     * M?todo llamado una vez por cada nodo, y todas las veces que se redibuja
180
     * en pantalla el TOC.
181
     *
182
     * @param tree
183
     * @param value
184
     * @param isSelected
185
     * @param expanded
186
     * @param leaf
187
     * @param row
188
     * @param hasFocus
189
     *
190
     * @return
191
     */
192
    public Component getTreeCellRendererComponent(JTree tree, Object value,
193
        boolean isSelected, boolean expanded, boolean leaf, int row,
194
        boolean hasFocus) {
195
                
196
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) value;
197
		String stringValue = "";
198
		this.setBackground(UIManager.getColor("Button.background"));
199
		this.label.setFont(tree.getFont());
200
		// System.out.println("ancho tree=" + tree.getWidth());
201

  
202
		if (n.getUserObject() instanceof ITocItem)
203
		{
204
			
205
	       	ITocItem item = (ITocItem) n.getUserObject();	       	
206
			stringValue = item.getLabel();
207
			
208
	        Dimension sizeNode = item.getSize(); // Se fija en el resize del TOC
209
	        
210
			this.setPreferredSize(sizeNode);
211
			
212
			if (item instanceof TocItemBranch)
213
			{
214
				TocItemBranch branch = (TocItemBranch) item;
215
				FLyrDefault lyr = (FLyrDefault)branch.getLayer();
216
				check.setVisible(true);
217
				check.setSelected(lyr.visibleRequired());
218
				if (!lyr.isAvailable()) {										
219
					check.setEnabled(false);
220
				} else {					
221
					check.setEnabled(true);
222
					if (!lyr.isWithinScale(lyr.getMapContext().getScaleView()))
223
						check.setEnabled(false);
224
					
225

  
226
					if (lyr.isEditing())
227
					{
228
						this.label.setForeground(Color.RED);
229
					}
230
					else this.label.setForeground(Color.BLACK);
231
				}
232
				if (lyr.isActive())
233
				{				
234
					this.setBorder(bordeSeleccionado);
235
					this.label.setFont(BIGGER_FONT);
236
				}
237
				else
238
				{				
239
					this.setBorder(bordeNormal);
240
				}				
241
	        }
242
			else
243
			{
244
				check.setVisible(false);
245
				this.setBorder(bordeNormal);			
246
				
247
			}
248
	        label.setText(stringValue);
249
	        Icon icono = item.getIcon();
250
	        if (icono != null)
251
	        {
252
	        	label.setIcon(icono);
253
	        	//System.out.println(">>>>>Pongo etiqueta " + stringValue + " con icono " + item.getIcon().toString());
254
	        }
255
	        this.setPreferredSize(sizeNode);
256
		}		
257
		// this.setPreferredSize(new Dimension(tree.getWidth()-60,24)); // sizeNode);
258

  
259
        if (leaf) {
260
            // label.setIcon(UIManager.getIcon("Tree.leafIcon"));
261
            
262
        } else if (expanded) {
263
            //label.setIcon(UIManager.getIcon("Tree.openIcon"));
264
        } else {
265
            //label.setIcon(UIManager.getIcon("Tree.closedIcon"));
266
        }
267

  
268
        return this;
269
    }
270

  
271
	public Rectangle getCheckBoxBounds() {
272
		return check.getBounds();
273
	}
274

  
275
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/gui/TOC.java
1
/*
2
 * Created on 13-may-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;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 com.hardcode.gdbms.driver.exceptions.ReadDriverException;
81
import com.iver.andami.PluginServices;
82
import com.iver.andami.messages.NotificationManager;
83
import com.iver.cit.gvsig.ProjectExtension;
84
import com.iver.cit.gvsig.fmap.AtomicEvent;
85
import com.iver.cit.gvsig.fmap.AtomicEventListener;
86
import com.iver.cit.gvsig.fmap.MapContext;
87
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
88
import com.iver.cit.gvsig.fmap.layers.CancelationException;
89
import com.iver.cit.gvsig.fmap.layers.FLayer;
90
import com.iver.cit.gvsig.fmap.layers.FLayers;
91
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
92
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
93
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent;
94
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener;
95
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent;
96
import com.iver.cit.gvsig.fmap.layers.LegendChangedEvent;
97
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
98
import com.iver.cit.gvsig.fmap.layers.layerOperations.IHasImageLegend;
99
import com.iver.cit.gvsig.fmap.layers.layerOperations.LayerCollection;
100
import com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend;
101
import com.iver.cit.gvsig.fmap.rendering.ILegend;
102
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend;
103
import com.iver.cit.gvsig.fmap.rendering.LegendListener;
104
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
105
import com.iver.cit.gvsig.project.Project;
106
import com.iver.cit.gvsig.project.documents.IContextMenuAction;
107
import com.iver.cit.gvsig.project.documents.view.toc.DnDJTree;
108
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
109
import com.iver.cit.gvsig.project.documents.view.toc.ITocOrderListener;
110
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch;
111
import com.iver.cit.gvsig.project.documents.view.toc.TocItemLeaf;
112

  
113

  
114
/**
115
 * DOCUMENT ME!
116
 *
117
 * @author fjp To change the template for this generated type comment go to
118
 *         Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
119
 *         Comments
120
 */
121
public class TOC extends JComponent implements ITocOrderListener,
122
    LegendListener, LayerCollectionListener, TreeExpansionListener,
123
    ComponentListener {
124
    private MapContext mapContext;
125
    private DnDJTree m_Tree;
126
    private DefaultTreeModel m_TreeModel;
127
    private DefaultMutableTreeNode m_Root;
128
    private TOCRenderer m_TocRenderer;
129
    private JScrollPane m_Scroller;
130

  
131
    //private ArrayList m_Listeners;
132
    private HashMap m_ItemsExpanded = new HashMap();
133
    private NodeSelectionListener nodeSelectionListener = null;
134

  
135
    /**
136
     * Crea un nuevo TOC.
137
     */
138
    public TOC() {
139
    	this.setName("TOC");
140
        this.setLayout(new BorderLayout());
141
        this.setMinimumSize(new Dimension(100, 80));
142
        this.setPreferredSize(new Dimension(100, 80));
143

  
144
        //Construct the tree.
145
        m_Root = new DefaultMutableTreeNode(java.lang.Object.class);
146
        m_TreeModel = new DefaultTreeModel(m_Root);
147
        m_Tree = new DnDJTree(m_TreeModel);
148

  
149
        m_TocRenderer = new TOCRenderer();
150
        m_Tree.setCellRenderer(m_TocRenderer);
151

  
152
        m_Tree.setRootVisible(false);
153

  
154
        // m_Tree.setExpandsSelectedPaths(true);
155
        // m_Tree.setAutoscrolls(true);
156
        m_Tree.setShowsRootHandles(true);
157

  
158
        //Posibilidad de seleccionar de forma aleatoria nodos de la leyenda.
159
        m_Tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
160
        nodeSelectionListener=new NodeSelectionListener(m_Tree);
161
        m_Tree.addMouseListener(nodeSelectionListener);
162
        m_Tree.setBackground(UIManager.getColor("Button.background"));
163
        m_Tree.setBorder(BorderFactory.createEtchedBorder());
164

  
165
        this.addComponentListener(this);
166

  
167
        m_Tree.addTreeExpansionListener(this);
168

  
169
        m_Tree.addOrderListener(this);
170

  
171
        m_Tree.setRowHeight(0); // Para que lo determine el renderer
172

  
173
        m_Scroller = new JScrollPane(m_Tree);
174
        m_Scroller.setBorder(BorderFactory.createEmptyBorder());
175

  
176
        // scrollPane.setPreferredSize(new Dimension(80,80));
177
        //Add everything to this panel.
178
        /* GridBagLayout gridbag = new GridBagLayout();
179
           GridBagConstraints c = new GridBagConstraints();
180
           setLayout(gridbag);
181
           c.fill = GridBagConstraints.BOTH;
182
           c.weightx = 1.0;
183
           gridbag.setConstraints(check,c); */
184
        add(m_Scroller); //, BorderLayout.WEST);
185

  
186
        //		refresh();
187
    }
188

  
189
    /**
190
     * Elimina los listeners que actuan sobre el TOC, lo ?nico que deja hacer
191
     * es desplegar la leyenda de las capas.
192
     */
193
    public void removeListeners() {
194
        m_Tree.removeMouseListener(nodeSelectionListener);
195
        m_Tree.invalidateListeners();
196
    }
197

  
198
    /**
199
     * Inserta el FMap.
200
     *
201
     * @param mc FMap.
202
     */
203
    public void setMapContext(MapContext mc) {
204
        mapContext = mc;
205
        mapContext.addAtomicEventListener(new AtomicEventListener() {
206
                /**
207
                 * @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
208
                 */
209
                public void atomicEvent(AtomicEvent e) {
210
                    if ((e.getLayerCollectionEvents().length > 0) ||
211
                            (e.getLegendEvents().length > 0)) {
212
                        SwingUtilities.invokeLater(new Runnable() {
213
                                public void run() {
214
                                    refresh();
215
                                }
216
                            });
217
                    }
218

  
219
                    if (e.getLayerEvents().length > 0) {
220
                        repaint();
221
                    }
222

  
223
                    if (e.getExtentEvents().length > 0) {
224
                        repaint();
225
                    }
226
                }
227
            });
228

  
229
        SwingUtilities.invokeLater(new Runnable() {
230
                public void run() {
231
                    refresh();
232
                }
233
            });
234
    }
235

  
236
    /**
237
     * DOCUMENT ME!
238
     */
239
     private void setExpandedNodes(DefaultMutableTreeNode node) {
240
        //int i = 0;
241
        // Las claves sobrantes de m_ItemsExpanded (provocadas
242
        // por layerRemove, se quitan en el evento layerRemoved
243
        // de este TOC
244
        DefaultMutableTreeNode n;
245
       Enumeration enumeration = node.children();
246

  
247
        while (enumeration.hasMoreElements()) {
248
            n = (DefaultMutableTreeNode) enumeration.nextElement();
249
			if (n.getChildCount()>0){
250
            	setExpandedNodes(n);
251
            }
252
            TreePath path = new TreePath(m_TreeModel.getPathToRoot(n));
253
            ITocItem item = (ITocItem) n.getUserObject();
254
            Boolean b = (Boolean) m_ItemsExpanded.get(item.getLabel());
255

  
256
            if (b == null) // No estaba en el hash todav?a: valor por defecto
257
             {
258
                // System.out.println("Primera expansi?n de " + item.getLabel());
259
                m_Tree.expandPath(path);
260

  
261
                return;
262
            }
263

  
264
            if (b.booleanValue()) {
265
                // System.out.println("Expansi?n de " + item.getLabel());
266
                m_Tree.expandPath(path);
267
            } else {
268
                // System.out.println("Colapso de " + item.getLabel());
269
                m_Tree.collapsePath(path);
270
            }
271
        }
272
    }
273

  
274
    /* (non-Javadoc)
275
     * @see com.iver.cit.opensig.gui.IToc#refresh()
276
     */
277
    public void refresh() {
278
        LayerCollection theLayers = mapContext.getLayers();
279
        m_Root.removeAllChildren();
280
        m_Root.setAllowsChildren(true);
281
        //System.out.println("Refresh del toc");
282
        doRefresh(theLayers, m_Root);
283

  
284
        m_TreeModel.reload();
285

  
286
       setExpandedNodes(m_Root);
287
    }
288

  
289
    /**
290
     * DOCUMENT ME!
291
     *
292
     * @param theLayers DOCUMENT ME!
293
     * @param parentNode DOCUMENT ME!
294
     */
295
    private void doRefresh(LayerCollection theLayers,
296
        DefaultMutableTreeNode parentNode) {
297
        Dimension sizeLeaf = new Dimension(m_Tree.getWidth(), 15);
298
        Dimension sizeBranch = new Dimension(m_Tree.getWidth(), 25);
299

  
300
        for (int i = theLayers.getLayersCount() - 1; i >= 0; i--) {
301
            FLayer lyr = theLayers.getLayer(i);
302
            if (!lyr.isInTOC())
303
            	continue;
304
            TocItemBranch elTema = new TocItemBranch(lyr);
305
            elTema.setSize(sizeBranch);
306

  
307
            DefaultMutableTreeNode nodeLayer = new DefaultMutableTreeNode(elTema);
308

  
309
            m_TreeModel.insertNodeInto(nodeLayer, parentNode,
310
                parentNode.getChildCount());
311

  
312
            //TreePath path = new TreePath(m_TreeModel.getPathToRoot(nodeLayer));
313
            // m_Tree.makeVisible(path);
314
            if (lyr instanceof LayerCollection) {
315
                LayerCollection group = (LayerCollection) lyr;
316
                doRefresh(group, nodeLayer);
317
            } else {
318
                if (lyr instanceof Classifiable && !(lyr instanceof FLyrAnnotation)) {
319

  
320
                    Classifiable aux = (Classifiable) lyr;
321
                    ILegend legendInfo = aux.getLegend();
322

  
323
                    try {
324
                        if (legendInfo instanceof IClassifiedLegend) {
325
                            IClassifiedLegend cl = (IClassifiedLegend) legendInfo;
326
                            String[] descriptions = cl.getDescriptions();
327
                            ISymbol[] symbols = cl.getSymbols();
328

  
329
                            for (int j = 0; j < descriptions.length; j++) {
330
                                TocItemLeaf itemLeaf;
331
                                itemLeaf = new TocItemLeaf(symbols[j],
332
                                        descriptions[j], aux.getShapeType());
333
                                itemLeaf.setSize(sizeLeaf);
334

  
335
                                DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf);
336
                                m_TreeModel.insertNodeInto(nodeValue,
337
                                    nodeLayer, nodeLayer.getChildCount());
338

  
339
                                //TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot(
340
                                //			nodeValue));
341
                                // m_Tree.makeVisible(pathSymbol);
342
                            }
343
                        }
344

  
345
                        if (legendInfo instanceof SingleSymbolLegend &&
346
                                (legendInfo.getDefaultSymbol() != null)) {
347
                            TocItemLeaf itemLeaf;
348
                            itemLeaf = new TocItemLeaf(legendInfo.getDefaultSymbol(),
349
                            		legendInfo.getDefaultSymbol().getDescription(), aux.getShapeType());
350
                            itemLeaf.setSize(sizeLeaf);
351

  
352
                            DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf);
353
                            m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
354
                                nodeLayer.getChildCount());
355

  
356
                            //TreePath pathSymbol = new TreePath(m_TreeModel.getPathToRoot(
357
                            //			nodeValue));
358
                            // m_Tree.makeVisible(pathSymbol);
359
                        }
360

  
361
                        if (lyr instanceof IHasImageLegend)
362
                        {
363
                            TocItemLeaf itemLeaf;
364
                            IHasImageLegend auxLayer = (IHasImageLegend) lyr;
365
                            Image image = auxLayer.getImageLegend();
366

  
367
                            if (image != null)
368
                            {
369
                            	itemLeaf = new TocItemLeaf();
370
                               	itemLeaf.setImageLegend(image, "",
371
                               							new Dimension(image.getWidth( null ),
372
                               							image.getHeight( null )));//new Dimension(150,200));
373

  
374
                                DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf);
375
                                m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
376
                                    nodeLayer.getChildCount());
377
                            }
378
                        }
379
                    } catch (ReadDriverException e) {
380
						e.printStackTrace();
381
					}
382
                }
383
            } // if instanceof layers
384
        }
385
    }
386

  
387
    /**
388
     * @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int,
389
     *      int)
390
     */
391
    public void orderChanged(int oldPos, int newPos, FLayers lpd) {
392
        //LayerCollection layers = mapContext.getLayers();
393
        // El orden es el contrario, hay que traducir.
394
        // El orden es el contrario, hay que traducir.
395
        ///oldPos = layers.getLayersCount() - 1 - oldPos;
396
        ///newPos = layers.getLayersCount() - 1 - newPos;
397
        try {
398
            lpd.moveTo(oldPos, newPos);
399
        } catch (CancelationException e) {
400
            // TODO Auto-generated catch block
401
            e.printStackTrace();
402
        }
403

  
404
        // No hace falta un refresh, lo hace mediante eventos.
405
        //refresh();
406
        mapContext.invalidate();
407
    }
408

  
409
    /**
410
     * DOCUMENT ME!
411
     *
412
     * @param lpo DOCUMENT ME!
413
     * @param lpd DOCUMENT ME!
414
     * @param ls DOCUMENT ME!
415
     */
416
    public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) {
417
        lpo.removeLayer(ls);
418
        lpd.addLayer(ls);
419
        PluginServices.getMainFrame().enableControls();
420
        /*if (lpo.getLayersCount()==0){
421
           lpo.getParentLayer().removeLayer(lpo);
422
           }*/
423
        mapContext.invalidate();
424

  
425
    }
426

  
427
    /* (non-Javadoc)
428
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
429
     */
430
    public void componentHidden(ComponentEvent e) {
431
    }
432

  
433
    /* (non-Javadoc)
434
     * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
435
     */
436
    public void componentMoved(ComponentEvent e) {
437
    }
438

  
439
    /* (non-Javadoc)
440
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
441
     */
442
    public void componentResized(ComponentEvent e) {
443
        System.out.println("Cambiando tama?o.");
444

  
445
        int i = 0;
446
        DefaultMutableTreeNode n;
447
        Enumeration enumeration = m_Root.children();
448

  
449
        while (enumeration.hasMoreElements()) {
450
            n = (DefaultMutableTreeNode) enumeration.nextElement();
451

  
452
            if (n.getUserObject() instanceof TocItemBranch) {
453
                ITocItem item = (ITocItem) n.getUserObject();
454
                Dimension szAnt = item.getSize();
455
                item.setSize(new Dimension(this.getWidth() - 40, szAnt.height));
456
            }
457

  
458
        }
459

  
460
        // m_Tree.setSize(this.getSize());
461
        System.out.println("Ancho del tree=" + m_Tree.getWidth() + " " +
462
            m_Tree.getComponentCount());
463
        System.out.println("Ancho del TOC=" + this.getWidth());
464

  
465
        // m_Tree.repaint();
466
    }
467

  
468
    /* (non-Javadoc)
469
     * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
470
     */
471
    public void componentShown(ComponentEvent e) {
472
    }
473

  
474
    /* (non-Javadoc)
475
     * @see com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent)
476
     */
477
    public void legendChanged(LegendChangedEvent e) {
478
        System.out.println("Refrescando TOC");
479
        refresh();
480
    }
481

  
482
    /* (non-Javadoc)
483
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
484
     */
485
    public void layerAdded(LayerCollectionEvent e) {
486
        refresh();
487
    }
488

  
489
    /* (non-Javadoc)
490
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
491
     */
492
    public void layerMoved(LayerPositionEvent e) {
493
        refresh();
494
    }
495

  
496
    /* (non-Javadoc)
497
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
498
     */
499
    public void layerRemoved(LayerCollectionEvent e) {
500
        m_ItemsExpanded.remove(e.getAffectedLayer().getName());
501
        refresh();
502
    }
503

  
504
    /* (non-Javadoc)
505
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
506
     */
507
    public void layerAdding(LayerCollectionEvent e) throws CancelationException {
508
    }
509

  
510
    /* (non-Javadoc)
511
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
512
     */
513
    public void layerMoving(LayerPositionEvent e) throws CancelationException {
514
    }
515

  
516
    /* (non-Javadoc)
517
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
518
     */
519
    public void layerRemoving(LayerCollectionEvent e)
520
        throws CancelationException {
521
    }
522

  
523
    /* (non-Javadoc)
524
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
525
     */
526
    public void activationChanged(LayerCollectionEvent e)
527
        throws CancelationException {
528
        repaint();
529
    }
530

  
531
    /* (non-Javadoc)
532
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
533
     */
534
    public void visibilityChanged(LayerCollectionEvent e)
535
        throws CancelationException {
536
        repaint();
537
    }
538

  
539
    /* (non-Javadoc)
540
     * @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
541
     */
542
    public void treeCollapsed(TreeExpansionEvent event) {
543
        TreePath path = event.getPath();
544
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent();
545

  
546
        if (n.getUserObject() instanceof ITocItem) {
547
            ITocItem item = (ITocItem) n.getUserObject();
548
            Boolean b = Boolean.FALSE;
549

  
550
            // System.out.println("Collapsed: " + item.getLabel());
551
            m_ItemsExpanded.put(item.getLabel(), b);
552
        }
553
    }
554

  
555
    /* (non-Javadoc)
556
     * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
557
     */
558
    public void treeExpanded(TreeExpansionEvent event) {
559
        TreePath path = event.getPath();
560
        DefaultMutableTreeNode n = (DefaultMutableTreeNode) path.getLastPathComponent();
561

  
562
        if (n.getUserObject() instanceof ITocItem) {
563
            ITocItem item = (ITocItem) n.getUserObject();
564
            Boolean b = Boolean.TRUE;
565

  
566
            // System.out.println("Expanded: " + item.getLabel());
567
            m_ItemsExpanded.put(item.getLabel(), b);
568
        }
569
    }
570

  
571
    /**
572
     * Obtiene el JScrollPane que contiene el TOC
573
     *
574
     * @return JScrollPane que contiene el TOC
575
     */
576
    public JScrollPane getJScrollPane() {
577
        return this.m_Scroller;
578
    }
579

  
580
    /**
581
     * DOCUMENT ME!
582
     *
583
     * @return DOCUMENT ME!
584
     */
585
    public DnDJTree getTree() {
586
        return m_Tree;
587
    }
588

  
589
    /**
590
     * Clase Listener que reacciona al pulsar sobre el checkbox de un nodo y
591
     * crea un popupmenu al pulsar el bot?n derecho.
592
     */
593
    class NodeSelectionListener extends MouseAdapter implements ActionListener {
594
        JTree tree;
595
        JDialog dlg;
596
        JColorChooser colorChooser;
597
        FPopupMenu popmenu = null;
598
        DefaultMutableTreeNode node;
599

  
600
        /**
601
         * Crea un nuevo NodeSelectionListener.
602
         *
603
         * @param tree DOCUMENT ME!
604
         */
605
        NodeSelectionListener(JTree tree) {
606
            this.tree = tree;
607
        }
608

  
609
        /**
610
         * DOCUMENT ME!
611
         *
612
         * @param e DOCUMENT ME!
613
         */
614
        public void mouseClicked(MouseEvent e) {
615
        	int x = e.getX();
616
        	int y = e.getY();
617
        	int row = tree.getRowForLocation(x, y);
618
        	TreePath path = tree.getPathForRow(row);
619
        	LayerCollection layers = mapContext.getLayers();
620

  
621
        	// System.out.println(e.getSource());
622
        	if (path != null) {
623
        		if (e.getClickCount() == 1) {
624
        			// this fixes a bug when double-clicking. JTree by default
625
        			// expands the tree when double-clicking, so we capture a
626
        			// different node in the second click than in the first
627
        			node = (DefaultMutableTreeNode) path.getLastPathComponent();
628
        		}
629

  
630
        		// System.out.println("Evento de rat?n originado por " +
631
        		// e.getSource().getClass().toString());
632
        		if (node != null && node.getUserObject() instanceof TocItemBranch) {
633
        			// double click with left button ON A BRANCH/NODE (layer)
634
        			if (e.getClickCount()>=2 && e.getButton() == MouseEvent.BUTTON1) {
635
        				e.consume();
636
        				PluginServices.getMDIManager().setWaitCursor();
637
        				try {
638
        					TocItemBranch leaf = (TocItemBranch) node.getUserObject();
639

  
640
        					IContextMenuAction action = leaf.getDoubleClickAction();
641
        					if (action != null) {
642
        						/* if there is an action associated with the double-clicked element
643
        						 * it will be fired for it and FOR ALL OTHER COMPATIBLES THAT HAVE
644
        						 * BEEN ACTIVATED.
645
        						 */
646
        						ArrayList<FLayer> targetLayers = new ArrayList<FLayer>();
647

  
648
        						TocItemBranch owner = (TocItemBranch) node.getUserObject();
649

  
650
        						FLayer masterLayer = owner.getLayer();
651
        						targetLayers.add(masterLayer);
652
        						FLayer[] actives = mapContext.getLayers().getActives();
653
        						for (int i = 0; i < actives.length; i++) {
654
									if (actives[i].getClass().equals(masterLayer.getClass())) {
655
										if (actives[i] instanceof FLyrVect && actives[i].isAvailable()) {
656
											FLyrVect vectorLayer = (FLyrVect) actives[i];
657
											FLyrVect vectorMaster = (FLyrVect) masterLayer;
658
											if (vectorLayer.getShapeType() == vectorMaster.getShapeType()) {
659
												targetLayers.add(vectorLayer);
660
											} else {
661
												vectorLayer.setActive(false);
662
											}
663
										}
664
										// TODO for the rest of layer types (i.e. FLyrRaster)
665
									} else {
666
										actives[i].setActive(false);
667
									}
668
								}
669
        						action.execute(leaf, targetLayers.toArray(new FLayer[0]));
670
        					}
671
        				} catch (Exception ex) {
672
        					NotificationManager.addError(ex);
673
        				} finally {
674
        					PluginServices.getMDIManager().restoreCursor();
675
        				}
676
        				return;
677
        			}
678

  
679
        			TocItemBranch elTema = (TocItemBranch) node.getUserObject();
680
        			FLayer lyr = elTema.getLayer();
681
        			lyr.getMapContext().beginAtomicEvent();
682

  
683
        			if (((e.getModifiers() & InputEvent.SHIFT_MASK) != 0)
684
        					&& (e.getButton() == MouseEvent.BUTTON1)) {
685
        				FLayer[] activeLayers = layers.getActives();
686
        				if (activeLayers.length > 0) {
687
        					selectInterval(layers,lyr);
688
        				} else {
689
        					updateActive(lyr, !lyr.isActive());
690
        				}
691

  
692
        			} else {
693
        				if (!((e.getModifiers() & InputEvent.CTRL_MASK) != 0)
694
        						&& (e.getButton() == MouseEvent.BUTTON1)) {
695
        					layers.setAllActives(false);
696
        				}
697
        				if (e.getButton() == MouseEvent.BUTTON1) {
698
        					// lyr.setActive(true);
699
        					updateActive(lyr, !lyr.isActive());
700
        				}
701
        			}
702
        			// Si pertenece a un grupo, lo ponemos activo tambi?n.
703
        			// FLayer parentLayer = lyr.getParentLayer();
704

  
705
        			/*
706
        			 * if (parentLayer != null) { parentLayer.setActive(true); }
707
        			 */
708
        			Point layerNodeLocation = tree.getUI().getPathBounds(tree,
709
        					path).getLocation();
710

  
711
        			// Rect?ngulo que representa el checkbox
712
        			Rectangle checkBoxBounds = m_TocRenderer
713
        			.getCheckBoxBounds();
714
        			checkBoxBounds.translate((int) layerNodeLocation.getX(),
715
        					(int) layerNodeLocation.getY());
716

  
717
        			if (checkBoxBounds.contains(e.getPoint())) {
718
        				updateVisible(lyr);
719
        			}
720

  
721
        			// }
722
        			if (e.getButton() == MouseEvent.BUTTON3) {
723
        				// Boton derecho sobre un nodo del arbol
724
        				// if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
725
        				popmenu = new FPopupMenu(mapContext, node);
726
        				tree.add(popmenu);
727

  
728
        				popmenu.show(e.getComponent(), e.getX(), e.getY());
729

  
730
        				// }
731
        			}
732

  
733
        			lyr.getMapContext().endAtomicEvent();
734
        		}
735

  
736
        		if (node!=null && node.getUserObject() instanceof TocItemLeaf) {
737
        			// double click with left button ON A LEAF (ISymbol)
738
        			if (e.getClickCount()>=2 && e.getButton() == MouseEvent.BUTTON1) {
739
        				e.consume();
740

  
741
        				PluginServices.getMDIManager().setWaitCursor();
742
        				try {
743
        					TocItemLeaf leaf = (TocItemLeaf) node.getUserObject();
744
        					IContextMenuAction action = leaf.getDoubleClickAction();
745
        					if (action != null) {
746
        						/* if there is an action associated with the double-clicked element
747
        						 * it will be fired for it and FOR ALL OTHER COMPATIBLES THAT HAVE
748
        						 * BEEN ACTIVATED.
749
        						 */
750
        						ArrayList<FLayer> targetLayers = new ArrayList<FLayer>();
751

  
752
        						TocItemBranch owner = (TocItemBranch) ((DefaultMutableTreeNode) node.getParent())
753
        													.getUserObject();
754

  
755
        						FLayer masterLayer = owner.getLayer();
756
        						targetLayers.add(masterLayer);
757
        						FLayer[] actives = mapContext.getLayers().getActives();
758

  
759
        						if ((e.getModifiers() & InputEvent.CTRL_MASK) != 0){
760
        							masterLayer.setActive(true);
761
        						}else{
762
        							for (int i = 0; i < actives.length; i++) {
763
        								actives[i].setActive(false);
764
        							}
765
        							masterLayer.setActive(true);
766
        						}
767

  
768
        						actives = mapContext.getLayers().getActives();
769

  
770
        						for (int i = 0; i < actives.length; i++) {
771
									if (actives[i].getClass().equals(masterLayer.getClass())) {
772
										if (actives[i] instanceof FLyrVect) {
773
											FLyrVect vectorLayer = (FLyrVect) actives[i];
774
											FLyrVect vectorMaster = (FLyrVect) masterLayer;
775
											int masterLayerShapetypeOF_THE_LEGEND = ((IVectorLegend) vectorMaster.getLegend()).getShapeType();
776
											int anotherVectorLayerShapetypeOF_THE_LEGEND = ((IVectorLegend) vectorLayer.getLegend()).getShapeType();
777
											if ( masterLayerShapetypeOF_THE_LEGEND == anotherVectorLayerShapetypeOF_THE_LEGEND) {
778
												targetLayers.add(vectorLayer);
779
											} else {
780
												vectorLayer.setActive(false);
781
											}
782
										}
783
										// TODO for the rest of layer types (i.e. FLyrRaster)
784
									} else {
785
										actives[i].setActive(false);
786
									}
787
								}
788
        						action.execute(leaf, targetLayers.toArray(new FLayer[0]));
789
        					}
790
        				} catch (Exception ex) {
791
        					NotificationManager.addError(ex);
792
        				} finally {
793
        					PluginServices.getMDIManager().restoreCursor();
794
        				}
795
        				return;
796
        			}
797

  
798

  
799
        			// Boton derecho sobre un Simbolo
800
        			// TocItemLeaf auxLeaf = (TocItemLeaf) node.getUserObject();
801
        			// FSymbol theSym = auxLeaf.getSymbol();
802
        			if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
803

  
804
        				TocItemBranch owner = (TocItemBranch) ((DefaultMutableTreeNode) node.getParent())
805
        				.getUserObject();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff