root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toc / actions / ChangeSymbolTocMenuEntry.java @ 29598
History | View | Annotate | Download (6.52 KB)
1 |
package org.gvsig.app.project.documents.view.toc.actions; |
---|---|
2 |
|
3 |
import org.gvsig.andami.PluginServices; |
4 |
import org.gvsig.andami.messages.NotificationManager; |
5 |
import org.gvsig.app.extension.ProjectExtension; |
6 |
import org.gvsig.app.gui.styling.SymbolSelector; |
7 |
import org.gvsig.app.project.Project; |
8 |
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
9 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
10 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
11 |
import org.gvsig.app.project.documents.view.toc.TocItemLeaf; |
12 |
import org.gvsig.fmap.dal.exception.ReadException; |
13 |
import org.gvsig.fmap.mapcontext.MapContext; |
14 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
15 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
16 |
import org.gvsig.fmap.mapcontext.rendering.legend.*; |
17 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
18 |
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerFillSymbol; |
19 |
import org.slf4j.Logger; |
20 |
import org.slf4j.LoggerFactory; |
21 |
|
22 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
23 |
*
|
24 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
25 |
*
|
26 |
* This program is free software; you can redistribute it and/or
|
27 |
* modify it under the terms of the GNU General Public License
|
28 |
* as published by the Free Software Foundation; either version 2
|
29 |
* of the License, or (at your option) any later version.
|
30 |
*
|
31 |
* This program is distributed in the hope that it will be useful,
|
32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
34 |
* GNU General Public License for more details.
|
35 |
*
|
36 |
* You should have received a copy of the GNU General Public License
|
37 |
* along with this program; if not, write to the Free Software
|
38 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
39 |
*
|
40 |
* For more information, contact:
|
41 |
*
|
42 |
* Generalitat Valenciana
|
43 |
* Conselleria d'Infraestructures i Transport
|
44 |
* Av. Blasco Ib??ez, 50
|
45 |
* 46010 VALENCIA
|
46 |
* SPAIN
|
47 |
*
|
48 |
* +34 963862235
|
49 |
* gvsig@gva.es
|
50 |
* www.gvsig.gva.es
|
51 |
*
|
52 |
* or
|
53 |
*
|
54 |
* IVER T.I. S.A
|
55 |
* Salamanca 50
|
56 |
* 46005 Valencia
|
57 |
* Spain
|
58 |
*
|
59 |
* +34 963163400
|
60 |
* dac@iver.es
|
61 |
*/
|
62 |
/* CVS MESSAGES:
|
63 |
*
|
64 |
* $Id: ChangeSymbolTocMenuEntry.java 29598 2009-06-29 16:09:14Z jpiera $
|
65 |
* $Log$
|
66 |
* Revision 1.3 2007-09-19 15:50:42 jaume
|
67 |
* refactor name IVectorialLegend -> IVectorLegend
|
68 |
*
|
69 |
* Revision 1.2 2007/09/17 09:22:21 jaume
|
70 |
* view draw frame rate now customizable
|
71 |
*
|
72 |
* Revision 1.1 2007/09/10 15:34:39 jaume
|
73 |
* improvements on usability (double-clicks on TOC and some minor shorcuts)
|
74 |
*
|
75 |
* Revision 1.5 2007/01/04 07:24:31 caballero
|
76 |
* isModified
|
77 |
*
|
78 |
* Revision 1.4 2006/10/02 13:52:34 jaume
|
79 |
* organize impots
|
80 |
*
|
81 |
* Revision 1.3 2006/09/29 07:07:41 caballero
|
82 |
* llamada a listener
|
83 |
*
|
84 |
* Revision 1.2 2006/09/28 15:00:45 fjp
|
85 |
* Usar siempre que se pueda ISymbol en lugar de FSymbol
|
86 |
*
|
87 |
* Revision 1.1 2006/09/15 10:41:30 caballero
|
88 |
* extensibilidad de documentos
|
89 |
*
|
90 |
* Revision 1.1 2006/09/12 15:58:14 jorpiell
|
91 |
* "Sacadas" las opcines del men? de FPopupMenu
|
92 |
*
|
93 |
*
|
94 |
*/
|
95 |
/**
|
96 |
* Directly opens the Symbol Selector if it is invoked from the TOC avoiding
|
97 |
* by-passing the Layer Properties window
|
98 |
*/
|
99 |
public class ChangeSymbolTocMenuEntry extends AbstractTocContextMenuAction { |
100 |
private static final Logger logger = LoggerFactory |
101 |
.getLogger(ChangeSymbolTocMenuEntry.class); |
102 |
|
103 |
public String getGroup() { |
104 |
return "group1"; //FIXME |
105 |
} |
106 |
|
107 |
public int getGroupOrder() { |
108 |
return 10; |
109 |
} |
110 |
|
111 |
public int getOrder() { |
112 |
return 0; |
113 |
} |
114 |
|
115 |
public String getText() { |
116 |
return PluginServices.getText(this, "change_symbol"); |
117 |
} |
118 |
|
119 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
120 |
return true; |
121 |
} |
122 |
|
123 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
124 |
return isTocItemLeaf(item);
|
125 |
} |
126 |
|
127 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
128 |
|
129 |
boolean showDialog = isTocItemLeaf(item);
|
130 |
|
131 |
if (!showDialog) {
|
132 |
return;
|
133 |
} |
134 |
|
135 |
try {
|
136 |
if(!(selectedItems[0] instanceof FLyrVect)) |
137 |
return;
|
138 |
FLyrVect layer = (FLyrVect) selectedItems[0];
|
139 |
ISymbol oldSymbol = ((TocItemLeaf) item).getSymbol(); |
140 |
// patch, figure out an ellegant way to solve this
|
141 |
if (oldSymbol instanceof MultiLayerFillSymbol) { |
142 |
MultiLayerFillSymbol ms = (MultiLayerFillSymbol) oldSymbol; |
143 |
for (int i = 0; i < ms.getLayerCount(); i++) { |
144 |
if (ms.getLayer(i).getClassName().equals("org.gvsig.symbology.symbols.DotDensityFillSymbol")) { |
145 |
/*
|
146 |
* since dot density symbol works together with the
|
147 |
* legend, there is no way to edit it from the symbol selector and editor
|
148 |
* we have to break now!
|
149 |
*/
|
150 |
return;
|
151 |
} |
152 |
} |
153 |
} |
154 |
// end patch
|
155 |
|
156 |
|
157 |
int shapeType = ((IVectorLegend) layer.getLegend()).getShapeType();
|
158 |
if (shapeType == 0) { |
159 |
logger.debug("Error legend " + layer.getLegend()
|
160 |
+ " does not have shapetype initialized");
|
161 |
shapeType = layer.getShapeType(); |
162 |
} |
163 |
|
164 |
ISymbolSelector symSel = null;
|
165 |
|
166 |
try {
|
167 |
symSel = SymbolSelector.createSymbolSelector(oldSymbol, shapeType); |
168 |
} catch (IllegalArgumentException iaEx) { |
169 |
/*
|
170 |
* this usually happens when the Legend has a composed
|
171 |
* symbol that collides with the normal operation and
|
172 |
* it only can be changed from the panel of the legend
|
173 |
*/
|
174 |
// TODO throw a signal and show a warning message box telling
|
175 |
// that the operation cannot be performed
|
176 |
return;
|
177 |
} |
178 |
PluginServices.getMDIManager().addWindow(symSel); |
179 |
ISymbol newSymbol = (ISymbol) symSel.getSelectedObject(); |
180 |
|
181 |
if (newSymbol == null) { |
182 |
return;
|
183 |
} |
184 |
|
185 |
newSymbol.setDescription(oldSymbol.getDescription()); |
186 |
|
187 |
for (int i = 0; i < selectedItems.length; i++) { |
188 |
FLyrVect theLayer = ((FLyrVect) selectedItems[i]); |
189 |
|
190 |
try {
|
191 |
ILegend legend = theLayer.getLegend(); |
192 |
if (legend instanceof IClassifiedVectorLegend) { |
193 |
IClassifiedVectorLegend cv = (IClassifiedVectorLegend) legend; |
194 |
cv.replace(oldSymbol, newSymbol); |
195 |
} else if (legend instanceof SingleSymbolLegend) { |
196 |
SingleSymbolLegend ss = (SingleSymbolLegend) legend; |
197 |
ss.setDefaultSymbol(newSymbol); |
198 |
} |
199 |
} catch (Exception e) { |
200 |
NotificationManager.addWarning(PluginServices.getText(this, "skipped_symbol_changed_for_layer")+": "+theLayer.getName(), e); |
201 |
} |
202 |
|
203 |
} |
204 |
// refresh view treak
|
205 |
MapContext mc = layer.getMapContext(); |
206 |
mc.invalidate(); |
207 |
Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
208 |
project.setModified(true);
|
209 |
mc.callLegendChanged(); |
210 |
|
211 |
} catch (ReadException e) {
|
212 |
NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), e); |
213 |
} |
214 |
} |
215 |
} |
216 |
|