Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FPopupMenu.java @ 2262

History | View | Annotate | Download (28.9 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 org.cresques.io.GeoRasterFile;
59
import org.cresques.io.raster.RasterFilterStackManager;
60
import org.cresques.ui.raster.BandSetupPanel;
61
import org.cresques.ui.raster.EnhancedPanel;
62
import org.cresques.ui.raster.FilterRasterDialogPanel;
63
import org.cresques.ui.raster.RasterTransparencyPanel;
64

    
65
import com.iver.andami.PluginServices;
66
import com.iver.cit.gvsig.fmap.DriverException;
67
import com.iver.cit.gvsig.fmap.FMap;
68
import com.iver.cit.gvsig.fmap.MapControl;
69
import com.iver.cit.gvsig.fmap.ViewPort;
70
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
71
import com.iver.cit.gvsig.fmap.layers.CancelationException;
72
import com.iver.cit.gvsig.fmap.layers.FLayer;
73
import com.iver.cit.gvsig.fmap.layers.FLayers;
74
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
75
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
76
import com.iver.cit.gvsig.fmap.layers.RasterAdapter;
77
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
78
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
79
import com.iver.cit.gvsig.gui.View;
80
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel;
81
import com.iver.cit.gvsig.gui.Panels.PropertiesRasterDialog;
82
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow;
83

    
84
/**
85
 * Realiza el cambio de color si se pulsa OK
86
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
87
 */
88
class FSymbolChangeColorTocMenuEntry extends TocMenuEntry {
89
    private JMenuItem color;    
90
        public void initialize(FPopupMenu m) {
91
                super.initialize(m);
92
                boolean bShow = false;
93
                if (isTocItemBranch())
94
                {
95
                        FLayer lyr = getNodeLayer();
96
                    if ((lyr instanceof ClassifiableVectorial))
97
                    {
98
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr;
99
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend)
100
                            bShow = true;
101
                    }
102
                }
103
                else
104
                    bShow = true;
105
                if (bShow)
106
                {
107
                color = new JMenuItem(PluginServices.getText(this, "Cambio_Color"));
108
                color.setFont(FPopupMenu.theFont);
109
                getMenu().add(color);        
110
                getMenu().setEnabled(true);
111
                //Cambio color
112
                color.addActionListener(this);
113
                }
114
        }
115
        
116
        /* (non-Javadoc)
117
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
118
         */
119
        public void actionPerformed(ActionEvent e) {
120
                ITocItem tocItem = (ITocItem) getNodeUserObject();
121
        
122
        Color newColor = JColorChooser.showDialog(null,                
123
                PluginServices.getText(this, "Elegir_Color"),
124
                null);
125
        if (newColor != null)
126
        {
127
                        if (isTocItemBranch())
128
                        {
129
                                FLayer lyr = getNodeLayer();
130
                            if ((lyr instanceof ClassifiableVectorial))
131
                            {
132
                                ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr;
133
                                if (lyrVect.getLegend() instanceof SingleSymbolLegend)
134
                                {
135
                                    SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend();
136
                        leg.getDefaultSymbol().setColor(newColor);
137
                    } 
138
                            }
139
                        }
140
                        else
141
                        {
142
                    TocItemLeaf leaf = (TocItemLeaf) tocItem;
143
                    FSymbol sym = leaf.getSymbol();
144
                    sym.setColor(newColor);
145
                                                
146
                        }
147
                // TRUCO PARA REFRESCAR.
148
                getMapContext().invalidate();                    
149

    
150
        }
151
        
152
        }
153
}
154
/**
155
 * Realiza un cambio de nombre en la capa seleccionada
156
 * 
157
 * @author Vicente Caballero Navarro
158
 */
159
class ChangeNameTocMenuEntry extends TocMenuEntry {
160
    private JMenuItem changename;    
161
        public void initialize(FPopupMenu m) {
162
                super.initialize(m);
163
                boolean bShow = false;
164
                if (isTocItemBranch())
165
                {
166
                        changename = new JMenuItem(PluginServices.getText(this, "cambio_nombre"));
167
                changename.setFont(FPopupMenu.theFont);
168
                getMenu().add(changename);        
169
                getMenu().setEnabled(true);
170
                //Cambio nombre
171
                changename.addActionListener(this);
172
                    
173
                }
174
        }
175
        
176
        /* (non-Javadoc)
177
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
178
         */
179
        public void actionPerformed(ActionEvent e) {
180
                ITocItem tocItem = (ITocItem) getNodeUserObject();
181
                if (isTocItemBranch())
182
                        {
183
                                FLayer lyr = getNodeLayer();
184
                                ChangeName chn=new ChangeName(lyr.getName());
185
                                PluginServices.getMDIManager().addView(chn);
186
                                 getNodeLayer().setName(chn.getName());
187
                        }
188
                // TRUCO PARA REFRESCAR.
189
                ///getMapContext().invalidate();                    
190

    
191
   }
192
}
193
/**
194
 * Muestra el men? de propiedades del tema.
195
 * 
196
 * @author jmorell
197
 *
198
 * TODO To change the template for this generated type comment go to
199
 * Window - Preferences - Java - Code Style - Code Templates
200
 */
201
class FLyrVectEditPropertiesTocMenuEntry extends TocMenuEntry {
202
    private JMenuItem prop;
203
        public void initialize(FPopupMenu m) {
204
                super.initialize(m);
205
                FLayer lyr = null;
206
                if (isTocItemBranch()) {
207
                        getMenu().addSeparator();
208
                        lyr = getNodeLayer();
209
                        if (lyr instanceof ClassifiableVectorial) {
210
                            prop = new JMenuItem(PluginServices.getText(this, "Cambio_Estilo"));
211
                                getMenu().add(prop);
212
                                prop.setFont(FPopupMenu.theFont);
213
                                //Cambio estilo
214
                                prop.addActionListener(this);
215
                        }
216
                }
217
        }
218
        /* (non-Javadoc)
219
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
220
         */
221
        public void actionPerformed(ActionEvent e) {
222
                /*FThemeManagerWindow fThemeManagerWindow = new FThemeManagerWindow();
223
                try {
224
                        fThemeManagerWindow.setMapContext(getMapContext());
225
                } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
226
                        e1.printStackTrace();
227
                }*/
228
                FLayer[] actives = getMapContext().getLayers().getActives();
229
                FThemeManagerWindow fThemeManagerWindow;
230
            if (actives.length==1) {
231
                    System.out.println("openPliegoThemeProperties(): Una sola capa. Abrimos el panel para la capa " + actives[0]);
232
                    fThemeManagerWindow = new FThemeManagerWindow();
233
                    try {
234
                            fThemeManagerWindow.setMapContext(getMapContext());
235
                    } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
236
                            e1.printStackTrace();
237
                    }
238
            //PluginServices.getMDIManager().addView(fThemeManagerWindow);
239
                    if (PluginServices.getMainFrame() == null) {
240
                            JDialog dlg = new JDialog();
241
                            fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
242
                            dlg.getContentPane().add(fThemeManagerWindow);
243
                            dlg.setModal(false);                        
244
                            dlg.pack();
245
                            dlg.show();
246
                    } else {
247
                            PluginServices.getMDIManager().addView(fThemeManagerWindow);
248
                    }
249
            } else {
250
                for (int i = 0; i < actives.length; i++){
251
                        System.out.println("openPliegoThemeProperties(): Muchas capas. Abrimos el panel para la capa " + actives[i]);
252
                        fThemeManagerWindow = new FThemeManagerWindow(actives[i], getMapContext());
253
                //PluginServices.getMDIManager().addView(fThemeManagerWindow);
254
                        if (PluginServices.getMainFrame() == null) {
255
                                JDialog dlg = new JDialog();
256
                                fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
257
                                dlg.getContentPane().add(fThemeManagerWindow);
258
                                dlg.setModal(false);                        
259
                                dlg.pack();
260
                                dlg.show();
261
                        } else {
262
                                PluginServices.getMDIManager().addView(fThemeManagerWindow);
263
                        }
264
                }
265
            }
266
                /*if (PluginServices.getMainFrame() == null) {
267
                        JDialog dlg = new JDialog();
268
                        fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
269
                        dlg.getContentPane().add(fThemeManagerWindow);
270
                        dlg.setModal(false);                        
271
                        dlg.pack();
272
                        dlg.show();
273
                } else {
274
                        PluginServices.getMDIManager().addView(fThemeManagerWindow);
275
                }*/
276
        }
277
}
278

    
279
class FLyrRasterAdjustTransparencyTocMenuEntry extends TocMenuEntry {
280
        private JMenuItem transparency;
281
        FLayer lyr = null;
282
        public void initialize(FPopupMenu m) {
283
                super.initialize(m);
284
                
285
                if (isTocItemBranch()) {
286
                        lyr = getNodeLayer();
287
                    // Opcciones para capas raster
288
                    if ((lyr instanceof FLyrRaster)) {
289
                        transparency = new JMenuItem(PluginServices.getText(this, "adjust_transparency"));
290
                            getMenu().add( transparency );
291
                            transparency.setFont(FPopupMenu.theFont);
292
                            getMenu().setEnabled(true);
293
                            //getMenu().addSeparator();
294
                    //Cambio color
295
                    transparency.addActionListener(this);
296
                     }
297
                }
298
        }
299
        /* (non-Javadoc)
300
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
301
         */
302
        public void actionPerformed(ActionEvent e) {
303
               lyr = getNodeLayer();
304
        AdjustTransparencyPanel transPanel = new AdjustTransparencyPanel((FLyrDefault) lyr);
305
                transPanel.openJDialog();
306
        //getMapContext().invalidate();                    
307
        }
308
}
309

    
310
class FLyrRasterAdjustPropertiesTocMenuEntry extends TocMenuEntry {
311
        private JMenuItem                                 properties;
312
        FLayer                                                         lyr = null;
313
        private PropertiesRasterDialog        propsDialog = null;
314
        private BandSetupPanel                         bandSetup = null;
315

    
316
        
317
        public void initialize(FPopupMenu m) {
318
                super.initialize(m);
319
                
320
                if (isTocItemBranch()) {
321
                        lyr = getNodeLayer();
322
                    // Opcciones para capas raster
323
                    if ((lyr instanceof FLyrRaster)) {
324
                            properties = new JMenuItem(PluginServices.getText(this, "propiedades_raster"));
325
                            getMenu().add( properties );
326
                            properties.setFont(FPopupMenu.theFont);
327
                            getMenu().setEnabled(true);
328
                            //getMenu().addSeparator();
329
                    //Cambio color
330
                            properties.addActionListener(this);
331
                     }
332
                }
333
        }
334
        
335
        /**
336
         * Gestiona la apertura del dialogo de propiedades de raster cuando se pulsa
337
         * la opci?n asignando a este las propiedades iniciales. 
338
         */
339
        public void actionPerformed(ActionEvent e) {
340
               lyr = getNodeLayer();
341
                   
342
               if(lyr instanceof FLyrRaster){
343
                       RasterFilterStackManager         stackManager = null;
344
       
345
                       stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
346
                                              
347
                       int[][] rangeR = stackManager.getTransparecyR();
348
                       int[][] rangeG = stackManager.getTransparecyG();
349
                       int[][] rangeB = stackManager.getTransparecyB();
350
                       
351
                       propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), rangeR, rangeG, rangeB);
352
                                              
353
                        int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency();
354
                        
355
                        bandSetup = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getBandSetup();
356
                        GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
357
                        bandSetup.addFiles(files);
358
                        for(int i=0; i< files.length;i++)
359
                                propsDialog.addNumBands(files[i].getBandCount());
360
                        
361
                        RasterAdapter rad = ((FLyrRaster)lyr).getSource();
362
                        int posR = 0, posG = 0, posB = 0;
363
                        
364
                        for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++)
365
                                posR += files[i].getBandCount();
366
                        posR += rad.getBand(GeoRasterFile.RED_BAND);
367
                        
368
                        for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++)
369
                                posG += files[i].getBandCount();
370
                        posG += rad.getBand(GeoRasterFile.GREEN_BAND);
371
                        
372
                        for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++)
373
                                posB += files[i].getBandCount();
374
                        posB += rad.getBand(GeoRasterFile.BLUE_BAND);
375
                        
376
                        bandSetup.assignBand(posR, GeoRasterFile.RED_BAND);
377
                        bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND);
378
                        bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND);        
379
                                                                        
380
                        //Asignaci?n del alpha actual de la imagen al dialogo
381
                        RasterTransparencyPanel rasterTrans = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getTransparencyPanel();
382
                        rasterTrans.setOpacity(alpha);
383
                                
384
                        //Asignaci?n del porcentaje de recorte actual de la imagen al dialogo
385
                        EnhancedPanel pEnhan =  ((FilterRasterDialogPanel)propsDialog.getContentPane()).getEnhancedPanel();
386
                        
387
                        propsDialog.setRasterFilterStackManager(stackManager);
388
                        
389
                        ArrayList stackList = stackManager.getStringsFromStack();
390
                        boolean remove = false;
391
                        for(int i=0;i<stackList.size();i++){
392
                                //System.out.println("*=>"+((String)stackList.get(i)));
393
                                if(((String)stackList.get(i)).startsWith("filter.tail.value")){
394
                                        int tail = (int)(Double.parseDouble(stackManager.getValue((String)stackList.get(i)))*200);
395
                                        pEnhan.setPercentTail(tail);
396
                                }
397
                                if(((String)stackList.get(i)).startsWith("filter.tail.remove"))
398
                                        remove = Boolean.valueOf(stackManager.getValue((String)stackList.get(i))).booleanValue();
399
                                
400
                                if(((String)stackList.get(i)).startsWith("filter.enhanced.remove"))
401
                                        remove = Boolean.valueOf(stackManager.getValue((String)stackList.get(i))).booleanValue();
402
                        }
403
                        
404
                        if(stackManager.isActive(stackManager.getTypeFilter("enhanced"))){
405
                                if(remove)
406
                                        pEnhan.setSelectedFilter(1);
407
                                else
408
                                        pEnhan.setSelectedFilter(2);
409
                        }else
410
                                pEnhan.setSelectedFilter(0);
411
                                                                                
412
                        propsDialog.readStat();
413
                        
414
                       PluginServices.getMDIManager().addView(propsDialog);
415
        }
416
        }
417
}
418

    
419
class ZoomAlTemaTocMenuEntry extends TocMenuEntry {
420
    private JMenuItem zoom;
421
        public void initialize(FPopupMenu m) {
422
                super.initialize(m);
423
                if (isTocItemBranch()) {
424
                        zoom = new JMenuItem(PluginServices.getText(this, "Zoom_al_Tema"));
425
                        getMenu().add(zoom);
426
                        zoom.setFont(FPopupMenu.theFont);
427
            
428
                zoom.addActionListener(this);
429
                }
430
        }
431
        /* (non-Javadoc)
432
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
433
         */
434
        public void actionPerformed(ActionEvent e) {
435
            /*FLayer lyr = getNodeLayer();
436
        try {
437
                getMapContext().getViewPort().setExtent(lyr.getFullExtent());
438
                } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
439
                        e1.printStackTrace();
440
                }*/
441
                // 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
442
                FLayer[] actives = getMapContext().getLayers().getActives();
443
                if (actives.length==1) {
444
                try {
445
                        getMapContext().getViewPort().setExtent(actives[0].getFullExtent());
446
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
447
                                e1.printStackTrace();
448
                        }
449
                } else {
450
                        try {
451
                                Rectangle2D maxExtent = setMaxExtent(actives);
452
                            getMapContext().getViewPort().setExtent(maxExtent);
453
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
454
                                e1.printStackTrace();
455
                        }
456
                }
457
        }
458
        
459
        private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException {
460
                Rectangle2D extRef = actives[0].getFullExtent();
461
                double minXRef = extRef.getMinX();
462
                double maxYRef = extRef.getMaxY();
463
                double maxXRef = extRef.getMaxX();
464
                double minYRef = extRef.getMinY();
465
                for (int i=0;i<actives.length;i++) {
466
                Rectangle2D extVar = actives[i].getFullExtent();
467
                    double minXVar = extVar.getMinX();
468
                    double maxYVar = extVar.getMaxY();
469
                    double maxXVar = extVar.getMaxX();
470
                    double minYVar = extVar.getMinY();
471
                    if (minXVar<=minXRef) minXRef=minXVar;
472
                    if (maxYVar>=maxYRef) maxYRef=maxYVar;
473
                    if (maxXVar>=maxXRef) maxXRef=maxXVar;
474
                    if (minYVar<=minYRef) minYRef=minYVar;
475
                    extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef);
476
                }
477
                return extRef;
478
        }
479
}
480

    
481
class EliminarCapaTocMenuEntry extends TocMenuEntry {
482
    private JMenuItem removeLayer;
483
        public void initialize(FPopupMenu m) {
484
                super.initialize(m);
485
                if (getNodeUserObject() instanceof TocItemBranch) {
486
                        removeLayer = new JMenuItem(PluginServices.getText(this, "eliminar_capa"));
487
                        removeLayer.setFont(FPopupMenu.theFont);
488
                        removeLayer.addActionListener(this);
489
                        getMenu().addSeparator();
490
                        getMenu().add(removeLayer);
491
                        getMenu().addSeparator();
492
                }
493
        }
494
        /* (non-Javadoc)
495
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
496
         */
497
        public void actionPerformed(ActionEvent e) {
498
            // 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
499
                //                                        Es necesario pulsar May?sculas a la vez que el bot?n derecho.
500
            FMap fMap = getMapContext();
501
            FLayer[] actives = fMap.getLayers().getActives();
502
            for (int i = actives.length-1; i>=0; i--){
503
                try {
504
                                actives[i].getParentLayer().removeLayer(actives[i]);
505
                                FLayers lyrs=getMapContext().getLayers();
506
                                lyrs.addLayer(actives[i]);
507
                                actives[i].getParentLayer().removeLayer(actives[i]);
508
                                
509
                                if (getMapContext().getLayers().getLayersCount()==0)
510
                        PluginServices.getMainFrame().enableControls();
511
                    } catch (CancelationException e1) {
512
                            e1.printStackTrace();
513
                    }
514
            }
515
                // 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
516
            /*FLayer lyr = getNodeLayer();
517
        try {
518
                getMapContext().getLayers().removeLayer(lyr);
519
                if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
520
                } catch (CancelationException e1) {
521
                        e1.printStackTrace();
522
                }*/
523
    }
524
}
525
/**
526
 * Realiza una agrupaci?n de capas, a partir de las capas que se encuentren activas.
527
 * 
528
 * @author Vicente Caballero Navarro
529
 */
530
class LayersGroupTocMenuEntry extends TocMenuEntry {
531
    private JMenuItem agrupar;    
532
        public void initialize(FPopupMenu m) {
533
                super.initialize(m);
534
                    agrupar = new JMenuItem(PluginServices.getText(this, "agrupar_capas"));
535
                agrupar.setFont(FPopupMenu.theFont);
536
                getMenu().add(agrupar);        
537
                getMenu().setEnabled(true);
538
                agrupar.addActionListener(this);
539
        }
540
        
541
        /* (non-Javadoc)
542
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
543
         */
544
        public void actionPerformed(ActionEvent e) {
545
                ITocItem tocItem = (ITocItem) getNodeUserObject();
546
        ChangeName changename=new ChangeName(null);
547
                PluginServices.getMDIManager().addView(changename);
548
                String nombre=changename.getName();
549
                
550
        if (nombre != null){
551
                        if (isTocItemBranch()){
552
                                FLayer[] actives = getMapContext().getLayers().getActives();
553
                                
554
                                if (actives.length>1) {
555
                                FLayers layerGroup=new FLayers(getMapContext(),getNodeLayer().getParentLayer());
556
                                        for (int i=0;i<actives.length;i++){
557
                                                actives[i].getParentLayer().removeLayer(actives[i]);
558
                                                layerGroup.addLayer(actives[i]);
559
                                        }
560
                                        layerGroup.setName(nombre);
561
                                        View theView = (View) PluginServices.getMDIManager().getActiveView();
562
                                        theView.getMapControl().getMapContext().getLayers()
563
                                           .addLayer(layerGroup);        
564
                            
565
                            }
566
                                
567
                        }
568
                        // TRUCO PARA REFRESCAR.
569
                getMapContext().invalidate();                    
570
}
571
}
572
}
573
/**
574
 * Realiza una desagrupaci?n de capas, a partir de las capas que se encuentren activas.
575
 * 
576
 * @author Vicente Caballero Navarro
577
 */
578
class LayersUngroupTocMenuEntry extends TocMenuEntry {
579
    private JMenuItem desagrupar;    
580
        public void initialize(FPopupMenu m) {
581
                super.initialize(m);
582
                boolean isFLayers=true;
583
                if (isTocItemBranch()){
584
                        FLayer lyr = getNodeLayer();
585
                        if (!(lyr instanceof FLayers)){
586
                                isFLayers=false;
587
                        }
588
                }
589
                if (isFLayers){
590
                        desagrupar = new JMenuItem(PluginServices.getText(this, "desagrupar_capas"));
591
                desagrupar.setFont(FPopupMenu.theFont);
592
                getMenu().add(desagrupar);        
593
                getMenu().setEnabled(true);
594
                desagrupar.addActionListener(this);
595
                }
596
        }
597
        
598
        /* (non-Javadoc)
599
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
600
         */
601
        public void actionPerformed(ActionEvent e) {
602
                ITocItem tocItem = (ITocItem) getNodeUserObject();
603
                        if (isTocItemBranch()){
604
                                FLayers agrupa = (FLayers)getNodeLayer();
605
                                FLayers parent=agrupa.getParentLayer();
606
                                if (parent!=null){
607
                                        for (int j=0;j<agrupa.getLayersCount();j++){
608
                                                parent.addLayer(agrupa.getLayer(j));
609
                                        }
610
                                        parent.removeLayer(agrupa);
611
                                }
612
                        }
613
                // TRUCO PARA REFRESCAR.
614
                getMapContext().invalidate();                    
615

    
616
        
617
        
618
        }
619
}
620
/**
621
 * Cambia la posici?n actual del layer a la primera posici?n.
622
 * 
623
 * @author Vicente Caballero Navarro
624
 */
625
class FirstLayerTocMenuEntry extends TocMenuEntry {
626
    private JMenuItem first;    
627
        public void initialize(FPopupMenu m) {
628
                super.initialize(m);
629
                    first = new JMenuItem(PluginServices.getText(this, "colocar_delante"));
630
                first.setFont(FPopupMenu.theFont);
631
                getMenu().add(first);        
632
                getMenu().setEnabled(true);
633
                first.addActionListener(this);
634
        }
635
        
636
        /* (non-Javadoc)
637
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
638
         */
639
        public void actionPerformed(ActionEvent e) {
640
                ITocItem tocItem = (ITocItem) getNodeUserObject();
641
      
642
              if (isTocItemBranch()){
643
                                FLayer layer=((TocItemBranch)tocItem).getLayer();
644
                                FLayers layers=layer.getParentLayer();
645
                                for (int i=0;i<layers.getLayersCount();i++){
646
                                        if(layers.getLayer(i).equals(layer)){
647
                                                layers.removeLayer(i);
648
                                                layers.addLayer(layer);
649
                                        }
650
                                }
651
                                
652
                                
653
                        }
654
                        // TRUCO PARA REFRESCAR.
655
                getMapContext().invalidate();                    
656
        
657
        }
658
}
659
/** 
660
 * @author Nacho Brodin <brodin_ign@gva.es>
661
 *
662
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
663
 * pixel.
664
 */
665
class ZoomPixelTocMenuEntry extends TocMenuEntry {
666
        public static final int ZOOM_TO_IMAGE_CENTER = 0x1;
667
        public static final int ZOOM_TO_VIEW_CENTER = 0x2;
668
        private JMenuItem properties;
669
        FLayer lyr = null;
670
        public int zoomType = ZOOM_TO_VIEW_CENTER;
671
        
672
        public void initialize(FPopupMenu m) {
673
                super.initialize(m);
674
                
675
                if (isTocItemBranch()) {
676
                        lyr = getNodeLayer();
677
                    // Opcciones para capas raster
678
                    if ((lyr instanceof FLyrRaster)) {
679
                            properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel"));
680
                            getMenu().add( properties );
681
                            properties.setFont(FPopupMenu.theFont);
682
                            getMenu().setEnabled(true);
683
                            // LWS getMenu().addSeparator();
684
                            properties.addActionListener(this);
685
                     }
686
                }
687
        }
688
        
689
        public void actionPerformed(ActionEvent e) {
690
                System.out.println("Zoom a un pixel");
691

    
692
                FLayer[] actives = getMapContext().getLayers().getActives();
693
                if (actives.length==1) {
694
                try {
695
                        Rectangle2D r = actives[0].getFullExtent();
696
              
697
                        ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes();
698
                        int width = 0, height = 0;
699
                               for (int i=0; i<attr.size(); i++) {
700
                                    Object[] a = (Object []) attr.get(i);
701
                                    if (a[0].toString().equals("Width"))
702
                                            width = ((Integer)a[1]).intValue();
703
                                    if (a[0].toString().equals("Height"))
704
                                            height = ((Integer)a[1]).intValue();                                                                
705
                            }
706
                        ViewPort v = getMapContext().getViewPort();
707
                        
708
                        if (zoomType == ZOOM_TO_IMAGE_CENTER) {
709
                                //A centro de imagen
710
                                /*double centroX = width/2;
711
                                        double centroY = height/2;
712
                                        int minX = (int)Math.round(centroX - (v.getImageWidth()/2));
713
                                        int minY = (int)Math.round(centroY - (v.getImageHeight()/2));
714
                                        int maxX = (int)Math.round(minX + v.getImageWidth());
715
                                        int maxY = (int)Math.round(minY + v.getImageHeight());
716
                                        double wcOriginWidth = r.getMaxX() - r.getMinX();
717
                                        double wcOriginHeight = r.getMaxY() - r.getMinY();
718
                                        
719
                                        double wcDstMinX = r.getMinX()+((minX*wcOriginWidth)/width);
720
                                        double wcDstMinY = r.getMinY()+((minY*wcOriginHeight)/height);
721
                                        double wcDstMaxX = r.getMinX()+((maxX*wcOriginWidth)/width);
722
                                        double wcDstMaxY = r.getMinY()+((maxY*wcOriginHeight)/height);
723
                                        
724
                                        double wcDstWidth = wcDstMaxX - wcDstMinX;
725
                                        double wcDstHeight = wcDstMaxY - wcDstMinY;*/
726
                        } else if (zoomType == ZOOM_TO_VIEW_CENTER) {
727
                                //A centro de vista
728
                                double wcOriginCenterX = v.getExtent().getMinX()+((v.getExtent().getMaxX()-v.getExtent().getMinX())/2);
729
                                double wcOriginCenterY = v.getExtent().getMinY()+((v.getExtent().getMaxY()-v.getExtent().getMinY())/2);
730
                                                                
731
                                //Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
732
                                        double relacionPixelWcWidth =  (r.getMaxX() - r.getMinX())/width;
733
                                        double relacionPixelWcHeight = (r.getMaxY() - r.getMinY())/height;
734
                                        double desplazamientoX = r.getMinX(); 
735
                                        double desplazamientoY = r.getMinY();
736
                                        
737
                                        double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2);
738
                                        double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2);
739
                                        
740
                                        double wcDstMinX = wcOriginX; 
741
                                        double wcDstMinY = wcOriginY; 
742
                                        double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
743
                                        double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
744
                                        
745
                                        double wcDstWidth = wcDstMaxX - wcDstMinX;
746
                                        double wcDstHeight = wcDstMaxY - wcDstMinY;
747
                                                                        
748
                                r = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
749
                                getMapContext().getViewPort().setExtent(r);
750
                        }
751
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
752
                                e1.printStackTrace();
753
                        }
754
                } 
755
                //View vista = (View) PluginServices.getMDIManager().getActiveView();
756
                //MapControl mapCtrl = vista.getMapControl();        
757
        }
758
}
759

    
760
/**
761
 * 
762
 * @author Nacho Brodin <brodin_ign@gva.es>
763
 *
764
 * Entrada de men? para la activaci?n de la funcionalidad de salvar
765
 * a raster una parte de la vista.
766
 */
767
class SaveRasterTocMenuEntry extends TocMenuEntry{
768
        private JMenuItem properties;
769
        FLayer lyr = null;
770
        
771
        public void initialize(FPopupMenu m) {
772
                super.initialize(m);
773
                
774
                if (isTocItemBranch()) {
775
                        lyr = getNodeLayer();
776
                    // Opcciones para capas raster
777
                    if ((lyr instanceof FLyrRaster)) {
778
                            properties = new JMenuItem(PluginServices.getText(this, "salvar_raster"));
779
                            getMenu().add( properties );
780
                            properties.setFont(FPopupMenu.theFont);
781
                            getMenu().setEnabled(true);
782
                            //getMenu().addSeparator();
783
                    //Cambio color
784
                            properties.addActionListener(this);
785
                     }
786
                }
787
        }
788
        
789
        public void actionPerformed(ActionEvent e) {
790
                lyr = getNodeLayer();
791
                View vista = (View) PluginServices.getMDIManager().getActiveView();
792
                MapControl mapCtrl = vista.getMapControl();
793
                mapCtrl.setTool("saveRaster");
794
        }
795
}
796

    
797
/**
798
 * Menu de bot?n derecho para el TOC.
799
 * Se pueden a?adir entradas facilmente desde una extensi?n,
800
 * creando una clase derivando de TocMenuEntry, y a?adiendola en
801
 * est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
802
 * (Las entradas actuales est?n hechas de esa manera).
803
 *
804
 * @author vcn To change the template for this generated type comment go to
805
 *         Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
806
 *         Comments
807
 */
808

    
809
public class FPopupMenu extends JPopupMenu {
810
        private static ArrayList menuEntrys = new ArrayList();
811
    public DefaultMutableTreeNode nodo;
812
    protected FMap mapContext;
813
    //private JMenuItem capa;
814
    // Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
815
    // TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
816
    public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10);
817
    
818
    static {
819
            FPopupMenu.addEntry(new FSymbolChangeColorTocMenuEntry());
820
            FPopupMenu.addEntry(new ChangeNameTocMenuEntry());
821
            menuEntrys.add(new FLyrVectEditPropertiesTocMenuEntry());
822
            //FPopupMenu.addEntry(new FLyrRasterAdjustTransparencyTocMenuEntry());
823
            FPopupMenu.addEntry(new ZoomAlTemaTocMenuEntry());
824
            FPopupMenu.addEntry(new ZoomPixelTocMenuEntry());
825
            FPopupMenu.addEntry(new EliminarCapaTocMenuEntry());
826
            menuEntrys.add(new LayersGroupTocMenuEntry());
827
                menuEntrys.add(new LayersUngroupTocMenuEntry());
828
                menuEntrys.add(new FirstLayerTocMenuEntry());
829
            FPopupMenu.addEntry(new FLyrRasterAdjustPropertiesTocMenuEntry());
830
    }
831

    
832
    public static void addEntry(TocMenuEntry entry) {
833
            menuEntrys.add(entry);
834
    }
835
    
836
    /**
837
     * Creates a new FPopupMenu object.
838
     *
839
     * @param nodo DOCUMENT ME!
840
     * @param vista DOCUMENT ME!
841
     */
842
    public FPopupMenu(FMap mc, DefaultMutableTreeNode node) {
843
        //super();
844
        this.mapContext = mc;
845
        this.nodo = node;
846
 
847
        //salir = new MenuItem("Salir");
848

    
849
        for (int i=0; i<menuEntrys.size(); i++) {
850
                ((TocMenuEntry) menuEntrys.get(i)).initialize(this);
851
        }
852
    }
853
    
854
    public FMap getMapContext() { return mapContext; }
855
        
856
}