Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / geolocation / GeoLocationTocMenuEntry.java @ 2480

History | View | Annotate | Download (6.08 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.geolocation;
23

    
24
import java.awt.Point;
25
import java.beans.PropertyChangeEvent;
26
import java.beans.PropertyChangeListener;
27

    
28
import javax.swing.Icon;
29

    
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
33
import org.gvsig.app.project.documents.view.gui.IView;
34
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
35
import org.gvsig.app.project.documents.view.toc.ITocItem;
36
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontext.layers.FLayers;
39
import org.gvsig.fmap.mapcontrol.MapControl;
40
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
41
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
42
import org.gvsig.raster.fmap.layers.FLyrRaster;
43
import org.gvsig.raster.fmap.layers.ILayerState;
44
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
45
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem;
46
import org.gvsig.raster.tools.app.basic.RasterToolsUtil;
47
import org.gvsig.raster.tools.app.basic.tool.geolocation.behavior.GeoRasterBehavior;
48
import org.gvsig.raster.tools.app.basic.tool.geolocation.listener.GeorefPanListener;
49
import org.gvsig.raster.tools.app.basic.tool.geolocation.ui.GeoLocationDialog;
50

    
51

    
52
/**
53
 * Herramienta del men? contextual que carga el raster en el localizador para tener una visi?n general de
54
 * esta y carga el zoom del cursor para tener una selecci?n de precisi?n.
55
 *
56
 * 16-jun-2007
57
 * @author Nacho Brodin (nachobrodin@gmail.com)
58
 */
59
public class GeoLocationTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener, IGenericToolBarMenuItem {
60
        static private GeoLocationTocMenuEntry singleton  = null;
61
        private GeoRasterBehavior mb = null;
62

    
63
        /**
64
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
65
         * getSingleton()
66
         */
67
        private GeoLocationTocMenuEntry() {}
68

    
69
        /**
70
         * Devuelve un objeto unico a dicha clase
71
         * @return
72
         */
73
        static public GeoLocationTocMenuEntry getSingleton() {
74
                if (singleton == null)
75
                        singleton = new GeoLocationTocMenuEntry();
76
                return singleton;
77
        }
78
        
79
        public String getGroup() {
80
                return "GeoRaster";
81
        }
82

    
83
        public int getGroupOrder() {
84
                return 10;
85
        }
86

    
87
        public int getOrder() {
88
                return 20;
89
        }
90

    
91
        public String getText() {
92
                return RasterToolsUtil.getText(this, "geolocation");
93
        }
94
        
95
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
96
                if ((selectedItems == null) || (selectedItems.length != 1))
97
                        return false;
98

    
99
                if (!(selectedItems[0] instanceof ILayerState))
100
                        return false;
101

    
102
                if (!((ILayerState) selectedItems[0]).isOpen())
103
                        return false;
104
                return true;
105
        }
106

    
107
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
108
                if ((selectedItems == null) || (selectedItems.length != 1))
109
                        return false;
110

    
111
                if (!(selectedItems[0] instanceof IRasterLayerActions))
112
                        return false;
113

    
114
                return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.GEOLOCATION);
115
        }
116

    
117
        public void execute(ITocItem item, FLayer[] selectedItems) {                
118
                boolean isOpen = false;
119
                
120
                AbstractViewPanel theView = (AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
121
                MapControl mapCtrl = theView.getMapControl();
122

    
123
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
124
                // la barra de estado
125
                StatusBarListener sbl = new StatusBarListener(mapCtrl);
126
                
127
                //Comprobamos si no hay capas activas. En este caso no lanzamos la ventana ni activamos la tool
128
                IWindow[] win = PluginServices.getMDIManager().getAllWindows();
129
                for (int i = 0; i < win.length; i++) {
130
                        if (win[i] instanceof IView) {
131
                                FLayers lyrs = ((IView) win[i]).getMapControl().getMapContext().getLayers();
132
                                FLayer[] actives = lyrs.getActives();
133
                                if (actives == null || actives.length == 0)
134
                                        return;
135
                        }
136
                        if (win[i] instanceof GeoLocationDialog)
137
                                isOpen = true;
138
                }
139
                
140
                if (selectedItems == null || selectedItems.length != 1 || !(selectedItems[0] instanceof FLyrRaster))
141
                        return;
142
                
143
                FLyrRaster lyr = (FLyrRaster)selectedItems[0];
144
                GeoLocationDialog gld = new GeoLocationDialog(lyr, mapCtrl.getViewPort(), theView);
145
                if(!isOpen) {
146
                        Point posit = RasterToolsUtil.iwindowPosition((int)gld.getSizeWindow().getWidth(), (int)gld.getSizeWindow().getHeight());
147
                        gld.setPosition((int)posit.getX(), (int)posit.getY());
148
                        RasterToolsUtil.addWindow(gld);
149
                }
150
                
151
                gld.init(mapCtrl);
152
                loadGeoPanListener(mapCtrl, sbl, gld, lyr);
153
                mapCtrl.setTool("geoPan");
154
        }
155

    
156
        /**
157
         * Carga el listener de selecci?n de raster en el MapControl.
158
         */
159
        private void loadGeoPanListener(MapControl mapCtrl, StatusBarListener sbl, GeoLocationDialog gld, FLyrRaster lyr) {
160
                if (mapCtrl.getNamesMapTools().get("geoPan") == null) {
161
                        GeorefPanListener pl = new GeorefPanListener(mapCtrl);
162
                        mb = new GeoRasterBehavior(pl, gld, lyr);
163
                        mapCtrl.addBehavior("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
164

    
165
                }
166
                
167
                if(mb != null) {
168
                        mb.setLayer(lyr);
169
                        mb.setITransformIO(gld);
170
                }
171
        }
172
        
173
        public Icon getIcon() {
174
                return RasterToolsUtil.getIcon("layer-geolocalization");
175
        }
176

    
177
        public void propertyChange(PropertyChangeEvent evt) {}
178
        
179
        public boolean isEnableEvents() {
180
                return true;
181
        }
182
}