Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / analysisview / ViewRasterAnalysisTocMenuEntry.java @ 31496

History | View | Annotate | Download (6.93 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.analysisview;
20

    
21
import java.beans.PropertyChangeEvent;
22
import java.beans.PropertyChangeListener;
23
import java.util.ArrayList;
24

    
25
import javax.swing.Icon;
26
import javax.swing.JOptionPane;
27

    
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.andami.ui.mdiManager.IWindow;
30
import org.gvsig.app.project.documents.view.MapOverview;
31
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
32
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
33
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
34
import org.gvsig.app.project.documents.view.toc.ITocItem;
35
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.fmap.mapcontrol.MapControl;
39
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
40
import org.gvsig.fmap.raster.layers.ILayerState;
41
import org.gvsig.raster.gui.IGenericToolBarMenuItem;
42
import org.gvsig.raster.util.RasterToolsUtil;
43
import org.gvsig.rastertools.pixelincrease.PixelIncreaseDialog;
44

    
45
/**
46
 * Herramienta del men? contextual que carga el raster en el localizador para tener una visi?n general de
47
 * esta y carga el zoom del cursor para tener una selecci?n de precisi?n.
48
 *
49
 * 16-jun-2007
50
 * @author Nacho Brodin (nachobrodin@gmail.com)
51
 */
52
public class ViewRasterAnalysisTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener, IGenericToolBarMenuItem {
53
        private boolean onView = false;
54
        private String rasterNameInLoc = "";
55
        static private ViewRasterAnalysisTocMenuEntry singleton = null;
56

    
57
        /**
58
         * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
59
         * getSingleton()
60
         */
61
        private ViewRasterAnalysisTocMenuEntry() {}
62

    
63
        /**
64
         * Devuelve un objeto unico a dicha clase
65
         * @return
66
         */
67
        static public ViewRasterAnalysisTocMenuEntry getSingleton() {
68
                if (singleton == null)
69
                        singleton = new ViewRasterAnalysisTocMenuEntry();
70

    
71
                return singleton;
72
        }
73

    
74
        /*
75
         * (non-Javadoc)
76
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
77
         */
78
        public String getGroup() {
79
                return "RasterLayer";
80
        }
81

    
82
        /*
83
         * (non-Javadoc)
84
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
85
         */
86
        public int getGroupOrder() {
87
                return 55;
88
        }
89

    
90
        /*
91
         * (non-Javadoc)
92
         * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
93
         */
94
        public int getOrder() {
95
                return 4;
96
        }
97

    
98
        /*
99
         * (non-Javadoc)
100
         * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
101
         */
102
        public String getText() {
103
                if (!onView)
104
                        return RasterToolsUtil.getText(this, "analysisview");
105
                else
106
                        return RasterToolsUtil.getText(this, "closeanalysisview");
107
        }
108
        
109
        /*
110
         * (non-Javadoc)
111
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
112
         */
113
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
114
                if ((selectedItems == null) || (selectedItems.length != 1))
115
                        return false;
116

    
117
                if (!(selectedItems[0] instanceof ILayerState))
118
                        return false;
119

    
120
                if (!((ILayerState) selectedItems[0]).isOpen())
121
                        return false;
122
                return true;
123
        }
124

    
125
        /*
126
         * (non-Javadoc)
127
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
128
         */
129
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
130
                if ((selectedItems == null) || (selectedItems.length != 1))
131
                        return false;
132

    
133
                if (!(selectedItems[0] instanceof FLyrRasterSE))
134
                        return false;
135

    
136
                return true;
137
        }
138

    
139
        /*
140
         * (non-Javadoc)
141
         * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
142
         */
143
        public void execute(ITocItem item, FLayer[] selectedItems) {                
144
                MapControl mcCurrentLoc = null;
145
                ArrayList mapControlListLoc = new ArrayList();
146
                IWindow[] w = PluginServices.getMDIManager().getAllWindows();
147
                IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow();
148
                FLayer lyr = selectedItems[0];
149

    
150
                // Cerramos cualquier inspector de pixeles anterior que est? abierto y
151
                // obtenemos el mapcontrol del localizador
152
                for (int i = 0; i < w.length; i++) {
153
                        if (w[i] instanceof PixelIncreaseDialog)
154
                                RasterToolsUtil.closeWindow(w[i]);
155
                        if (w[i] instanceof DefaultViewPanel && w[i].equals(activeWindow))
156
                                mcCurrentLoc = ((AbstractViewPanel) w[i]).getMapOverview();
157
                        if (w[i] instanceof DefaultViewPanel)
158
                                mapControlListLoc.add(((AbstractViewPanel) w[i]).getMapOverview());
159
                }
160

    
161
                if (!onView) {
162
                        // Abrimos el inspector de pixeles
163
                        PixelIncreaseDialog pIncrease = new PixelIncreaseDialog();
164
                        RasterToolsUtil.addWindow(pIncrease);
165

    
166
                        // Cargamos el raster en el localizador
167
                        mcCurrentLoc.getMapContext().beginAtomicEvent();
168

    
169
                        Object path = null;
170
                        if (lyr instanceof FLyrRasterSE)
171
                                path = ((FLyrRasterSE) lyr).getLoadParams();
172

    
173
                        try {
174
                                lyr = FLyrRasterSE.createLayer(lyr.getName(), path, lyr.getProjection());
175
                                rasterNameInLoc = lyr.getName();
176
                                mcCurrentLoc.getMapContext().getLayers().addLayer(lyr);
177
                        } catch (LoadLayerException e) {
178
                                JOptionPane.showMessageDialog(null, RasterToolsUtil.getText(this, "coordenadas_erroneas"));
179
                        }
180
                        mcCurrentLoc.getMapContext().endAtomicEvent();
181
                } else {
182
                        for (int nViews = 0; nViews < mapControlListLoc.size(); nViews++) {
183
                                MapControl mc = ((MapControl) mapControlListLoc.get(nViews));
184
                                FLayers lyrs = mc.getMapContext().getLayers();
185
                                for (int i = 0; i < lyrs.getLayersCount(); i++) {
186
                                        if (lyrs.getLayer(i).getName().compareTo(rasterNameInLoc) == 0)
187
                                                lyrs.removeLayer(i);
188
                                }
189
                                if (mc instanceof MapOverview)
190
                                        ((MapOverview) mc).refreshExtent();
191
                        }
192
                }
193
                onView = !onView;
194
        }
195

    
196
        /*
197
         * (non-Javadoc)
198
         * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
199
         */
200
        public Icon getIcon() {
201
                return RasterToolsUtil.getIcon("analisis-icon");
202
        }
203

    
204
        public void propertyChange(PropertyChangeEvent evt) {}
205
}