svn-gvsig-desktop / branches / piloto3d / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / FSymbolChangeColorTocMenuEntry.java @ 9627
History | View | Annotate | Download (6.02 KB)
1 |
package com.iver.cit.gvsig.project.documents.view.toc.actions; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import javax.swing.JColorChooser; |
6 |
|
7 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
8 |
import com.iver.andami.PluginServices; |
9 |
import com.iver.cit.gvsig.fmap.DriverException; |
10 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
11 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
12 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
13 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
14 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
15 |
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
16 |
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
17 |
import com.iver.cit.gvsig.project.documents.view.toc.TocItemLeaf; |
18 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
19 |
*
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
21 |
*
|
22 |
* This program is free software; you can redistribute it and/or
|
23 |
* modify it under the terms of the GNU General Public License
|
24 |
* as published by the Free Software Foundation; either version 2
|
25 |
* of the License, or (at your option) any later version.
|
26 |
*
|
27 |
* This program is distributed in the hope that it will be useful,
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
* GNU General Public License for more details.
|
31 |
*
|
32 |
* You should have received a copy of the GNU General Public License
|
33 |
* along with this program; if not, write to the Free Software
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
35 |
*
|
36 |
* For more information, contact:
|
37 |
*
|
38 |
* Generalitat Valenciana
|
39 |
* Conselleria d'Infraestructures i Transport
|
40 |
* Av. Blasco Ib??ez, 50
|
41 |
* 46010 VALENCIA
|
42 |
* SPAIN
|
43 |
*
|
44 |
* +34 963862235
|
45 |
* gvsig@gva.es
|
46 |
* www.gvsig.gva.es
|
47 |
*
|
48 |
* or
|
49 |
*
|
50 |
* IVER T.I. S.A
|
51 |
* Salamanca 50
|
52 |
* 46005 Valencia
|
53 |
* Spain
|
54 |
*
|
55 |
* +34 963163400
|
56 |
* dac@iver.es
|
57 |
*/
|
58 |
/* CVS MESSAGES:
|
59 |
*
|
60 |
* $Id: FSymbolChangeColorTocMenuEntry.java 9627 2007-01-10 13:42:08Z sbayarri $
|
61 |
* $Log$
|
62 |
* Revision 1.4.4.2 2007-01-10 13:42:08 sbayarri
|
63 |
* Fix bug: color change in layer wasn't refreshing layer in 3D
|
64 |
*
|
65 |
* Revision 1.4.4.1 2007/01/03 17:07:30 sbayarri
|
66 |
* Fix wrong files
|
67 |
*
|
68 |
* Revision 1.4.2.1 2006/11/15 04:10:44 jjdelcerro
|
69 |
* *** empty log message ***
|
70 |
*
|
71 |
* Revision 1.4 2006/10/02 13:52:34 jaume
|
72 |
* organize impots
|
73 |
*
|
74 |
* Revision 1.3 2006/09/29 07:07:41 caballero
|
75 |
* llamada a listener
|
76 |
*
|
77 |
* Revision 1.2 2006/09/28 15:00:45 fjp
|
78 |
* Usar siempre que se pueda ISymbol en lugar de FSymbol
|
79 |
*
|
80 |
* Revision 1.1 2006/09/15 10:41:30 caballero
|
81 |
* extensibilidad de documentos
|
82 |
*
|
83 |
* Revision 1.1 2006/09/12 15:58:14 jorpiell
|
84 |
* "Sacadas" las opcines del men? de FPopupMenu
|
85 |
*
|
86 |
*
|
87 |
*/
|
88 |
/**
|
89 |
* Realiza el cambio de color si se pulsa OK
|
90 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
91 |
*/
|
92 |
public class FSymbolChangeColorTocMenuEntry extends AbstractTocContextMenuAction { |
93 |
public String getGroup() { |
94 |
return "group1"; //FIXME |
95 |
} |
96 |
|
97 |
public int getGroupOrder() { |
98 |
return 10; |
99 |
} |
100 |
|
101 |
public int getOrder() { |
102 |
return 0; |
103 |
} |
104 |
|
105 |
public String getText() { |
106 |
return PluginServices.getText(this, "Cambio_Color"); |
107 |
} |
108 |
|
109 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
110 |
return true; |
111 |
} |
112 |
|
113 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
114 |
boolean bShow = false; |
115 |
if (isTocItemBranch(item))
|
116 |
{ |
117 |
FLayer lyr = getNodeLayer(item); |
118 |
if ((lyr instanceof ClassifiableVectorial)) |
119 |
{ |
120 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr; |
121 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
122 |
if (lyrVect.getLegend().getDefaultSymbol() instanceof FSymbol) |
123 |
bShow = true;
|
124 |
} |
125 |
} else if (isTocItemLeaf(item)) { |
126 |
//bShow = true;
|
127 |
|
128 |
} |
129 |
return bShow;
|
130 |
} |
131 |
|
132 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
133 |
|
134 |
boolean showDialog=false; |
135 |
if (isTocItemBranch(item)) {
|
136 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
137 |
if (actives.length > 0) { |
138 |
for (int i=0;i<actives.length;i++){ |
139 |
if ((actives[i] instanceof ClassifiableVectorial)) |
140 |
{ |
141 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i]; |
142 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend && actives[i].isAvailable() ) |
143 |
{ |
144 |
showDialog=true;
|
145 |
break;
|
146 |
} |
147 |
} |
148 |
} |
149 |
} |
150 |
} |
151 |
|
152 |
if (!showDialog) return; |
153 |
|
154 |
Color newColor = JColorChooser.showDialog(null, |
155 |
PluginServices.getText(this, "Elegir_Color"), |
156 |
null);
|
157 |
if (newColor != null) |
158 |
{ |
159 |
if (isTocItemBranch(item))
|
160 |
{ |
161 |
//FLayer lyr = getNodeLayer();
|
162 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
163 |
for (int i=0;i<actives.length;i++){ |
164 |
if ((actives[i] instanceof ClassifiableVectorial)) |
165 |
{ |
166 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i]; |
167 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
168 |
{ |
169 |
SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend(); |
170 |
((FSymbol)leg.getDefaultSymbol()).setColor(newColor); |
171 |
// set changed legend, so layer event is fired
|
172 |
try {
|
173 |
lyrVect.setLegend((VectorialLegend)leg); |
174 |
} catch (FieldNotFoundException e) {
|
175 |
// TODO Auto-generated catch block
|
176 |
e.printStackTrace(); |
177 |
} catch (DriverException e) {
|
178 |
// TODO Auto-generated catch block
|
179 |
e.printStackTrace(); |
180 |
} |
181 |
} |
182 |
} |
183 |
} |
184 |
} |
185 |
else
|
186 |
{ |
187 |
TocItemLeaf leaf = (TocItemLeaf) item; |
188 |
FSymbol sym = (FSymbol) leaf.getSymbol(); |
189 |
sym.setColor(newColor); |
190 |
} |
191 |
// TRUCO PARA REFRESCAR.
|
192 |
getMapContext().invalidate(); |
193 |
getMapContext().callLegendChanged(); |
194 |
} |
195 |
|
196 |
} |
197 |
} |
198 |
|