svn-gvsig-desktop / 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 / actions / ChangeSymbolTocMenuEntry.java @ 40596
History | View | Annotate | Download (5.69 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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.
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.toc.actions; |
25 |
|
26 |
import org.gvsig.andami.PluginServices; |
27 |
import org.gvsig.andami.messages.NotificationManager; |
28 |
import org.gvsig.app.extension.ProjectExtension; |
29 |
import org.gvsig.app.gui.styling.SymbolSelector; |
30 |
import org.gvsig.app.project.Project; |
31 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
32 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
33 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
34 |
import org.gvsig.app.project.documents.view.toc.TocItemLeaf; |
35 |
import org.gvsig.fmap.dal.exception.ReadException; |
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
39 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
40 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
41 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
42 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
43 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol; |
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
/**
|
48 |
* Directly opens the Symbol Selector if it is invoked from the TOC avoiding
|
49 |
* by-passing the Layer Properties window
|
50 |
*/
|
51 |
public class ChangeSymbolTocMenuEntry extends AbstractTocContextMenuAction { |
52 |
private static final Logger logger = LoggerFactory |
53 |
.getLogger(ChangeSymbolTocMenuEntry.class); |
54 |
|
55 |
public String getGroup() { |
56 |
return "group1"; //FIXME |
57 |
} |
58 |
|
59 |
public int getGroupOrder() { |
60 |
return 10; |
61 |
} |
62 |
|
63 |
public int getOrder() { |
64 |
return 0; |
65 |
} |
66 |
|
67 |
public String getText() { |
68 |
return PluginServices.getText(this, "change_symbol"); |
69 |
} |
70 |
|
71 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
72 |
return true; |
73 |
} |
74 |
|
75 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
76 |
return isTocItemLeaf(item);
|
77 |
} |
78 |
|
79 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
80 |
|
81 |
boolean showDialog = isTocItemLeaf(item);
|
82 |
|
83 |
if (!showDialog) {
|
84 |
return;
|
85 |
} |
86 |
|
87 |
try {
|
88 |
if(!(selectedItems[0] instanceof FLyrVect)) |
89 |
return;
|
90 |
FLyrVect layer = (FLyrVect) selectedItems[0];
|
91 |
ISymbol oldSymbol = ((TocItemLeaf) item).getSymbol(); |
92 |
// patch, figure out an ellegant way to solve this
|
93 |
if (oldSymbol instanceof MultiLayerFillSymbol) { |
94 |
MultiLayerFillSymbol ms = (MultiLayerFillSymbol) oldSymbol; |
95 |
for (int i = 0; i < ms.getLayerCount(); i++) { |
96 |
if (ms.getLayer(i).getClass().getName().equals("org.gvsig.symbology.symbols.DotDensityFillSymbol")) { |
97 |
/*
|
98 |
* since dot density symbol works together with the
|
99 |
* legend, there is no way to edit it from the symbol selector and editor
|
100 |
* we have to break now!
|
101 |
*/
|
102 |
return;
|
103 |
} |
104 |
} |
105 |
} |
106 |
// end patch
|
107 |
|
108 |
|
109 |
int shapeType = ((IVectorLegend) layer.getLegend()).getShapeType();
|
110 |
if (shapeType == 0) { |
111 |
logger.debug("Error legend " + layer.getLegend()
|
112 |
+ " does not have shapetype initialized");
|
113 |
shapeType = layer.getShapeType(); |
114 |
} |
115 |
|
116 |
ISymbolSelector symSel = null;
|
117 |
|
118 |
try {
|
119 |
symSel = SymbolSelector.createSymbolSelector(oldSymbol, shapeType); |
120 |
} catch (IllegalArgumentException iaEx) { |
121 |
/*
|
122 |
* this usually happens when the Legend has a composed
|
123 |
* symbol that collides with the normal operation and
|
124 |
* it only can be changed from the panel of the legend
|
125 |
*/
|
126 |
// TODO throw a signal and show a warning message box telling
|
127 |
// that the operation cannot be performed
|
128 |
return;
|
129 |
} |
130 |
PluginServices.getMDIManager().addWindow(symSel); |
131 |
ISymbol newSymbol = (ISymbol) symSel.getSelectedObject(); |
132 |
|
133 |
if (newSymbol == null) { |
134 |
return;
|
135 |
} |
136 |
|
137 |
newSymbol.setDescription(oldSymbol.getDescription()); |
138 |
|
139 |
for (int i = 0; i < selectedItems.length; i++) { |
140 |
FLyrVect theLayer = ((FLyrVect) selectedItems[i]); |
141 |
|
142 |
try {
|
143 |
ILegend legend = theLayer.getLegend(); |
144 |
if (legend instanceof IClassifiedVectorLegend) { |
145 |
IClassifiedVectorLegend cv = (IClassifiedVectorLegend) legend; |
146 |
cv.replace(oldSymbol, newSymbol); |
147 |
} else if (legend instanceof ISingleSymbolLegend) { |
148 |
ISingleSymbolLegend ss = (ISingleSymbolLegend) legend; |
149 |
ss.setDefaultSymbol(newSymbol); |
150 |
} |
151 |
} catch (Exception e) { |
152 |
NotificationManager.addWarning(PluginServices.getText(this, "skipped_symbol_changed_for_layer")+": "+theLayer.getName(), e); |
153 |
} |
154 |
|
155 |
} |
156 |
// refresh view treak
|
157 |
MapContext mc = layer.getMapContext(); |
158 |
mc.invalidate(); |
159 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
160 |
project.setModified(true);
|
161 |
mc.callLegendChanged(); |
162 |
|
163 |
} catch (ReadException e) {
|
164 |
NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), e); |
165 |
} |
166 |
} |
167 |
} |
168 |
|