Revision 43100 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/project/documents/view/toc/gui/TOC.java
TOC.java | ||
---|---|---|
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2007-2013 gvSIG Association. |
5 | 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 3
|
|
9 |
* of the License, or (at your option) any later version.
|
|
6 |
* This program is free software; you can redistribute it and/or modify it under
|
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
|
9 |
* version. |
|
10 | 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.
|
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
* details. |
|
15 | 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. |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
20 | 19 |
* |
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
23 | 22 |
*/ |
24 | 23 |
package org.gvsig.app.project.documents.view.toc.gui; |
25 | 24 |
|
... | ... | |
30 | 29 |
import java.awt.Image; |
31 | 30 |
import java.awt.Point; |
32 | 31 |
import java.awt.Rectangle; |
33 |
import java.awt.event.ActionEvent; |
|
34 |
import java.awt.event.ActionListener; |
|
35 | 32 |
import java.awt.event.ComponentEvent; |
36 | 33 |
import java.awt.event.ComponentListener; |
37 | 34 |
import java.awt.event.InputEvent; |
... | ... | |
42 | 39 |
import java.util.Enumeration; |
43 | 40 |
import java.util.HashMap; |
44 | 41 |
import java.util.Map; |
45 |
|
|
46 | 42 |
import javax.swing.BorderFactory; |
47 | 43 |
import javax.swing.JColorChooser; |
48 | 44 |
import javax.swing.JComponent; |
... | ... | |
54 | 50 |
import javax.swing.event.TreeExpansionListener; |
55 | 51 |
import javax.swing.tree.DefaultMutableTreeNode; |
56 | 52 |
import javax.swing.tree.DefaultTreeModel; |
53 |
import javax.swing.tree.TreeNode; |
|
57 | 54 |
import javax.swing.tree.TreePath; |
58 | 55 |
import javax.swing.tree.TreeSelectionModel; |
59 |
import org.apache.commons.lang3.BooleanUtils; |
|
60 |
|
|
56 |
import org.apache.commons.lang.BooleanUtils; |
|
61 | 57 |
import org.gvsig.andami.PluginServices; |
62 |
import org.gvsig.andami.PluginsLocator; |
|
63 |
import org.gvsig.andami.actioninfo.ActionInfo; |
|
64 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
|
65 | 58 |
import org.gvsig.andami.messages.NotificationManager; |
66 | 59 |
import org.gvsig.app.ApplicationLocator; |
67 |
import org.gvsig.app.gui.preferencespage.ViewPage; |
|
68 | 60 |
import org.gvsig.app.project.ProjectPreferences; |
69 | 61 |
import org.gvsig.app.project.documents.view.IContextMenuAction; |
70 | 62 |
import org.gvsig.app.project.documents.view.toc.DnDJTree; |
... | ... | |
72 | 64 |
import org.gvsig.app.project.documents.view.toc.ITocOrderListener; |
73 | 65 |
import org.gvsig.app.project.documents.view.toc.TocItemBranch; |
74 | 66 |
import org.gvsig.app.project.documents.view.toc.TocItemLeaf; |
75 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
76 | 67 |
import org.gvsig.fmap.mapcontext.MapContext; |
77 | 68 |
import org.gvsig.fmap.mapcontext.events.AtomicEvent; |
78 | 69 |
import org.gvsig.fmap.mapcontext.events.listeners.AtomicEventListener; |
... | ... | |
80 | 71 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
81 | 72 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
82 | 73 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
83 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
|
84 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
|
85 | 74 |
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
86 | 75 |
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend; |
87 | 76 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
... | ... | |
89 | 78 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend; |
90 | 79 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
91 | 80 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
92 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
93 | 81 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
94 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
|
95 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
|
96 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
97 | 82 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
98 | 83 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
99 |
import org.gvsig.tools.dynobject.DynObject; |
|
100 |
import org.gvsig.utils.XMLEntity; |
|
101 | 84 |
import org.slf4j.Logger; |
102 | 85 |
import org.slf4j.LoggerFactory; |
103 | 86 |
|
... | ... | |
105 | 88 |
* |
106 | 89 |
* @author fjp |
107 | 90 |
*/ |
108 |
public class TOC extends JComponent implements ITocOrderListener, |
|
109 |
LegendListener, LayerCollectionListener, TreeExpansionListener, |
|
110 |
ComponentListener, LegendContentsChangedListener { |
|
91 |
public class TOC extends JComponent // implements |
|
92 |
// ITocOrderListener, |
|
93 |
// LegendListener, |
|
94 |
// LayerCollectionListener, |
|
95 |
// LegendContentsChangedListener, |
|
96 |
// TreeExpansionListener |
|
97 |
{ |
|
111 | 98 |
|
112 | 99 |
/** |
113 | 100 |
* |
114 | 101 |
*/ |
115 | 102 |
private static final long serialVersionUID = 5689047685537359038L; |
116 | 103 |
|
117 |
/** |
|
118 |
* Useful for debug the problems during the implementation. |
|
119 |
*/ |
|
120 |
private static Logger logger = LoggerFactory.getLogger(TOC.class); |
|
104 |
private static final Logger logger = LoggerFactory.getLogger(TOC.class); |
|
121 | 105 |
|
122 |
private MapContext mapContext;
|
|
106 |
private static class ItemsExpandeds {
|
|
123 | 107 |
|
124 |
private DnDJTree m_Tree; |
|
108 |
private final Map<Object, Boolean> itemsExpanded = new HashMap<>(); |
|
109 |
private boolean expandingNodes = false; |
|
125 | 110 |
|
126 |
private DefaultTreeModel m_TreeModel; |
|
111 |
public boolean isMarked(ITocItem item) { |
|
112 |
Object key = item.getLabel(); |
|
113 |
boolean isItemExpanded = BooleanUtils.isTrue(this.itemsExpanded.get(key)); |
|
114 |
return isItemExpanded; |
|
115 |
} |
|
127 | 116 |
|
128 |
private DefaultMutableTreeNode m_Root; |
|
117 |
public void setMark(ITocItem item, boolean expanded) { |
|
118 |
Object key = item.getLabel(); |
|
119 |
this.itemsExpanded.put(key, expanded); |
|
120 |
} |
|
129 | 121 |
|
130 |
private TOCRenderer m_TocRenderer; |
|
122 |
public void removeLayer(FLayer layer) { |
|
123 |
Object key = layer.getName(); |
|
124 |
this.itemsExpanded.remove(key); |
|
125 |
} |
|
131 | 126 |
|
132 |
private JScrollPane m_Scroller; |
|
127 |
public void update(JTree tree, TreeNode node) { |
|
128 |
if (expandingNodes) { |
|
129 |
return; |
|
130 |
} |
|
131 |
try { |
|
132 |
expandingNodes = true; |
|
133 |
DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); |
|
134 |
Enumeration<DefaultMutableTreeNode> nodes = node.children(); |
|
135 |
while (nodes.hasMoreElements()) { |
|
136 |
DefaultMutableTreeNode curNode = nodes.nextElement(); |
|
137 |
if (curNode.getChildCount() > 0) { |
|
138 |
update(tree, curNode); |
|
139 |
} |
|
140 |
TreePath path = new TreePath(treeModel.getPathToRoot(curNode)); |
|
141 |
ITocItem item = (ITocItem) curNode.getUserObject(); |
|
142 |
if (this.isMarked(item)) { |
|
143 |
tree.expandPath(path); |
|
144 |
} else { |
|
145 |
tree.collapsePath(path); |
|
146 |
} |
|
147 |
} |
|
148 |
} finally { |
|
149 |
expandingNodes = false; |
|
150 |
} |
|
133 | 151 |
|
134 |
// private ArrayList m_Listeners; |
|
135 |
private Map<String, Boolean> m_ItemsExpanded = |
|
136 |
new HashMap<String, Boolean>(); |
|
152 |
} |
|
153 |
} |
|
137 | 154 |
|
155 |
private MapContext mapContext; |
|
156 |
|
|
157 |
private final DnDJTree m_Tree; |
|
158 |
private final DefaultTreeModel m_TreeModel; |
|
159 |
private final DefaultMutableTreeNode m_Root; |
|
160 |
private final TOCRenderer m_TocRenderer; |
|
161 |
private final JScrollPane m_Scroller; |
|
162 |
|
|
163 |
private final ItemsExpandeds itemsExpandeds = new ItemsExpandeds(); |
|
164 |
|
|
138 | 165 |
private NodeSelectionListener nodeSelectionListener = null; |
139 | 166 |
|
140 | 167 |
/** |
... | ... | |
146 | 173 |
this.setMinimumSize(new Dimension(100, 80)); |
147 | 174 |
this.setPreferredSize(new Dimension(100, 80)); |
148 | 175 |
|
149 |
// Construct the tree. |
|
150 | 176 |
m_Root = new DefaultMutableTreeNode(java.lang.Object.class); |
151 | 177 |
m_TreeModel = new DefaultTreeModel(m_Root); |
152 | 178 |
m_Tree = new DnDJTree(m_TreeModel); |
153 | 179 |
|
154 | 180 |
m_TocRenderer = new TOCRenderer(m_Tree.getBackground()); |
155 | 181 |
m_Tree.setCellRenderer(m_TocRenderer); |
156 |
|
|
157 | 182 |
m_Tree.setRootVisible(false); |
158 |
|
|
159 |
// m_Tree.setExpandsSelectedPaths(true); |
|
160 |
// m_Tree.setAutoscrolls(true); |
|
161 | 183 |
m_Tree.setShowsRootHandles(true); |
162 |
|
|
163 |
// Posibilidad de seleccionar de forma aleatoria nodos de la leyenda. |
|
164 | 184 |
m_Tree.getSelectionModel().setSelectionMode( |
165 |
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); |
|
185 |
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION |
|
186 |
); |
|
166 | 187 |
nodeSelectionListener = new NodeSelectionListener(m_Tree); |
167 | 188 |
m_Tree.addMouseListener(nodeSelectionListener); |
168 |
// m_Tree.setBackground(UIManager.getColor("Button.background")); |
|
169 |
// m_Tree.setBorder(BorderFactory.createEtchedBorder()); |
|
170 | 189 |
|
171 |
this.addComponentListener(this);
|
|
190 |
this.addComponentListener(new ComponentListener() {
|
|
172 | 191 |
|
173 |
m_Tree.addTreeExpansionListener(this); |
|
192 |
@Override |
|
193 |
public void componentResized(ComponentEvent e) { |
|
194 |
tocResized(); |
|
195 |
} |
|
174 | 196 |
|
175 |
m_Tree.addOrderListener(this); |
|
197 |
@Override |
|
198 |
public void componentMoved(ComponentEvent e) { |
|
199 |
} |
|
176 | 200 |
|
201 |
@Override |
|
202 |
public void componentShown(ComponentEvent e) { |
|
203 |
} |
|
204 |
|
|
205 |
@Override |
|
206 |
public void componentHidden(ComponentEvent e) { |
|
207 |
} |
|
208 |
}); |
|
209 |
|
|
210 |
m_Tree.addOrderListener(new ITocOrderListener() { |
|
211 |
@Override |
|
212 |
public void orderChanged(int oldPos, int newPos, FLayers layers) { |
|
213 |
try { |
|
214 |
layers.moveTo(oldPos, newPos); |
|
215 |
} catch (Exception e) { |
|
216 |
logger.warn("Can't change order of layers in TOC", e); |
|
217 |
} |
|
218 |
mapContext.invalidate(); |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public void parentChanged(FLayers source, FLayers targer, FLayer layer) { |
|
223 |
try { |
|
224 |
source.move(layer, targer); |
|
225 |
} catch (Exception e) { |
|
226 |
logger.warn("Can't move layers in TOC", e); |
|
227 |
} |
|
228 |
mapContext.invalidate(); |
|
229 |
} |
|
230 |
}); |
|
231 |
|
|
232 |
m_Tree.addTreeExpansionListener(new TreeExpansionListener() { |
|
233 |
@Override |
|
234 |
public void treeCollapsed(TreeExpansionEvent event) { |
|
235 |
TreePath path = event.getPath(); |
|
236 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); |
|
237 |
if (node.getUserObject() instanceof ITocItem) { |
|
238 |
itemsExpandeds.setMark((ITocItem) node.getUserObject(), false); |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
@Override |
|
243 |
public void treeExpanded(TreeExpansionEvent event) { |
|
244 |
TreePath path = event.getPath(); |
|
245 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); |
|
246 |
if (node.getUserObject() instanceof ITocItem) { |
|
247 |
itemsExpandeds.setMark((ITocItem) node.getUserObject(), true); |
|
248 |
} |
|
249 |
} |
|
250 |
}); |
|
251 |
|
|
177 | 252 |
m_Tree.setRowHeight(0); // Para que lo determine el renderer |
178 | 253 |
|
179 | 254 |
m_Scroller = new JScrollPane(m_Tree); |
180 | 255 |
m_Scroller.setBorder(BorderFactory.createEmptyBorder()); |
181 | 256 |
|
182 |
// scrollPane.setPreferredSize(new Dimension(80,80)); |
|
183 |
// Add everything to this panel. |
|
184 |
/* |
|
185 |
* GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = |
|
186 |
* new GridBagConstraints(); setLayout(gridbag); c.fill = |
|
187 |
* GridBagConstraints.BOTH; c.weightx = 1.0; |
|
188 |
* gridbag.setConstraints(check,c); |
|
189 |
*/ |
|
190 |
add(m_Scroller); // , BorderLayout.WEST); |
|
257 |
add(m_Scroller); |
|
191 | 258 |
|
192 |
// refresh(); |
|
193 | 259 |
} |
194 | 260 |
|
195 | 261 |
/** |
... | ... | |
201 | 267 |
m_Tree.invalidateListeners(); |
202 | 268 |
} |
203 | 269 |
|
204 |
/** |
|
205 |
* Inserta el FMap. |
|
206 |
* |
|
207 |
* @param mc |
|
208 |
* FMap. |
|
209 |
*/ |
|
210 | 270 |
public void setMapContext(MapContext mc) { |
211 |
mapContext = mc; |
|
212 |
mapContext.addAtomicEventListener(new AtomicEventListener() { |
|
271 |
this.mapContext = mc;
|
|
272 |
this.mapContext.addAtomicEventListener(new AtomicEventListener() {
|
|
213 | 273 |
|
214 |
/** |
|
215 |
* @see org.gvsig.fmap.mapcontext.events.listeners.AtomicEventListener#atomicEvent(org.gvsig.fmap.mapcontext.events.AtomicEvent) |
|
216 |
*/ |
|
274 |
@Override |
|
217 | 275 |
public void atomicEvent(final AtomicEvent e) { |
218 | 276 |
if (!SwingUtilities.isEventDispatchThread()) { |
219 | 277 |
SwingUtilities.invokeLater(new Runnable() { |
220 | 278 |
|
279 |
@Override |
|
221 | 280 |
public void run() { |
222 | 281 |
atomicEvent(e); |
223 | 282 |
} |
... | ... | |
226 | 285 |
} |
227 | 286 |
|
228 | 287 |
if ((e.getLayerCollectionEvents().length > 0) |
229 |
|| (e.getLegendEvents().length > 0)) { |
|
230 |
refresh();
|
|
288 |
|| (e.getLegendEvents().length > 0)) {
|
|
289 |
reloadLayers();
|
|
231 | 290 |
} |
232 | 291 |
|
233 | 292 |
if (e.getLayerEvents().length > 0) { |
... | ... | |
238 | 297 |
repaint(); |
239 | 298 |
} |
240 | 299 |
LayerCollectionEvent[] events = e.getLayerCollectionEvents(); |
241 |
for( int i=0; i<events.length ; i++ ) { |
|
242 |
if( events[i].getEventType() == LayerCollectionEvent.LAYER_ADDED ) { |
|
243 |
if (PluginServices.getMainFrame() != null) { |
|
244 |
PluginServices.getMainFrame().enableControls(); |
|
245 |
} |
|
246 |
} |
|
247 |
// =================================================== |
|
248 |
// Change visibility of layer before adding, according to app preferences |
|
249 |
if( events[i].getEventType() == LayerCollectionEvent.LAYER_ADDING ) { |
|
250 |
|
|
251 |
if (invisibilityIsForced()) { |
|
252 |
events[i].getAffectedLayer().setVisible(false); |
|
253 |
} |
|
254 |
} |
|
255 |
// =================================================== |
|
300 |
for (int i = 0; i < events.length; i++) { |
|
301 |
if (events[i].getEventType() == LayerCollectionEvent.LAYER_ADDED) { |
|
302 |
if (PluginServices.getMainFrame() != null) { |
|
303 |
PluginServices.getMainFrame().enableControls(); |
|
304 |
} |
|
305 |
} |
|
306 |
// =================================================== |
|
307 |
// Change visibility of layer before adding, according to app preferences |
|
308 |
if (events[i].getEventType() == LayerCollectionEvent.LAYER_ADDING) { |
|
309 |
if (haveToAddNewLayersInInvisibleMode()) { |
|
310 |
events[i].getAffectedLayer().setVisible(false); |
|
311 |
} |
|
312 |
} |
|
256 | 313 |
} |
257 | 314 |
} |
258 | 315 |
}); |
316 |
|
|
317 |
this.mapContext.getLayers().addLegendListener(new LegendListener() { |
|
259 | 318 |
|
260 |
refresh(); |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* DOCUMENT ME! |
|
265 |
*/ |
|
266 |
private void setExpandedNodes(DefaultMutableTreeNode node) { |
|
267 |
// int i = 0; |
|
268 |
// Las claves sobrantes de m_ItemsExpanded (provocadas |
|
269 |
// por layerRemove, se quitan en el evento layerRemoved |
|
270 |
// de este TOC |
|
271 |
DefaultMutableTreeNode n; |
|
272 |
@SuppressWarnings("rawtypes") |
|
273 |
Enumeration enumeration = node.children(); |
|
274 |
//Copia necesaria para que los cambios no adulteren el estado inicial del TOC |
|
275 |
Map<String, Boolean> itemsExpanded_copy = new HashMap<String, Boolean>(m_ItemsExpanded); |
|
276 |
|
|
277 |
while (enumeration.hasMoreElements()) { |
|
278 |
n = (DefaultMutableTreeNode) enumeration.nextElement(); |
|
279 |
if (n.getChildCount() > 0) { |
|
280 |
setExpandedNodes(n); |
|
319 |
@Override |
|
320 |
public void legendChanged(LegendChangedEvent e) { |
|
321 |
reloadLayers(); |
|
281 | 322 |
} |
282 |
TreePath path = new TreePath(m_TreeModel.getPathToRoot(n)); |
|
283 |
ITocItem item = (ITocItem) n.getUserObject(); |
|
284 |
Boolean b = (Boolean) itemsExpanded_copy.get(item.getLabel()); |
|
285 |
|
|
286 |
if (b == null) // No estaba en el hash todav?a: valor por defecto |
|
287 |
{ |
|
288 |
m_Tree.expandPath(path); |
|
289 |
|
|
290 |
return; |
|
291 |
} |
|
292 |
|
|
293 |
if (b.booleanValue()) { |
|
294 |
m_Tree.expandPath(path); |
|
295 |
} else { |
|
296 |
m_Tree.collapsePath(path); |
|
297 |
} |
|
298 |
} |
|
323 |
}); |
|
324 |
|
|
325 |
reloadLayers(); |
|
299 | 326 |
} |
300 | 327 |
|
301 |
/* |
|
302 |
* (non-Javadoc) |
|
303 |
* |
|
304 |
* @see com.iver.cit.opensig.gui.IToc#refresh() |
|
305 |
*/ |
|
306 | 328 |
public void refresh() { |
329 |
reloadLayers(); |
|
330 |
} |
|
331 |
|
|
332 |
public void reloadLayers() { |
|
307 | 333 |
if (!SwingUtilities.isEventDispatchThread()) { |
308 | 334 |
SwingUtilities.invokeLater(new Runnable() { |
309 | 335 |
|
336 |
@Override |
|
310 | 337 |
public void run() { |
311 |
refresh();
|
|
338 |
reloadLayers();
|
|
312 | 339 |
} |
313 | 340 |
}); |
314 | 341 |
return; |
... | ... | |
316 | 343 |
LayerCollection theLayers = mapContext.getLayers(); |
317 | 344 |
m_Root.removeAllChildren(); |
318 | 345 |
m_Root.setAllowsChildren(true); |
319 |
doRefresh(theLayers, m_Root);
|
|
346 |
reloadLayers(theLayers, m_Root);
|
|
320 | 347 |
|
321 | 348 |
m_TreeModel.reload(); |
322 | 349 |
|
323 |
setExpandedNodes(m_Root);
|
|
350 |
itemsExpandeds.update(m_Tree, m_Root);
|
|
324 | 351 |
} |
325 | 352 |
|
326 |
private void doRefresh(LayerCollection theLayers, |
|
327 |
DefaultMutableTreeNode parentNode) { |
|
353 |
private void reloadLayers(LayerCollection theLayers, |
|
354 |
DefaultMutableTreeNode parentNode) { |
|
355 |
|
|
328 | 356 |
int width = m_Tree.getWidth(); |
329 | 357 |
if (width == 0) { |
330 | 358 |
width = 300; |
331 | 359 |
} |
332 |
Dimension sizeLeaf = new Dimension(width, 15); |
|
360 |
|
|
333 | 361 |
// Get the tree font height |
334 | 362 |
Font font = m_Tree.getFont(); |
335 | 363 |
FontMetrics metrics = this.getFontMetrics(font); |
... | ... | |
343 | 371 |
TocItemBranch elTema = new TocItemBranch(lyr); |
344 | 372 |
elTema.setSize(sizeBranch); |
345 | 373 |
|
346 |
DefaultMutableTreeNode nodeLayer = |
|
347 |
new DefaultMutableTreeNode(elTema); |
|
374 |
DefaultMutableTreeNode nodeLayer = new DefaultMutableTreeNode(elTema); |
|
348 | 375 |
|
349 |
m_TreeModel.insertNodeInto(nodeLayer, parentNode, |
|
350 |
parentNode.getChildCount()); |
|
351 |
|
|
376 |
m_TreeModel.insertNodeInto( |
|
377 |
nodeLayer, |
|
378 |
parentNode, |
|
379 |
parentNode.getChildCount() |
|
380 |
); |
|
352 | 381 |
if (lyr instanceof LayerCollection) { |
353 | 382 |
LayerCollection group = (LayerCollection) lyr; |
354 |
doRefresh(group, nodeLayer); |
|
355 |
} else { |
|
356 |
if (lyr instanceof Classifiable) {// && !(lyr instanceof |
|
357 |
// FLyrAnnotation)) { |
|
383 |
reloadLayers(group, nodeLayer); |
|
358 | 384 |
|
359 |
Classifiable classifiable = (Classifiable) lyr; |
|
360 |
ILegend legendInfo = classifiable.getLegend(); |
|
385 |
} else if (haveToShowLeyendOfLayer(lyr)) { |
|
386 |
this.addLegend(nodeLayer, lyr); |
|
387 |
} |
|
388 |
} |
|
389 |
} |
|
361 | 390 |
|
362 |
try {
|
|
363 |
if (legendInfo instanceof IClassifiedLegend) {
|
|
364 |
IClassifiedLegend cl =
|
|
365 |
(IClassifiedLegend) legendInfo;
|
|
366 |
String[] descriptions = cl.getDescriptions();
|
|
367 |
ISymbol[] symbols = cl.getSymbols();
|
|
391 |
private void addLegend(final DefaultMutableTreeNode nodeLayer, FLayer lyr) {
|
|
392 |
int width = m_Tree.getWidth();
|
|
393 |
if (width == 0) {
|
|
394 |
width = 300;
|
|
395 |
}
|
|
396 |
Dimension sizeLeaf = new Dimension(width, 15);
|
|
368 | 397 |
|
369 |
for (int j = 0; j < descriptions.length; j++) { |
|
370 |
TocItemLeaf itemLeaf; |
|
371 |
itemLeaf = |
|
372 |
new TocItemLeaf(symbols[j], |
|
398 |
if (lyr instanceof Classifiable) { |
|
399 |
Classifiable classifiable = (Classifiable) lyr; |
|
400 |
ILegend legendInfo = classifiable.getLegend(); |
|
401 |
|
|
402 |
try { |
|
403 |
if (legendInfo instanceof IClassifiedLegend) { |
|
404 |
IClassifiedLegend cl |
|
405 |
= (IClassifiedLegend) legendInfo; |
|
406 |
String[] descriptions = cl.getDescriptions(); |
|
407 |
ISymbol[] symbols = cl.getSymbols(); |
|
408 |
|
|
409 |
for (int j = 0; j < descriptions.length; j++) { |
|
410 |
TocItemLeaf itemLeaf; |
|
411 |
itemLeaf |
|
412 |
= new TocItemLeaf(symbols[j], |
|
373 | 413 |
descriptions[j], classifiable.getShapeType()); |
374 |
itemLeaf.setSize(sizeLeaf);
|
|
414 |
itemLeaf.setSize(sizeLeaf); |
|
375 | 415 |
|
376 |
DefaultMutableTreeNode nodeValue =
|
|
377 |
new DefaultMutableTreeNode(itemLeaf);
|
|
378 |
m_TreeModel.insertNodeInto(nodeValue,
|
|
379 |
nodeLayer, nodeLayer.getChildCount());
|
|
416 |
DefaultMutableTreeNode nodeValue
|
|
417 |
= new DefaultMutableTreeNode(itemLeaf);
|
|
418 |
m_TreeModel.insertNodeInto(nodeValue, |
|
419 |
nodeLayer, nodeLayer.getChildCount()); |
|
380 | 420 |
|
381 |
}
|
|
382 |
}
|
|
421 |
} |
|
422 |
} |
|
383 | 423 |
|
384 |
if (legendInfo instanceof ISingleSymbolLegend
|
|
385 |
&& (legendInfo.getDefaultSymbol() != null)) {
|
|
386 |
TocItemLeaf itemLeaf;
|
|
387 |
itemLeaf =
|
|
388 |
new TocItemLeaf(legendInfo.getDefaultSymbol(),
|
|
424 |
if (legendInfo instanceof ISingleSymbolLegend |
|
425 |
&& (legendInfo.getDefaultSymbol() != null)) { |
|
426 |
TocItemLeaf itemLeaf; |
|
427 |
itemLeaf
|
|
428 |
= new TocItemLeaf(legendInfo.getDefaultSymbol(),
|
|
389 | 429 |
legendInfo.getDefaultSymbol() |
390 |
.getDescription(), classifiable.getShapeType());
|
|
391 |
itemLeaf.setSize(sizeLeaf);
|
|
430 |
.getDescription(), classifiable.getShapeType()); |
|
431 |
itemLeaf.setSize(sizeLeaf); |
|
392 | 432 |
|
393 |
DefaultMutableTreeNode nodeValue =
|
|
394 |
new DefaultMutableTreeNode(itemLeaf);
|
|
395 |
m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
|
|
396 |
nodeLayer.getChildCount());
|
|
397 |
}
|
|
433 |
DefaultMutableTreeNode nodeValue
|
|
434 |
= new DefaultMutableTreeNode(itemLeaf);
|
|
435 |
m_TreeModel.insertNodeInto(nodeValue, nodeLayer, |
|
436 |
nodeLayer.getChildCount()); |
|
437 |
} |
|
398 | 438 |
|
399 |
if (legendInfo instanceof IHasImageLegend) { |
|
400 |
TocItemLeaf itemLeaf; |
|
401 |
IHasImageLegend imageLegend = (IHasImageLegend) legendInfo; |
|
402 |
Image image = imageLegend.getImageLegend(); |
|
439 |
if (legendInfo instanceof IHasImageLegend) { |
|
440 |
final IHasImageLegend imageLegend = (IHasImageLegend) legendInfo; |
|
441 |
// Las imagenes de la leyenda que vienen de servicios remotos pueden |
|
442 |
// ser lentas de pintar y relentizan todo gvSIG, asi que mejor si |
|
443 |
// podemos hacerlo en segundo plano. |
|
444 |
Thread thread = new Thread(new Runnable() { |
|
403 | 445 |
|
404 |
int w = 0; |
|
405 |
int h = 0; |
|
446 |
@Override |
|
447 |
public void run() { |
|
448 |
final Image image = imageLegend.getImageLegend(); |
|
449 |
// Una vez obtenida la imagen, la actualizacion del ToC |
|
450 |
// la hacemos en el thread de Swing para evitar problemas. |
|
451 |
SwingUtilities.invokeLater(new Runnable() { |
|
406 | 452 |
|
407 |
if(image != null) {
|
|
408 |
w = image.getWidth(null);
|
|
409 |
h = image.getHeight(null);
|
|
410 |
}
|
|
453 |
@Override
|
|
454 |
public void run() {
|
|
455 |
int w = 0;
|
|
456 |
int h = 0;
|
|
411 | 457 |
|
412 |
if (image != null && w > 0 && h > 0) { |
|
413 |
itemLeaf = new TocItemLeaf(); |
|
414 |
itemLeaf.setImageLegend(image, "", new Dimension(w, h)); |
|
458 |
if (image != null) { |
|
459 |
w = image.getWidth(null); |
|
460 |
h = image.getHeight(null); |
|
461 |
} |
|
415 | 462 |
|
416 |
DefaultMutableTreeNode nodeValue = |
|
417 |
new DefaultMutableTreeNode(itemLeaf); |
|
418 |
m_TreeModel.insertNodeInto(nodeValue, nodeLayer, |
|
419 |
nodeLayer.getChildCount()); |
|
420 |
} |
|
463 |
if (image != null && w > 0 && h > 0) { |
|
464 |
TocItemLeaf itemLeaf = new TocItemLeaf(); |
|
465 |
itemLeaf.setImageLegend(image, "", new Dimension(w, h)); |
|
466 |
DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf); |
|
467 |
m_TreeModel.insertNodeInto( |
|
468 |
nodeValue, |
|
469 |
nodeLayer, |
|
470 |
nodeLayer.getChildCount() |
|
471 |
); |
|
472 |
} |
|
473 |
// Aqui habria que forzar a refrescar el nodo nodeLayer |
|
474 |
} |
|
475 |
}); |
|
421 | 476 |
} |
422 |
} catch (ReadException e) { |
|
423 |
logger.error(MessageFormat.format( |
|
424 |
"Can't add leyend of layer {0} to the TOC.", lyr), |
|
425 |
e); |
|
426 |
} |
|
477 |
}, "ToCImageLegendUpdate"); |
|
478 |
thread.start(); |
|
427 | 479 |
} |
428 |
} // if instanceof layers |
|
480 |
} catch (Throwable e) { |
|
481 |
logger.warn( |
|
482 |
MessageFormat.format( |
|
483 |
"Can't add leyend of layer {0} to the TOC.", |
|
484 |
lyr |
|
485 |
), |
|
486 |
e |
|
487 |
); |
|
488 |
} |
|
429 | 489 |
} |
430 |
} |
|
431 | 490 |
|
432 |
/** |
|
433 |
* @see com.iver.cit.opensig.gui.toc.ITocOrderListener#orderChanged(int, |
|
434 |
* int) |
|
435 |
*/ |
|
436 |
public void orderChanged(int oldPos, int newPos, FLayers lpd) { |
|
437 |
try { |
|
438 |
lpd.moveTo(oldPos, newPos); |
|
439 |
} catch (CancelationException e) { |
|
440 |
logger.error("Can't change order of layers in TOC", e); |
|
441 |
} |
|
442 |
mapContext.invalidate(); |
|
443 | 491 |
} |
492 |
// |
|
493 |
//// @Override |
|
494 |
// public void orderChanged(int oldPos, int newPos, FLayers lpd) { |
|
495 |
// try { |
|
496 |
// lpd.moveTo(oldPos, newPos); |
|
497 |
// } catch (CancelationException e) { |
|
498 |
// logger.warn("Can't change order of layers in TOC", e); |
|
499 |
// } |
|
500 |
// mapContext.invalidate(); |
|
501 |
// } |
|
502 |
// |
|
503 |
//// @Override |
|
504 |
// public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) { |
|
505 |
// lpo.move(ls, lpd); |
|
506 |
// mapContext.invalidate(); |
|
507 |
// } |
|
444 | 508 |
|
445 |
public void parentChanged(FLayers lpo, FLayers lpd, FLayer ls) { |
|
446 |
lpo.move(ls, lpd); |
|
447 |
mapContext.invalidate(); |
|
448 |
} |
|
449 |
|
|
450 |
/* |
|
451 |
* (non-Javadoc) |
|
452 |
* |
|
453 |
* @see java.awt.event.ComponentListener#componentHidden(java.awt.event. |
|
454 |
* ComponentEvent) |
|
455 |
*/ |
|
456 |
public void componentHidden(ComponentEvent e) { |
|
457 |
} |
|
458 |
|
|
459 |
/* |
|
460 |
* (non-Javadoc) |
|
461 |
* |
|
462 |
* @see |
|
463 |
* java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent |
|
464 |
* ) |
|
465 |
*/ |
|
466 |
public void componentMoved(ComponentEvent e) { |
|
467 |
} |
|
468 |
|
|
469 |
/* |
|
470 |
* (non-Javadoc) |
|
471 |
* |
|
472 |
* @see java.awt.event.ComponentListener#componentResized(java.awt.event. |
|
473 |
* ComponentEvent) |
|
474 |
*/ |
|
475 |
public void componentResized(ComponentEvent e) { |
|
509 |
private void tocResized() { |
|
476 | 510 |
DefaultMutableTreeNode n; |
477 |
@SuppressWarnings("rawtypes") |
|
478 |
Enumeration enumeration = m_Root.children(); |
|
511 |
Enumeration<DefaultMutableTreeNode> enumeration = m_Root.children(); |
|
479 | 512 |
|
480 | 513 |
while (enumeration.hasMoreElements()) { |
481 | 514 |
n = (DefaultMutableTreeNode) enumeration.nextElement(); |
... | ... | |
488 | 521 |
|
489 | 522 |
} |
490 | 523 |
} |
524 |
// |
|
525 |
// // @Override |
|
526 |
// public void legendChanged(final LegendChangedEvent e) { |
|
527 |
// if (!SwingUtilities.isEventDispatchThread()) { |
|
528 |
// SwingUtilities.invokeLater(new Runnable() { |
|
529 |
// |
|
530 |
// @Override |
|
531 |
// public void run() { |
|
532 |
// legendChanged(e); |
|
533 |
// } |
|
534 |
// }); |
|
535 |
// return; |
|
536 |
// } |
|
537 |
// refresh(); |
|
538 |
// } |
|
539 |
// |
|
540 |
//// @Override |
|
541 |
// public void layerAdded(final LayerCollectionEvent e) { |
|
542 |
// if (!SwingUtilities.isEventDispatchThread()) { |
|
543 |
// SwingUtilities.invokeLater(new Runnable() { |
|
544 |
// |
|
545 |
// @Override |
|
546 |
// public void run() { |
|
547 |
// layerAdded(e); |
|
548 |
// } |
|
549 |
// }); |
|
550 |
// return; |
|
551 |
// } |
|
552 |
// FLayer layer = e.getAffectedLayer(); |
|
553 |
// if (layer instanceof FLyrVect) { |
|
554 |
// FLyrVect layerVect = (FLyrVect) layer; |
|
555 |
// ILegend legend = layerVect.getLegend(); |
|
556 |
// switch (e.getEventType()) { |
|
557 |
// case LayerCollectionEvent.LAYER_ADDED: |
|
558 |
// legend.addLegendListener(new LegendContentsChangedListener() { |
|
559 |
// @Override |
|
560 |
// public boolean symbolChanged(SymbolLegendEvent e) { |
|
561 |
// refresh(); |
|
562 |
// return true; |
|
563 |
// } |
|
564 |
// |
|
565 |
// @Override |
|
566 |
// public void legendCleared(LegendClearEvent event) { |
|
567 |
// refresh(); |
|
568 |
// } |
|
569 |
// }); |
|
570 |
// break; |
|
571 |
// case LayerCollectionEvent.LAYER_REMOVED: |
|
572 |
// legend.removeLegendListener(new LegendContentsChangedListener() { |
|
573 |
// @Override |
|
574 |
// public boolean symbolChanged(SymbolLegendEvent e) { |
|
575 |
// refresh(); |
|
576 |
// return true; |
|
577 |
// } |
|
578 |
// |
|
579 |
// @Override |
|
580 |
// public void legendCleared(LegendClearEvent event) { |
|
581 |
// refresh(); |
|
582 |
// } |
|
583 |
// }); |
|
584 |
// break; |
|
585 |
// } |
|
586 |
// } |
|
587 |
// refresh(); |
|
588 |
// } |
|
491 | 589 |
|
492 |
/* |
|
493 |
* (non-Javadoc) |
|
494 |
* |
|
495 |
* @see |
|
496 |
* java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent |
|
497 |
* ) |
|
498 |
*/ |
|
499 |
public void componentShown(ComponentEvent e) { |
|
500 |
} |
|
590 |
// @Override |
|
591 |
// public boolean symbolChanged(SymbolLegendEvent e) { |
|
592 |
// refresh(); |
|
593 |
// return true; |
|
594 |
// } |
|
595 |
// |
|
596 |
// @Override |
|
597 |
// public void legendCleared(LegendClearEvent event) { |
|
598 |
// refresh(); |
|
599 |
// } |
|
600 |
// @Override |
|
601 |
// public void layerMoved(final LayerPositionEvent e) { |
|
602 |
// if (!SwingUtilities.isEventDispatchThread()) { |
|
603 |
// SwingUtilities.invokeLater(new Runnable() { |
|
604 |
// |
|
605 |
// @Override |
|
606 |
// public void run() { |
|
607 |
// layerMoved(e); |
|
608 |
// } |
|
609 |
// }); |
|
610 |
// return; |
|
611 |
// } |
|
612 |
// refresh(); |
|
613 |
// } |
|
614 |
// |
|
615 |
//// @Override |
|
616 |
// public void layerRemoved(final LayerCollectionEvent e) { |
|
617 |
// if (!SwingUtilities.isEventDispatchThread()) { |
|
618 |
// SwingUtilities.invokeLater(new Runnable() { |
|
619 |
// |
|
620 |
// @Override |
|
621 |
// public void run() { |
|
622 |
// layerRemoved(e); |
|
623 |
// } |
|
624 |
// }); |
|
625 |
// return; |
|
626 |
// } |
|
627 |
// this.itemsExpandeds.removeLayer(e.getAffectedLayer()); |
|
628 |
// refresh(); |
|
629 |
// } |
|
630 |
// |
|
631 |
//// @Override |
|
632 |
// public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
|
633 |
// } |
|
634 |
// |
|
635 |
//// @Override |
|
636 |
// public void layerMoving(LayerPositionEvent e) throws CancelationException { |
|
637 |
// } |
|
638 |
// |
|
639 |
//// @Override |
|
640 |
// public void layerRemoving(LayerCollectionEvent e) |
|
641 |
// throws CancelationException { |
|
642 |
// } |
|
643 |
// |
|
644 |
// public void activationChanged(LayerCollectionEvent e) |
|
645 |
// throws CancelationException { |
|
646 |
// repaint(); |
|
647 |
// } |
|
648 |
// |
|
649 |
//// @Override |
|
650 |
// public void visibilityChanged(final LayerCollectionEvent e) |
|
651 |
// throws CancelationException { |
|
652 |
// if (!SwingUtilities.isEventDispatchThread()) { |
|
653 |
// SwingUtilities.invokeLater(new Runnable() { |
|
654 |
// |
|
655 |
// @Override |
|
656 |
// public void run() { |
|
657 |
// visibilityChanged(e); |
|
658 |
// } |
|
659 |
// }); |
|
660 |
// return; |
|
661 |
// } |
|
662 |
// repaint(); |
|
663 |
// } |
|
664 |
// |
|
665 |
//// @Override |
|
666 |
// public void treeCollapsed(TreeExpansionEvent event) { |
|
667 |
// TreePath path = event.getPath(); |
|
668 |
// DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); |
|
669 |
// if (node.getUserObject() instanceof ITocItem) { |
|
670 |
// this.itemsExpandeds.setMark((ITocItem) node.getUserObject(), false); |
|
671 |
// } |
|
672 |
// } |
|
673 |
// |
|
674 |
//// @Override |
|
675 |
// public void treeExpanded(TreeExpansionEvent event) { |
|
676 |
// TreePath path = event.getPath(); |
|
677 |
// DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); |
|
678 |
// if (node.getUserObject() instanceof ITocItem) { |
|
679 |
// this.itemsExpandeds.setMark((ITocItem) node.getUserObject(), true); |
|
680 |
// } |
|
681 |
// } |
|
501 | 682 |
|
502 |
/* |
|
503 |
* (non-Javadoc) |
|
504 |
* |
|
505 |
* @see |
|
506 |
* com.iver.cit.gvsig.fmap.layers.LayerListener#legendChanged(com.iver.cit |
|
507 |
* .gvsig.fmap.rendering.LegendChangedEvent) |
|
508 |
*/ |
|
509 |
public void legendChanged(final LegendChangedEvent e) { |
|
510 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
511 |
SwingUtilities.invokeLater(new Runnable() { |
|
512 |
|
|
513 |
public void run() { |
|
514 |
legendChanged(e); |
|
515 |
} |
|
516 |
}); |
|
517 |
return; |
|
518 |
} |
|
519 |
refresh(); |
|
520 |
} |
|
521 |
|
|
522 |
/* |
|
523 |
* (non-Javadoc) |
|
524 |
* |
|
525 |
* @see |
|
526 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com |
|
527 |
* .iver.cit.gvsig.fmap.layers.LayerCollectionEvent) |
|
528 |
*/ |
|
529 |
public void layerAdded(final LayerCollectionEvent e) { |
|
530 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
531 |
SwingUtilities.invokeLater(new Runnable() { |
|
532 |
|
|
533 |
public void run() { |
|
534 |
layerAdded(e); |
|
535 |
} |
|
536 |
}); |
|
537 |
return; |
|
538 |
} |
|
539 |
FLayer layer = e.getAffectedLayer(); |
|
540 |
if( layer instanceof FLyrVect ) { |
|
541 |
FLyrVect layerVect = (FLyrVect)layer; |
|
542 |
ILegend legend = layerVect.getLegend(); |
|
543 |
switch( e.getEventType() ) { |
|
544 |
case LayerCollectionEvent.LAYER_ADDED : |
|
545 |
legend.addLegendListener(this); |
|
546 |
break; |
|
547 |
case LayerCollectionEvent.LAYER_REMOVED : |
|
548 |
legend.removeLegendListener(this); |
|
549 |
break; |
|
550 |
} |
|
551 |
} |
|
552 |
refresh(); |
|
553 |
} |
|
554 |
|
|
555 |
public boolean symbolChanged(SymbolLegendEvent e) { |
|
556 |
refresh(); |
|
557 |
return true; |
|
558 |
} |
|
559 |
|
|
560 |
public void legendCleared(LegendClearEvent event) { |
|
561 |
refresh(); |
|
562 |
} |
|
563 |
|
|
564 |
/* |
|
565 |
* (non-Javadoc) |
|
566 |
* |
|
567 |
* @see |
|
568 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com |
|
569 |
* .iver.cit.gvsig.fmap.layers.LayerPositionEvent) |
|
570 |
*/ |
|
571 |
public void layerMoved(final LayerPositionEvent e) { |
|
572 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
573 |
SwingUtilities.invokeLater(new Runnable() { |
|
574 |
|
|
575 |
public void run() { |
|
576 |
layerMoved(e); |
|
577 |
} |
|
578 |
}); |
|
579 |
return; |
|
580 |
} |
|
581 |
refresh(); |
|
582 |
} |
|
583 |
|
|
584 |
/* |
|
585 |
* (non-Javadoc) |
|
586 |
* |
|
587 |
* @see |
|
588 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com |
|
589 |
* .iver.cit.gvsig.fmap.layers.LayerCollectionEvent) |
|
590 |
*/ |
|
591 |
public void layerRemoved(final LayerCollectionEvent e) { |
|
592 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
593 |
SwingUtilities.invokeLater(new Runnable() { |
|
594 |
|
|
595 |
public void run() { |
|
596 |
layerRemoved(e); |
|
597 |
} |
|
598 |
}); |
|
599 |
return; |
|
600 |
} |
|
601 |
m_ItemsExpanded.remove(e.getAffectedLayer().getName()); |
|
602 |
refresh(); |
|
603 |
} |
|
604 |
|
|
605 |
/* |
|
606 |
* (non-Javadoc) |
|
607 |
* |
|
608 |
* @see |
|
609 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com |
|
610 |
* .iver.cit.gvsig.fmap.layers.LayerCollectionEvent) |
|
611 |
*/ |
|
612 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
|
613 |
} |
|
614 |
|
|
615 |
/* |
|
616 |
* (non-Javadoc) |
|
617 |
* |
|
618 |
* @see |
|
619 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com |
|
620 |
* .iver.cit.gvsig.fmap.layers.LayerPositionEvent) |
|
621 |
*/ |
|
622 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
|
623 |
} |
|
624 |
|
|
625 |
/* |
|
626 |
* (non-Javadoc) |
|
627 |
* |
|
628 |
* @see |
|
629 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving( |
|
630 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent) |
|
631 |
*/ |
|
632 |
public void layerRemoving(LayerCollectionEvent e) |
|
633 |
throws CancelationException { |
|
634 |
} |
|
635 |
|
|
636 |
/* |
|
637 |
* (non-Javadoc) |
|
638 |
* |
|
639 |
* @see |
|
640 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged |
|
641 |
* (com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent) |
|
642 |
*/ |
|
643 |
public void activationChanged(LayerCollectionEvent e) |
|
644 |
throws CancelationException { |
|
645 |
repaint(); |
|
646 |
} |
|
647 |
|
|
648 |
/* |
|
649 |
* (non-Javadoc) |
|
650 |
* |
|
651 |
* @see |
|
652 |
* com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged |
|
653 |
* (com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent) |
|
654 |
*/ |
|
655 |
public void visibilityChanged(final LayerCollectionEvent e) |
|
656 |
throws CancelationException { |
|
657 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
658 |
SwingUtilities.invokeLater(new Runnable() { |
|
659 |
|
|
660 |
public void run() { |
|
661 |
visibilityChanged(e); |
|
662 |
} |
|
663 |
}); |
|
664 |
return; |
|
665 |
} |
|
666 |
repaint(); |
|
667 |
} |
|
668 |
|
|
669 |
/* |
|
670 |
* (non-Javadoc) |
|
671 |
* |
|
672 |
* @see |
|
673 |
* javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event |
|
674 |
* .TreeExpansionEvent) |
|
675 |
*/ |
|
676 |
public void treeCollapsed(TreeExpansionEvent event) { |
|
677 |
TreePath path = event.getPath(); |
|
678 |
DefaultMutableTreeNode n = |
|
679 |
(DefaultMutableTreeNode) path.getLastPathComponent(); |
|
680 |
|
|
681 |
if (n.getUserObject() instanceof ITocItem) { |
|
682 |
ITocItem item = (ITocItem) n.getUserObject(); |
|
683 |
Boolean b = Boolean.FALSE; |
|
684 |
|
|
685 |
m_ItemsExpanded.put(item.getLabel(), b); |
|
686 |
} |
|
687 |
} |
|
688 |
|
|
689 |
/* |
|
690 |
* (non-Javadoc) |
|
691 |
* |
|
692 |
* @see |
|
693 |
* javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event |
|
694 |
* .TreeExpansionEvent) |
|
695 |
*/ |
|
696 |
public void treeExpanded(TreeExpansionEvent event) { |
|
697 |
TreePath path = event.getPath(); |
|
698 |
DefaultMutableTreeNode n = |
|
699 |
(DefaultMutableTreeNode) path.getLastPathComponent(); |
|
700 |
|
|
701 |
if (n.getUserObject() instanceof ITocItem) { |
|
702 |
ITocItem item = (ITocItem) n.getUserObject(); |
|
703 |
Boolean b = Boolean.TRUE; |
|
704 |
|
|
705 |
m_ItemsExpanded.put(item.getLabel(), b); |
|
706 |
} |
|
707 |
} |
|
708 |
|
|
709 | 683 |
/** |
710 | 684 |
* Obtiene el JScrollPane que contiene el TOC |
711 | 685 |
* |
... | ... | |
715 | 689 |
return this.m_Scroller; |
716 | 690 |
} |
717 | 691 |
|
718 |
/** |
|
719 |
* DOCUMENT ME! |
|
720 |
* |
|
721 |
* @return DOCUMENT ME! |
|
722 |
*/ |
|
723 | 692 |
public DnDJTree getTree() { |
724 | 693 |
return m_Tree; |
725 | 694 |
} |
... | ... | |
728 | 697 |
* Clase Listener que reacciona al pulsar sobre el checkbox de un nodo y |
729 | 698 |
* crea un popupmenu al pulsar el bot?n derecho. |
730 | 699 |
*/ |
731 |
class NodeSelectionListener extends MouseAdapter implements ActionListener { |
|
700 |
class NodeSelectionListener extends MouseAdapter { //implements ActionListener {
|
|
732 | 701 |
|
733 | 702 |
JTree tree; |
734 |
|
|
735 | 703 |
JDialog dlg; |
736 |
|
|
737 | 704 |
JColorChooser colorChooser; |
738 |
|
|
739 | 705 |
FPopupMenu popmenu = null; |
740 |
|
|
741 | 706 |
DefaultMutableTreeNode node; |
742 | 707 |
|
743 | 708 |
/** |
744 | 709 |
* Crea un nuevo NodeSelectionListener. |
745 | 710 |
* |
746 |
* @param tree |
|
747 |
* DOCUMENT ME! |
|
711 |
* @param tree ! |
|
748 | 712 |
*/ |
749 | 713 |
NodeSelectionListener(JTree tree) { |
750 | 714 |
this.tree = tree; |
751 | 715 |
} |
752 | 716 |
|
753 |
/** |
|
754 |
* DOCUMENT ME! |
|
755 |
* |
|
756 |
* @param e |
|
757 |
* DOCUMENT ME! |
|
758 |
*/ |
|
717 |
@Override |
|
759 | 718 |
public void mouseClicked(MouseEvent e) { |
760 | 719 |
int x = e.getX(); |
761 | 720 |
int y = e.getY(); |
... | ... | |
772 | 731 |
} |
773 | 732 |
|
774 | 733 |
if (node != null |
775 |
&& node.getUserObject() instanceof TocItemBranch) { |
|
734 |
&& node.getUserObject() instanceof TocItemBranch) {
|
|
776 | 735 |
// double click with left button ON A BRANCH/NODE (layer) |
777 | 736 |
if (e.getClickCount() >= 2 |
778 |
&& e.getButton() == MouseEvent.BUTTON1) { |
|
737 |
&& e.getButton() == MouseEvent.BUTTON1) {
|
|
779 | 738 |
e.consume(); |
780 | 739 |
PluginServices.getMDIManager().setWaitCursor(); |
781 | 740 |
try { |
782 |
TocItemBranch leaf = |
|
783 |
(TocItemBranch) node.getUserObject(); |
|
784 |
|
|
785 |
IContextMenuAction action = |
|
786 |
leaf.getDoubleClickAction(); |
|
741 |
TocItemBranch leaf = (TocItemBranch) node.getUserObject(); |
|
742 |
IContextMenuAction action = leaf.getDoubleClickAction(); |
|
787 | 743 |
if (action != null) { |
788 | 744 |
/* |
789 | 745 |
* if there is an action associated with the |
... | ... | |
791 | 747 |
* it and FOR ALL OTHER COMPATIBLES THAT HAVE |
792 | 748 |
* BEEN ACTIVATED. |
793 | 749 |
*/ |
794 |
ArrayList<FLayer> targetLayers = |
|
795 |
new ArrayList<FLayer>(); |
|
750 |
ArrayList<FLayer> targetLayers = new ArrayList<>(); |
|
796 | 751 |
|
797 |
TocItemBranch owner = |
|
798 |
(TocItemBranch) node.getUserObject(); |
|
752 |
TocItemBranch owner = (TocItemBranch) node.getUserObject(); |
|
799 | 753 |
|
800 | 754 |
FLayer masterLayer = owner.getLayer(); |
801 | 755 |
targetLayers.add(masterLayer); |
802 |
FLayer[] actives = |
|
803 |
mapContext.getLayers().getActives(); |
|
756 |
FLayer[] actives = mapContext.getLayers().getActives(); |
|
804 | 757 |
for (int i = 0; i < actives.length; i++) { |
805 | 758 |
if (actives[i].getClass().equals( |
806 |
masterLayer.getClass())) { |
|
759 |
masterLayer.getClass())) {
|
|
807 | 760 |
if (actives[i] instanceof FLyrVect) { |
808 |
FLyrVect vectorLayer = |
|
809 |
(FLyrVect) actives[i]; |
|
810 |
FLyrVect vectorMaster = |
|
811 |
(FLyrVect) masterLayer; |
|
761 |
FLyrVect vectorLayer = (FLyrVect) actives[i]; |
|
762 |
FLyrVect vectorMaster = (FLyrVect) masterLayer; |
|
812 | 763 |
if (vectorLayer.getShapeType() == vectorMaster |
813 |
.getShapeType()) { |
|
764 |
.getShapeType()) {
|
|
814 | 765 |
targetLayers.add(vectorLayer); |
815 | 766 |
} else { |
816 | 767 |
vectorLayer.setActive(false); |
... | ... | |
824 | 775 |
} |
825 | 776 |
|
826 | 777 |
// Do nothing if there is a non-available layer |
827 |
for (int k=0; k<targetLayers.size(); k++) {
|
|
778 |
for (int k = 0; k < targetLayers.size(); k++) {
|
|
828 | 779 |
if (!targetLayers.get(k).isAvailable()) { |
829 | 780 |
return; |
830 | 781 |
} |
831 | 782 |
} |
832 | 783 |
|
833 |
action.execute(leaf, |
|
834 |
targetLayers.toArray(new FLayer[0])); |
|
784 |
action.execute(leaf, targetLayers.toArray(new FLayer[0])); |
|
835 | 785 |
} |
836 | 786 |
} catch (Exception ex) { |
837 | 787 |
NotificationManager.addError(ex); |
... | ... | |
846 | 796 |
lyr.getMapContext().beginAtomicEvent(); |
847 | 797 |
|
848 | 798 |
if (((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) |
849 |
&& ( |
|
850 |
e.getButton() == MouseEvent.BUTTON1 || |
|
851 |
e.getButton() == MouseEvent.BUTTON3 |
|
852 |
) |
|
853 |
) { |
|
799 |
&& (e.getButton() == MouseEvent.BUTTON1 |
|
800 |
|| e.getButton() == MouseEvent.BUTTON3)) { |
|
854 | 801 |
FLayer[] activeLayers = layers.getActives(); |
855 | 802 |
if (activeLayers.length > 0) { |
856 | 803 |
selectInterval(layers, lyr); |
... | ... | |
860 | 807 |
|
861 | 808 |
} else { |
862 | 809 |
if (!((e.getModifiers() & InputEvent.CTRL_MASK) != 0) |
863 |
&& ( |
|
864 |
e.getButton() == MouseEvent.BUTTON1 || |
|
865 |
e.getButton() == MouseEvent.BUTTON3 |
|
866 |
) |
|
867 |
) { |
|
810 |
&& (e.getButton() == MouseEvent.BUTTON1 |
|
811 |
|| e.getButton() == MouseEvent.BUTTON3)) { |
|
868 | 812 |
layers.setAllActives(false); |
869 | 813 |
} |
870 | 814 |
if (e.getButton() == MouseEvent.BUTTON1 |
871 |
||e.getButton() == MouseEvent.BUTTON3) {
|
|
815 |
|| e.getButton() == MouseEvent.BUTTON3) {
|
|
872 | 816 |
// lyr.setActive(true); |
873 | 817 |
updateActive(lyr, !lyr.isActive()); |
874 | 818 |
} |
875 | 819 |
} |
876 |
// Si pertenece a un grupo, lo ponemos activo tambi?n. |
|
877 |
// FLayer parentLayer = lyr.getParentLayer(); |
|
878 | 820 |
|
879 |
/* |
|
880 |
* if (parentLayer != null) { parentLayer.setActive(true); } |
|
881 |
*/ |
|
882 |
Point layerNodeLocation = |
|
883 |
tree.getUI().getPathBounds(tree, path).getLocation(); |
|
821 |
Point layerNodeLocation |
|
822 |
= tree.getUI().getPathBounds(tree, path).getLocation(); |
|
884 | 823 |
|
885 | 824 |
// Rect?ngulo que representa el checkbox |
886 |
Rectangle checkBoxBounds =
|
|
887 |
m_TocRenderer.getCheckBoxBounds(); |
|
825 |
Rectangle checkBoxBounds |
|
826 |
= m_TocRenderer.getCheckBoxBounds();
|
|
888 | 827 |
checkBoxBounds.translate((int) layerNodeLocation.getX(), |
889 |
(int) layerNodeLocation.getY()); |
|
828 |
(int) layerNodeLocation.getY());
|
|
890 | 829 |
|
891 | 830 |
if (checkBoxBounds.contains(e.getPoint())) { |
892 | 831 |
updateVisible(lyr); |
832 |
// si node no tiene leyenda llamar a addLegend |
|
893 | 833 |
} |
894 | 834 |
|
895 | 835 |
// } |
896 | 836 |
if (e.getButton() == MouseEvent.BUTTON3) { |
897 |
// Boton derecho sobre un nodo del arbol |
|
898 |
// if ((e.getModifiers() & InputEvent.META_MASK) != 0) { |
|
899 |
//***** Change selection |
|
900 |
// if(!lyr.isActive()){ |
|
901 |
// layers.setAllActives(false); |
|
902 |
// updateActive(lyr, true); |
|
903 |
// } |
|
904 |
//***** |
|
905 | 837 |
popmenu = new FPopupMenu(mapContext, node); |
906 | 838 |
tree.add(popmenu); |
907 |
|
|
908 | 839 |
popmenu.show(e.getComponent(), e.getX(), e.getY()); |
909 |
|
|
910 |
// } |
|
911 | 840 |
} |
912 |
|
|
913 | 841 |
lyr.getMapContext().endAtomicEvent(); |
914 | 842 |
} |
915 | 843 |
|
916 | 844 |
if (node != null && node.getUserObject() instanceof TocItemLeaf) { |
917 |
TocItemBranch owner =
|
|
918 |
(TocItemBranch) ((DefaultMutableTreeNode) node |
|
845 |
TocItemBranch owner |
|
846 |
= (TocItemBranch) ((DefaultMutableTreeNode) node
|
|
919 | 847 |
.getParent()).getUserObject(); |
920 | 848 |
|
921 | 849 |
FLayer masterLayer = owner.getLayer(); |
922 | 850 |
|
923 | 851 |
if (((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) |
924 |
&& ( |
|
925 |
e.getButton() == MouseEvent.BUTTON1 || |
|
926 |
e.getButton() == MouseEvent.BUTTON3 |
|
927 |
) |
|
928 |
) { |
|
852 |
&& (e.getButton() == MouseEvent.BUTTON1 |
|
853 |
|| e.getButton() == MouseEvent.BUTTON3)) { |
|
929 | 854 |
FLayer[] activeLayers = layers.getActives(); |
930 | 855 |
if (activeLayers.length > 0) { |
931 | 856 |
selectInterval(layers, masterLayer); |
... | ... | |
935 | 860 |
|
936 | 861 |
} else { |
937 | 862 |
if (!((e.getModifiers() & InputEvent.CTRL_MASK) != 0) |
938 |
&& ( |
|
939 |
e.getButton() == MouseEvent.BUTTON1 || |
|
940 |
e.getButton() == MouseEvent.BUTTON3 |
|
941 |
) |
|
942 |
) { |
|
863 |
&& (e.getButton() == MouseEvent.BUTTON1 |
|
864 |
|| e.getButton() == MouseEvent.BUTTON3)) { |
|
943 | 865 |
layers.setAllActives(false); |
944 | 866 |
} |
945 | 867 |
if (e.getButton() == MouseEvent.BUTTON1 |
946 |
||e.getButton() == MouseEvent.BUTTON3) { |
|
947 |
// lyr.setActive(true); |
|
868 |
|| e.getButton() == MouseEvent.BUTTON3) { |
|
948 | 869 |
updateActive(masterLayer, !masterLayer.isActive()); |
949 | 870 |
} |
950 | 871 |
} |
951 | 872 |
|
952 | 873 |
// double click with left button ON A LEAF (ISymbol) |
953 | 874 |
if (e.getClickCount() >= 2 |
954 |
&& e.getButton() == MouseEvent.BUTTON1) { |
|
875 |
&& e.getButton() == MouseEvent.BUTTON1) {
|
|
955 | 876 |
e.consume(); |
956 | 877 |
|
957 | 878 |
PluginServices.getMDIManager().setWaitCursor(); |
958 | 879 |
try { |
959 |
TocItemLeaf leaf = |
|
960 |
(TocItemLeaf) node.getUserObject(); |
|
961 |
IContextMenuAction action = |
|
962 |
leaf.getDoubleClickAction(); |
|
880 |
TocItemLeaf leaf = (TocItemLeaf) node.getUserObject(); |
|
881 |
IContextMenuAction action = leaf.getDoubleClickAction(); |
|
963 | 882 |
if (action != null) { |
964 | 883 |
/* |
965 | 884 |
* if there is an action associated with the |
... | ... | |
971 | 890 |
* #3035: Symbology is applied to active layers too |
972 | 891 |
* Now it will be done only on the double-clicked one |
973 | 892 |
*/ |
974 |
ArrayList<FLayer> targetLayers = |
|
975 |
new ArrayList<FLayer>(); |
|
976 |
|
|
977 |
|
|
978 |
targetLayers.add(masterLayer); |
|
979 |
// FLayer[] actives = |
|
980 |
// mapContext.getLayers().getActives(); |
|
981 |
// for (int i = 0; i < actives.length; i++) { |
|
982 |
// if (actives[i].getClass().equals( |
|
983 |
// masterLayer.getClass())) { |
|
984 |
// if (actives[i] instanceof FLyrVect) { |
|
985 |
// FLyrVect vectorLayer = |
|
986 |
// (FLyrVect) actives[i]; |
|
987 |
// FLyrVect vectorMaster = |
|
988 |
// (FLyrVect) masterLayer; |
|
989 |
// int masterLayerShapetypeOF_THE_LEGEND = |
|
990 |
// ((IVectorLegend) vectorMaster |
|
991 |
// .getLegend()) |
|
992 |
// .getShapeType(); |
|
993 |
// int anotherVectorLayerShapetypeOF_THE_LEGEND = |
|
994 |
// ((IVectorLegend) vectorLayer |
|
995 |
// .getLegend()) |
|
996 |
// .getShapeType(); |
|
997 |
// if (masterLayerShapetypeOF_THE_LEGEND == anotherVectorLayerShapetypeOF_THE_LEGEND) { |
|
998 |
// targetLayers.add(vectorLayer); |
|
999 |
// } else { |
|
1000 |
// vectorLayer.setActive(false); |
|
1001 |
// } |
|
1002 |
// } |
|
1003 |
// // TODO for the rest of layer types |
|
1004 |
// // (i.e. FLyrRaster) |
|
1005 |
// } else { |
|
1006 |
// actives[i].setActive(false); |
|
1007 |
// } |
|
1008 |
// } |
|
1009 |
action.execute(leaf, |
|
1010 |
targetLayers.toArray(new FLayer[0])); |
|
893 |
action.execute(leaf, new FLayer[]{masterLayer}); |
|
1011 | 894 |
} |
1012 | 895 |
} catch (Exception ex) { |
1013 |
NotificationManager.addError(ex);
|
|
896 |
logger.warn("Problems executing action in the ToC.", ex);
|
|
1014 | 897 |
} finally { |
1015 | 898 |
PluginServices.getMDIManager().restoreCursor(); |
1016 | 899 |
} |
... | ... | |
1022 | 905 |
// FSymbol theSym = auxLeaf.getSymbol(); |
1023 | 906 |
if ((e.getModifiers() & InputEvent.META_MASK) != 0) { |
1024 | 907 |
//***** Change selection |
1025 |
if (!masterLayer.isActive()){ |
|
908 |
if (!masterLayer.isActive()) {
|
|
1026 | 909 |
layers.setAllActives(false); |
1027 | 910 |
updateActive(masterLayer, true); |
1028 | 911 |
} |
... | ... | |
1056 | 939 |
|
1057 | 940 |
private void selectInterval(LayerCollection layers, FLayer lyr) { |
1058 | 941 |
FLayer[] activeLayers = layers.getActives(); |
1059 |
// if (activeLayers[0].getParentLayer() instanceof FLayers && |
|
1060 |
// activeLayers[0].getParentLayer().getParentLayer()!=null) { |
|
1061 |
// selectInterval((LayerCollection)activeLayers[0].getParentLayer(),lyr); |
|
1062 |
// } |
|
1063 | 942 |
for (int j = 0; j < layers.getLayersCount(); j++) { |
1064 | 943 |
FLayer layerAux = layers.getLayer(j); |
1065 | 944 |
// Si se cumple esta condici?n es porque la primera capa que nos |
... | ... | |
1078 | 957 |
} |
1079 | 958 |
} |
1080 | 959 |
break; |
1081 |
} else |
|
1082 |
// Si se cumple esta condici?n es porque la primera capa que |
|
1083 |
// nos |
|
1084 |
// encontramos en el TOC es la que acabamos de seleccionar |
|
1085 |
if (lyr.equals(layerAux)) { |
|
1086 |
boolean isSelected = false; |
|
1087 |
for (int i = layers.getLayersCount() - 1; i >= 0; i--) { |
|
1088 |
FLayer layer = layers.getLayer(i); |
|
1089 |
if (!isSelected) { |
|
1090 |
isSelected = layer.isActive(); |
|
1091 |
} else { |
|
1092 |
updateActive(layer, true); |
|
1093 |
if (lyr.equals(layer)) { |
|
1094 |
isSelected = false; |
|
1095 |
} |
|
960 |
} else // Si se cumple esta condici?n es porque la primera capa que |
|
961 |
// nos encontramos en el TOC es la que acabamos de seleccionar |
|
962 |
if (lyr.equals(layerAux)) { |
|
963 |
boolean isSelected = false; |
|
964 |
for (int i = layers.getLayersCount() - 1; i >= 0; i--) { |
|
965 |
FLayer layer = layers.getLayer(i); |
|
966 |
if (!isSelected) { |
|
967 |
isSelected = layer.isActive(); |
|
968 |
} else { |
|
969 |
updateActive(layer, true); |
|
970 |
if (lyr.equals(layer)) { |
|
971 |
isSelected = false; |
|
1096 | 972 |
} |
1097 | 973 |
} |
1098 |
break; |
|
1099 | 974 |
} |
975 |
break; |
|
976 |
} |
|
1100 | 977 |
} |
1101 | 978 |
|
1102 | 979 |
} |
1103 | 980 |
|
1104 |
/** |
Also available in: Unified diff