Revision 37945

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/CopyPasteLayersUtiles.java
46 46
			//If the parent of my parent is not null, the layer is a root layer
47 47
			if (actives[i].getParentLayer().getParentLayer() == null){
48 48
				if (!this.addToXMLLayer(actives[i],xmlLayers ,xmlTables,xmlDataSources)) return null;
49
			}//If the layer is not a root layer, is copied if its parent layer is not active
49
			}//If the layer is not a root layer, is copied if its parent layer is active
50 50
			else if (!actives[i].getParentLayer().isActive()){
51 51
				if (!this.addToXMLLayer(actives[i],xmlLayers ,xmlTables,xmlDataSources)) return null;
52 52
			}
......
333 333

  
334 334
	private boolean addToXMLLayer(FLayer lyr,XMLEntity xmlLayers,XMLEntity xmlTables,XMLEntity xmlDataSources) {
335 335
		try {
336
			xmlLayers.addChild(lyr.getXMLEntity());
336
			XMLEntity lyrXml = lyr.getXMLEntity();
337
			if (lyrXml == null) {
338
				if (!lyr.isAvailable()) {
339
					lyr.reload();
340
					lyrXml = lyr.getXMLEntity();
341
				}
342
			}
343
			xmlLayers.addChild(lyrXml);
337 344

  
338 345
			return this.addToXMLLayerDependencies(lyr,xmlTables,xmlDataSources);
339 346

  
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/MyMoveListener.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 (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2011 Software Colaborativo (www.scolab.es)   development
26
 */
27

  
28
package com.iver.cit.gvsig.project.documents.view.toc.actions;
29

  
30
import java.awt.event.ActionEvent;
31

  
32
import javax.swing.AbstractAction;
33
import javax.swing.JDialog;
34

  
35
import com.iver.andami.PluginServices;
36
import com.iver.cit.gvsig.ProjectExtension;
37
import com.iver.cit.gvsig.fmap.MapContext;
38
import com.iver.cit.gvsig.fmap.layers.FLayer;
39
import com.iver.cit.gvsig.fmap.layers.FLayers;
40
import com.iver.cit.gvsig.project.Project;
41
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
42
import com.iver.cit.gvsig.project.documents.view.toc.gui.ChangeName;
43

  
44
public class MyMoveListener extends AbstractAction {
45

  
46
	private FLayers lpd;
47
	private int oldPos;
48
	private int newto;
49
	private MapContext mapContext;
50
	private JDialog dlgPop;
51

  
52
	public MyMoveListener(FLayers lpd, int newto, int oldPos,
53
			MapContext mapContext, JDialog dlgPop) {
54
		this.lpd = lpd;
55
		this.newto = newto;
56
		this.oldPos = oldPos;
57
		this.mapContext = mapContext;
58
		this.dlgPop = dlgPop;
59

  
60
	}
61

  
62
	public void createLayerGroup(FLayer[] selectedLayers) {
63
		// ITocItem tocItem = (ITocItem) getNodeUserObject();
64
		ChangeName changename = new ChangeName(null);
65
		PluginServices.getMDIManager().addWindow(changename);
66
		if (!changename.isAccepted())
67
			return;
68
		String nombre = changename.getName();
69

  
70
		if (nombre != null) {
71

  
72
			FLayers parent = selectedLayers[0].getParentLayer();
73
			// FLayers newGroup = new FLayers(getMapContext(),parent);
74
			FLayers newGroup = mapContext.getNewGroupLayer(parent);
75
			newGroup.setName(nombre);
76
			int pos = 0;
77
			for (int i = 0; i < parent.getLayersCount(); i++) {
78
				if (parent.getLayer(i).equals(selectedLayers[0])) {
79
					pos = i;
80
					continue;
81
				}
82
			}
83
			for (int j = 0; j < selectedLayers.length; j++) {
84
				FLayer layer = selectedLayers[j];
85
				parent.removeLayer(layer);
86
				newGroup.addLayer(layer);
87
			}
88
			parent.addLayer(pos, newGroup);
89
		}
90
	}
91

  
92
	public void actionPerformed(ActionEvent e) {
93
		mapContext.beginAtomicEvent();
94
		try {
95

  
96
			FLayers all = mapContext.getLayers();
97

  
98
			// obtenemos la capa sobre la que hemos dejado caer la otra.
99
			String layerName = lpd.getLayer(newto).getName();
100
			int pos = -1;
101
			for (int j = 0; j < lpd.getLayersCount(); j++) {
102
				if (lpd.getLayer(j).getName().equalsIgnoreCase(layerName)) {
103
					pos = lpd.getLayersCount() - j - 1;
104
					break;
105
				}
106
			}
107
			if (e.getActionCommand().equalsIgnoreCase("UP")) {
108
				if (oldPos > pos)
109
					pos = pos;
110
				else
111
					pos = pos - 1;
112
			}
113
			if (e.getActionCommand().equalsIgnoreCase("DOWN")) {
114
				if (oldPos > pos)
115
					pos = pos + 1;
116
				else
117
					pos = pos;
118
			}
119

  
120
//			System.out.println("oldPos=" + oldPos + " newto=" + newto + " pos="
121
//					+ pos);
122
			if (e.getActionCommand().equalsIgnoreCase("GROUP")) {
123
				FLayer origin = lpd.getLayer(lpd.getLayersCount() - oldPos - 1);
124
				FLayer dest = lpd.getLayer(layerName);
125
				// Creamos una nueva agrupaci?n
126
				FLayer[] selected = new FLayer[2];
127
				selected[0] = origin;
128
				selected[1] = dest;
129
				createLayerGroup(selected);
130

  
131
			} else
132
				lpd.moveTo(oldPos, pos);
133

  
134
		} catch (Exception ex) {
135
			ex.printStackTrace();
136
		}
137

  
138
		dlgPop.setVisible(false);
139
		dlgPop.dispose();
140
		mapContext.endAtomicEvent();
141
		
142

  
143
	}
144

  
145
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/MyPasteListener.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 (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2011 Software Colaborativo (www.scolab.es)   development
26
*/
27
 
28
package com.iver.cit.gvsig.project.documents.view.toc.actions;
29

  
30
import java.awt.event.ActionEvent;
31

  
32
import javax.swing.AbstractAction;
33
import javax.swing.JOptionPane;
34
import javax.swing.JPopupMenu;
35

  
36
import com.iver.andami.PluginServices;
37
import com.iver.cit.gvsig.fmap.MapContext;
38
import com.iver.cit.gvsig.fmap.layers.FLayer;
39
import com.iver.cit.gvsig.fmap.layers.FLayers;
40
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
41
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
42
import com.iver.cit.gvsig.project.documents.view.toc.gui.ChangeName;
43
import com.iver.utiles.Utils;
44
import com.iver.utiles.XMLEntity;
45

  
46
public class MyPasteListener extends AbstractAction {
47

  
48
	private XMLEntity xml;
49
	private ITocItem item;
50
	private FLayer root;
51
	private MapContext mapContext;
52
	private JPopupMenu pop;
53

  
54
	public MyPasteListener(JPopupMenu pop, ITocItem item, XMLEntity xml, FLayer root,
55
			MapContext mapContext) {
56
		this.item = item;
57
		this.xml = xml;
58
		this.root = root;
59
		this.mapContext = mapContext;
60
		this.pop = pop;
61
	}
62

  
63
	public void actionPerformed(ActionEvent e) {
64
		// JOptionPane.showMessageDialog(null, e.getActionCommand());
65
		
66
		mapContext.beginAtomicEvent();
67
		try {
68
			
69
			FLayers all = mapContext.getLayers();
70
			CopyPasteLayersUtiles.getInstance().loadLayersFromXML(xml, all);
71
				// ponemos las capas en posici?n
72
				int pos = -1;
73
				for (int j=0; j < all.getLayersCount(); j++) {
74
					if (all.getLayer(j).getName().equalsIgnoreCase(root.getName())) {
75
						pos = j;
76
						break;
77
					}
78
				}
79
				int corrected = 1;
80
				if (e.getActionCommand().equalsIgnoreCase("UP"))
81
					corrected = 2;
82
				all.moveTo(0, all.getLayersCount()-corrected-pos);
83
		} catch (Exception ex) {
84
			ex.printStackTrace();
85
		}
86
				
87
		mapContext.endAtomicEvent();
88
		mapContext.invalidate();
89

  
90
	}
91
	
92

  
93
}
94

  
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/TestDlg.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 (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2011 Software Colaborativo (www.scolab.es)   development
26
*/
27
 
28
package com.iver.cit.gvsig.project.documents.view.toc.actions;
29

  
30
import java.awt.MouseInfo;
31
import java.awt.Point;
32
import java.awt.PointerInfo;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35

  
36
import javax.swing.JDialog;
37
import javax.swing.JMenu;
38
import javax.swing.JMenuItem;
39
import javax.swing.JPopupMenu;
40
import javax.swing.Popup;
41
import javax.swing.PopupFactory;
42

  
43
public class TestDlg {
44

  
45
	/**
46
	 * @param args
47
	 */
48
	public static void main(String[] args) {
49
		final JPopupMenu pop = new JPopupMenu();
50
		JMenuItem itUp = new JMenuItem("Move_above_layer");
51
		JMenuItem itDown = new JMenuItem("Move_below_layer");
52
		JMenuItem itGroup = new JMenuItem("Group_with_layer");
53

  
54
		itUp.setActionCommand("UP");
55
		itDown.setActionCommand("DOWN");
56
		itGroup.setActionCommand("GROUP");
57

  
58
		final JDialog dlgPop = new JDialog();
59
		dlgPop.setUndecorated(true);
60
		dlgPop.getContentPane().add(pop);
61
		
62

  
63

  
64
		ActionListener lis = new ActionListener() {
65
			public void actionPerformed(ActionEvent e) {
66
				dlgPop.dispose();
67
			}
68
		};
69
		
70
		itUp.addActionListener(lis);
71
		itDown.addActionListener(lis);
72
		itGroup.addActionListener(lis);
73

  
74
		pop.add(itUp);
75
		pop.add(itDown);
76
		pop.add(itGroup);
77

  
78
		
79
		dlgPop.setModal(true);
80
//		
81
		
82

  
83
		PointerInfo pi = MouseInfo.getPointerInfo();
84
		final Point p = pi.getLocation();
85
		dlgPop.pack();
86
//		dlgPop.setSize(600, 600);
87
//		dlgPop.setLocation(300, 300);
88

  
89
		pop.setLocation(p.x, p.y);
90
//		Popup pop2 = PopupFactory.getSharedInstance().getPopup(dlgPop, pop, p.x, p.y);
91
		pop.setInvoker(dlgPop);
92
		pop.setVisible(true);
93
		itDown.validate();
94
		dlgPop.setVisible(true);
95

  
96
	}
97

  
98
}
99

  
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/CopyLayersTocMenuEntry.java
67 67
					);
68 68
			return;
69 69
		}
70

  
70
// 		System.out.println("texto xml copy:" + data);
71 71
		PluginServices.putInClipboard(data);
72 72
		Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
73 73
		project.setModified(true);
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/actions/PasteLayersTocMenuEntry.java
1 1
package com.iver.cit.gvsig.project.documents.view.toc.actions;
2 2

  
3
import java.awt.MouseInfo;
4
import java.awt.PointerInfo;
5

  
6
import javax.swing.JMenuItem;
7
import javax.swing.JPopupMenu;
8
import javax.swing.SwingUtilities;
9

  
3 10
import org.exolab.castor.xml.MarshalException;
4 11
import org.exolab.castor.xml.ValidationException;
5 12

  
......
36 43
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
37 44
		if (isTocItemBranch(item)) {
38 45
			FLayer lyr = getNodeLayer(item);
39
			if (lyr instanceof FLayers) {
46
//			if (lyr instanceof FLayers) {
40 47
				this.xml = this.getCheckedXMLFromClipboard();
41
				return true;
42
			}
48
//				return true;
49
//			}
50
			return this.xml != null; // Podemos hacer paste en cualquier sitio y nos preguntar? si queremos meter la capa en ese sitio
43 51

  
44 52
		} else if (!isTocItemLeaf(item)) {
45 53
			if (getNodeLayer(item) == null) {
......
54 62
		String sourceString = PluginServices.getFromClipboard();
55 63
		if (sourceString == null) return null;
56 64

  
65
//		System.out.println(sourceString);
57 66
		XMLEntity xml;
58 67
		try {
59 68
			xml = XMLEntity.parse(sourceString);
......
76 85

  
77 86
		if (this.xml == null) return;
78 87

  
88
		FLayer lyrOn = getNodeLayer(item);
79 89
		if (isTocItemBranch(item)) {
80
			root = (FLayers)getNodeLayer(item);
81
		} else if (getNodeLayer(item) == null){
90
			if (lyrOn instanceof FLayers) {
91
				root = (FLayers)getNodeLayer(item);
92
			}
93
			else
94
			{
95
				JPopupMenu pop = new JPopupMenu(PluginServices.getText(this, "Paste"));
96
				JMenuItem itUp = new JMenuItem(PluginServices.getText(this, "Paste_above_layer") + " " + lyrOn.getName());
97
				JMenuItem itDown = new JMenuItem(PluginServices.getText(this, "Paste_below_layer") + " " + lyrOn.getName());
98
				
99
				itUp.setActionCommand("UP");
100
				itDown.setActionCommand("DOWN");
101
				
102
				MyPasteListener lis = new MyPasteListener(pop, item, this.xml, lyrOn, getMapContext());		
103
				
104
				itUp.addActionListener(lis);
105
				itDown.addActionListener(lis);
106
				
107
				pop.add(itUp);
108
				pop.add(itDown);
109
				
110
				PointerInfo pi = MouseInfo.getPointerInfo();
111
				
112
				pop.show(null, pi.getLocation().x, pi.getLocation().y);
113

  
114
				return;
115
			}
116
		} else if (lyrOn == null){
82 117
			root = getMapContext().getLayers();
83 118
		} else {
84 119
			return;
85 120
		}
121

  
86 122
		getMapContext().beginAtomicEvent();
87

  
123
		
88 124
		boolean isOK = this.utiles.loadLayersFromXML(this.xml,root);
89 125

  
90 126
		getMapContext().endAtomicEvent();
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/impl/DefaultToc.java
22 22
package com.iver.cit.gvsig.project.documents.view.toc.impl;
23 23

  
24 24
import java.awt.BorderLayout;
25
import java.awt.Dialog.ModalityType;
25 26
import java.awt.Dimension;
27
import java.awt.Frame;
26 28
import java.awt.Image;
29
import java.awt.MouseInfo;
27 30
import java.awt.Point;
31
import java.awt.PointerInfo;
28 32
import java.awt.Rectangle;
29 33
import java.awt.event.ActionEvent;
30 34
import java.awt.event.ActionListener;
......
33 37
import java.awt.event.InputEvent;
34 38
import java.awt.event.MouseAdapter;
35 39
import java.awt.event.MouseEvent;
40
import java.lang.reflect.InvocationTargetException;
36 41
import java.util.ArrayList;
37 42
import java.util.Enumeration;
38 43
import java.util.HashMap;
......
44 49
import javax.swing.JColorChooser;
45 50
import javax.swing.JComponent;
46 51
import javax.swing.JDialog;
52
import javax.swing.JMenuItem;
53
import javax.swing.JPopupMenu;
47 54
import javax.swing.JScrollBar;
48 55
import javax.swing.JScrollPane;
49 56
import javax.swing.JTree;
......
56 63
import javax.swing.tree.TreePath;
57 64
import javax.swing.tree.TreeSelectionModel;
58 65

  
66
import org.apache.log4j.Logger;
67
import org.gvsig.fmap.swing.toc.TOC;
68
import org.gvsig.fmap.swing.toc.TOCFactory;
69
import org.gvsig.fmap.swing.toc.TOCLocator;
70
import org.gvsig.fmap.swing.toc.action.TOCAction;
71
import org.gvsig.fmap.swing.toc.event.ActiveLayerChangeEvent;
72
import org.gvsig.fmap.swing.toc.event.ActiveLayerChangeEventListener;
73
import org.gvsig.fmap.swing.toc.event.LayerActionEvent;
74
import org.gvsig.fmap.swing.toc.event.LayerActionEventListener;
75
import org.gvsig.fmap.swing.toc.event.LegendActionEvent;
76
import org.gvsig.fmap.swing.toc.event.LegendActionEventListener;
77
import org.gvsig.tools.dynobject.DynObject;
78
import org.gvsig.tools.service.Manager;
79
import org.gvsig.tools.service.ServiceException;
80

  
59 81
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
60 82
import com.iver.andami.PluginServices;
61 83
import com.iver.andami.messages.NotificationManager;
......
86 108
import com.iver.cit.gvsig.project.documents.view.toc.ITocOrderListener;
87 109
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch;
88 110
import com.iver.cit.gvsig.project.documents.view.toc.TocItemLeaf;
111
import com.iver.cit.gvsig.project.documents.view.toc.actions.MyMoveListener;
89 112
import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu;
90 113
import com.iver.cit.gvsig.project.documents.view.toc.util.EventUtil;
91 114

  
92
import org.apache.log4j.Logger;
93

  
94
import org.gvsig.fmap.swing.toc.TOC;
95
import org.gvsig.fmap.swing.toc.TOCFactory;
96
import org.gvsig.fmap.swing.toc.TOCLocator;
97
import org.gvsig.fmap.swing.toc.action.TOCAction;
98
import org.gvsig.fmap.swing.toc.event.ActiveLayerChangeEvent;
99
import org.gvsig.fmap.swing.toc.event.ActiveLayerChangeEventListener;
100
import org.gvsig.fmap.swing.toc.event.LayerActionEvent;
101
import org.gvsig.fmap.swing.toc.event.LayerActionEventListener;
102
import org.gvsig.fmap.swing.toc.event.LegendActionEvent;
103
import org.gvsig.fmap.swing.toc.event.LegendActionEventListener;
104
import org.gvsig.tools.dynobject.DynObject;
105
import org.gvsig.tools.service.Manager;
106
import org.gvsig.tools.service.ServiceException;
107

  
108 115
/**
109
 * Default implementation of the TOC. It's the original gvSIG "TOC.java"
110
 * with little changes to make it implement the new TOC interface
116
 * Default implementation of the TOC. It's the original gvSIG "TOC.java" with
117
 * little changes to make it implement the new TOC interface
111 118
 * 
112 119
 * @author gvSIG Team
113 120
 * @author Juan Lucas Dominguez jldominguez prodevelop es
114 121
 * @version $Id$
115
 *
122
 * 
116 123
 */
117 124
public class DefaultToc extends JComponent implements TOC,
118
    TreeExpansionListener, ComponentListener, ITocOrderListener,
119
    LegendListener, LayerCollectionListener {
125
		TreeExpansionListener, ComponentListener, ITocOrderListener,
126
		LegendListener, LayerCollectionListener {
120 127

  
121
    /**
128
	/**
122 129
     * 
123 130
     */
124
    private static final long serialVersionUID = 8704106636809906947L;
131
	private static final long serialVersionUID = 8704106636809906947L;
125 132

  
126
    private static Logger logger = Logger.getLogger(DefaultToc.class);
133
	private static Logger logger = Logger.getLogger(DefaultToc.class);
127 134

  
135
	/**
136
	 * String key to be used in persisted properties
137
	 */
138
	public static final String TOC_CURRENT_TOC_KEY = "TOC_CURRENT_TOC";
128 139

  
129
    /**
130
     * String key to be used in persisted properties
131
     */
132
    public static final String TOC_CURRENT_TOC_KEY = "TOC_CURRENT_TOC";
140
	// =======================================
133 141

  
134
    // =======================================
142
	private MapContext mapContext;
143
	private DnDJTree m_Tree;
144
	private DefaultTreeModel m_TreeModel;
145
	private DefaultMutableTreeNode m_Root;
146
	private TOCRenderer m_TocRenderer;
147
	private JScrollPane m_Scroller;
135 148

  
136
    private MapContext mapContext;
137
    private DnDJTree m_Tree;
138
    private DefaultTreeModel m_TreeModel;
139
    private DefaultMutableTreeNode m_Root;
140
    private TOCRenderer m_TocRenderer;
141
    private JScrollPane m_Scroller;
149
	// private ArrayList m_Listeners;
150
	private HashMap m_ItemsExpanded = new HashMap();
151
	private NodeSelectionListener nodeSelectionListener = null;
142 152

  
143
    // private ArrayList m_Listeners;
144
    private HashMap m_ItemsExpanded = new HashMap();
145
    private NodeSelectionListener nodeSelectionListener = null;
153
	private TOCFactory tocFactory = null;
146 154

  
147
    private TOCFactory tocFactory = null;
155
	private ArrayList activeLayerChangeListeners = new ArrayList();
156
	private ArrayList legendActionListeners = new ArrayList();
157
	private ArrayList layerActionListeners = new ArrayList();
148 158

  
149
    private ArrayList activeLayerChangeListeners = new ArrayList();
150
    private ArrayList legendActionListeners = new ArrayList();
151
    private ArrayList layerActionListeners = new ArrayList();
159
	public DefaultToc(TOCFactory tf) {
152 160

  
153
    public DefaultToc(TOCFactory tf) {
161
		tocFactory = tf;
154 162

  
155
        tocFactory = tf;
163
		this.setLayout(new BorderLayout());
164
		this.setMinimumSize(new Dimension(100, 80));
165
		this.setPreferredSize(new Dimension(100, 80));
156 166

  
157
        this.setLayout(new BorderLayout());
158
        this.setMinimumSize(new Dimension(100, 80));
159
        this.setPreferredSize(new Dimension(100, 80));
167
		// Construct the tree.
168
		m_Root = new DefaultMutableTreeNode(java.lang.Object.class);
169
		m_TreeModel = new DefaultTreeModel(m_Root);
170
		m_Tree = new DnDJTree(m_TreeModel);
160 171

  
161
        // Construct the tree.
162
        m_Root = new DefaultMutableTreeNode(java.lang.Object.class);
163
        m_TreeModel = new DefaultTreeModel(m_Root);
164
        m_Tree = new DnDJTree(m_TreeModel);
172
		m_TocRenderer = new TOCRenderer();
173
		m_Tree.setCellRenderer(m_TocRenderer);
165 174

  
166
        m_TocRenderer = new TOCRenderer();
167
        m_Tree.setCellRenderer(m_TocRenderer);
175
		m_Tree.setRootVisible(false);
168 176

  
169
        m_Tree.setRootVisible(false);
177
		m_Tree.setShowsRootHandles(true);
170 178

  
171
        m_Tree.setShowsRootHandles(true);
179
		// Posibilidad de seleccionar de forma aleatoria nodos de la leyenda.
180
		m_Tree.getSelectionModel().setSelectionMode(
181
				TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
182
		nodeSelectionListener = new NodeSelectionListener(m_Tree, this);
183
		m_Tree.addMouseListener(nodeSelectionListener);
184
		m_Tree.setBackground(UIManager.getColor("Button.background"));
185
		m_Tree.setBorder(BorderFactory.createEtchedBorder());
172 186

  
173
        // Posibilidad de seleccionar de forma aleatoria nodos de la leyenda.
174
        m_Tree.getSelectionModel().setSelectionMode(
175
            TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
176
        nodeSelectionListener = new NodeSelectionListener(m_Tree, this);
177
        m_Tree.addMouseListener(nodeSelectionListener);
178
        m_Tree.setBackground(UIManager.getColor("Button.background"));
179
        m_Tree.setBorder(BorderFactory.createEtchedBorder());
187
		this.addComponentListener(this);
180 188

  
181
        this.addComponentListener(this);
189
		m_Tree.addTreeExpansionListener(this);
182 190

  
183
        m_Tree.addTreeExpansionListener(this);
191
		m_Tree.addOrderListener(this); // listenerx
184 192

  
185
        m_Tree.addOrderListener(this); // listenerx
193
		m_Tree.setRowHeight(0); // Para que lo determine el renderer
186 194

  
187
        m_Tree.setRowHeight(0); // Para que lo determine el renderer
195
		m_Scroller = new JScrollPane(m_Tree);
196
		m_Scroller.setBorder(BorderFactory.createEmptyBorder());
188 197

  
189
        m_Scroller = new JScrollPane(m_Tree);
190
        m_Scroller.setBorder(BorderFactory.createEmptyBorder());
198
		add(m_Scroller);
199
	}
191 200

  
192
        add(m_Scroller);
193
    }
201
	public JComponent getComponent() {
202
		return this;
203
	}
194 204

  
195
    public JComponent getComponent() {
196
        return this;
197
    }
205
	public MapContext getMapContext() {
206
		return mapContext;
207
	}
198 208

  
199
    public MapContext getMapContext() {
200
        return mapContext;
201
    }
209
	public void makeTocVisibleAreaIncludeLayer(FLayer lyr) {
202 210

  
203
    public void makeTocVisibleAreaIncludeLayer(FLayer lyr) {
211
		int pos = 0;
212
		FLayers plyr = lyr.getParentLayer();
213
		if (plyr != null) {
214
			try {
215
				pos = getIndexForChild(plyr, lyr);
216
			} catch (Exception e) {
217
				logger.error("While proving layer is listed in TOC. ", e);
218
			}
219
		}
204 220

  
205
        int pos = 0;
206
        FLayers plyr = lyr.getParentLayer();
207
        if (plyr != null) {
208
            try {
209
                pos = getIndexForChild(plyr, lyr);
210
            } catch (Exception e) {
211
                logger.error("While proving layer is listed in TOC. ", e);
212
            }
213
        }
221
		JScrollBar verticalBar = m_Scroller.getVerticalScrollBar();
222
		double widthPerEntry = verticalBar.getMaximum()
223
				/ lyr.getMapContext().getLayers().getLayersCount();
224
		verticalBar.setValue((int) widthPerEntry
225
				* (lyr.getMapContext().getLayers().getLayersCount() - pos - 1));
226
	}
214 227

  
215
        JScrollBar verticalBar = m_Scroller.getVerticalScrollBar();
216
        double widthPerEntry =
217
            verticalBar.getMaximum()
218
                / lyr.getMapContext().getLayers().getLayersCount();
219
        verticalBar.setValue((int) widthPerEntry
220
            * (lyr.getMapContext().getLayers().getLayersCount() - pos - 1));
221
    }
228
	private int getIndexForChild(FLayers _lyrs, FLayer _lyr) throws Exception {
222 229

  
223
    private int getIndexForChild(FLayers _lyrs, FLayer _lyr) throws Exception {
230
		int cnt = _lyrs.getLayersCount();
231
		for (int i = 0; i < cnt; i++) {
232
			if (_lyr == _lyrs.getLayer(i)) {
233
				return i;
234
			}
235
		}
236
		throw new Exception("Layer not found in FLayers");
237
	}
224 238

  
225
        int cnt = _lyrs.getLayersCount();
226
        for (int i = 0; i < cnt; i++) {
227
            if (_lyr == _lyrs.getLayer(i)) {
228
                return i;
229
            }
230
        }
231
        throw new Exception("Layer not found in FLayers");
232
    }
239
	public void refresh(FLayer lyr) {
240
		// needs to be improved
241
		refresh();
242
	}
233 243

  
234
    public void refresh(FLayer lyr) {
235
        // needs to be improved
236
        refresh();
237
    }
244
	// =============================================
238 245

  
239
    // =============================================
246
	/**
247
	 * Set the FMap. Not part of the API. Used only by DefaultTOCFactory
248
	 * 
249
	 * @param mc
250
	 *            FMap.
251
	 */
252
	public void setMapContext(MapContext mc) {
240 253

  
241
    /**
242
     * Set the FMap. Not part of the API. Used only by DefaultTOCFactory
243
     * 
244
     * @param mc
245
     *            FMap.
246
     */
247
    public void setMapContext(MapContext mc) {
254
		if (mapContext == mc) {
255
			return;
256
		}
248 257

  
249
        if (mapContext == mc) {
250
            return;
251
        }
258
		mapContext = mc;
252 259

  
253
        mapContext = mc;
260
		mapContext.getLayers().addLegendListener(this);
254 261

  
255
        mapContext.getLayers().addLegendListener(this);
262
		mapContext.addAtomicEventListener(new AtomicEventListener() {
256 263

  
257
        mapContext.addAtomicEventListener(new AtomicEventListener() {
264
			/**
265
			 * @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
266
			 */
267
			public void atomicEvent(AtomicEvent e) {
268
				if ((e.getLayerCollectionEvents().length > 0)
269
						|| (e.getLegendEvents().length > 0)) {
270
//					for (LayerCollectionEvent ev : e.getLayerCollectionEvents()) {
271
//						System.out.println("Evento: " + ev.getEventType() + " " + ev.getAffectedLayer().getName());
272
//					}
273
					SwingUtilities.invokeLater(new Runnable() {
258 274

  
259
            /**
260
             * @see com.iver.cit.gvsig.fmap.AtomicEventListener#atomicEvent(com.iver.cit.gvsig.fmap.AtomicEvent)
261
             */
262
            public void atomicEvent(AtomicEvent e) {
263
                if ((e.getLayerCollectionEvents().length > 0)
264
                    || (e.getLegendEvents().length > 0)) {
265
                    SwingUtilities.invokeLater(new Runnable() {
275
						public void run() {
276
							refresh();
277
						}
278
					});
279
				}
266 280

  
267
                        public void run() {
268
                            refresh();
269
                        }
270
                    });
271
                }
281
				if (e.getLayerEvents().length > 0) {
282
					repaint();
283
				}
272 284

  
273
                if (e.getLayerEvents().length > 0) {
274
                    repaint();
275
                }
285
				if (e.getExtentEvents().length > 0) {
286
					repaint();
287
				}
288
			}
289
		});
276 290

  
277
                if (e.getExtentEvents().length > 0) {
278
                    repaint();
279
                }
280
            }
281
        });
291
		SwingUtilities.invokeLater(new Runnable() {
282 292

  
283
        SwingUtilities.invokeLater(new Runnable() {
293
			public void run() {
294
				refresh();
295
			}
296
		});
297
	}
284 298

  
285
            public void run() {
286
                refresh();
287
            }
288
        });
289
    }
299
	/**
300
	 * DOCUMENT ME!
301
	 */
302
	private void setExpandedNodes(DefaultMutableTreeNode node) {
303
		// int i = 0;
304
		// Las claves sobrantes de m_ItemsExpanded (provocadas
305
		// por layerRemove, se quitan en el evento layerRemoved
306
		// de este TOC
307
		DefaultMutableTreeNode n;
308
		Enumeration enumeration = node.children();
290 309

  
291
    /**
292
     * DOCUMENT ME!
293
     */
294
    private void setExpandedNodes(DefaultMutableTreeNode node) {
295
        // int i = 0;
296
        // Las claves sobrantes de m_ItemsExpanded (provocadas
297
        // por layerRemove, se quitan en el evento layerRemoved
298
        // de este TOC
299
        DefaultMutableTreeNode n;
300
        Enumeration enumeration = node.children();
310
		// Si el padre no est? expandido, no sigas.
311
		TreePath pathParent = new TreePath(node);
312
		if (node.getUserObject() instanceof ITocItem) {
313
			ITocItem itemP = (ITocItem) node.getUserObject();
314
			if (itemP != null) {
315
				Boolean b = (Boolean) m_ItemsExpanded.get(itemP.getLabel());
316
				if ((b!=null) && (b.booleanValue()==false)) {
317
//					m_Tree.collapsePath(pathParent);
318
					return;
319
				}
320
			}
321
		}
322
//		System.out.println("Expandiendo el nodo " + node.getUserObject());
323
		
324
		while (enumeration.hasMoreElements()) {
325
			
326
			n = (DefaultMutableTreeNode) enumeration.nextElement();
327
			if (n.getChildCount() > 0) {
328
				setExpandedNodes(n); // Problem: if we call setExpand on a leaf, there will be a TreeExpansionEvent and 
329
									 // treeExpanded method is called, where a TRUE is used for the branch (layers group).
330
									 // To avoid this problem, we will use a boolean variable to indicate we should not update
331
									 // m_ItmesExpanded while we are in these method (something like a "synchronized" method (sem?mforo)
332
			}
333
			TreePath path = new TreePath(m_TreeModel.getPathToRoot(n));
334
			ITocItem item = (ITocItem) n.getUserObject();
335
			Boolean b = (Boolean) m_ItemsExpanded.get(item.getLabel());
301 336

  
302
        while (enumeration.hasMoreElements()) {
303
            n = (DefaultMutableTreeNode) enumeration.nextElement();
304
            if (n.getChildCount() > 0) {
305
                setExpandedNodes(n);
306
            }
307
            TreePath path = new TreePath(m_TreeModel.getPathToRoot(n));
308
            ITocItem item = (ITocItem) n.getUserObject();
309
            Boolean b = (Boolean) m_ItemsExpanded.get(item.getLabel());
337
			if (b == null) // No estaba en el hash todav?a: valor por defecto
338
			{
339
				// System.out.println("Primera expansi?n de " +
340
				// item.getLabel());
341
//				m_Tree.expandPath(path);
342
//				return;
343
				continue;
344
			}
310 345

  
311
            if (b == null) // No estaba en el hash todav?a: valor por defecto
312
            {
313
                // System.out.println("Primera expansi?n de " +
314
                // item.getLabel());
315
                m_Tree.expandPath(path);
346
			if (b.booleanValue()) {
347
				// System.out.println("Expansi?n de " + item.getLabel());
348
				m_Tree.expandPath(path);
349
			} else {
350
				// System.out.println("Colapso de " + item.getLabel());
351
				m_Tree.collapsePath(path);
352
			}
353
		}
354
	}
316 355

  
317
                return;
318
            }
356
	/*
357
	 * (non-Javadoc)
358
	 * 
359
	 * @see com.iver.cit.opensig.gui.IToc#refresh()
360
	 */
361
	public void refresh() {
362
		LayerCollection theLayers = mapContext.getLayers();
363
		m_Root.removeAllChildren();
364
		m_Root.setAllowsChildren(true);
365
		System.out.println("Refresh del toc");
366
		doRefresh(theLayers, m_Root);
319 367

  
320
            if (b.booleanValue()) {
321
                // System.out.println("Expansi?n de " + item.getLabel());
322
                m_Tree.expandPath(path);
323
            } else {
324
                // System.out.println("Colapso de " + item.getLabel());
325
                m_Tree.collapsePath(path);
326
            }
327
        }
328
    }
368
		m_TreeModel.reload();
369
		setExpandedNodes(m_Root);
370
	}
329 371

  
330
    /*
331
     * (non-Javadoc)
332
     * 
333
     * @see com.iver.cit.opensig.gui.IToc#refresh()
334
     */
335
    public void refresh() {
336
        LayerCollection theLayers = mapContext.getLayers();
337
        m_Root.removeAllChildren();
338
        m_Root.setAllowsChildren(true);
339
        // System.out.println("Refresh del toc");
340
        doRefresh(theLayers, m_Root);
372
	/**
373
	 * DOCUMENT ME!
374
	 * 
375
	 * @param theLayers
376
	 *            DOCUMENT ME!
377
	 * @param parentNode
378
	 *            DOCUMENT ME!
379
	 */
380
	private void doRefresh(LayerCollection theLayers,
381
			DefaultMutableTreeNode parentNode) {
382
		Dimension sizeLeaf = new Dimension(m_Tree.getWidth(), 15);
383
		Dimension sizeBranch = new Dimension(m_Tree.getWidth(), 25);
341 384

  
342
        m_TreeModel.reload();
385
		for (int i = theLayers.getLayersCount() - 1; i >= 0; i--) {
386
			FLayer lyr = theLayers.getLayer(i);
387
			if (!lyr.isInTOC()) {
388
				continue;
389
			}
390
			TocItemBranch elTema = new TocItemBranch(lyr);
391
			elTema.setSize(sizeBranch);
343 392

  
344
        setExpandedNodes(m_Root);
345
    }
393
			DefaultMutableTreeNode nodeLayer = new DefaultMutableTreeNode(
394
					elTema);
346 395

  
347
    /**
348
     * DOCUMENT ME!
349
     * 
350
     * @param theLayers
351
     *            DOCUMENT ME!
352
     * @param parentNode
353
     *            DOCUMENT ME!
354
     */
355
    private void doRefresh(LayerCollection theLayers,
356
        DefaultMutableTreeNode parentNode) {
357
        Dimension sizeLeaf = new Dimension(m_Tree.getWidth(), 15);
358
        Dimension sizeBranch = new Dimension(m_Tree.getWidth(), 25);
396
			m_TreeModel.insertNodeInto(nodeLayer, parentNode,
397
					parentNode.getChildCount());
359 398

  
360
        for (int i = theLayers.getLayersCount() - 1; i >= 0; i--) {
361
            FLayer lyr = theLayers.getLayer(i);
362
            if (!lyr.isInTOC()) {
363
                continue;
364
            }
365
            TocItemBranch elTema = new TocItemBranch(lyr);
366
            elTema.setSize(sizeBranch);
399
			// TreePath path = new
400
			// TreePath(m_TreeModel.getPathToRoot(nodeLayer));
401
			// m_Tree.makeVisible(path);
402
			if (lyr instanceof LayerCollection) {
403
				LayerCollection group = (LayerCollection) lyr;
404
				doRefresh(group, nodeLayer);
405
			} else {
406
				if ((lyr instanceof Classifiable)
407
						&& !(lyr instanceof FLyrAnnotation)) {
367 408

  
368
            DefaultMutableTreeNode nodeLayer =
369
                new DefaultMutableTreeNode(elTema);
409
					Classifiable aux = (Classifiable) lyr;
410
					ILegend legendInfo = aux.getLegend();
370 411

  
371
            m_TreeModel.insertNodeInto(nodeLayer, parentNode, parentNode
372
                .getChildCount());
412
					try {
413
						if (legendInfo instanceof IClassifiedLegend) {
414
							IClassifiedLegend cl = (IClassifiedLegend) legendInfo;
415
							String[] descriptions = cl.getDescriptions();
416
							ISymbol[] symbols = cl.getSymbols();
373 417

  
374
            // TreePath path = new
375
            // TreePath(m_TreeModel.getPathToRoot(nodeLayer));
376
            // m_Tree.makeVisible(path);
377
            if (lyr instanceof LayerCollection) {
378
                LayerCollection group = (LayerCollection) lyr;
379
                doRefresh(group, nodeLayer);
380
            } else {
381
                if ((lyr instanceof Classifiable)
382
                    && !(lyr instanceof FLyrAnnotation)) {
418
							for (int j = 0; j < descriptions.length; j++) {
419
								TocItemLeaf itemLeaf;
420
								itemLeaf = new TocItemLeaf(symbols[j],
421
										descriptions[j], aux.getShapeType());
422
								itemLeaf.setSize(sizeLeaf);
383 423

  
384
                    Classifiable aux = (Classifiable) lyr;
385
                    ILegend legendInfo = aux.getLegend();
424
								DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(
425
										itemLeaf);
426
								m_TreeModel.insertNodeInto(nodeValue,
427
										nodeLayer, nodeLayer.getChildCount());
386 428

  
387
                    try {
388
                        if (legendInfo instanceof IClassifiedLegend) {
389
                            IClassifiedLegend cl =
390
                                (IClassifiedLegend) legendInfo;
391
                            String[] descriptions = cl.getDescriptions();
392
                            ISymbol[] symbols = cl.getSymbols();
429
								// TreePath pathSymbol = new
430
								// TreePath(m_TreeModel.getPathToRoot(
431
								// nodeValue));
432
								// m_Tree.makeVisible(pathSymbol);
433
							}
434
						}
393 435

  
394
                            for (int j = 0; j < descriptions.length; j++) {
395
                                TocItemLeaf itemLeaf;
396
                                itemLeaf =
397
                                    new TocItemLeaf(symbols[j],
398
                                        descriptions[j], aux.getShapeType());
399
                                itemLeaf.setSize(sizeLeaf);
436
						if ((legendInfo instanceof SingleSymbolLegend)
437
								&& (legendInfo.getDefaultSymbol() != null)) {
438
							TocItemLeaf itemLeaf;
439
							itemLeaf = new TocItemLeaf(
440
									legendInfo.getDefaultSymbol(), legendInfo
441
											.getDefaultSymbol()
442
											.getDescription(),
443
									aux.getShapeType());
444
							itemLeaf.setSize(sizeLeaf);
400 445

  
401
                                DefaultMutableTreeNode nodeValue =
402
                                    new DefaultMutableTreeNode(itemLeaf);
403
                                m_TreeModel.insertNodeInto(nodeValue,
404
                                    nodeLayer, nodeLayer.getChildCount());
446
							DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(
447
									itemLeaf);
448
							m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
449
									nodeLayer.getChildCount());
405 450

  
406
                                // TreePath pathSymbol = new
407
                                // TreePath(m_TreeModel.getPathToRoot(
408
                                // nodeValue));
409
                                // m_Tree.makeVisible(pathSymbol);
410
                            }
411
                        }
451
							// TreePath pathSymbol = new
452
							// TreePath(m_TreeModel.getPathToRoot(
453
							// nodeValue));
454
							// m_Tree.makeVisible(pathSymbol);
455
						}
412 456

  
413
                        if ((legendInfo instanceof SingleSymbolLegend)
414
                            && (legendInfo.getDefaultSymbol() != null)) {
415
                            TocItemLeaf itemLeaf;
416
                            itemLeaf =
417
                                new TocItemLeaf(legendInfo.getDefaultSymbol(),
418
                                    legendInfo.getDefaultSymbol()
419
                                        .getDescription(), aux.getShapeType());
420
                            itemLeaf.setSize(sizeLeaf);
457
						if (lyr instanceof IHasImageLegend) {
458
							TocItemLeaf itemLeaf;
459
							IHasImageLegend auxLayer = (IHasImageLegend) lyr;
460
							Image image = auxLayer.getImageLegend();
421 461

  
422
                            DefaultMutableTreeNode nodeValue =
423
                                new DefaultMutableTreeNode(itemLeaf);
424
                            m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
425
                                nodeLayer.getChildCount());
462
							if (image != null) {
463
								itemLeaf = new TocItemLeaf();
464
								itemLeaf.setImageLegend(image, "",
465
										new Dimension(image.getWidth(null),
466
												image.getHeight(null)));// new
467
																		// Dimension(150,200));
426 468

  
427
                            // TreePath pathSymbol = new
428
                            // TreePath(m_TreeModel.getPathToRoot(
429
                            // nodeValue));
430
                            // m_Tree.makeVisible(pathSymbol);
431
                        }
469
								DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(
470
										itemLeaf);
471
								m_TreeModel.insertNodeInto(nodeValue,
472
										nodeLayer, nodeLayer.getChildCount());
473
							}
474
						}
475
					} catch (ReadDriverException e) {
476
						e.printStackTrace();
477
					}
478
				}
479
			} // if instanceof layers
480
		}
481
	}
432 482

  
433
                        if (lyr instanceof IHasImageLegend) {
434
                            TocItemLeaf itemLeaf;
435
                            IHasImageLegend auxLayer = (IHasImageLegend) lyr;
436
                            Image image = auxLayer.getImageLegend();
483
	/**
484
	 * @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int,
485
	 *      int)
486
	 */
487
	public void orderChanged(int oldPos, int newPos, FLayers lpd) {
488
		// LayerCollection layers = mapContext.getLayers();
489
		// El orden es el contrario, hay que traducir.
490
		// El orden es el contrario, hay que traducir.
491
		// /oldPos = layers.getLayersCount() - 1 - oldPos;
492
		// /newPos = layers.getLayersCount() - 1 - newPos;
493
		try {
494
			// Si lpd es un grupo de capas, el usuario tiene m?s opciones: Mover
495
			// la capa arriba o abajo del grupo de capas, o a?adir la capa a
496
			// ese grupo de capas
437 497

  
438
                            if (image != null) {
439
                                itemLeaf = new TocItemLeaf();
440
                                itemLeaf.setImageLegend(image, "",
441
                                    new Dimension(image.getWidth(null), image
442
                                        .getHeight(null)));// new
443
                                                            // Dimension(150,200));
498
			int newto = lpd.getLayersCount() - newPos - 1;
499
			String layerName = lpd.getLayer(newto).getName();
500
			System.out.println("NewPos = " + layerName);
501
			final JPopupMenu pop = new JPopupMenu(PluginServices.getText(this,
502
					"Move"));
503
			JMenuItem itUp = new JMenuItem(PluginServices.getText(this,
504
					"Move_above_layer") + " " + layerName);
505
			JMenuItem itDown = new JMenuItem(PluginServices.getText(this,
506
					"Move_below_layer") + " " + layerName);
507
			JMenuItem itGroup = new JMenuItem(PluginServices.getText(this,
508
					"Group_with_layer") + " " + layerName);
444 509

  
445
                                DefaultMutableTreeNode nodeValue =
446
                                    new DefaultMutableTreeNode(itemLeaf);
447
                                m_TreeModel.insertNodeInto(nodeValue,
448
                                    nodeLayer, nodeLayer.getChildCount());
449
                            }
450
                        }
451
                    } catch (ReadDriverException e) {
452
                        e.printStackTrace();
453
                    }
454
                }
455
            } // if instanceof layers
456
        }
457
    }
510
			itUp.setActionCommand("UP");
511
			itDown.setActionCommand("DOWN");
512
			itGroup.setActionCommand("GROUP");
458 513

  
459
    /**
460
     * @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int,
461
     *      int)
462
     */
463
    public void orderChanged(int oldPos, int newPos, FLayers lpd) {
464
        // LayerCollection layers = mapContext.getLayers();
465
        // El orden es el contrario, hay que traducir.
466
        // El orden es el contrario, hay que traducir.
467
        // /oldPos = layers.getLayersCount() - 1 - oldPos;
468
        // /newPos = layers.getLayersCount() - 1 - newPos;
469
        try {
470
            lpd.moveTo(oldPos, newPos);
471
        } catch (CancelationException e) {
472
            // TODO Auto-generated catch block
473
            e.printStackTrace();
474
        }
514
			JDialog dlgPop = new JDialog((Frame) null);
515
			dlgPop.setUndecorated(true);
516
			dlgPop.getContentPane().add(pop);
517
			dlgPop.setModal(true);
475 518

  
476
        // No hace falta un refresh, lo hace mediante eventos.
477
        // refresh();
478
        mapContext.invalidate();
479
    }
519
			MyMoveListener lis = new MyMoveListener(lpd, newto, oldPos,
520
					getMapContext(), dlgPop);
480 521

  
481
    /**
482
     * DOCUMENT ME!
483
     * 
484
     * @param lpo
485
     *            DOCUMENT ME!
486
     * @param lpd
487
     *            DOCUMENT ME!
488
     * @param ls
489
     *            DOCUMENT ME!
490
     */
491
    public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) {
492
        lpo.removeLayer(ls);
493
        lpd.addLayer(ls);
494
        PluginServices.getMainFrame().enableControls();
495
        /*
496
         * if (lpo.getLayersCount()==0){ lpo.getParentLayer().removeLayer(lpo); }
497
         */
498
        mapContext.invalidate();
522
			itUp.addActionListener(lis);
523
			itDown.addActionListener(lis);
524
			itGroup.addActionListener(lis);
499 525

  
500
    }
526
			pop.add(itUp);
527
			pop.add(itDown);
528
			pop.add(itGroup);
501 529

  
502
    /*
503
     * (non-Javadoc)
504
     * 
505
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.ComponentEvent)
506
     */
507
    public void componentHidden(ComponentEvent e) {
508
    }
530
			PointerInfo pi = MouseInfo.getPointerInfo();
531
			final Point p = pi.getLocation();
532
			//SwingUtilities.convertPointToScreen(p, this);
533
//			pop.show(this, p.x, p.y);
534
			pop.setInvoker(dlgPop);
535
			pop.setLocation(p.x, p.y);
536
			pop.setVisible(true);			
537
			dlgPop.pack();
538
			
539
			dlgPop.setVisible(true);
540
			
541
		} catch (CancelationException e) {
542
			// TODO Auto-generated catch block
543
			e.printStackTrace();
544
		}
509 545

  
510
    /*
511
     * (non-Javadoc)
512
     * 
513
     * @see java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent)
514
     */
515
    public void componentMoved(ComponentEvent e) {
516
    }
546
		// No hace falta un refresh, lo hace mediante eventos.
547
		// refresh();
548
		mapContext.invalidate();
549
	}
517 550

  
518
    /*
519
     * (non-Javadoc)
520
     * 
521
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
522
     */
523
    public void componentResized(ComponentEvent e) {
524
        System.out.println("Cambiando tama?o.");
551
	/**
552
	 * DOCUMENT ME!
553
	 * 
554
	 * @param lpo
555
	 *            DOCUMENT ME!
556
	 * @param lpd
557
	 *            DOCUMENT ME!
558
	 * @param ls
559
	 *            DOCUMENT ME!
560
	 */
561
	public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) {
562
		lpo.removeLayer(ls);
563
		if (lpo.getLayersCount() == 0)
564
			lpo.getParentLayer().removeLayer(lpo);
565
		Integer drop_pos = (Integer) ls.getProperty("DROP_POS");
566
		lpd.addLayer(lpd.getLayersCount() - drop_pos - 1, ls);
567
		ls.getExtendedProperties().remove("DROP_POS");
568
		PluginServices.getMainFrame().enableControls();
569
		/*
570
		 * if (lpo.getLayersCount()==0){ lpo.getParentLayer().removeLayer(lpo);
571
		 * }
572
		 */
573
		mapContext.invalidate();
525 574

  
526
        int i = 0;
527
        DefaultMutableTreeNode n;
528
        Enumeration enumeration = m_Root.children();
575
	}
529 576

  
530
        while (enumeration.hasMoreElements()) {
531
            n = (DefaultMutableTreeNode) enumeration.nextElement();
577
	/*
578
	 * (non-Javadoc)
579
	 * 
580
	 * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.
581
	 * ComponentEvent)
582
	 */
583
	public void componentHidden(ComponentEvent e) {
584
	}
532 585

  
533
            if (n.getUserObject() instanceof TocItemBranch) {
534
                ITocItem item = (ITocItem) n.getUserObject();
535
                Dimension szAnt = item.getSize();
536
                item.setSize(new Dimension(this.getWidth() - 40, szAnt.height));
537
            }
586
	/*
587
	 * (non-Javadoc)
588
	 * 
589
	 * @see
590
	 * java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent
591
	 * )
592
	 */
593
	public void componentMoved(ComponentEvent e) {
594
	}
538 595

  
539
        }
596
	/*
597
	 * (non-Javadoc)
598
	 * 
599
	 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.
600
	 * ComponentEvent)
601
	 */
602
	public void componentResized(ComponentEvent e) {
603
		System.out.println("Cambiando tama?o.");
540 604

  
541
        // m_Tree.setSize(this.getSize());
542
        System.out.println("Ancho del tree=" + m_Tree.getWidth() + " "
543
            + m_Tree.getComponentCount());
544
        System.out.println("Ancho del TOC=" + this.getWidth());
605
		int i = 0;
606
		DefaultMutableTreeNode n;
607
		Enumeration enumeration = m_Root.children();
545 608

  
546
        // m_Tree.repaint();
547
    }
609
		while (enumeration.hasMoreElements()) {
610
			n = (DefaultMutableTreeNode) enumeration.nextElement();
548 611

  
549
    /*
550
     * (non-Javadoc)
551
     * 
552
     * @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
553
     */
554
    public void componentShown(ComponentEvent e) {
555
    }
612
			if (n.getUserObject() instanceof TocItemBranch) {
613
				ITocItem item = (ITocItem) n.getUserObject();
614
				Dimension szAnt = item.getSize();
615
				item.setSize(new Dimension(this.getWidth() - 40, szAnt.height));
616
			}
556 617

  
557
    /*
558
     * (non-Javadoc)
559
     * 
560
     * @see com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent)
561
     */
562
    public void legendChanged(LegendChangedEvent e) {
563
        System.out.println("Refrescando TOC");
564
        refresh();
565
    }
618
		}
566 619

  
567
    /*
568
     * (non-Javadoc)
569
     * 
570
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
571
     */
572
    public void layerAdded(LayerCollectionEvent e) {
573
        refresh();
574
    }
620
		// m_Tree.setSize(this.getSize());
621
		System.out.println("Ancho del tree=" + m_Tree.getWidth() + " "
622
				+ m_Tree.getComponentCount());
623
		System.out.println("Ancho del TOC=" + this.getWidth());
575 624

  
576
    /*
577
     * (non-Javadoc)
578
     * 
579
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
580
     */
581
    public void layerMoved(LayerPositionEvent e) {
582
        refresh();
583
    }
625
		// m_Tree.repaint();
626
	}
584 627

  
585
    /*
586
     * (non-Javadoc)
587
     * 
588
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
589
     */
590
    public void layerRemoved(LayerCollectionEvent e) {
591
        m_ItemsExpanded.remove(e.getAffectedLayer().getName());
592
        refresh();
593
    }
628
	/*
629
	 * (non-Javadoc)
630
	 * 
631
	 * @see
632
	 * java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent
633
	 * )
634
	 */
635
	public void componentShown(ComponentEvent e) {
636
	}
594 637

  
595
    /*
596
     * (non-Javadoc)
597
     * 
598
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
599
     */
600
    public void layerAdding(LayerCollectionEvent e) throws CancelationException {
601
    }
638
	/*
639
	 * (non-Javadoc)
640
	 * 
641
	 * @see
642
	 * com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit
643
	 * .gvsig.fmap.rendering.LegendChangedEvent)
644
	 */
645
	public void legendChanged(LegendChangedEvent e) {
646
		System.out.println("Refrescando TOC");
647
		refresh();
648
	}
602 649

  
603
    /*
604
     * (non-Javadoc)
605
     * 
606
     * @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
607
     */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff