Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / RasterBarToolsModule.java @ 20856

History | View | Annotate | Download (5.29 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools;
20

    
21
import java.awt.Point;
22

    
23
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
24
import org.gvsig.fmap.raster.layers.IRasterLayerActions;
25
import org.gvsig.raster.util.RasterToolsUtil;
26
import org.gvsig.rastertools.geolocation.behavior.GeoRasterBehavior;
27
import org.gvsig.rastertools.geolocation.listener.GeorefPanListener;
28
import org.gvsig.rastertools.geolocation.ui.GeoLocationDialog;
29

    
30
import com.iver.andami.PluginServices;
31
import com.iver.andami.plugins.Extension;
32
import com.iver.andami.ui.mdiManager.IWindow;
33
import com.iver.cit.gvsig.fmap.MapContext;
34
import com.iver.cit.gvsig.fmap.MapControl;
35
import com.iver.cit.gvsig.fmap.layers.FLayer;
36
import com.iver.cit.gvsig.fmap.layers.FLayers;
37
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
38
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
39
import com.iver.cit.gvsig.project.documents.view.IProjectView;
40
import com.iver.cit.gvsig.project.documents.view.gui.IView;
41
import com.iver.cit.gvsig.project.documents.view.gui.View;
42
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
43
/**
44
 * Extensi?n con las herramientas del men? que contienen usos especificos para capas 
45
 * raster. Estas no apareceran si la capa seleccionada del TOC no es raster.
46
 * 
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 */
49
public class RasterBarToolsModule extends Extension{
50
        private GeoLocationDialog gld = null;
51
        /*
52
         * (non-Javadoc)
53
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
54
         */
55
        public void execute(String actionCommand) {
56
                View theView = (View) PluginServices.getMDIManager().getActiveWindow();
57
                MapControl mapCtrl = theView.getMapControl();
58

    
59
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
60
                // la barra de estado
61
                StatusBarListener sbl = new StatusBarListener(mapCtrl);
62
                
63
                if (actionCommand.equals("GEO_PAN")) {
64
                                boolean isOpen = false;
65
                        
66
                                //Comprobamos si no hay capas activas. En este caso no lanzamos la ventana ni activamos la tool
67
                                IWindow[] win = PluginServices.getMDIManager().getAllWindows();
68
                                for (int i = 0; i < win.length; i++) {
69
                                        if (win[i] instanceof IView) {
70
                                                FLayers lyrs = ((IView)win[i]).getMapControl().getMapContext().getLayers();
71
                                                FLayer[] actives = lyrs.getActives();
72
                                                if(actives == null || actives.length == 0)
73
                                                        return;
74
                                        }
75
                                        if(win[i] instanceof GeoLocationDialog)
76
                                                isOpen = true;
77
                                }
78
                                if(gld == null)
79
                                        gld = new GeoLocationDialog();
80
                                if(!isOpen) {
81
                                        Point posit = RasterToolsUtil.iwindowPosition((int)gld.getSizeWindow().getWidth(), (int)gld.getSizeWindow().getHeight());
82
                                        gld.setPosition((int)posit.getX(), (int)posit.getY());
83
                                        RasterToolsUtil.addWindow(gld);
84
                                }
85
                                gld.init(mapCtrl);
86
                        loadGeoPanListener(mapCtrl, sbl, gld);
87
                        mapCtrl.setTool("geoPan");
88
                }
89
                
90
        }
91
        
92
        /**
93
         * Carga el listener de selecci?n de raster en el MapControl.
94
         */
95
        private void loadGeoPanListener(MapControl mapCtrl, StatusBarListener sbl, GeoLocationDialog gld) {
96
                if (mapCtrl.getNamesMapTools().get("geoPan") == null) {
97
                        GeorefPanListener pl = new GeorefPanListener(mapCtrl);
98
                        GeoRasterBehavior mb = new GeoRasterBehavior(pl, gld);
99
                        mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
100

    
101
                }
102
        }
103

    
104
        /*
105
         * (non-Javadoc)
106
         * @see com.iver.andami.plugins.IExtension#initialize()
107
         */
108
        public void initialize() {
109
                registerIcons();
110
        }
111

    
112
        private void registerIcons(){
113
                PluginServices.getIconTheme().register(
114
                                "forward-icon",
115
                                this.getClass().getClassLoader().getResource("images/forward.png")
116
                );
117
                PluginServices.getIconTheme().register(
118
                                "backwardward-icon",
119
                                this.getClass().getClassLoader().getResource("images/backward.png")
120
                );
121
        }
122

    
123
        /*
124
         * (non-Javadoc)
125
         * @see com.iver.andami.plugins.IExtension#isEnabled()
126
         */
127
        public boolean isEnabled() {
128
                return true;
129
        }
130

    
131
        /**
132
         * Mostramos el control si hay alguna capa cargada.
133
         */
134
        public boolean isVisible() {
135
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
136
                if (f == null)
137
                        return false;
138

    
139
                if (f instanceof View) {
140
                        View vista = (View) f;
141
                        IProjectView model = vista.getModel();
142
                        MapContext mapa = model.getMapContext();
143
                        if (mapa.getLayers().getLayersCount() > 0) {
144
                                if( mapa.getLayers().getActives().length == 1 &&
145
                                        mapa.getLayers().getActives()[0] instanceof FLyrRasterSE &&
146
                                        ((FLyrRasterSE)mapa.getLayers().getActives()[0]).isActionEnabled(IRasterLayerActions.FLYRASTER_BAR_TOOLS))
147
                                return true;
148
                        }
149
                }
150

    
151
                return false;
152
        }
153
}