root / branches / gvSIG_03_SLD / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeControls.java @ 2104
History | View | Annotate | Download (7.67 KB)
1 |
/*
|
---|---|
2 |
* Created on 31-may-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig; |
48 |
|
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.andami.messages.NotificationManager; |
51 |
import com.iver.andami.plugins.Extension; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.FMap; |
55 |
import com.iver.cit.gvsig.fmap.MapControl; |
56 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
57 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
59 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
60 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
61 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
62 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
63 |
import com.iver.cit.gvsig.gui.View; |
64 |
import com.iver.cit.gvsig.project.ProjectView; |
65 |
|
66 |
import com.iver.utiles.GenericFileFilter; |
67 |
|
68 |
import org.apache.log4j.Logger; |
69 |
|
70 |
import java.awt.Component; |
71 |
import java.awt.geom.Rectangle2D; |
72 |
import java.io.File; |
73 |
|
74 |
import java.util.BitSet; |
75 |
|
76 |
import javax.swing.JFileChooser; |
77 |
|
78 |
|
79 |
/**
|
80 |
* Extensi?n de operaciones sobre el tema.
|
81 |
*
|
82 |
* @author Vicente Caballero Navarro
|
83 |
*/
|
84 |
public class ThemeControls implements Extension { |
85 |
private static Logger logger = Logger.getLogger(ThemeControls.class.getName()); |
86 |
|
87 |
/**
|
88 |
* @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
|
89 |
*/
|
90 |
public void execute(String s) { |
91 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
92 |
ProjectView model = vista.getModel(); |
93 |
FMap mapa = model.getMapContext(); |
94 |
MapControl mapCtrl = vista.getMapControl(); |
95 |
logger.debug("Comand : " + s);
|
96 |
|
97 |
if (s.compareTo("PROPERTIES") == 0) { |
98 |
vista.openThemeProperties(); |
99 |
} else if (s.compareTo("SHAPE_SELECTED") == 0) { |
100 |
createShape(mapa); |
101 |
} else if (s.compareTo("DXF_SELECTED") == 0) { |
102 |
createDxf(mapa); |
103 |
} else if (s.compareTo("DEL_SELECTION") == 0) { |
104 |
boolean refresh = false; |
105 |
|
106 |
for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
107 |
if (mapa.getLayers().getLayer(i) instanceof Selectable) { |
108 |
if (mapa.getLayers().getLayer(i).isActive()) {
|
109 |
BitSet bitset = ((Selectable) mapa.getLayers().getLayer(i)).getSelection();
|
110 |
|
111 |
if (bitset.cardinality() != 0) { |
112 |
refresh = true;
|
113 |
} |
114 |
|
115 |
bitset.clear(); |
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
if (refresh) {
|
121 |
mapCtrl.drawMap(false);
|
122 |
} |
123 |
} else if (s.compareTo("ZOOM_SELECT") == 0) { |
124 |
Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
125 |
|
126 |
if (selectedExtent != null) { |
127 |
mapa.getViewPort().setExtent(selectedExtent); |
128 |
} |
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Crea un nuevo shape.
|
134 |
*
|
135 |
* @param map FMap de donde coger las capas a copiar.
|
136 |
*/
|
137 |
private void createShape(FMap map) { |
138 |
if (map.getSelectionBounds() != null) { |
139 |
JFileChooser jfc = new JFileChooser(); |
140 |
jfc.addChoosableFileFilter(new GenericFileFilter("shp", |
141 |
PluginServices.getText(this, "ShapeFile"))); |
142 |
|
143 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
144 |
File file=jfc.getSelectedFile();
|
145 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
146 |
file=new File(file.getPath()+".shp"); |
147 |
} |
148 |
//SHP.SHPFileFromSelected(map, file);
|
149 |
SelectedShapeVisitor ssv=new SelectedShapeVisitor();
|
150 |
try {
|
151 |
map.getLayers().process(ssv); |
152 |
} catch (DriverException e1) {
|
153 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
154 |
e1); |
155 |
} catch (VisitException e) {
|
156 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
157 |
e); |
158 |
} |
159 |
IGeometry[] fgs=ssv.getSelectedGeometries();
|
160 |
SelectableDataSource sds=ssv.getSelectableDataSource(); |
161 |
BitSet bitset=ssv.getBitSet();
|
162 |
try {
|
163 |
sds.start(); |
164 |
SHP.SHPFileFromGeometries(fgs,bitset,sds,file); |
165 |
sds.stop(); |
166 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e2) {
|
167 |
NotificationManager.addError("No se pudo escribir la capa", e2);
|
168 |
} |
169 |
} |
170 |
} // else {
|
171 |
|
172 |
//}
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Crea un DXF partiendo de los objetos seleccionados. Desarrollado en el
|
177 |
* piloto de CAD. Lo de aqu? no sirve.
|
178 |
* @param map
|
179 |
*/
|
180 |
private void createDxf(FMap map) { |
181 |
if (map.getSelectionBounds() != null) { |
182 |
JFileChooser jfc = new JFileChooser(); |
183 |
jfc.addChoosableFileFilter(new GenericFileFilter("dxf", |
184 |
PluginServices.getText(this, "DxfFile"))); |
185 |
|
186 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
187 |
File file=jfc.getSelectedFile();
|
188 |
if (!(file.getPath().endsWith(".dxf") || file.getPath().endsWith(".DXF"))){ |
189 |
file=new File(file.getPath()+".dxf"); |
190 |
} |
191 |
//SHP.SHPFileFromSelected(map, file);
|
192 |
SelectedShapeVisitor ssv=new SelectedShapeVisitor();
|
193 |
try {
|
194 |
map.getLayers().process(ssv); |
195 |
} catch (DriverException e1) {
|
196 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
197 |
e1); |
198 |
} catch (VisitException e) {
|
199 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
200 |
e); |
201 |
} |
202 |
IGeometry[] fgs=ssv.getSelectedGeometries();
|
203 |
/*DxfWriter dxfWriter = new DxfWriter();
|
204 |
try {
|
205 |
dxfWriter.write(fgs, file);
|
206 |
} catch (Exception e2) {
|
207 |
// TODO Auto-generated catch block
|
208 |
e2.printStackTrace();
|
209 |
}*/
|
210 |
/*SelectableDataSource sds=ssv.getSelectableDataSource();
|
211 |
BitSet bitset=ssv.getBitSet();
|
212 |
try {
|
213 |
sds.start();
|
214 |
SHP.SHPFileFromGeometries(fgs,bitset,sds,file);
|
215 |
sds.stop();
|
216 |
} catch (com.hardcode.gdbms.engine.data.DriverException e2) {
|
217 |
NotificationManager.addError("No se pudo escribir la capa", e2);
|
218 |
}*/
|
219 |
} |
220 |
} |
221 |
} |
222 |
|
223 |
/**
|
224 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
225 |
*/
|
226 |
public boolean isVisible() { |
227 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
228 |
.getActiveView(); |
229 |
|
230 |
if (f == null) { |
231 |
return false; |
232 |
} |
233 |
|
234 |
if (f.getClass() == View.class) { |
235 |
FMap mapa = ((View) f).getModel().getMapContext();
|
236 |
|
237 |
View v = (View) f; |
238 |
|
239 |
return mapa.getLayers().getLayersCount() > 0; |
240 |
} else {
|
241 |
return false; |
242 |
} |
243 |
} |
244 |
|
245 |
/**
|
246 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
247 |
*/
|
248 |
public boolean isEnabled() { |
249 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
250 |
|
251 |
if (f == null) { |
252 |
return false; |
253 |
} |
254 |
|
255 |
FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
256 |
|
257 |
return selected.length > 0; |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
262 |
*/
|
263 |
public void inicializar() { |
264 |
} |
265 |
} |