svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeControls.java @ 3479
History | View | Annotate | Download (8.15 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.dxf.write.DxfGisWriter; |
58 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
61 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
62 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
63 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
64 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
65 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
66 |
import com.iver.cit.gvsig.gui.View; |
67 |
import com.iver.cit.gvsig.project.ProjectView; |
68 |
|
69 |
import com.iver.utiles.GenericFileFilter; |
70 |
|
71 |
import org.apache.log4j.Logger; |
72 |
|
73 |
import java.awt.Component; |
74 |
import java.awt.geom.Rectangle2D; |
75 |
import java.io.File; |
76 |
|
77 |
import java.util.BitSet; |
78 |
|
79 |
import javax.swing.JFileChooser; |
80 |
|
81 |
|
82 |
/**
|
83 |
* Extensi?n de operaciones sobre el tema.
|
84 |
*
|
85 |
* @author Vicente Caballero Navarro
|
86 |
*/
|
87 |
public class ThemeControls implements Extension { |
88 |
private static Logger logger = Logger.getLogger(ThemeControls.class.getName()); |
89 |
|
90 |
/**
|
91 |
* @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
|
92 |
*/
|
93 |
public void execute(String s) { |
94 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
95 |
ProjectView model = vista.getModel(); |
96 |
FMap mapa = model.getMapContext(); |
97 |
MapControl mapCtrl = vista.getMapControl(); |
98 |
logger.debug("Comand : " + s);
|
99 |
|
100 |
if (s.compareTo("SHAPE_SELECTED") == 0) { |
101 |
createShape(mapa); |
102 |
} else if (s.compareTo("DXF_SELECTED") == 0) { |
103 |
createDxf(mapa); |
104 |
} else if (s.compareTo("DEL_SELECTION") == 0) { |
105 |
boolean refresh = false; |
106 |
|
107 |
for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
108 |
if (mapa.getLayers().getLayer(i) instanceof Selectable) { |
109 |
if (mapa.getLayers().getLayer(i).isActive()) {
|
110 |
Selectable selectable = (Selectable) mapa.getLayers().getLayer(i); |
111 |
|
112 |
if (selectable.getSelection().cardinality() != 0) { |
113 |
refresh = true;
|
114 |
} |
115 |
selectable.clearSelection(); |
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 |
DxfGisWriter dxfGisWriter = new DxfGisWriter();
|
204 |
try {
|
205 |
// map.getLayers() devuelve solo una capa porque la
|
206 |
// herramienta est? inhabilitada cuando hay varias capas
|
207 |
// seleccionadas.
|
208 |
FLayer layer = map.getLayers().getActives()[0];
|
209 |
//dxfGisWriter.write(fgs, layer, file);
|
210 |
} catch (Exception e2) { |
211 |
// TODO Auto-generated catch block
|
212 |
e2.printStackTrace(); |
213 |
} |
214 |
/*SelectableDataSource sds=ssv.getSelectableDataSource();
|
215 |
BitSet bitset=ssv.getBitSet();
|
216 |
try {
|
217 |
sds.start();
|
218 |
SHP.SHPFileFromGeometries(fgs,bitset,sds,file);
|
219 |
sds.stop();
|
220 |
} catch (com.hardcode.gdbms.engine.data.DriverException e2) {
|
221 |
NotificationManager.addError("No se pudo escribir la capa", e2);
|
222 |
}*/
|
223 |
} |
224 |
} |
225 |
} |
226 |
|
227 |
/**
|
228 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
229 |
*/
|
230 |
public boolean isVisible() { |
231 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
232 |
.getActiveView(); |
233 |
|
234 |
if (f == null) { |
235 |
return false; |
236 |
} |
237 |
|
238 |
if (f.getClass() == View.class) { |
239 |
FMap mapa = ((View) f).getModel().getMapContext();
|
240 |
|
241 |
//View v = (View) f;
|
242 |
|
243 |
return mapa.getLayers().getLayersCount() > 0; |
244 |
} else {
|
245 |
return false; |
246 |
} |
247 |
} |
248 |
|
249 |
/**
|
250 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
251 |
*/
|
252 |
public boolean isEnabled() { |
253 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
254 |
|
255 |
if (f == null) { |
256 |
return false; |
257 |
} |
258 |
|
259 |
FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
260 |
if (selected.length == 1 && selected[0] instanceof FLyrVect){ |
261 |
return true; |
262 |
} |
263 |
return false; |
264 |
} |
265 |
|
266 |
/**
|
267 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
268 |
*/
|
269 |
public void inicializar() { |
270 |
} |
271 |
} |