svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FPopupMenu.java @ 1827
History | View | Annotate | Download (15.3 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.awt.geom.Rectangle2D; |
51 |
import java.util.ArrayList; |
52 |
|
53 |
import javax.swing.JColorChooser; |
54 |
import javax.swing.JDialog; |
55 |
import javax.swing.JFrame; |
56 |
import javax.swing.JMenuItem; |
57 |
import javax.swing.JPopupMenu; |
58 |
import javax.swing.JTabbedPane; |
59 |
import javax.swing.tree.DefaultMutableTreeNode; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.cit.gvsig.fmap.DriverException; |
63 |
import com.iver.cit.gvsig.fmap.FMap; |
64 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
65 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
69 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
70 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
71 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
72 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
73 |
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel; |
74 |
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow; |
75 |
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow; |
76 |
|
77 |
/**
|
78 |
* Realiza el cambio de color si se pulsa OK
|
79 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
80 |
*/
|
81 |
class FSymbolChangeColorTocMenuEntry extends TocMenuEntry { |
82 |
private JMenuItem color; |
83 |
public void initialize(FPopupMenu m) { |
84 |
super.initialize(m);
|
85 |
boolean bShow = false; |
86 |
if (isTocItemBranch())
|
87 |
{ |
88 |
FLayer lyr = getNodeLayer(); |
89 |
if ((lyr instanceof ClassifiableVectorial)) |
90 |
{ |
91 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr; |
92 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
93 |
bShow = true;
|
94 |
} |
95 |
} |
96 |
else
|
97 |
bShow = true;
|
98 |
if (bShow)
|
99 |
{ |
100 |
color = new JMenuItem(PluginServices.getText(this, "Cambio_Color")); |
101 |
color.setFont(FPopupMenu.theFont); |
102 |
getMenu().add(color); |
103 |
getMenu().setEnabled(true);
|
104 |
//Cambio color
|
105 |
color.addActionListener(this);
|
106 |
} |
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
111 |
*/
|
112 |
public void actionPerformed(ActionEvent e) { |
113 |
ITocItem tocItem = (ITocItem) getNodeUserObject(); |
114 |
|
115 |
Color newColor = JColorChooser.showDialog(null, |
116 |
PluginServices.getText(this, "Elegir_Color"), |
117 |
null);
|
118 |
if (newColor != null) |
119 |
{ |
120 |
if (isTocItemBranch())
|
121 |
{ |
122 |
FLayer lyr = getNodeLayer(); |
123 |
if ((lyr instanceof ClassifiableVectorial)) |
124 |
{ |
125 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr; |
126 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
127 |
{ |
128 |
SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend(); |
129 |
leg.getDefaultSymbol().setColor(newColor); |
130 |
} |
131 |
} |
132 |
} |
133 |
else
|
134 |
{ |
135 |
TocItemLeaf leaf = (TocItemLeaf) tocItem; |
136 |
FSymbol sym = leaf.getSymbol(); |
137 |
sym.setColor(newColor); |
138 |
|
139 |
} |
140 |
// TRUCO PARA REFRESCAR.
|
141 |
getMapContext().invalidate(); |
142 |
|
143 |
} |
144 |
|
145 |
} |
146 |
} |
147 |
|
148 |
class FLyrVectChangeStyleTocMenuEntry extends TocMenuEntry { |
149 |
private JMenuItem estilo; |
150 |
public void initialize(FPopupMenu m) { |
151 |
super.initialize(m);
|
152 |
FLayer lyr = null;
|
153 |
|
154 |
if (isTocItemBranch()) {
|
155 |
lyr = getNodeLayer(); |
156 |
if (lyr instanceof ClassifiableVectorial) { |
157 |
estilo = new JMenuItem(PluginServices.getText(this, "Cambio_Estilo")); |
158 |
getMenu().add(estilo); |
159 |
estilo.setFont(FPopupMenu.theFont); |
160 |
//Cambio estilo
|
161 |
estilo.addActionListener(this);
|
162 |
} |
163 |
} |
164 |
} |
165 |
/* (non-Javadoc)
|
166 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
167 |
*/
|
168 |
public void actionPerformed(ActionEvent e) { |
169 |
FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow();
|
170 |
try {
|
171 |
m_LegendEditor.setMapContext(getMapContext()); |
172 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
173 |
e1.printStackTrace(); |
174 |
} |
175 |
if (PluginServices.getMainFrame() == null) { |
176 |
JDialog dlg = new JDialog(); |
177 |
|
178 |
m_LegendEditor.setPreferredSize(m_LegendEditor.getSize()); |
179 |
dlg.getContentPane().add(m_LegendEditor); |
180 |
dlg.setModal(false);
|
181 |
dlg.pack(); |
182 |
dlg.show(); |
183 |
|
184 |
} else
|
185 |
PluginServices.getMDIManager().addView(m_LegendEditor); |
186 |
} |
187 |
} |
188 |
|
189 |
/**
|
190 |
* Muestra el men? de propiedades del tema.
|
191 |
*
|
192 |
* @author jmorell
|
193 |
*
|
194 |
* TODO To change the template for this generated type comment go to
|
195 |
* Window - Preferences - Java - Code Style - Code Templates
|
196 |
*/
|
197 |
class FLyrVectEditPropertiesTocMenuEntry extends TocMenuEntry { |
198 |
private JMenuItem prop; |
199 |
public void initialize(FPopupMenu m) { |
200 |
super.initialize(m);
|
201 |
FLayer lyr = null;
|
202 |
if (isTocItemBranch()) {
|
203 |
getMenu().addSeparator(); |
204 |
lyr = getNodeLayer(); |
205 |
if (lyr instanceof ClassifiableVectorial) { |
206 |
prop = new JMenuItem("Propiedades Pliego"); |
207 |
getMenu().add(prop); |
208 |
prop.setFont(FPopupMenu.theFont); |
209 |
//Cambio estilo
|
210 |
prop.addActionListener(this);
|
211 |
} |
212 |
} |
213 |
} |
214 |
/* (non-Javadoc)
|
215 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
216 |
*/
|
217 |
public void actionPerformed(ActionEvent e) { |
218 |
/*FThemeManagerWindow fThemeManagerWindow = new FThemeManagerWindow();
|
219 |
try {
|
220 |
fThemeManagerWindow.setMapContext(getMapContext());
|
221 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
222 |
e1.printStackTrace();
|
223 |
}*/
|
224 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
225 |
FThemeManagerWindow fThemeManagerWindow; |
226 |
if (actives.length==1) { |
227 |
System.out.println("openPliegoThemeProperties(): Una sola capa. Abrimos el panel para la capa " + actives[0]); |
228 |
fThemeManagerWindow = new FThemeManagerWindow();
|
229 |
try {
|
230 |
fThemeManagerWindow.setMapContext(getMapContext()); |
231 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
232 |
e1.printStackTrace(); |
233 |
} |
234 |
//PluginServices.getMDIManager().addView(fThemeManagerWindow);
|
235 |
if (PluginServices.getMainFrame() == null) { |
236 |
JDialog dlg = new JDialog(); |
237 |
fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize()); |
238 |
dlg.getContentPane().add(fThemeManagerWindow); |
239 |
dlg.setModal(false);
|
240 |
dlg.pack(); |
241 |
dlg.show(); |
242 |
} else {
|
243 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
244 |
} |
245 |
} else {
|
246 |
for (int i = 0; i < actives.length; i++){ |
247 |
System.out.println("openPliegoThemeProperties(): Muchas capas. Abrimos el panel para la capa " + actives[i]); |
248 |
fThemeManagerWindow = new FThemeManagerWindow(actives[i], getMapContext());
|
249 |
//PluginServices.getMDIManager().addView(fThemeManagerWindow);
|
250 |
if (PluginServices.getMainFrame() == null) { |
251 |
JDialog dlg = new JDialog(); |
252 |
fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize()); |
253 |
dlg.getContentPane().add(fThemeManagerWindow); |
254 |
dlg.setModal(false);
|
255 |
dlg.pack(); |
256 |
dlg.show(); |
257 |
} else {
|
258 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
259 |
} |
260 |
} |
261 |
} |
262 |
/*if (PluginServices.getMainFrame() == null) {
|
263 |
JDialog dlg = new JDialog();
|
264 |
fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
|
265 |
dlg.getContentPane().add(fThemeManagerWindow);
|
266 |
dlg.setModal(false);
|
267 |
dlg.pack();
|
268 |
dlg.show();
|
269 |
} else {
|
270 |
PluginServices.getMDIManager().addView(fThemeManagerWindow);
|
271 |
}*/
|
272 |
} |
273 |
} |
274 |
|
275 |
class FLyrRasterAdjustTransparencyTocMenuEntry extends TocMenuEntry { |
276 |
private JMenuItem transparency; |
277 |
FLayer lyr = null;
|
278 |
public void initialize(FPopupMenu m) { |
279 |
super.initialize(m);
|
280 |
|
281 |
if (isTocItemBranch()) {
|
282 |
lyr = getNodeLayer(); |
283 |
// Opcciones para capas raster
|
284 |
if ((lyr instanceof FLyrRaster)) { |
285 |
transparency = new JMenuItem(PluginServices.getText(this, "adjust_transparency")); |
286 |
getMenu().add( transparency ); |
287 |
transparency.setFont(FPopupMenu.theFont); |
288 |
getMenu().setEnabled(true);
|
289 |
getMenu().addSeparator(); |
290 |
//Cambio color
|
291 |
transparency.addActionListener(this);
|
292 |
} |
293 |
} |
294 |
} |
295 |
/* (non-Javadoc)
|
296 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
297 |
*/
|
298 |
public void actionPerformed(ActionEvent e) { |
299 |
lyr = getNodeLayer(); |
300 |
AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
|
301 |
transPanel.openJDialog(); |
302 |
//getMapContext().invalidate();
|
303 |
} |
304 |
} |
305 |
|
306 |
class ZoomAlTemaTocMenuEntry extends TocMenuEntry { |
307 |
private JMenuItem zoom; |
308 |
public void initialize(FPopupMenu m) { |
309 |
super.initialize(m);
|
310 |
if (isTocItemBranch()) {
|
311 |
zoom = new JMenuItem(PluginServices.getText(this, "Zoom_al_Tema")); |
312 |
getMenu().add(zoom); |
313 |
zoom.setFont(FPopupMenu.theFont); |
314 |
|
315 |
zoom.addActionListener(this);
|
316 |
} |
317 |
} |
318 |
/* (non-Javadoc)
|
319 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
320 |
*/
|
321 |
public void actionPerformed(ActionEvent e) { |
322 |
/*FLayer lyr = getNodeLayer();
|
323 |
try {
|
324 |
getMapContext().getViewPort().setExtent(lyr.getFullExtent());
|
325 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
326 |
e1.printStackTrace();
|
327 |
}*/
|
328 |
// 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
|
329 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
330 |
if (actives.length==1) { |
331 |
try {
|
332 |
getMapContext().getViewPort().setExtent(actives[0].getFullExtent());
|
333 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
334 |
e1.printStackTrace(); |
335 |
} |
336 |
} else {
|
337 |
try {
|
338 |
Rectangle2D maxExtent = setMaxExtent(actives);
|
339 |
getMapContext().getViewPort().setExtent(maxExtent); |
340 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
341 |
e1.printStackTrace(); |
342 |
} |
343 |
} |
344 |
} |
345 |
|
346 |
private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException { |
347 |
Rectangle2D extRef = actives[0].getFullExtent(); |
348 |
double minXRef = extRef.getMinX();
|
349 |
double maxYRef = extRef.getMaxY();
|
350 |
double maxXRef = extRef.getMaxX();
|
351 |
double minYRef = extRef.getMinY();
|
352 |
for (int i=0;i<actives.length;i++) { |
353 |
Rectangle2D extVar = actives[i].getFullExtent();
|
354 |
double minXVar = extVar.getMinX();
|
355 |
double maxYVar = extVar.getMaxY();
|
356 |
double maxXVar = extVar.getMaxX();
|
357 |
double minYVar = extVar.getMinY();
|
358 |
if (minXVar<=minXRef) minXRef=minXVar;
|
359 |
if (maxYVar>=maxYRef) maxYRef=maxYVar;
|
360 |
if (maxXVar>=maxXRef) maxXRef=maxXVar;
|
361 |
if (minYVar<=minYRef) minYRef=minYVar;
|
362 |
extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef); |
363 |
} |
364 |
return extRef;
|
365 |
} |
366 |
} |
367 |
|
368 |
class EliminarCapaTocMenuEntry extends TocMenuEntry { |
369 |
private JMenuItem removeLayer; |
370 |
public void initialize(FPopupMenu m) { |
371 |
super.initialize(m);
|
372 |
if (getNodeUserObject() instanceof TocItemBranch) { |
373 |
getMenu().addSeparator(); |
374 |
removeLayer = new JMenuItem(PluginServices.getText(this, "eliminar_capa")); |
375 |
getMenu().add(removeLayer); |
376 |
removeLayer.setFont(FPopupMenu.theFont); |
377 |
removeLayer.addActionListener(this);
|
378 |
} |
379 |
} |
380 |
/* (non-Javadoc)
|
381 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
382 |
*/
|
383 |
public void actionPerformed(ActionEvent e) { |
384 |
// 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
|
385 |
// Es necesario pulsar May?sculas a la vez que el bot?n derecho.
|
386 |
FMap fMap = getMapContext(); |
387 |
FLayer[] actives = fMap.getLayers().getActives();
|
388 |
for (int i = 0; i < actives.length; i++){ |
389 |
try {
|
390 |
getMapContext().getLayers().removeLayer(actives[i]); |
391 |
if (getMapContext().getLayers().getLayersCount()==0) |
392 |
PluginServices.getMainFrame().enableControls(); |
393 |
} catch (CancelationException e1) {
|
394 |
e1.printStackTrace(); |
395 |
} |
396 |
} |
397 |
// 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
|
398 |
/*FLayer lyr = getNodeLayer();
|
399 |
try {
|
400 |
getMapContext().getLayers().removeLayer(lyr);
|
401 |
if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
|
402 |
} catch (CancelationException e1) {
|
403 |
e1.printStackTrace();
|
404 |
}*/
|
405 |
} |
406 |
} |
407 |
|
408 |
/**
|
409 |
* Menu de bot?n derecho para el TOC.
|
410 |
* Se pueden a?adir entradas facilmente desde una extensi?n,
|
411 |
* creando una clase derivando de TocMenuEntry, y a?adiendola en
|
412 |
* est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
|
413 |
* (Las entradas actuales est?n hechas de esa manera).
|
414 |
*
|
415 |
* @author vcn To change the template for this generated type comment go to
|
416 |
* Window>Preferences>Java>Code Generation>Code and
|
417 |
* Comments
|
418 |
*/
|
419 |
|
420 |
public class FPopupMenu extends JPopupMenu { |
421 |
private static ArrayList menuEntrys = null; |
422 |
public DefaultMutableTreeNode nodo; |
423 |
protected FMap mapContext;
|
424 |
//private JMenuItem capa;
|
425 |
// Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
|
426 |
// TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
|
427 |
public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10); |
428 |
|
429 |
static {
|
430 |
menuEntrys = new ArrayList(); |
431 |
menuEntrys.add(new FSymbolChangeColorTocMenuEntry());
|
432 |
menuEntrys.add(new FLyrVectChangeStyleTocMenuEntry());
|
433 |
menuEntrys.add(new FLyrRasterAdjustTransparencyTocMenuEntry());
|
434 |
menuEntrys.add(new ZoomAlTemaTocMenuEntry());
|
435 |
menuEntrys.add(new EliminarCapaTocMenuEntry());
|
436 |
//050201 jmorell: Acceso al men? propiedades.
|
437 |
menuEntrys.add(new FLyrVectEditPropertiesTocMenuEntry());
|
438 |
} |
439 |
|
440 |
public static void addEntry(TocMenuEntry entry) { |
441 |
menuEntrys.add(entry); |
442 |
} |
443 |
|
444 |
/**
|
445 |
* Creates a new FPopupMenu object.
|
446 |
*
|
447 |
* @param nodo DOCUMENT ME!
|
448 |
* @param vista DOCUMENT ME!
|
449 |
*/
|
450 |
public FPopupMenu(FMap mc, DefaultMutableTreeNode node) { |
451 |
//super();
|
452 |
this.mapContext = mc;
|
453 |
this.nodo = node;
|
454 |
|
455 |
//salir = new MenuItem("Salir");
|
456 |
|
457 |
for (int i=0; i<menuEntrys.size(); i++) { |
458 |
((TocMenuEntry) menuEntrys.get(i)).initialize(this);
|
459 |
} |
460 |
} |
461 |
|
462 |
public FMap getMapContext() { return mapContext; } |
463 |
|
464 |
} |