Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / GeneralToolsModule.java @ 15804

History | View | Annotate | Download (3.92 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 org.gvsig.rastertools.pixelincrease.PixelncreaseDialog;
22
import org.gvsig.rastertools.saveraster.map.SaveRasterListener;
23

    
24
import com.iver.andami.PluginServices;
25
import com.iver.andami.plugins.Extension;
26
import com.iver.andami.ui.mdiManager.IWindow;
27
import com.iver.cit.gvsig.fmap.MapContext;
28
import com.iver.cit.gvsig.fmap.MapControl;
29
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
30
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
31
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
32
import com.iver.cit.gvsig.project.documents.view.IProjectView;
33
import com.iver.cit.gvsig.project.documents.view.gui.View;
34
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
35
/**
36
 * Extensi?n que contiene herramientas generales para gvSIG y que no son 
37
 * especificas de raster. Para este otro tipo es mejor utilizar RasterModule.
38
 *
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class GeneralToolsModule extends Extension{
42
        /*
43
         * (non-Javadoc)
44
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
45
         */
46
        public void execute(String actionCommand) {
47
                View theView = (View) PluginServices.getMDIManager().getActiveWindow();
48
                MapControl mapCtrl = theView.getMapControl();
49

    
50
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
51
                // la barra de estado
52
                StatusBarListener sbl = new StatusBarListener(mapCtrl);
53

    
54
                if (actionCommand.equals("SAVERASTER")) {
55
                        loadSaveRasterListener(mapCtrl, sbl);
56
                        mapCtrl.setTool("saveRaster");
57
                }
58

    
59
                if (actionCommand.equals("PIXELINCREASE")) {
60
                        IWindow[] win = PluginServices.getMDIManager().getAllWindows();
61
                        for (int i = 0; i < win.length; i++) {
62
                                if (win[i] instanceof PixelncreaseDialog) {
63
                                        PluginServices.getMDIManager().closeWindow(win[i]);
64
                                        return;
65
                                }
66
                        }
67
                        PixelncreaseDialog pIncrease = new PixelncreaseDialog();
68
                        PluginServices.getMDIManager().addWindow(pIncrease);
69
                }
70
        }
71

    
72
        /**
73
         * Carga el listener de salvar a raster en el MapControl.
74
         */
75
        private void loadSaveRasterListener(MapControl m_MapControl, StatusBarListener sbl) {
76
                // Si no se ha cargado el listener a?n lo cargamos.
77
                if (m_MapControl.getNamesMapTools().get("saveRaster") == null) {
78
                        SaveRasterListener srl = new SaveRasterListener(m_MapControl);
79
                        m_MapControl.addMapTool("saveRaster", new Behavior[] { new RectangleBehavior(srl), new MouseMovementBehavior(sbl) });
80
                }
81
        }
82
        
83
        /*
84
         * (non-Javadoc)
85
         * @see com.iver.andami.plugins.IExtension#initialize()
86
         */
87
        public void initialize() {
88
        }
89

    
90
        /*
91
         * (non-Javadoc)
92
         * @see com.iver.andami.plugins.IExtension#isEnabled()
93
         */
94
        public boolean isEnabled() {
95
                return true;
96
        }
97

    
98
        /**
99
         * Mostramos el control si hay alguna capa cargada.
100
         */
101
        public boolean isVisible() {
102
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
103
                if (f == null)
104
                        return false;
105

    
106
                if (f instanceof View) {
107
                        View vista = (View) f;
108
                        IProjectView model = vista.getModel();
109
                        MapContext mapa = model.getMapContext();
110
                        if (mapa.getLayers().getLayersCount() > 0) 
111
                                return true;
112
                }
113

    
114
                return false;
115
        }
116
}