Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_03_raster / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / FPopupMenu.java @ 1930

History | View | Annotate | Download (22.8 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 org.cresques.io.GeoRasterFile;
62
import org.cresques.io.raster.RasterFilterStackManager;
63
import org.cresques.ui.raster.BandSetupPanel;
64
import org.cresques.ui.raster.FilterRasterDialogPanel;
65

    
66
import com.iver.andami.PluginServices;
67
import com.iver.cit.gvsig.fmap.DriverException;
68
import com.iver.cit.gvsig.fmap.FMap;
69
import com.iver.cit.gvsig.fmap.MapControl;
70
import com.iver.cit.gvsig.fmap.ViewPort;
71
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
72
import com.iver.cit.gvsig.fmap.layers.CancelationException;
73
import com.iver.cit.gvsig.fmap.layers.FLayer;
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.LegendFactory;
79
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
80
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
81
import com.iver.cit.gvsig.gui.View;
82
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel;
83
import com.iver.cit.gvsig.gui.Panels.PropertiesRasterDialog;
84
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow;
85
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow;
86

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

    
153
        }
154
        
155
        }
156
}
157

    
158
class FLyrVectChangeStyleTocMenuEntry extends TocMenuEntry {
159
    private JMenuItem estilo;
160
        public void initialize(FPopupMenu m) {
161
                super.initialize(m);
162
                FLayer lyr = null;
163
                
164
                if (isTocItemBranch()) {
165
                        lyr = getNodeLayer();
166
                        if (lyr instanceof ClassifiableVectorial) {
167
                            estilo = new JMenuItem(PluginServices.getText(this, "Cambio_Estilo"));
168
                                getMenu().add(estilo);
169
                                estilo.setFont(FPopupMenu.theFont);
170
                                //Cambio estilo
171
                                estilo.addActionListener(this);
172
                        }
173
                }
174
        }
175
        /* (non-Javadoc)
176
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
177
         */
178
        public void actionPerformed(ActionEvent e) {
179
                FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow();
180
                try {
181
                        m_LegendEditor.setMapContext(getMapContext());
182
                } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
183
                        e1.printStackTrace();
184
                }
185
                if (PluginServices.getMainFrame() == null) {
186
                        JDialog dlg = new JDialog();
187
                                                                                    
188
                        m_LegendEditor.setPreferredSize(m_LegendEditor.getSize());
189
                        dlg.getContentPane().add(m_LegendEditor);
190
                        dlg.setModal(false);                        
191
                        dlg.pack();
192
                        dlg.show();
193
                        
194
                } else
195
                        PluginServices.getMDIManager().addView(m_LegendEditor);
196
        }
197
}
198

    
199
/**
200
 * 
201
 * @author Nacho Brodin <brodin_ign@gva.es>
202
 *
203
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
204
 * pixel.
205
 */
206
class ZoomPixelTocMenuEntry extends TocMenuEntry{
207
        private JMenuItem properties;
208
        FLayer lyr = null;
209
        
210
        public void initialize(FPopupMenu m) {
211
                super.initialize(m);
212
                
213
                if (isTocItemBranch()) {
214
                        lyr = getNodeLayer();
215
                    // Opcciones para capas raster
216
                    if ((lyr instanceof FLyrRaster)) {
217
                            properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel"));
218
                            getMenu().add( properties );
219
                            properties.setFont(FPopupMenu.theFont);
220
                            getMenu().setEnabled(true);
221
                            getMenu().addSeparator();
222
                            properties.addActionListener(this);
223
                     }
224
                }
225
        }
226
        
227
        public void actionPerformed(ActionEvent e) {
228
                System.out.println("Zoom a un pixel");
229

    
230
                FLayer[] actives = getMapContext().getLayers().getActives();
231
                if (actives.length==1) {
232
                try {
233
                        Rectangle2D r = actives[0].getFullExtent();
234
              
235
                        ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes();
236
                        int width = 0, height = 0;
237
                               for (int i=0; i<attr.size(); i++) {
238
                                    Object[] a = (Object []) attr.get(i);
239
                                    if(a[0].toString().equals("Width"))
240
                                            width = ((Integer)a[1]).intValue();
241
                                    if(a[0].toString().equals("Height"))
242
                                            height = ((Integer)a[1]).intValue();                                                                
243
                            }
244
                        ViewPort v = getMapContext().getViewPort();
245
                        
246
                        //A centro de imagen
247
                        
248
                        /*double centroX = width/2;
249
                                double centroY = height/2;
250
                                int minX = (int)Math.round(centroX - (v.getImageWidth()/2));
251
                                int minY = (int)Math.round(centroY - (v.getImageHeight()/2));
252
                                int maxX = (int)Math.round(minX + v.getImageWidth());
253
                                int maxY = (int)Math.round(minY + v.getImageHeight());
254
                                double wcOriginWidth = r.getMaxX() - r.getMinX();
255
                                double wcOriginHeight = r.getMaxY() - r.getMinY();
256
                                
257
                                double wcDstMinX = r.getMinX()+((minX*wcOriginWidth)/width);
258
                                double wcDstMinY = r.getMinY()+((minY*wcOriginHeight)/height);
259
                                double wcDstMaxX = r.getMinX()+((maxX*wcOriginWidth)/width);
260
                                double wcDstMaxY = r.getMinY()+((maxY*wcOriginHeight)/height);
261
                                
262
                                double wcDstWidth = wcDstMaxX - wcDstMinX;
263
                                double wcDstHeight = wcDstMaxY - wcDstMinY;*/
264
                                
265
                        //A centro de vista
266
                        double wcOriginCenterX = v.getExtent().getMinX()+((v.getExtent().getMaxX()-v.getExtent().getMinX())/2);
267
                        double wcOriginCenterY = v.getExtent().getMinY()+((v.getExtent().getMaxY()-v.getExtent().getMinY())/2);
268
                                                        
269
                        //Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
270
                                double relacionPixelWcWidth =  (r.getMaxX() - r.getMinX())/width;
271
                                double relacionPixelWcHeight = (r.getMaxY() - r.getMinY())/height;
272
                                double desplazamientoX = r.getMinX(); 
273
                                double desplazamientoY = r.getMinY();
274
                                
275
                                double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2);
276
                                double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2);
277
                                
278
                                double wcDstMinX = wcOriginX; 
279
                                double wcDstMinY = wcOriginY; 
280
                                double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
281
                                double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
282
                                
283
                                double wcDstWidth = wcDstMaxX - wcDstMinX;
284
                                double wcDstHeight = wcDstMaxY - wcDstMinY;
285
                                                                
286
                        r = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
287
                        getMapContext().getViewPort().setExtent(r);
288
                                                
289
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
290
                                e1.printStackTrace();
291
                        }
292
                } 
293
                //View vista = (View) PluginServices.getMDIManager().getActiveView();
294
                //MapControl mapCtrl = vista.getMapControl();
295
        
296
        }
297
}
298

    
299
/**
300
 * 
301
 * @author Nacho Brodin <brodin_ign@gva.es>
302
 *
303
 * Entrada de men? para la activaci?n de la funcionalidad de salvar
304
 * a raster una parte de la vista.
305
 */
306
class SaveRasterTocMenuEntry extends TocMenuEntry{
307
        private JMenuItem properties;
308
        FLayer lyr = null;
309
        
310
        public void initialize(FPopupMenu m) {
311
                super.initialize(m);
312
                
313
                if (isTocItemBranch()) {
314
                        lyr = getNodeLayer();
315
                    // Opcciones para capas raster
316
                    if ((lyr instanceof FLyrRaster)) {
317
                            properties = new JMenuItem(PluginServices.getText(this, "salvar_raster"));
318
                            getMenu().add( properties );
319
                            properties.setFont(FPopupMenu.theFont);
320
                            getMenu().setEnabled(true);
321
                            getMenu().addSeparator();
322
                    //Cambio color
323
                            properties.addActionListener(this);
324
                     }
325
                }
326
        }
327
        
328
        public void actionPerformed(ActionEvent e) {
329
                lyr = getNodeLayer();
330
                View vista = (View) PluginServices.getMDIManager().getActiveView();
331
                MapControl mapCtrl = vista.getMapControl();
332
                mapCtrl.setTool("saveRaster");
333
        }
334
}
335

    
336
/**
337
 * Muestra el men? de propiedades del tema.
338
 * 
339
 * @author jmorell
340
 *
341
 * TODO To change the template for this generated type comment go to
342
 * Window - Preferences - Java - Code Style - Code Templates
343
 */
344
class FLyrVectEditPropertiesTocMenuEntry extends TocMenuEntry {
345
    private JMenuItem prop;
346
        public void initialize(FPopupMenu m) {
347
                super.initialize(m);
348
                FLayer lyr = null;
349
                if (isTocItemBranch()) {
350
                        getMenu().addSeparator();
351
                        lyr = getNodeLayer();
352
                        if (lyr instanceof ClassifiableVectorial) {
353
                            prop = new JMenuItem("Propiedades Pliego");
354
                                getMenu().add(prop);
355
                                prop.setFont(FPopupMenu.theFont);
356
                                //Cambio estilo
357
                                prop.addActionListener(this);
358
                        }
359
                }
360
        }
361
        /* (non-Javadoc)
362
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
363
         */
364
        public void actionPerformed(ActionEvent e) {
365
                /*FThemeManagerWindow fThemeManagerWindow = new FThemeManagerWindow();
366
                try {
367
                        fThemeManagerWindow.setMapContext(getMapContext());
368
                } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
369
                        e1.printStackTrace();
370
                }*/
371
                FLayer[] actives = getMapContext().getLayers().getActives();
372
                FThemeManagerWindow fThemeManagerWindow;
373
            if (actives.length==1) {
374
                    System.out.println("openPliegoThemeProperties(): Una sola capa. Abrimos el panel para la capa " + actives[0]);
375
                    fThemeManagerWindow = new FThemeManagerWindow();
376
                    try {
377
                            fThemeManagerWindow.setMapContext(getMapContext());
378
                    } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
379
                            e1.printStackTrace();
380
                    }
381
            //PluginServices.getMDIManager().addView(fThemeManagerWindow);
382
                    if (PluginServices.getMainFrame() == null) {
383
                            JDialog dlg = new JDialog();
384
                            fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
385
                            dlg.getContentPane().add(fThemeManagerWindow);
386
                            dlg.setModal(false);                        
387
                            dlg.pack();
388
                            dlg.show();
389
                    } else {
390
                            PluginServices.getMDIManager().addView(fThemeManagerWindow);
391
                    }
392
            } else {
393
                for (int i = 0; i < actives.length; i++){
394
                        System.out.println("openPliegoThemeProperties(): Muchas capas. Abrimos el panel para la capa " + actives[i]);
395
                        fThemeManagerWindow = new FThemeManagerWindow(actives[i], getMapContext());
396
                //PluginServices.getMDIManager().addView(fThemeManagerWindow);
397
                        if (PluginServices.getMainFrame() == null) {
398
                                JDialog dlg = new JDialog();
399
                                fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
400
                                dlg.getContentPane().add(fThemeManagerWindow);
401
                                dlg.setModal(false);                        
402
                                dlg.pack();
403
                                dlg.show();
404
                        } else {
405
                                PluginServices.getMDIManager().addView(fThemeManagerWindow);
406
                        }
407
                }
408
            }
409
                /*if (PluginServices.getMainFrame() == null) {
410
                        JDialog dlg = new JDialog();
411
                        fThemeManagerWindow.setPreferredSize(fThemeManagerWindow.getSize());
412
                        dlg.getContentPane().add(fThemeManagerWindow);
413
                        dlg.setModal(false);                        
414
                        dlg.pack();
415
                        dlg.show();
416
                } else {
417
                        PluginServices.getMDIManager().addView(fThemeManagerWindow);
418
                }*/
419
        }
420
}
421

    
422
/**
423
 * 
424
 * @author Nacho Brodin <brodin_ign@gva.es>
425
 *
426
 * Entrada de men? para el dialogo de propiedades del raster
427
 */
428
class FLyrRasterAdjustPropertiesTocMenuEntry extends TocMenuEntry {
429
        private JMenuItem                                 properties;
430
        FLayer                                                         lyr = null;
431
        private PropertiesRasterDialog        propsDialog = null;
432
        private BandSetupPanel                         bandSetup = null;
433

    
434
        
435
        public void initialize(FPopupMenu m) {
436
                super.initialize(m);
437
                
438
                if (isTocItemBranch()) {
439
                        lyr = getNodeLayer();
440
                    // Opcciones para capas raster
441
                    if ((lyr instanceof FLyrRaster)) {
442
                            properties = new JMenuItem(PluginServices.getText(this, "propiedades_raster"));
443
                            getMenu().add( properties );
444
                            properties.setFont(FPopupMenu.theFont);
445
                            getMenu().setEnabled(true);
446
                            getMenu().addSeparator();
447
                    //Cambio color
448
                            properties.addActionListener(this);
449
                     }
450
                }
451
        }
452
        
453
        /**
454
         * Gestiona la apertura del dialogo de propiedades de raster cuando se pulsa
455
         * la opci?n asignando a este las propiedades iniciales. 
456
         */
457
        public void actionPerformed(ActionEvent e) {
458
               lyr = getNodeLayer();
459
                   
460
               if(lyr instanceof FLyrRaster){
461
                       RasterFilterStackManager         stackManager = null;
462
       
463
                       stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
464
                       int[][] rangeR = stackManager.getTransparecyR();
465
                       int[][] rangeG = stackManager.getTransparecyG();
466
                       int[][] rangeB = stackManager.getTransparecyB();
467
                       
468
                       propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), rangeR, rangeG, rangeB);
469
                                              
470
                        int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency();
471
                        
472
                        bandSetup = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getBandSetup();
473
                        GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
474
                        bandSetup.addFiles(files);
475
                        RasterAdapter rad = ((FLyrRaster)lyr).getSource();
476
                        int posR = 0, posG = 0, posB = 0;
477
                        
478
                        for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++)
479
                                posR += files[i].getBandCount();
480
                        posR += rad.getBand(GeoRasterFile.RED_BAND);
481
                        
482
                        for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++)
483
                                posG += files[i].getBandCount();
484
                        posG += rad.getBand(GeoRasterFile.GREEN_BAND);
485
                        
486
                        for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++)
487
                                posB += files[i].getBandCount();
488
                        posB += rad.getBand(GeoRasterFile.BLUE_BAND);
489
                        
490
                        bandSetup.assignBand(posR, GeoRasterFile.RED_BAND);
491
                        bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND);
492
                        bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND);        
493
                                                                        
494
                        //Asignaci?n del alpha actual de la imagen al dialogo
495
                        RasterTransparencyPanel rasterTrans = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getTransparencyPanel();
496
                        rasterTrans.setOpacity(alpha);
497
                                
498
                        //Asignaci?n del porcentaje de recorte actual de la imagen al dialogo
499
                        EnhancedPanel pEnhan =  ((FilterRasterDialogPanel)propsDialog.getContentPane()).getEnhancedPanel();
500
                        
501
                        propsDialog.setRasterFilterStackManager(stackManager);
502
                        int tail = 0;
503
                        if(        pEnhan != null &&
504
                                stackManager.getStackStats() != null){
505
                                tail = (int)(stackManager.getStackStats().tailPercent*200);
506
                                pEnhan.setPercentTail(tail);
507
                        }
508
                        if(stackManager.isActive(stackManager.getTypeFilter("enhanced")))
509
                                pEnhan.setSelectedFilter(1);
510
                        else
511
                                pEnhan.setSelectedFilter(0);
512
                                                        
513
                        propsDialog.readStat();
514
                        
515
                       PluginServices.getMDIManager().addView(propsDialog);
516
        }
517
        }
518
}
519

    
520
class ZoomAlTemaTocMenuEntry extends TocMenuEntry {
521
    private JMenuItem zoom;
522
        public void initialize(FPopupMenu m) {
523
                super.initialize(m);
524
                if (isTocItemBranch()) {
525
                        zoom = new JMenuItem(PluginServices.getText(this, "Zoom_al_Tema"));
526
                        getMenu().add(zoom);
527
                        zoom.setFont(FPopupMenu.theFont);
528
            
529
                zoom.addActionListener(this);
530
                }
531
        }
532
        /* (non-Javadoc)
533
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
534
         */
535
        public void actionPerformed(ActionEvent e) {
536
            /*FLayer lyr = getNodeLayer();
537
        try {
538
                getMapContext().getViewPort().setExtent(lyr.getFullExtent());
539
                } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
540
                        e1.printStackTrace();
541
                }*/
542
                // 050209, jmorell: Para que haga un zoom a un grupo de capas seleccionadas.
543
                FLayer[] actives = getMapContext().getLayers().getActives();
544
                if (actives.length==1) {
545
                try {
546
                        getMapContext().getViewPort().setExtent(actives[0].getFullExtent());
547
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
548
                                e1.printStackTrace();
549
                        }
550
                } else {
551
                        try {
552
                                Rectangle2D maxExtent = setMaxExtent(actives);
553
                            getMapContext().getViewPort().setExtent(maxExtent);
554
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
555
                                e1.printStackTrace();
556
                        }
557
                }
558
        }
559
        
560
        private Rectangle2D setMaxExtent(FLayer[] actives) throws DriverException {
561
                Rectangle2D extRef = actives[0].getFullExtent();
562
                double minXRef = extRef.getMinX();
563
                double maxYRef = extRef.getMaxY();
564
                double maxXRef = extRef.getMaxX();
565
                double minYRef = extRef.getMinY();
566
                for (int i=0;i<actives.length;i++) {
567
                Rectangle2D extVar = actives[i].getFullExtent();
568
                    double minXVar = extVar.getMinX();
569
                    double maxYVar = extVar.getMaxY();
570
                    double maxXVar = extVar.getMaxX();
571
                    double minYVar = extVar.getMinY();
572
                    if (minXVar<=minXRef) minXRef=minXVar;
573
                    if (maxYVar>=maxYRef) maxYRef=maxYVar;
574
                    if (maxXVar>=maxXRef) maxXRef=maxXVar;
575
                    if (minYVar<=minYRef) minYRef=minYVar;
576
                    extRef.setRect(minXRef, minYRef, maxXRef-minXRef, maxYRef-minYRef);
577
                }
578
                return extRef;
579
        }
580
}
581

    
582
class EliminarCapaTocMenuEntry extends TocMenuEntry {
583
    private JMenuItem removeLayer;
584
        public void initialize(FPopupMenu m) {
585
                super.initialize(m);
586
                if (getNodeUserObject() instanceof TocItemBranch) {
587
                        getMenu().addSeparator();
588
                        removeLayer = new JMenuItem(PluginServices.getText(this, "eliminar_capa"));
589
                        getMenu().add(removeLayer);
590
                        removeLayer.setFont(FPopupMenu.theFont);
591
                        removeLayer.addActionListener(this);
592
                }
593
        }
594
        /* (non-Javadoc)
595
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
596
         */
597
        public void actionPerformed(ActionEvent e) {
598
            // 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
599
                //                                        Es necesario pulsar May?sculas a la vez que el bot?n derecho.
600
            FMap fMap = getMapContext();
601
            FLayer[] actives = fMap.getLayers().getActives();
602
            for (int i = 0; i < actives.length; i++){
603
                try {
604
                    getMapContext().getLayers().removeLayer(actives[i]);
605
                    if (getMapContext().getLayers().getLayersCount()==0)
606
                        PluginServices.getMainFrame().enableControls();
607
                    } catch (CancelationException e1) {
608
                            e1.printStackTrace();
609
                    }
610
            }
611
                // 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
612
            /*FLayer lyr = getNodeLayer();
613
        try {
614
                getMapContext().getLayers().removeLayer(lyr);
615
                if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
616
                } catch (CancelationException e1) {
617
                        e1.printStackTrace();
618
                }*/
619
    }
620
}
621

    
622
/**
623
 * Menu de bot?n derecho para el TOC.
624
 * Se pueden a?adir entradas facilmente desde una extensi?n,
625
 * creando una clase derivando de TocMenuEntry, y a?adiendola en
626
 * est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
627
 * (Las entradas actuales est?n hechas de esa manera).
628
 *
629
 * @author vcn To change the template for this generated type comment go to
630
 *         Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
631
 *         Comments
632
 */
633

    
634
public class FPopupMenu extends JPopupMenu {
635
        private static ArrayList menuEntrys = null;
636
    public DefaultMutableTreeNode nodo;
637
    protected FMap mapContext;
638
    //private JMenuItem capa;
639
    // Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
640
    // TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
641
    public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10);
642
    
643
    static {
644
            menuEntrys = new ArrayList();
645
            menuEntrys.add(new FSymbolChangeColorTocMenuEntry());
646
            menuEntrys.add(new FLyrVectChangeStyleTocMenuEntry());
647
            menuEntrys.add(new FLyrRasterAdjustPropertiesTocMenuEntry());
648
            menuEntrys.add(new ZoomPixelTocMenuEntry());
649
            menuEntrys.add(new ZoomAlTemaTocMenuEntry());
650
            menuEntrys.add(new EliminarCapaTocMenuEntry());
651
            //050201 jmorell: Acceso al men? propiedades.
652
            menuEntrys.add(new FLyrVectEditPropertiesTocMenuEntry());
653
    }
654

    
655
    public static void addEntry(TocMenuEntry entry) {
656
            menuEntrys.add(entry);
657
    }
658
    
659
    /**
660
     * Creates a new FPopupMenu object.
661
     *
662
     * @param nodo DOCUMENT ME!
663
     * @param vista DOCUMENT ME!
664
     */
665
    public FPopupMenu(FMap mc, DefaultMutableTreeNode node) {
666
        //super();
667
        this.mapContext = mc;
668
        this.nodo = node;
669
 
670
        //salir = new MenuItem("Salir");
671

    
672
        for (int i=0; i<menuEntrys.size(); i++) {
673
                ((TocMenuEntry) menuEntrys.get(i)).initialize(this);
674
        }
675
    }
676
    
677
    public FMap getMapContext() { return mapContext; }
678

    
679
}