svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FPopupMenu.java @ 1454
History | View | Annotate | Download (9.92 KB)
1 |
/*
|
---|---|
2 |
* Created on 02-mar-2004
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.gui.toc; |
45 |
|
46 |
import java.awt.Color; |
47 |
import java.awt.Font; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import javax.swing.JColorChooser; |
53 |
import javax.swing.JDialog; |
54 |
import javax.swing.JFrame; |
55 |
import javax.swing.JMenuItem; |
56 |
import javax.swing.JPopupMenu; |
57 |
import javax.swing.tree.DefaultMutableTreeNode; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.cit.gvsig.fmap.DriverException; |
61 |
import com.iver.cit.gvsig.fmap.FMap; |
62 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
63 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
64 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
67 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
68 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
69 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
70 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
71 |
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel; |
72 |
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow; |
73 |
|
74 |
/**
|
75 |
* Realiza el cambio de color si se pulsa OK
|
76 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
77 |
*/
|
78 |
class FSymbolChangeColorTocMenuEntry extends TocMenuEntry { |
79 |
private JMenuItem color; |
80 |
public void initialize(FPopupMenu m) { |
81 |
super.initialize(m);
|
82 |
boolean bShow = false; |
83 |
if (isTocItemBranch())
|
84 |
{ |
85 |
FLayer lyr = getNodeLayer(); |
86 |
if ((lyr instanceof ClassifiableVectorial)) |
87 |
{ |
88 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr; |
89 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
90 |
bShow = true;
|
91 |
} |
92 |
} |
93 |
else
|
94 |
bShow = true;
|
95 |
if (bShow)
|
96 |
{ |
97 |
color = new JMenuItem(PluginServices.getText(this, "Cambio_Color")); |
98 |
color.setFont(FPopupMenu.theFont); |
99 |
getMenu().add(color); |
100 |
getMenu().enable(); |
101 |
//Cambio color
|
102 |
color.addActionListener(this);
|
103 |
} |
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
108 |
*/
|
109 |
public void actionPerformed(ActionEvent e) { |
110 |
ITocItem tocItem = (ITocItem) getNodeUserObject(); |
111 |
|
112 |
Color newColor = JColorChooser.showDialog(null, |
113 |
PluginServices.getText(this, "Elegir_Color"), |
114 |
null);
|
115 |
if (newColor != null) |
116 |
{ |
117 |
if (isTocItemBranch())
|
118 |
{ |
119 |
FLayer lyr = getNodeLayer(); |
120 |
if ((lyr instanceof ClassifiableVectorial)) |
121 |
{ |
122 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr; |
123 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
124 |
{ |
125 |
SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend(); |
126 |
leg.getDefaultSymbol().setColor(newColor); |
127 |
} |
128 |
} |
129 |
} |
130 |
else
|
131 |
{ |
132 |
TocItemLeaf leaf = (TocItemLeaf) tocItem; |
133 |
FSymbol sym = leaf.getSymbol(); |
134 |
sym.setColor(newColor); |
135 |
|
136 |
} |
137 |
// TRUCO PARA REFRESCAR.
|
138 |
getMapContext().invalidate(); |
139 |
|
140 |
} |
141 |
|
142 |
} |
143 |
} |
144 |
|
145 |
class FLyrVectChangeStyleTocMenuEntry extends TocMenuEntry { |
146 |
private JMenuItem estilo; |
147 |
public void initialize(FPopupMenu m) { |
148 |
super.initialize(m);
|
149 |
FLayer lyr = null;
|
150 |
|
151 |
if (isTocItemBranch()) {
|
152 |
lyr = getNodeLayer(); |
153 |
if (lyr instanceof ClassifiableVectorial) { |
154 |
estilo = new JMenuItem(PluginServices.getText(this, "Cambio_Estilo")); |
155 |
getMenu().add(estilo); |
156 |
estilo.setFont(FPopupMenu.theFont); |
157 |
//Cambio estilo
|
158 |
estilo.addActionListener(this);
|
159 |
} |
160 |
} |
161 |
} |
162 |
/* (non-Javadoc)
|
163 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
164 |
*/
|
165 |
public void actionPerformed(ActionEvent e) { |
166 |
FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow();
|
167 |
try {
|
168 |
m_LegendEditor.setMapContext(getMapContext()); |
169 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
170 |
e1.printStackTrace(); |
171 |
} |
172 |
if (PluginServices.getMainFrame() == null) { |
173 |
JDialog dlg = new JDialog(); |
174 |
|
175 |
m_LegendEditor.setPreferredSize(m_LegendEditor.getSize()); |
176 |
dlg.getContentPane().add(m_LegendEditor); |
177 |
dlg.setModal(false);
|
178 |
dlg.pack(); |
179 |
dlg.show(); |
180 |
|
181 |
} else
|
182 |
PluginServices.getMDIManager().addView(m_LegendEditor); |
183 |
} |
184 |
} |
185 |
|
186 |
|
187 |
class FLyrRasterAdjustTransparencyTocMenuEntry extends TocMenuEntry { |
188 |
private JMenuItem transparency; |
189 |
FLayer lyr = null;
|
190 |
public void initialize(FPopupMenu m) { |
191 |
super.initialize(m);
|
192 |
|
193 |
if (isTocItemBranch()) {
|
194 |
lyr = getNodeLayer(); |
195 |
// Opcciones para capas raster
|
196 |
if ((lyr instanceof FLyrRaster)) { |
197 |
transparency = new JMenuItem(PluginServices.getText(this, "adjust_transparency")); |
198 |
getMenu().add( transparency ); |
199 |
transparency.setFont(FPopupMenu.theFont); |
200 |
getMenu().enable(); |
201 |
getMenu().addSeparator(); |
202 |
//Cambio color
|
203 |
transparency.addActionListener(this);
|
204 |
} |
205 |
} |
206 |
} |
207 |
/* (non-Javadoc)
|
208 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
209 |
*/
|
210 |
public void actionPerformed(ActionEvent e) { |
211 |
lyr = getNodeLayer(); |
212 |
AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
|
213 |
transPanel.openJDialog(); |
214 |
//getMapContext().invalidate();
|
215 |
} |
216 |
} |
217 |
|
218 |
class ZoomAlTemaTocMenuEntry extends TocMenuEntry { |
219 |
private JMenuItem zoom; |
220 |
public void initialize(FPopupMenu m) { |
221 |
super.initialize(m);
|
222 |
|
223 |
if (isTocItemBranch()) {
|
224 |
zoom = new JMenuItem(PluginServices.getText(this, "Zoom_al_Tema")); |
225 |
getMenu().add(zoom); |
226 |
zoom.setFont(FPopupMenu.theFont); |
227 |
|
228 |
zoom.addActionListener(this);
|
229 |
} |
230 |
} |
231 |
/* (non-Javadoc)
|
232 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
233 |
*/
|
234 |
public void actionPerformed(ActionEvent e) { |
235 |
FLayer lyr = getNodeLayer(); |
236 |
|
237 |
try {
|
238 |
getMapContext().getViewPort().setExtent(lyr.getFullExtent()); |
239 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
240 |
e1.printStackTrace(); |
241 |
} |
242 |
} |
243 |
} |
244 |
|
245 |
class EliminarCapaTocMenuEntry extends TocMenuEntry { |
246 |
private JMenuItem removeLayer; |
247 |
public void initialize(FPopupMenu m) { |
248 |
super.initialize(m);
|
249 |
|
250 |
if (getNodeUserObject() instanceof TocItemBranch) { |
251 |
getMenu().addSeparator(); |
252 |
removeLayer = new JMenuItem(PluginServices.getText(this, "eliminar_capa")); |
253 |
getMenu().add(removeLayer); |
254 |
removeLayer.setFont(FPopupMenu.theFont); |
255 |
removeLayer.addActionListener(this);
|
256 |
} |
257 |
} |
258 |
/* (non-Javadoc)
|
259 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
260 |
*/
|
261 |
public void actionPerformed(ActionEvent e) { |
262 |
FLayer lyr = getNodeLayer(); |
263 |
|
264 |
try {
|
265 |
getMapContext().getLayers().removeLayer(lyr); |
266 |
if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls(); |
267 |
} catch (CancelationException e1) {
|
268 |
e1.printStackTrace(); |
269 |
} |
270 |
} |
271 |
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* Menu de bot?n derecho para el TOC.
|
276 |
* Se pueden a?adir entradas facilmente desde una extensi?n,
|
277 |
* creando una clase derivando de TocMenuEntry, y a?adiendola en
|
278 |
* est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
|
279 |
* (Las entradas actuales est?n hechas de esa manera).
|
280 |
*
|
281 |
* @author vcn To change the template for this generated type comment go to
|
282 |
* Window>Preferences>Java>Code Generation>Code and
|
283 |
* Comments
|
284 |
*/
|
285 |
|
286 |
public class FPopupMenu extends JPopupMenu { |
287 |
private static ArrayList menuEntrys = null; |
288 |
public DefaultMutableTreeNode nodo; |
289 |
protected FMap mapContext;
|
290 |
//private JMenuItem capa;
|
291 |
// Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
|
292 |
// TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
|
293 |
public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10); |
294 |
|
295 |
static {
|
296 |
menuEntrys = new ArrayList(); |
297 |
menuEntrys.add(new FSymbolChangeColorTocMenuEntry());
|
298 |
menuEntrys.add(new FLyrVectChangeStyleTocMenuEntry());
|
299 |
menuEntrys.add(new FLyrRasterAdjustTransparencyTocMenuEntry());
|
300 |
menuEntrys.add(new ZoomAlTemaTocMenuEntry());
|
301 |
menuEntrys.add(new EliminarCapaTocMenuEntry());
|
302 |
} |
303 |
|
304 |
public static void addEntry(TocMenuEntry entry) { |
305 |
menuEntrys.add(entry); |
306 |
} |
307 |
|
308 |
/**
|
309 |
* Creates a new FPopupMenu object.
|
310 |
*
|
311 |
* @param nodo DOCUMENT ME!
|
312 |
* @param vista DOCUMENT ME!
|
313 |
*/
|
314 |
public FPopupMenu(FMap mc, DefaultMutableTreeNode node) { |
315 |
//super();
|
316 |
this.mapContext = mc;
|
317 |
this.nodo = node;
|
318 |
|
319 |
//salir = new MenuItem("Salir");
|
320 |
|
321 |
for (int i=0; i<menuEntrys.size(); i++) { |
322 |
((TocMenuEntry) menuEntrys.get(i)).initialize(this);
|
323 |
} |
324 |
} |
325 |
|
326 |
public FMap getMapContext() { return mapContext; } |
327 |
|
328 |
} |