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