Statistics
| Revision:

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

History | View | Annotate | Download (23.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.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.EnhancedPanel;
65
import org.cresques.ui.raster.FilterRasterDialogPanel;
66
import org.cresques.ui.raster.RasterTransparencyPanel;
67

    
68
import com.iver.andami.PluginServices;
69
import com.iver.cit.gvsig.fmap.DriverException;
70
import com.iver.cit.gvsig.fmap.FMap;
71
import com.iver.cit.gvsig.fmap.MapControl;
72
import com.iver.cit.gvsig.fmap.ViewPort;
73
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
74
import com.iver.cit.gvsig.fmap.layers.CancelationException;
75
import com.iver.cit.gvsig.fmap.layers.FLayer;
76
import com.iver.cit.gvsig.fmap.layers.FLyrDefault;
77
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
78
import com.iver.cit.gvsig.fmap.layers.RasterAdapter;
79
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
80
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
81
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
82
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
83
import com.iver.cit.gvsig.gui.View;
84
import com.iver.cit.gvsig.gui.Panels.AdjustTransparencyPanel;
85
import com.iver.cit.gvsig.gui.Panels.PropertiesRasterDialog;
86
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow;
87
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow;
88

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

    
155
        }
156
        
157
        }
158
}
159

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

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

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

    
318
class FLyrRasterAdjustPropertiesTocMenuEntry extends TocMenuEntry {
319
        private JMenuItem                                 properties;
320
        FLayer                                                         lyr = null;
321
        private PropertiesRasterDialog        propsDialog = null;
322
        private BandSetupPanel                         bandSetup = null;
323

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

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

    
472
class EliminarCapaTocMenuEntry extends TocMenuEntry {
473
    private JMenuItem removeLayer;
474
        public void initialize(FPopupMenu m) {
475
                super.initialize(m);
476
                if (getNodeUserObject() instanceof TocItemBranch) {
477
                        getMenu().addSeparator();
478
                        removeLayer = new JMenuItem(PluginServices.getText(this, "eliminar_capa"));
479
                        getMenu().add(removeLayer);
480
                        removeLayer.setFont(FPopupMenu.theFont);
481
                        removeLayer.addActionListener(this);
482
                }
483
        }
484
        /* (non-Javadoc)
485
         * @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
486
         */
487
        public void actionPerformed(ActionEvent e) {
488
            // 050209, jmorell: Para poder borrar todas las capas seleccionadas desde el FPopUpMenu.
489
                //                                        Es necesario pulsar May?sculas a la vez que el bot?n derecho.
490
            FMap fMap = getMapContext();
491
            FLayer[] actives = fMap.getLayers().getActives();
492
            for (int i = 0; i < actives.length; i++){
493
                try {
494
                    getMapContext().getLayers().removeLayer(actives[i]);
495
                    if (getMapContext().getLayers().getLayersCount()==0)
496
                        PluginServices.getMainFrame().enableControls();
497
                    } catch (CancelationException e1) {
498
                            e1.printStackTrace();
499
                    }
500
            }
501
                // 050209, jmorell: As? solo borra una capa (sobre la que pulsas).
502
            /*FLayer lyr = getNodeLayer();
503
        try {
504
                getMapContext().getLayers().removeLayer(lyr);
505
                if (getMapContext().getLayers().getLayersCount()==0)PluginServices.getMainFrame().enableControls();
506
                } catch (CancelationException e1) {
507
                        e1.printStackTrace();
508
                }*/
509
    }
510
}
511

    
512
/** 
513
 * @author Nacho Brodin <brodin_ign@gva.es>
514
 *
515
 * Entrada de men? para la activaci?n de la funcionalidad de zoom a un
516
 * pixel.
517
 */
518
class ZoomPixelTocMenuEntry extends TocMenuEntry{
519
        private JMenuItem properties;
520
        FLayer lyr = null;
521
        
522
        public void initialize(FPopupMenu m) {
523
                super.initialize(m);
524
                
525
                if (isTocItemBranch()) {
526
                        lyr = getNodeLayer();
527
                    // Opcciones para capas raster
528
                    if ((lyr instanceof FLyrRaster)) {
529
                            properties = new JMenuItem(PluginServices.getText(this, "Zoom_pixel"));
530
                            getMenu().add( properties );
531
                            properties.setFont(FPopupMenu.theFont);
532
                            getMenu().setEnabled(true);
533
                            getMenu().addSeparator();
534
                            properties.addActionListener(this);
535
                     }
536
                }
537
        }
538
        
539
        public void actionPerformed(ActionEvent e) {
540
                System.out.println("Zoom a un pixel");
541

    
542
                FLayer[] actives = getMapContext().getLayers().getActives();
543
                if (actives.length==1) {
544
                try {
545
                        Rectangle2D r = actives[0].getFullExtent();
546
              
547
                        ArrayList attr = ((FLyrRaster)actives[0]).getSource().getAttributes();
548
                        int width = 0, height = 0;
549
                               for (int i=0; i<attr.size(); i++) {
550
                                    Object[] a = (Object []) attr.get(i);
551
                                    if(a[0].toString().equals("Width"))
552
                                            width = ((Integer)a[1]).intValue();
553
                                    if(a[0].toString().equals("Height"))
554
                                            height = ((Integer)a[1]).intValue();                                                                
555
                            }
556
                        ViewPort v = getMapContext().getViewPort();
557
                        
558
                        //A centro de imagen
559
                        
560
                        /*double centroX = width/2;
561
                                double centroY = height/2;
562
                                int minX = (int)Math.round(centroX - (v.getImageWidth()/2));
563
                                int minY = (int)Math.round(centroY - (v.getImageHeight()/2));
564
                                int maxX = (int)Math.round(minX + v.getImageWidth());
565
                                int maxY = (int)Math.round(minY + v.getImageHeight());
566
                                double wcOriginWidth = r.getMaxX() - r.getMinX();
567
                                double wcOriginHeight = r.getMaxY() - r.getMinY();
568
                                
569
                                double wcDstMinX = r.getMinX()+((minX*wcOriginWidth)/width);
570
                                double wcDstMinY = r.getMinY()+((minY*wcOriginHeight)/height);
571
                                double wcDstMaxX = r.getMinX()+((maxX*wcOriginWidth)/width);
572
                                double wcDstMaxY = r.getMinY()+((maxY*wcOriginHeight)/height);
573
                                
574
                                double wcDstWidth = wcDstMaxX - wcDstMinX;
575
                                double wcDstHeight = wcDstMaxY - wcDstMinY;*/
576
                                
577
                        //A centro de vista
578
                        double wcOriginCenterX = v.getExtent().getMinX()+((v.getExtent().getMaxX()-v.getExtent().getMinX())/2);
579
                        double wcOriginCenterY = v.getExtent().getMinY()+((v.getExtent().getMaxY()-v.getExtent().getMinY())/2);
580
                                                        
581
                        //Hallamos la relaci?n entre el pixel y las WC a partir de la imagen de la capa
582
                                double relacionPixelWcWidth =  (r.getMaxX() - r.getMinX())/width;
583
                                double relacionPixelWcHeight = (r.getMaxY() - r.getMinY())/height;
584
                                double desplazamientoX = r.getMinX(); 
585
                                double desplazamientoY = r.getMinY();
586
                                
587
                                double wcOriginX = wcOriginCenterX - ((v.getImageWidth()*relacionPixelWcWidth)/2);
588
                                double wcOriginY = wcOriginCenterY - ((v.getImageHeight()*relacionPixelWcHeight)/2);
589
                                
590
                                double wcDstMinX = wcOriginX; 
591
                                double wcDstMinY = wcOriginY; 
592
                                double wcDstMaxX = wcDstMinX + (v.getImageWidth()*relacionPixelWcWidth);
593
                                double wcDstMaxY = wcDstMinY + (v.getImageHeight()*relacionPixelWcHeight);
594
                                
595
                                double wcDstWidth = wcDstMaxX - wcDstMinX;
596
                                double wcDstHeight = wcDstMaxY - wcDstMinY;
597
                                                                
598
                        r = new Rectangle2D.Double(wcDstMinX, wcDstMinY, wcDstWidth, wcDstHeight);
599
                        getMapContext().getViewPort().setExtent(r);
600
                                                
601
                        } catch (com.iver.cit.gvsig.fmap.DriverException e1) {
602
                                e1.printStackTrace();
603
                        }
604
                } 
605
                //View vista = (View) PluginServices.getMDIManager().getActiveView();
606
                //MapControl mapCtrl = vista.getMapControl();
607
        
608
        }
609
}
610

    
611
/**
612
 * 
613
 * @author Nacho Brodin <brodin_ign@gva.es>
614
 *
615
 * Entrada de men? para la activaci?n de la funcionalidad de salvar
616
 * a raster una parte de la vista.
617
 */
618
class SaveRasterTocMenuEntry extends TocMenuEntry{
619
        private JMenuItem properties;
620
        FLayer lyr = null;
621
        
622
        public void initialize(FPopupMenu m) {
623
                super.initialize(m);
624
                
625
                if (isTocItemBranch()) {
626
                        lyr = getNodeLayer();
627
                    // Opcciones para capas raster
628
                    if ((lyr instanceof FLyrRaster)) {
629
                            properties = new JMenuItem(PluginServices.getText(this, "salvar_raster"));
630
                            getMenu().add( properties );
631
                            properties.setFont(FPopupMenu.theFont);
632
                            getMenu().setEnabled(true);
633
                            getMenu().addSeparator();
634
                    //Cambio color
635
                            properties.addActionListener(this);
636
                     }
637
                }
638
        }
639
        
640
        public void actionPerformed(ActionEvent e) {
641
                lyr = getNodeLayer();
642
                View vista = (View) PluginServices.getMDIManager().getActiveView();
643
                MapControl mapCtrl = vista.getMapControl();
644
                mapCtrl.setTool("saveRaster");
645
        }
646
}
647

    
648
/**
649
 * Menu de bot?n derecho para el TOC.
650
 * Se pueden a?adir entradas facilmente desde una extensi?n,
651
 * creando una clase derivando de TocMenuEntry, y a?adiendola en
652
 * est?tico (o en tiempo de carga de la extensi?n) a FPopupMenu.
653
 * (Las entradas actuales est?n hechas de esa manera).
654
 *
655
 * @author vcn To change the template for this generated type comment go to
656
 *         Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and
657
 *         Comments
658
 */
659

    
660
public class FPopupMenu extends JPopupMenu {
661
        private static ArrayList menuEntrys = new ArrayList();
662
    public DefaultMutableTreeNode nodo;
663
    protected FMap mapContext;
664
    //private JMenuItem capa;
665
    // Lo de fijar la fuente es porque en linux se ve?a mal si no se fija.
666
    // TODO: Esto no funcionar? para idiomas como el chino. Hay que cambiarlo.
667
    public final static Font theFont = new Font("SansSerif", Font.PLAIN, 10);
668
    
669
    static {
670
            FPopupMenu.addEntry(new FSymbolChangeColorTocMenuEntry());
671
            FPopupMenu.addEntry(new FLyrVectChangeStyleTocMenuEntry());
672
            FPopupMenu.addEntry(new FLyrRasterAdjustTransparencyTocMenuEntry());
673
            FPopupMenu.addEntry(new FLyrRasterAdjustPropertiesTocMenuEntry());
674
            FPopupMenu.addEntry(new ZoomPixelTocMenuEntry());
675
            FPopupMenu.addEntry(new ZoomAlTemaTocMenuEntry());
676
            FPopupMenu.addEntry(new EliminarCapaTocMenuEntry());
677
            //050201 jmorell: Acceso al men? propiedades.
678
            FPopupMenu.addEntry(new FLyrVectEditPropertiesTocMenuEntry());
679
    }
680

    
681
    public static void addEntry(TocMenuEntry entry) {
682
            menuEntrys.add(entry);
683
    }
684
    
685
    /**
686
     * Creates a new FPopupMenu object.
687
     *
688
     * @param nodo DOCUMENT ME!
689
     * @param vista DOCUMENT ME!
690
     */
691
    public FPopupMenu(FMap mc, DefaultMutableTreeNode node) {
692
        //super();
693
        this.mapContext = mc;
694
        this.nodo = node;
695
 
696
        //salir = new MenuItem("Salir");
697

    
698
        for (int i=0; i<menuEntrys.size(); i++) {
699
                ((TocMenuEntry) menuEntrys.get(i)).initialize(this);
700
        }
701
    }
702
    
703
    public FMap getMapContext() { return mapContext; }
704

    
705
}