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