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