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 / infobypoint / InfoByRasterPointExtension.java @ 1194

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

    
24
import java.awt.Component;
25
import java.util.Observable;
26
import java.util.Observer;
27

    
28
import javax.swing.JOptionPane;
29

    
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.PluginsLocator;
32
import org.gvsig.andami.actioninfo.ActionInfoManager;
33
import org.gvsig.andami.plugins.Extension;
34
import org.gvsig.andami.ui.mdiManager.IWindow;
35
import org.gvsig.app.project.documents.view.ViewDocument;
36
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
37
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener;
38
import org.gvsig.fmap.mapcontext.MapContext;
39
import org.gvsig.fmap.mapcontext.layers.FLayers;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior;
42
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior;
43
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior;
44
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
45
import org.gvsig.raster.fmap.layers.FLyrRaster;
46
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel;
47
import org.gvsig.raster.tools.app.basic.tool.infobypoint.viewtool.InfoByPixelPointViewTool;
48
import org.gvsig.raster.tools.app.basic.tool.infobypoint.viewtool.PixelInspectorViewTool;
49

    
50
/**
51
 * Plugin for the information by point of a raster layer
52
 * @author Nacho Brodin (nachobrodin@gmail.com)
53
 */
54
public class InfoByRasterPointExtension extends Extension {
55
        private InfoByPixelPointViewTool     lastTool      = null;
56
        public static Behavior               oldBehavior   = null;
57
        
58
        /*
59
         * (non-Javadoc)
60
         * @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
61
         */
62
        public void execute(String actionCommand) {
63
                if(actionCommand.compareTo("INFO_BY_PIXEL") == 0) {
64
                        MapControl mapCtrl = getMapControl();
65
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
66
                        
67
                        IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
68
                        for (int i = 0; i < wList.length; i++) {
69
                                if(wList[i] instanceof MainInfoByPointDialog) {
70
                                        JOptionPane.showMessageDialog(
71
                                                        (Component)wList[i], 
72
                                                        PluginServices.getText(this, "open_window"), 
73
                                                        PluginServices.getText(this, "Information"), 
74
                                                        JOptionPane.INFORMATION_MESSAGE);
75
                                        mapCtrl.addBehavior("infoByRasterPoint", 
76
                                                        new Behavior[]{new PointBehavior(lastTool),
77
                                                        new MouseMovementBehavior(sbl)});
78
                                        mapCtrl.setTool("infoByRasterPoint");
79
                                        return;
80
                                }
81
                        }
82
                        MainInfoByPointDialog dialog = new MainInfoByPointDialog();
83
                        InfoByPointDataModel model = dialog.getInfoByPointDataModel();
84
                        ((Observable)model).addObserver((Observer)dialog.getMainPanel());
85
                        
86
                        lastTool = new InfoByPixelPointViewTool(mapCtrl, model);
87
                        mapCtrl.addBehavior("infoByRasterPoint", 
88
                                        new Behavior[]{new PointBehavior(lastTool),
89
                                        new MouseMovementBehavior(sbl)});
90
                        mapCtrl.setTool("infoByRasterPoint");
91
                        oldBehavior = CompoundBehavior.getAllControlsBehavior();
92
                        CompoundBehavior.setAllControlsBehavior(new PixelInspectorViewTool(mapCtrl, model, dialog.getPixelInspector()));
93
                        
94
                        model.notifyObservers();
95
                        PluginServices.getMDIManager().addWindow(dialog);
96
                }
97
        }
98
        
99
        private MapControl getMapControl() {
100
                IWindow theView = PluginServices.getMDIManager().getActiveWindow();
101
                if(!(theView instanceof AbstractViewPanel)) {
102
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "window_not_valid"));
103
                        return null;
104
                }
105
                return ((AbstractViewPanel)theView).getMapControl();
106
        }
107
        
108
        /*
109
         * (non-Javadoc)
110
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
111
         */
112
        @SuppressWarnings("deprecation")
113
        public boolean isEnabled() {
114
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
115
                if (f == null)
116
                        return false;
117
                if (f instanceof AbstractViewPanel) {
118
                        AbstractViewPanel vista = (AbstractViewPanel) f;
119
                        ViewDocument model = vista.getModel();
120
                        MapContext mapa = model.getMapContext();
121
                        FLayers layers = mapa.getLayers();
122
                        for (int i = 0; i < layers.getLayersCount(); i++)
123
                                if (layers.getLayer(i) instanceof FLyrRaster) {
124
                                        FLyrRaster lyr = (FLyrRaster)layers.getLayer(i);
125
                                        if(lyr.isActive())
126
                                                return true;
127
                                }
128
                }
129
                return false;
130
        }
131
        
132
        /*
133
         * (non-Javadoc)
134
         * @see org.gvsig.andami.plugins.IExtension#isVisible()
135
         */
136
        public boolean isVisible() {
137
                return isEnabled();
138
        }
139

    
140
        /*
141
         * (non-Javadoc)
142
         * @see org.gvsig.andami.plugins.IExtension#initialize()
143
         */
144
        public void initialize() {
145
        }
146
        
147
        @Override
148
        public void postInitialize() {
149
                super.postInitialize();
150
                ActionInfoManager manager = PluginsLocator.getActionInfoManager();
151
                manager.redirect("layer-info-by-point", "layer-info-by-raster-point");
152
        }
153
}