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

History | View | Annotate | Download (5.16 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
        public void execute(String actionCommand) {
59
                if(actionCommand.compareTo("INFO_BY_PIXEL") == 0) {
60
                        MapControl mapCtrl = getMapControl();
61
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
62
                        
63
                        IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
64
                        for (int i = 0; i < wList.length; i++) {
65
                                if(wList[i] instanceof MainInfoByPointDialog) {
66
                                        JOptionPane.showMessageDialog(
67
                                                        (Component)wList[i], 
68
                                                        PluginServices.getText(this, "open_window"), 
69
                                                        PluginServices.getText(this, "Information"), 
70
                                                        JOptionPane.INFORMATION_MESSAGE);
71
                                        mapCtrl.addBehavior("infoByRasterPoint", 
72
                                                        new Behavior[]{new PointBehavior(lastTool),
73
                                                        new MouseMovementBehavior(sbl)});
74
                                        mapCtrl.setTool("infoByRasterPoint");
75
                                        return;
76
                                }
77
                        }
78
                        MainInfoByPointDialog dialog = new MainInfoByPointDialog();
79
                        InfoByPointDataModel model = dialog.getInfoByPointDataModel();
80
                        ((Observable)model).addObserver((Observer)dialog.getMainPanel());
81
                        
82
                        lastTool = new InfoByPixelPointViewTool(mapCtrl, model);
83
                        mapCtrl.addBehavior("infoByRasterPoint", 
84
                                        new Behavior[]{new PointBehavior(lastTool),
85
                                        new MouseMovementBehavior(sbl)});
86
                        mapCtrl.setTool("infoByRasterPoint");
87
                        oldBehavior = CompoundBehavior.getAllControlsBehavior();
88
                        CompoundBehavior.setAllControlsBehavior(new PixelInspectorViewTool(mapCtrl, model, dialog.getPixelInspector()));
89
                        
90
                        model.notifyObservers();
91
                        PluginServices.getMDIManager().addWindow(dialog);
92
                }
93
        }
94
        
95
        private MapControl getMapControl() {
96
                IWindow theView = PluginServices.getMDIManager().getActiveWindow();
97
                if(!(theView instanceof AbstractViewPanel)) {
98
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "window_not_valid"));
99
                        return null;
100
                }
101
                return ((AbstractViewPanel)theView).getMapControl();
102
        }
103
        
104
        @SuppressWarnings("deprecation")
105
        public boolean isEnabled() {
106
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow();
107
                if (f == null)
108
                        return false;
109
                if (f instanceof AbstractViewPanel) {
110
                        AbstractViewPanel vista = (AbstractViewPanel) f;
111
                        ViewDocument model = vista.getModel();
112
                        MapContext mapa = model.getMapContext();
113
                        FLayers layers = mapa.getLayers();
114
                        for (int i = 0; i < layers.getLayersCount(); i++)
115
                                if (layers.getLayer(i) instanceof FLyrRaster) {
116
                                        FLyrRaster lyr = (FLyrRaster)layers.getLayer(i);
117
                                        if(lyr.isActive())
118
                                                return true;
119
                                }
120
                }
121
                return false;
122
        }
123
        
124
        public boolean isVisible() {
125
                return isEnabled();
126
        }
127

    
128
        public void initialize() {
129
        }
130
        
131
        @Override
132
        public void postInitialize() {
133
                super.postInitialize();
134
                ActionInfoManager manager = PluginsLocator.getActionInfoManager();
135
                manager.redirect("layer-info-by-point", "layer-info-by-raster-point");
136
        }
137
}