svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FPopupMenu.java @ 5258
History | View | Annotate | Download (29 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.geom.Rectangle2D; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import javax.swing.JColorChooser; |
53 |
import javax.swing.JDialog; |
54 |
import javax.swing.JMenuItem; |
55 |
import javax.swing.JPopupMenu; |
56 |
import javax.swing.tree.DefaultMutableTreeNode; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.cit.gvsig.ProjectExtension; |
60 |
import com.iver.cit.gvsig.fmap.DriverException; |
61 |
import com.iver.cit.gvsig.fmap.FMap; |
62 |
import com.iver.cit.gvsig.fmap.MapControl; |
63 |
import com.iver.cit.gvsig.fmap.ViewPort; |
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.FLayers; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
70 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
71 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
72 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
73 |
import com.iver.cit.gvsig.gui.View; |
74 |
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel; |
75 |
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow; |
76 |
import com.iver.cit.gvsig.project.Project; |
77 |
import com.iver.cit.gvsig.project.ProjectTable; |
78 |
|
79 |
/**
|
80 |
* Realiza el cambio de color si se pulsa OK
|
81 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
82 |
*/
|
83 |
class FSymbolChangeColorTocMenuEntry extends TocMenuEntry { |
84 |
private JMenuItem color; |
85 |
public void initialize(FPopupMenu m) { |
86 |
super.initialize(m);
|
87 |
boolean bShow = false; |
88 |
if (isTocItemBranch())
|
89 |
{ |
90 |
FLayer lyr = getNodeLayer(); |
91 |
if ((lyr instanceof ClassifiableVectorial)) |
92 |
{ |
93 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr; |
94 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
95 |
bShow = true;
|
96 |
} |
97 |
} |
98 |
else
|
99 |
bShow = true;
|
100 |
if (bShow)
|
101 |
{ |
102 |
color = new JMenuItem(PluginServices.getText(this, "Cambio_Color")); |
103 |
color.setFont(FPopupMenu.theFont); |
104 |
getMenu().add(color); |
105 |
getMenu().setEnabled(true);
|
106 |
//Cambio color
|
107 |
color.addActionListener(this);
|
108 |
} |
109 |
} |
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
113 |
*/
|
114 |
public void actionPerformed(ActionEvent e) { |
115 |
ITocItem tocItem = (ITocItem) getNodeUserObject(); |
116 |
|
117 |
Color newColor = JColorChooser.showDialog(null, |
118 |
PluginServices.getText(this, "Elegir_Color"), |
119 |
null);
|
120 |
if (newColor != null) |
121 |
{ |
122 |
if (isTocItemBranch())
|
123 |
{ |
124 |
//FLayer lyr = getNodeLayer();
|
125 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
126 |
for (int i=0;i<actives.length;i++){ |
127 |
if ((actives[i] instanceof ClassifiableVectorial)) |
128 |
{ |
129 |
ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i]; |
130 |
if (lyrVect.getLegend() instanceof SingleSymbolLegend) |
131 |
{ |
132 |
SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend(); |
133 |
leg.getDefaultSymbol().setColor(newColor); |
134 |
} |
135 |
} |
136 |
} |
137 |
} |
138 |
else
|
139 |
{ |
140 |
TocItemLeaf leaf = (TocItemLeaf) tocItem; |
141 |
FSymbol sym = leaf.getSymbol(); |
142 |
sym.setColor(newColor); |
143 |
|
144 |
} |
145 |
// TRUCO PARA REFRESCAR.
|
146 |
getMapContext().invalidate(); |
147 |
|
148 |
} |
149 |
|
150 |
} |
151 |
} |
152 |
/**
|
153 |
* Realiza un cambio de nombre en la capa seleccionada
|
154 |
*
|
155 |
* @author Vicente Caballero Navarro
|
156 |
*/
|
157 |
class ChangeNameTocMenuEntry extends TocMenuEntry { |
158 |
private JMenuItem changename; |
159 |
public void initialize(FPopupMenu m) { |
160 |
super.initialize(m);
|
161 |
//boolean bShow = false;
|
162 |
if (isTocItemBranch())
|
163 |
{ |
164 |
changename = new JMenuItem(PluginServices.getText(this, "cambio_nombre")); |
165 |
changename.setFont(FPopupMenu.theFont); |
166 |
getMenu().add(changename); |
167 |
getMenu().setEnabled(true);
|
168 |
if (getMapContext().getLayers().getActives().length == 1) { |
169 |
changename.setEnabled(true);
|
170 |
} else {
|
171 |
changename.setEnabled(false);
|
172 |
} |
173 |
//Cambio nombre
|
174 |
changename.addActionListener(this);
|
175 |
|
176 |
} |
177 |
} |
178 |
|
179 |
/* (non-Javadoc)
|
180 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
181 |
*/
|
182 |
public void actionPerformed(ActionEvent e) { |
183 |
//ITocItem tocItem = (ITocItem) getNodeUserObject();
|
184 |
if (isTocItemBranch())
|
185 |
{ |
186 |
FLayer lyr = getNodeLayer(); |
187 |
ChangeName chn=new ChangeName(lyr.getName());
|
188 |
PluginServices.getMDIManager().addView(chn); |
189 |
getNodeLayer().setName(chn.getName()); |
190 |
} |
191 |
// TRUCO PARA REFRESCAR.
|
192 |
///getMapContext().invalidate();
|
193 |
|
194 |
} |
195 |
} |
196 |
/**
|
197 |
* Muestra el men? de propiedades del tema.
|
198 |
*
|
199 |
* @author jmorell
|
200 |
*
|
201 |
* TODO To change the template for this generated type comment go to
|
202 |
* Window - Preferences - Java - Code Style - Code Templates
|
203 |
*/
|
204 |
class FLyrVectEditPropertiesTocMenuEntry extends TocMenuEntry { |
205 |
private JMenuItem prop; |
206 |
public void initialize(FPopupMenu m) { |
207 |
super.initialize(m);
|
208 |
FLayer lyr = null;
|
209 |
if (isTocItemBranch()) {
|
210 |
getMenu().addSeparator(); |
211 |
lyr = getNodeLayer(); |
212 |
//if ((lyr instanceof ClassifiableVectorial) && (getMapContext().getLayers().getActives().length == 1)) {
|
213 |
if ((lyr instanceof ClassifiableVectorial)) { |
214 |
prop = new JMenuItem(PluginServices.getText(this, "propiedades")); |
215 |
getMenu().add(prop); |
216 |
prop.setFont(FPopupMenu.theFont); |
217 |
if (getMapContext().getLayers().getActives().length == 1) { |
218 |
prop.setEnabled(true);
|
219 |
} else {
|
220 |
prop.setEnabled(false);
|
221 |
} |
222 |
//Cambio estilo
|
223 |
prop.addActionListener(this);
|
224 |
} |
225 |
} |
226 |
} |
227 |
/* (non-Javadoc)
|
228 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
229 |
*/
|
230 |
public void actionPerformed(ActionEvent e) { |
231 |
/*FThemeManagerWindow fThemeManagerWindow = new FThemeManagerWindow();
|
232 |
try {
|
233 |
fThemeManagerWindow.setMapContext(getMapContext());
|
234 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
235 |
e1.printStackTrace();
|
236 |
}*/
|
237 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
238 |
FThemeManagerWindow fThemeManagerWindow; |
239 |
if (actives.length==1) { |
240 |
System.out.println("openPliegoThemeProperties(): Una sola capa. Abrimos el panel para la capa " + actives[0]); |
241 |
fThemeManagerWindow = new FThemeManagerWindow();
|
242 |
try {
|
243 |
fThemeManagerWindow.setMapContext(getMapContext()); |
244 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
245 |
e1.printStackTrace(); |
246 |
} |
247 |
//PluginServices.getMDIManager().addView(fThemeManagerWindow);
|
248 |
if (PluginServices.getMainFrame() == null) { |
249 |
JDialog dlg = new JDialog(); |
250 |
fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize()); |
251 |
dlg.getContentPane().add(fThemeManagerWindow); |
252 |
dlg.setModal(false);
|
253 |
dlg.pack(); |
254 |
dlg.show(); |
255 |
} else {
|
256 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
257 |
} |
258 |
} else {
|
259 |
for (int i = 0; i < actives.length; i++){ |
260 |
System.out.println("openPliegoThemeProperties(): Muchas capas. Abrimos el panel para la capa " + actives[i]); |
261 |
fThemeManagerWindow = new FThemeManagerWindow(actives[i], getMapContext());
|
262 |
//PluginServices.getMDIManager().addView(fThemeManagerWindow);
|
263 |
if (PluginServices.getMainFrame() == null) { |
264 |
JDialog dlg = new JDialog(); |
265 |
fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize()); |
266 |
dlg.getContentPane().add(fThemeManagerWindow); |
267 |
dlg.setModal(false);
|
268 |
dlg.pack(); |
269 |
dlg.show(); |
270 |
} else {
|
271 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
272 |
} |
273 |
} |
274 |
} |
275 |
/*if (PluginServices.getMainFrame() == null) {
|
276 |
JDialog dlg = new JDialog();
|
277 |
fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
|
278 |
dlg.getContentPane().add(fThemeManagerWindow);
|
279 |
dlg.setModal(false);
|
280 |
dlg.pack();
|
281 |
dlg.show();
|
282 |
} else {
|
283 |
PluginServices.getMDIManager().addView(fThemeManagerWindow);
|
284 |
}*/
|
285 |
} |
286 |
} |
287 |
|
288 |
class FLyrRasterAdjustTransparencyTocMenuEntry extends TocMenuEntry { |
289 |
private JMenuItem transparency; |
290 |
FLayer lyr = null;
|
291 |
public void initialize(FPopupMenu m) { |
292 |
super.initialize(m);
|
293 |
|
294 |
if (isTocItemBranch()) {
|
295 |
lyr = getNodeLayer(); |
296 |
// Opcciones para capas raster
|
297 |
if ((lyr instanceof FLyrRaster)) { |
298 |
transparency = new JMenuItem(PluginServices.getText(this, "adjust_transparency")); |
299 |
getMenu().add( transparency ); |
300 |
transparency.setFont(FPopupMenu.theFont); |
301 |
getMenu().setEnabled(true);
|
302 |
//getMenu().addSeparator();
|
303 |
//Cambio color
|
304 |
transparency.addActionListener(this);
|
305 |
} |
306 |
} |
307 |
} |
308 |
/* (non-Javadoc)
|
309 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
310 |
*/
|
311 |
public void actionPerformed(ActionEvent e) { |
312 |
lyr = getNodeLayer(); |
313 |
AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
|
314 |
transPanel.openJDialog(); |
315 |
//getMapContext().invalidate();
|
316 |
} |
317 |
} |
318 |
|
319 |
class ZoomAlTemaTocMenuEntry extends TocMenuEntry { |
320 |
private JMenuItem zoom; |
321 |
public void initialize(FPopupMenu m) { |
322 |
super.initialize(m);
|
323 |
if (isTocItemBranch()) {
|
324 |
zoom = new JMenuItem(PluginServices.getText(this, "Zoom_a_la_capa")); |
325 |
getMenu().add(zoom); |
326 |
zoom.setFont(FPopupMenu.theFont); |
327 |
|
328 |
zoom.addActionListener(this);
|
329 |
} |
330 |
} |
331 |
/* (non-Javadoc)
|
332 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
333 |
*/
|
334 |
public void actionPerformed(ActionEvent e) { |
335 |
/*FLayer lyr = getNodeLayer();
|
336 |
try {
|
337 |
getMapContext().getViewPort().setExtent(lyr.getFullExtent());
|
338 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
339 |
e1.printStackTrace();
|
340 |
}*/
|
341 |
// 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
|
342 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
343 |
if (actives.length==1) { |
344 |
try {
|
345 |
getMapContext().getViewPort().setExtent(actives[0].getFullExtent());
|
346 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
347 |
e1.printStackTrace(); |
348 |
} |
349 |
} else {
|
350 |
try {
|
351 |
Rectangle2D maxExtent = setMaxExtent(actives);
|
352 |
getMapContext().getViewPort().setExtent(maxExtent); |
353 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
354 |
e1.printStackTrace(); |
355 |
} |
356 |
} |
357 |
} |
358 |
|
359 |
private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException { |
360 |
Rectangle2D extRef = actives[0].getFullExtent(); |
361 |
double minXRef = extRef.getMinX();
|
362 |
double maxYRef = extRef.getMaxY();
|
363 |
double maxXRef = extRef.getMaxX();
|
364 |
double minYRef = extRef.getMinY();
|
365 |
for (int i=0;i<actives.length;i++) { |
366 |
Rectangle2D extVar = actives[i].getFullExtent();
|
367 |
double minXVar = extVar.getMinX();
|
368 |
double maxYVar = extVar.getMaxY();
|
369 |
double maxXVar = extVar.getMaxX();
|
370 |
double minYVar = extVar.getMinY();
|
371 |
if (minXVar<=minXRef) minXRef=minXVar;
|
372 |
if (maxYVar>=maxYRef) maxYRef=maxYVar;
|
373 |
if (maxXVar>=maxXRef) maxXRef=maxXVar;
|
374 |
if (minYVar<=minYRef) minYRef=minYVar;
|
375 |
extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef); |
376 |
} |
377 |
return extRef;
|
378 |
} |
379 |
} |
380 |
|
381 |
class EliminarCapaTocMenuEntry extends TocMenuEntry { |
382 |
private JMenuItem removeLayer; |
383 |
public void initialize(FPopupMenu m) { |
384 |
super.initialize(m);
|
385 |
if (getNodeUserObject() instanceof TocItemBranch) { |
386 |
removeLayer = new JMenuItem(PluginServices.getText(this, "eliminar_capa")); |
387 |
removeLayer.setFont(FPopupMenu.theFont); |
388 |
removeLayer.addActionListener(this);
|
389 |
getMenu().addSeparator(); |
390 |
getMenu().add(removeLayer); |
391 |
getMenu().addSeparator(); |
392 |
} |
393 |
} |
394 |
/* (non-Javadoc)
|
395 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
396 |
*/
|
397 |
public void actionPerformed(ActionEvent e) { |
398 |
// 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
|
399 |
// Es necesario pulsar May?sculas a la vez que el bot?n derecho.
|
400 |
FMap fMap = getMapContext(); |
401 |
FLayer[] actives = fMap.getLayers().getActives();
|
402 |
for (int i = actives.length-1; i>=0; i--){ |
403 |
try {
|
404 |
actives[i].getParentLayer().removeLayer(actives[i]); |
405 |
FLayers lyrs=getMapContext().getLayers(); |
406 |
lyrs.addLayer(actives[i]); |
407 |
actives[i].getParentLayer().removeLayer(actives[i]); |
408 |
|
409 |
if (actives[i] instanceof AlphanumericData){ |
410 |
Project project = ((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject(); |
411 |
ProjectTable pt = project.getTable((AlphanumericData) actives[i]); |
412 |
|
413 |
ArrayList tables = project.getTables();
|
414 |
for (int j = 0; j < tables.size(); j++) { |
415 |
if (tables.get(j) == pt){
|
416 |
project.delTable(j); |
417 |
break;
|
418 |
} |
419 |
} |
420 |
|
421 |
PluginServices.getMDIManager().closeSingletonView(pt); |
422 |
} |
423 |
|
424 |
if (getMapContext().getLayers().getLayersCount()==0) |
425 |
PluginServices.getMainFrame().enableControls(); |
426 |
} catch (CancelationException e1) {
|
427 |
e1.printStackTrace(); |
428 |
} |
429 |
} |
430 |
// 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
|
431 |
/*FLayer lyr = getNodeLayer();
|
432 |
try {
|
433 |
getMapContext().getLayers().removeLayer(lyr);
|
434 |
if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
|
435 |
} catch (CancelationException e1) {
|
436 |
e1.printStackTrace();
|
437 |
}*/
|
438 |
} |
439 |
} |
440 |
/**
|
441 |
* Realiza una agrupaci?n de capas, a partir de las capas que se encuentren activas.
|
442 |
*
|
443 |
* @author Vicente Caballero Navarro
|
444 |
*/
|
445 |
class LayersGroupTocMenuEntry extends TocMenuEntry { |
446 |
private JMenuItem agrupar; |
447 |
public void initialize(FPopupMenu m) { |
448 |
super.initialize(m);
|
449 |
if (isTocItemBranch()) {
|
450 |
agrupar = new JMenuItem(PluginServices.getText(this, "agrupar_capas")); |
451 |
agrupar.setFont(FPopupMenu.theFont); |
452 |
getMenu().add(agrupar); |
453 |
getMenu().setEnabled(true);
|
454 |
if (getMapContext().getLayers().getActives().length > 1) { |
455 |
agrupar.setEnabled(true);
|
456 |
} else {
|
457 |
agrupar.setEnabled(false);
|
458 |
} |
459 |
agrupar.addActionListener(this);
|
460 |
} |
461 |
} |
462 |
|
463 |
/* (non-Javadoc)
|
464 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
465 |
*/
|
466 |
public void actionPerformed(ActionEvent e) { |
467 |
//ITocItem tocItem = (ITocItem) getNodeUserObject();
|
468 |
ChangeName changename=new ChangeName(null); |
469 |
PluginServices.getMDIManager().addView(changename); |
470 |
String nombre=changename.getName();
|
471 |
|
472 |
if (nombre != null){ |
473 |
if (isTocItemBranch()){
|
474 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
475 |
|
476 |
if (actives.length>1) { |
477 |
|
478 |
FLayers layerGroup=new FLayers(getMapContext(),getNodeLayer().getParentLayer());
|
479 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
480 |
theView.getMapControl().getMapContext().getLayers() |
481 |
.addLayer(layerGroup); |
482 |
for (int i=0;i<actives.length;i++){ |
483 |
|
484 |
if(actives[i] instanceof FLyrRaster) |
485 |
((FLyrRaster)actives[i]).setRemoveRasterFlag(false);
|
486 |
|
487 |
actives[i].getParentLayer().removeLayer(actives[i]); |
488 |
layerGroup.addLayer(actives[i]); |
489 |
} |
490 |
layerGroup.setName(nombre); |
491 |
|
492 |
|
493 |
} |
494 |
|
495 |
} |
496 |
// TRUCO PARA REFRESCAR.
|
497 |
getMapContext().invalidate(); |
498 |
} |
499 |
} |
500 |
} |
501 |
/**
|
502 |
* Realiza una desagrupaci?n de capas, a partir de las capas que se encuentren activas.
|
503 |
*
|
504 |
* @author Vicente Caballero Navarro
|
505 |
*/
|
506 |
class LayersUngroupTocMenuEntry extends TocMenuEntry { |
507 |
private JMenuItem desagrupar; |
508 |
public void initialize(FPopupMenu m) { |
509 |
super.initialize(m);
|
510 |
if (isTocItemBranch()) {
|
511 |
boolean isFLayers=true; |
512 |
if (isTocItemBranch()){
|
513 |
FLayer lyr = getNodeLayer(); |
514 |
if (!(lyr instanceof FLayers)){ |
515 |
isFLayers=false;
|
516 |
} |
517 |
} |
518 |
if (isFLayers){
|
519 |
desagrupar = new JMenuItem(PluginServices.getText(this, "desagrupar_capas")); |
520 |
desagrupar.setFont(FPopupMenu.theFont); |
521 |
getMenu().add(desagrupar); |
522 |
getMenu().setEnabled(true);
|
523 |
desagrupar.addActionListener(this);
|
524 |
} |
525 |
} |
526 |
} |
527 |
|
528 |
/* (non-Javadoc)
|
529 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
530 |
*/
|
531 |
public void actionPerformed(ActionEvent e) { |
532 |
//ITocItem tocItem = (ITocItem) getNodeUserObject();
|
533 |
if (isTocItemBranch()){
|
534 |
FLayers agrupa = (FLayers)getNodeLayer(); |
535 |
FLayers parent=agrupa.getParentLayer(); |
536 |
if (parent!=null){ |
537 |
for (int j=0;j<agrupa.getLayersCount();j++){ |
538 |
parent.addLayer(agrupa.getLayer(j)); |
539 |
} |
540 |
parent.removeLayer(agrupa); |
541 |
} |
542 |
} |
543 |
// TRUCO PARA REFRESCAR.
|
544 |
getMapContext().invalidate(); |
545 |
|
546 |
|
547 |
|
548 |
} |
549 |
} |
550 |
/**
|
551 |
* Cambia la posici?n actual del layer a la primera posici?n.
|
552 |
*
|
553 |
* @author Vicente Caballero Navarro
|
554 |
*/
|
555 |
class FirstLayerTocMenuEntry extends TocMenuEntry { |
556 |
private JMenuItem first; |
557 |
public void initialize(FPopupMenu m) { |
558 |
super.initialize(m);
|
559 |
if (isTocItemBranch()) {
|
560 |
first = new JMenuItem(PluginServices.getText(this, "colocar_delante")); |
561 |
first.setFont(FPopupMenu.theFont); |
562 |
getMenu().add(first); |
563 |
getMenu().setEnabled(true);
|
564 |
first.addActionListener(this);
|
565 |
} |
566 |
} |
567 |
|
568 |
/* (non-Javadoc)
|
569 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
570 |
*/
|
571 |
public void actionPerformed(ActionEvent e) { |
572 |
ITocItem tocItem = (ITocItem) getNodeUserObject(); |
573 |
|
574 |
if (isTocItemBranch()){
|
575 |
if (getMapContext().getLayers().getActives().length == 1) { |
576 |
FLayer layer=((TocItemBranch)tocItem).getLayer(); |
577 |
FLayers layers=layer.getParentLayer(); |
578 |
for (int i=0;i<layers.getLayersCount();i++){ |
579 |
if(layers.getLayer(i).equals(layer)){
|
580 |
layers.removeLayer(i); |
581 |
layers.addLayer(layer); |
582 |
} |
583 |
} |
584 |
} else if (getMapContext().getLayers().getActives().length > 1) { |
585 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
586 |
FLayers layers=actives[0].getParentLayer();
|
587 |
//FLayers layerGroup=new FLayers(getMapContext(),getNodeLayer().getParentLayer());
|
588 |
for (int i=0;i<actives.length;i++){ |
589 |
for (int j=0;j<layers.getLayersCount();j++){ |
590 |
if(layers.getLayer(j).equals(actives[i])){
|
591 |
layers.removeLayer(j); |
592 |
layers.addLayer(actives[i]); |
593 |
} |
594 |
} |
595 |
} |
596 |
} |
597 |
} |
598 |
// TRUCO PARA REFRESCAR.
|
599 |
getMapContext().invalidate(); |
600 |
} |
601 |
} |
602 |
/**
|
603 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
604 |
*
|
605 |
* Entrada de men? para la activaci?n de la funcionalidad de zoom a un
|
606 |
* pixel.
|
607 |
*/
|
608 |
class ZoomPixelTocMenuEntry extends TocMenuEntry { |
609 |
public static final int ZOOM_TO_IMAGE_CENTER = 0x1; |
610 |
public static final int ZOOM_TO_VIEW_CENTER = 0x2; |
611 |
private JMenuItem properties; |
612 |
FLayer lyr = null;
|
613 |
public int zoomType = ZOOM_TO_VIEW_CENTER; |
614 |
|
615 |
public void initialize(FPopupMenu m) { |
616 |
super.initialize(m);
|
617 |
|
618 |
if (isTocItemBranch()) {
|
619 |
lyr = getNodeLayer(); |
620 |
// Opcciones para capas raster
|
621 |
if ((lyr instanceof FLyrRaster)) { |
622 |
properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel")); |
623 |
getMenu().add( properties ); |
624 |
properties.setFont(FPopupMenu.theFont); |
625 |
getMenu().setEnabled(true);
|
626 |
|
627 |
properties.addActionListener(this);
|
628 |
} |
629 |
} |
630 |
} |
631 |
|
632 |
public void actionPerformed(ActionEvent e) { |
633 |
|
634 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
635 |
if (actives.length==1) { |
636 |
try {
|
637 |
Rectangle2D r = actives[0].getFullExtent(); |
638 |
|
639 |
ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes(); |
640 |
int width = 0, height = 0; |
641 |
for (int i=0; i<attr.size(); i++) { |
642 |
Object[] a = (Object []) attr.get(i); |
643 |
if (a[0].toString().equals("Width")) |
644 |
width = ((Integer)a[1]).intValue(); |
645 |
if (a[0].toString().equals("Height")) |
646 |
height = ((Integer)a[1]).intValue(); |
647 |
} |
648 |
ViewPort v = getMapContext().getViewPort(); |
649 |
|
650 |
if (zoomType == ZOOM_TO_IMAGE_CENTER) {
|
651 |
//A centro de imagen
|
652 |
/*double centroX = width/2;
|
653 |
double centroY = height/2;
|
654 |
int minX = (int)Math.round(centroX - (v.getImageWidth()/2));
|
655 |
int minY = (int)Math.round(centroY - (v.getImageHeight()/2));
|
656 |
int maxX = (int)Math.round(minX + v.getImageWidth());
|
657 |
int maxY = (int)Math.round(minY + v.getImageHeight());
|
658 |
double wcOriginWidth = r.getMaxX() - r.getMinX();
|
659 |
double wcOriginHeight = r.getMaxY() - r.getMinY();
|
660 |
|
661 |
double wcDstMinX = r.getMinX()+((minX*wcOriginWidth)/width);
|
662 |
double wcDstMinY = r.getMinY()+((minY*wcOriginHeight)/height);
|
663 |
double wcDstMaxX = r.getMinX()+((maxX*wcOriginWidth)/width);
|
664 |
double wcDstMaxY = r.getMinY()+((maxY*wcOriginHeight)/height);
|
665 |
|
666 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
667 |
double wcDstHeight = wcDstMaxY - wcDstMinY;*/
|
668 |
} else if (zoomType == ZOOM_TO_VIEW_CENTER) { |
669 |
//A centro de vista
|
670 |
double wcOriginCenterX = v.getExtent().getMinX()+((v.getExtent().getMaxX()-v.getExtent().getMinX())/2); |
671 |
double wcOriginCenterY = v.getExtent().getMinY()+((v.getExtent().getMaxY()-v.getExtent().getMinY())/2); |
672 |
|
673 |
//Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
|
674 |
double relacionPixelWcWidth = (r.getMaxX() - r.getMinX())/width;
|
675 |
double relacionPixelWcHeight = (r.getMaxY() - r.getMinY())/height;
|
676 |
//double desplazamientoX = r.getMinX();
|
677 |
//double desplazamientoY = r.getMinY();
|
678 |
|
679 |
double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2); |
680 |
double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2); |
681 |
|
682 |
double wcDstMinX = wcOriginX;
|
683 |
double wcDstMinY = wcOriginY;
|
684 |
double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
|
685 |
double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
|
686 |
|
687 |
double wcDstWidth = wcDstMaxX - wcDstMinX;
|
688 |
double wcDstHeight = wcDstMaxY - wcDstMinY;
|
689 |
|
690 |
r = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight); |
691 |
getMapContext().getViewPort().setExtent(r); |
692 |
} |
693 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
694 |
e1.printStackTrace(); |
695 |
} |
696 |
} |
697 |
//View vista = (View) PluginServices.getMDIManager().getActiveView();
|
698 |
//MapControl mapCtrl = vista.getMapControl();
|
699 |
} |
700 |
} |
701 |
|
702 |
/**
|
703 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
704 |
*
|
705 |
* Entrada de men? para la activaci?n de la funcionalidad de zoom a un
|
706 |
* pixel centrado en el cursor.
|
707 |
*/
|
708 |
class ZoomPixelCursorTocMenuEntry extends TocMenuEntry { |
709 |
public static final int ZOOM_TO_IMAGE_CENTER = 0x1; |
710 |
public static final int ZOOM_TO_VIEW_CENTER = 0x2; |
711 |
private JMenuItem properties; |
712 |
FLayer lyr = null;
|
713 |
public int zoomType = ZOOM_TO_VIEW_CENTER; |
714 |
|
715 |
public void initialize(FPopupMenu m) { |
716 |
super.initialize(m);
|
717 |
|
718 |
if (isTocItemBranch()) {
|
719 |
lyr = getNodeLayer(); |
720 |
// Opcciones para capas raster
|
721 |
if ((lyr instanceof FLyrRaster)) { |
722 |
properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel")); |
723 |
getMenu().add( properties ); |
724 |
properties.setFont(FPopupMenu.theFont); |
725 |
getMenu().setEnabled(true);
|
726 |
properties.addActionListener(this);
|
727 |
} |
728 |
} |
729 |
} |
730 |
|
731 |
public void actionPerformed(ActionEvent e) { |
732 |
|
733 |
FLayer[] actives = getMapContext().getLayers().getActives();
|
734 |
if (actives.length==1) { |
735 |
|
736 |
lyr = getNodeLayer(); |
737 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
738 |
MapControl mapCtrl = vista.getMapControl(); |
739 |
mapCtrl.setTool("zoom_pixel_cursor");
|
740 |
|
741 |
} |
742 |
//View vista = (View) PluginServices.getMDIManager().getActiveView();
|
743 |
//MapControl mapCtrl = vista.getMapControl();
|
744 |
} |
745 |
} |
746 |
|
747 |
/**
|
748 |
*
|
749 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
750 |
*
|
751 |
* Entrada de men? para la activaci?n de la funcionalidad de salvar
|
752 |
* a raster una parte de la vista.
|
753 |
*/
|
754 |
class SaveRasterTocMenuEntry extends TocMenuEntry{ |
755 |
private JMenuItem properties; |
756 |
FLayer lyr = null;
|
757 |
|
758 |
public void initialize(FPopupMenu m) { |
759 |
super.initialize(m);
|
760 |
|
761 |
if (isTocItemBranch()) {
|
762 |
lyr = getNodeLayer(); |
763 |
// Opcciones para capas raster
|
764 |
if ((lyr instanceof FLyrRaster)) { |
765 |
properties = new JMenuItem(PluginServices.getText(this, "salvar_raster")); |
766 |
getMenu().add( properties ); |
767 |
properties.setFont(FPopupMenu.theFont); |
768 |
getMenu().setEnabled(true);
|
769 |
//getMenu().addSeparator();
|
770 |
//Cambio color
|
771 |
properties.addActionListener(this);
|
772 |
} |
773 |
} |
774 |
} |
775 |
|
776 |
public void actionPerformed(ActionEvent e) { |
777 |
lyr = getNodeLayer(); |
778 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
779 |
MapControl mapCtrl = vista.getMapControl(); |
780 |
mapCtrl.setTool("saveRaster");
|
781 |
} |
782 |
} |
783 |
|
784 |
/**
|
785 |
* Menu de bot?n derecho para el TOC.
|
786 |
* Se pueden a?adir entradas facilmente desde una extensi?n,
|
787 |
* creando una clase derivando de TocMenuEntry, y a?adiendola en
|
788 |
* est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
|
789 |
* (Las entradas actuales est?n hechas de esa manera).
|
790 |
*
|
791 |
* @author vcn To change the template for this generated type comment go to
|
792 |
* Window>Preferences>Java>Code Generation>Code and
|
793 |
* Comments
|
794 |
*/
|
795 |
|
796 |
public class FPopupMenu extends JPopupMenu { |
797 |
private static ArrayList menuEntrys = new ArrayList(); |
798 |
public DefaultMutableTreeNode nodo; |
799 |
protected FMap mapContext;
|
800 |
//private JMenuItem capa;
|
801 |
// Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
|
802 |
// TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
|
803 |
public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10); |
804 |
|
805 |
static {
|
806 |
FPopupMenu.addEntry(new FSymbolChangeColorTocMenuEntry());
|
807 |
FPopupMenu.addEntry(new ChangeNameTocMenuEntry());
|
808 |
menuEntrys.add(new FLyrVectEditPropertiesTocMenuEntry());
|
809 |
//FPopupMenu.addEntry(new FLyrRasterAdjustTransparencyTocMenuEntry());
|
810 |
FPopupMenu.addEntry(new ZoomAlTemaTocMenuEntry());
|
811 |
//FPopupMenu.addEntry(new ZoomPixelTocMenuEntry());
|
812 |
FPopupMenu.addEntry(new ZoomPixelCursorTocMenuEntry());
|
813 |
FPopupMenu.addEntry(new EliminarCapaTocMenuEntry());
|
814 |
menuEntrys.add(new LayersGroupTocMenuEntry());
|
815 |
menuEntrys.add(new LayersUngroupTocMenuEntry());
|
816 |
menuEntrys.add(new FirstLayerTocMenuEntry());
|
817 |
FPopupMenu.addEntry(new FLyrRasterAdjustPropertiesTocMenuEntry());
|
818 |
} |
819 |
|
820 |
public static void addEntry(TocMenuEntry entry) { |
821 |
menuEntrys.add(entry); |
822 |
} |
823 |
|
824 |
public static Object getEntry(String className) { |
825 |
for(int i=0;i<menuEntrys.size();i++){ |
826 |
if(menuEntrys.get(i).getClass().getName().endsWith(className)){
|
827 |
return menuEntrys.get(i);
|
828 |
} |
829 |
} |
830 |
return null; |
831 |
} |
832 |
|
833 |
/**
|
834 |
* Creates a new FPopupMenu object.
|
835 |
*
|
836 |
* @param nodo DOCUMENT ME!
|
837 |
* @param vista DOCUMENT ME!
|
838 |
*/
|
839 |
public FPopupMenu(FMap mc, DefaultMutableTreeNode node) { |
840 |
//super();
|
841 |
this.mapContext = mc;
|
842 |
this.nodo = node;
|
843 |
|
844 |
//salir = new MenuItem("Salir");
|
845 |
|
846 |
for (int i=0; i<menuEntrys.size(); i++) { |
847 |
((TocMenuEntry) menuEntrys.get(i)).initialize(this);
|
848 |
} |
849 |
} |
850 |
|
851 |
public FMap getMapContext() { return mapContext; } |
852 |
|
853 |
} |