svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / analysisview / ViewRasterAnalysisTocMenuEntry.java @ 18014
History | View | Annotate | Download (6.48 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.awt.Component; |
22 |
import java.beans.PropertyChangeEvent; |
23 |
import java.beans.PropertyChangeListener; |
24 |
import java.util.ArrayList; |
25 |
|
26 |
import javax.swing.JOptionPane; |
27 |
|
28 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
29 |
import org.gvsig.fmap.raster.layers.ILayerState; |
30 |
import org.gvsig.raster.Configuration; |
31 |
import org.gvsig.rastertools.pixelincrease.PixelncreaseDialog; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.ui.mdiManager.IWindow; |
35 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
36 |
import com.iver.cit.gvsig.fmap.MapControl; |
37 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
38 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
39 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
40 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
41 |
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
42 |
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
43 |
|
44 |
/**
|
45 |
* Herramienta del men? contextual que carga el raster en el localizador para tener una visi?n general de
|
46 |
* esta y carga el zoom del cursor para tener una selecci?n de precisi?n.
|
47 |
*
|
48 |
* 16-jun-2007
|
49 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
50 |
*/
|
51 |
public class ViewRasterAnalysisTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener { |
52 |
|
53 |
private boolean onView = false; |
54 |
private String rasterNameInLoc = ""; |
55 |
|
56 |
/*
|
57 |
* (non-Javadoc)
|
58 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
|
59 |
*/
|
60 |
public String getGroup() { |
61 |
return "RasterTools"; |
62 |
} |
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
|
67 |
*/
|
68 |
public int getGroupOrder() { |
69 |
return 55; |
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
|
75 |
*/
|
76 |
public int getOrder() { |
77 |
return 4; |
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
* @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
|
83 |
*/
|
84 |
public String getText() { |
85 |
if(!onView)
|
86 |
return PluginServices.getText(this, "analysisview"); |
87 |
else
|
88 |
return PluginServices.getText(this, "closeanalysisview"); |
89 |
} |
90 |
|
91 |
/*
|
92 |
* (non-Javadoc)
|
93 |
* @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[])
|
94 |
*/
|
95 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
96 |
if(getNodeLayer(item) instanceof ILayerState) |
97 |
if(!((ILayerState)getNodeLayer(item)).isOpen())
|
98 |
return false; |
99 |
return selectedItems.length == 1; |
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @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[])
|
105 |
*/
|
106 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
107 |
if (isTocItemBranch(item)) {
|
108 |
if(selectedItems == null || selectedItems.length != 1) |
109 |
return false; |
110 |
return (getNodeLayer(item) instanceof FLyrRasterSE); |
111 |
} |
112 |
return false; |
113 |
} |
114 |
|
115 |
/*
|
116 |
* (non-Javadoc)
|
117 |
* @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[])
|
118 |
*/
|
119 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
120 |
|
121 |
MapControl mcCurrentLoc = null;
|
122 |
ArrayList mapControlListLoc = new ArrayList(); |
123 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
124 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
125 |
FLayer lyr = selectedItems[0];
|
126 |
|
127 |
//Cerramos cualquier inspector de pixeles anterior que est? abierto y obtenemos el mapcontrol del localizador
|
128 |
for(int i = 0 ; i < w.length; i ++) { |
129 |
if(w[i] instanceof PixelncreaseDialog) |
130 |
PluginServices.getMDIManager().closeWindow(w[i]); |
131 |
if(w[i] instanceof View && w[i].equals(activeWindow)) |
132 |
mcCurrentLoc = ((View)w[i]).getMapOverview();
|
133 |
if(w[i] instanceof View) |
134 |
mapControlListLoc.add(((View)w[i]).getMapOverview());
|
135 |
} |
136 |
|
137 |
|
138 |
if(!onView) {
|
139 |
//Abrimos el inspector de pixeles
|
140 |
PixelncreaseDialog pIncrease = new PixelncreaseDialog();
|
141 |
PluginServices.getMDIManager().addWindow(pIncrease); |
142 |
|
143 |
//Cargamos el raster en el localizador
|
144 |
mcCurrentLoc.getMapContext().beginAtomicEvent(); |
145 |
|
146 |
Object path = null; |
147 |
if (lyr instanceof FLyrRasterSE) |
148 |
path = ((FLyrRasterSE) lyr).getLoadParams(); |
149 |
|
150 |
try {
|
151 |
lyr = FLyrRasterSE.createLayer(lyr.getName(), path, lyr.getProjection(), Configuration.getSingleton());
|
152 |
rasterNameInLoc = lyr.getName(); |
153 |
mcCurrentLoc.getMapContext().getLayers().addLayer(lyr); |
154 |
} catch (LoadLayerException e) {
|
155 |
JOptionPane.showMessageDialog(
|
156 |
(Component) PluginServices.getMainFrame(), PluginServices.getText(
|
157 |
this, "coordenadas_erroneas")); |
158 |
} |
159 |
mcCurrentLoc.getMapContext().endAtomicEvent(); |
160 |
} else {
|
161 |
for (int nViews = 0; nViews < mapControlListLoc.size(); nViews++) { |
162 |
MapControl mc = ((MapControl)mapControlListLoc.get(nViews)); |
163 |
FLayers lyrs = mc.getMapContext().getLayers(); |
164 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
165 |
if(lyrs.getLayer(i).getName().compareTo(rasterNameInLoc) == 0) |
166 |
lyrs.removeLayer(i); |
167 |
} |
168 |
if (mc instanceof MapOverview) |
169 |
((MapOverview)mc).refreshExtent(); |
170 |
} |
171 |
/*FLayers lyrs = mcCurrentLoc.getMapContext().getLayers();
|
172 |
for (int i = 0; i < lyrs.getLayersCount(); i++) {
|
173 |
if(lyrs.getLayer(i).getName().compareTo(lyr.getName()) == 0)
|
174 |
lyrs.removeLayer(i);
|
175 |
}
|
176 |
if (mcCurrentLoc instanceof MapOverview)
|
177 |
((MapOverview)mcCurrentLoc).refreshExtent();*/
|
178 |
} |
179 |
onView = !onView; |
180 |
} |
181 |
|
182 |
public void propertyChange(PropertyChangeEvent evt) { |
183 |
} |
184 |
|
185 |
} |