Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / saveraster / map / SaveRasterListener.java @ 1354

History | View | Annotate | Download (4.13 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.raster.tools.app.basic.tool.saveraster.map;
23

    
24

    
25
import java.awt.Image;
26
import java.awt.geom.Point2D;
27
import java.text.NumberFormat;
28

    
29
import org.gvsig.andami.IconThemeHelper;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.fmap.mapcontext.ViewPort;
33
import org.gvsig.fmap.mapcontext.layers.FLayers;
34
import org.gvsig.fmap.mapcontrol.MapControl;
35
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent;
36
import org.gvsig.raster.fmap.tool.SaveRasterListenerImpl;
37
import org.gvsig.raster.tools.app.basic.tool.saveraster.ui.SaveRasterDialog;
38
import org.gvsig.raster.tools.app.basic.tool.saveraster.ui.SaveRasterPanel;
39

    
40

    
41

    
42
/**
43
 * Extensi?n de la clase SaveRasterListenerImpl de FMap para poder llamar a m?todos
44
 * de andami o de gvSIG.
45
 *
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class SaveRasterListener extends SaveRasterListenerImpl {
49
        private final Image isaveraster = IconThemeHelper.getImage("rectangle-select-cursor");
50

    
51
        public SaveRasterListener(MapControl mapCtrl) {
52
                super(mapCtrl);
53
        }
54

    
55
        public void rectangle(EnvelopeEvent event) {
56
                super.rectangle(event);
57

    
58
                if (PluginServices.getMainFrame() != null)
59
                                PluginServices.getMainFrame().enableControls();
60

    
61
                FLayers layers = mapCtrl.getMapContext().getLayers();
62

    
63
                SaveRasterDialog saveRaster = null;
64
                boolean open = false;
65
                IWindow[] win = PluginServices.getMDIManager().getAllWindows();
66
                for(int i = 0; i < win.length; i++) {
67
                        if(win[i] instanceof SaveRasterDialog) {
68
                                saveRaster = (SaveRasterDialog)win[i];
69
                                open = true;
70
                        }
71
                }
72
                if(saveRaster == null)
73
                        saveRaster = new SaveRasterDialog(layers, mapCtrl);
74

    
75
                ViewPort vp = mapCtrl.getViewPort();
76
                Point2D ini = vp.fromMapPoint(rect.getMinimum(0), rect.getMinimum(1));
77
                Point2D fin = vp.fromMapPoint(rect.getMaximum(0), rect.getMaximum(1));
78
                if(Math.abs(fin.getY() - ini.getY()) > 10 && Math.abs(fin.getX() - ini.getX()) > 10) {
79
                        SaveRasterPanel dialog = saveRaster.getControlsPanel();
80
                        dialog.getBProperties().setEnabled(false);
81
                        dialog.setViewPort(vp);
82

    
83
                        NumberFormat nf = NumberFormat.getInstance();
84
                nf.setMaximumFractionDigits(4);
85
                
86
                        if(!vp.getProjection().isProjected())
87
                                nf.setMaximumFractionDigits(6);
88

    
89
                        try{
90
                                dialog.getTInfDerX().setValue(nf.format(rect.getMaximum(0)).replace(",", ""));
91
                        }catch(IndexOutOfBoundsException ex){
92
                                dialog.getTInfDerX().setValue(String.valueOf(rect.getMaximum(0)));
93
                        }
94

    
95
                        try{
96
                                dialog.getTInfDerY().setValue(nf.format(rect.getMinimum(1)).replace(",", ""));
97
                        }catch(IndexOutOfBoundsException ex){
98
                                dialog.getTInfDerY().setValue(String.valueOf(rect.getMinimum(1)));
99
                        }
100

    
101
                        try{
102
                                dialog.getTSupIzqX().setValue(nf.format(rect.getMinimum(0)).replace(",", ""));
103
                        }catch(IndexOutOfBoundsException ex){
104
                                dialog.getTSupIzqX().setValue(String.valueOf(rect.getMinimum(0)));
105
                        }
106

    
107
                        try{
108
                                dialog.getTSupIzqY().setValue(nf.format(rect.getMaximum(1)).replace(",", ""));
109
                        }catch(IndexOutOfBoundsException ex){
110
                                dialog.getTSupIzqY().setValue(String.valueOf(rect.getMaximum(1)));
111
                        }
112
                        if(!open)
113
                                PluginServices.getMDIManager().addWindow(saveRaster);
114
                }
115
        }
116
        
117
        /*
118
         * (non-Javadoc)
119
         * @see org.gvsig.fmap.mapcontrol.tools.Listeners.ToolListener#getImageCursor()
120
         */
121
        public Image getImageCursor() {
122
                return isaveraster;
123
        }
124
}