root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeControls.java @ 9212
History | View | Annotate | Download (7.55 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
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 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig; |
48 | |||
49 | 5005 | jorpiell | import java.awt.Component; |
50 | import java.awt.geom.Rectangle2D; |
||
51 | import java.io.File; |
||
52 | import java.util.BitSet; |
||
53 | |||
54 | import javax.swing.JFileChooser; |
||
55 | |||
56 | import org.apache.log4j.Logger; |
||
57 | |||
58 | 596 | fernando | import com.iver.andami.PluginServices; |
59 | 1294 | fernando | import com.iver.andami.messages.NotificationManager; |
60 | 596 | fernando | import com.iver.andami.plugins.Extension; |
61 | 1270 | vcaballero | import com.iver.cit.gvsig.fmap.DriverException; |
62 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
63 | 1223 | fernando | import com.iver.cit.gvsig.fmap.MapControl; |
64 | 1270 | vcaballero | import com.iver.cit.gvsig.fmap.core.IGeometry; |
65 | 3186 | jmorell | import com.iver.cit.gvsig.fmap.drivers.dxf.write.DxfGisWriter; |
66 | 1169 | vcaballero | import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
67 | 312 | fernando | import com.iver.cit.gvsig.fmap.layers.FLayer; |
68 | 2421 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
69 | 1270 | vcaballero | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
70 | import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
||
71 | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
||
72 | 7392 | sbayarri | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
73 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
74 | 1169 | vcaballero | import com.iver.utiles.GenericFileFilter; |
75 | 312 | fernando | |
76 | |||
77 | /**
|
||
78 | 1219 | vcaballero | * Extensi?n de operaciones sobre el tema.
|
79 | 312 | fernando | *
|
80 | * @author Vicente Caballero Navarro
|
||
81 | */
|
||
82 | 5005 | jorpiell | public class ThemeControls extends Extension { |
83 | 1219 | vcaballero | private static Logger logger = Logger.getLogger(ThemeControls.class.getName()); |
84 | 312 | fernando | |
85 | 1219 | vcaballero | /**
|
86 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
87 | 1219 | vcaballero | */
|
88 | public void execute(String s) { |
||
89 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
90 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
91 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
92 | 1223 | fernando | MapControl mapCtrl = vista.getMapControl(); |
93 | 1169 | vcaballero | logger.debug("Comand : " + s);
|
94 | 1219 | vcaballero | |
95 | 6599 | caballero | if (s.equals("SHAPE_SELECTED")) { |
96 | 1169 | vcaballero | createShape(mapa); |
97 | 6599 | caballero | } else if (s.equals("DXF_SELECTED")) { |
98 | 1668 | jmorell | createDxf(mapa); |
99 | 6599 | caballero | } else if (s.equals("ZOOM_SELECT")) { |
100 | 1169 | vcaballero | Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
101 | |||
102 | if (selectedExtent != null) { |
||
103 | mapa.getViewPort().setExtent(selectedExtent); |
||
104 | } |
||
105 | } |
||
106 | 1219 | vcaballero | } |
107 | |||
108 | /**
|
||
109 | * Crea un nuevo shape.
|
||
110 | *
|
||
111 | * @param map FMap de donde coger las capas a copiar.
|
||
112 | */
|
||
113 | 6878 | cesar | private void createShape(MapContext map) { |
114 | 1169 | vcaballero | if (map.getSelectionBounds() != null) { |
115 | JFileChooser jfc = new JFileChooser(); |
||
116 | 1219 | vcaballero | jfc.addChoosableFileFilter(new GenericFileFilter("shp", |
117 | 5503 | cesar | PluginServices.getText(this, "Shapefile"))); |
118 | 1219 | vcaballero | |
119 | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
||
120 | File file=jfc.getSelectedFile();
|
||
121 | if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
||
122 | file=new File(file.getPath()+".shp"); |
||
123 | } |
||
124 | 1270 | vcaballero | //SHP.SHPFileFromSelected(map, file);
|
125 | SelectedShapeVisitor ssv=new SelectedShapeVisitor();
|
||
126 | try {
|
||
127 | map.getLayers().process(ssv); |
||
128 | } catch (DriverException e1) {
|
||
129 | throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
||
130 | e1); |
||
131 | } catch (VisitException e) {
|
||
132 | throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
||
133 | e); |
||
134 | } |
||
135 | IGeometry[] fgs=ssv.getSelectedGeometries();
|
||
136 | SelectableDataSource sds=ssv.getSelectableDataSource(); |
||
137 | BitSet bitset=ssv.getBitSet();
|
||
138 | 1294 | fernando | try {
|
139 | sds.start(); |
||
140 | SHP.SHPFileFromGeometries(fgs,bitset,sds,file); |
||
141 | sds.stop(); |
||
142 | 1830 | fernando | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e2) {
|
143 | 1294 | fernando | NotificationManager.addError("No se pudo escribir la capa", e2);
|
144 | } |
||
145 | 1169 | vcaballero | } |
146 | 1219 | vcaballero | } // else {
|
147 | |||
148 | 1169 | vcaballero | //}
|
149 | 1219 | vcaballero | } |
150 | 6599 | caballero | |
151 | 1668 | jmorell | /**
|
152 | * Crea un DXF partiendo de los objetos seleccionados. Desarrollado en el
|
||
153 | * piloto de CAD. Lo de aqu? no sirve.
|
||
154 | * @param map
|
||
155 | */
|
||
156 | 6878 | cesar | private void createDxf(MapContext map) { |
157 | 1668 | jmorell | if (map.getSelectionBounds() != null) { |
158 | JFileChooser jfc = new JFileChooser(); |
||
159 | jfc.addChoosableFileFilter(new GenericFileFilter("dxf", |
||
160 | 5503 | cesar | PluginServices.getText(this, "Dxffiles"))); |
161 | 1219 | vcaballero | |
162 | 1668 | jmorell | if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
163 | File file=jfc.getSelectedFile();
|
||
164 | if (!(file.getPath().endsWith(".dxf") || file.getPath().endsWith(".DXF"))){ |
||
165 | file=new File(file.getPath()+".dxf"); |
||
166 | } |
||
167 | //SHP.SHPFileFromSelected(map, file);
|
||
168 | SelectedShapeVisitor ssv=new SelectedShapeVisitor();
|
||
169 | try {
|
||
170 | map.getLayers().process(ssv); |
||
171 | } catch (DriverException e1) {
|
||
172 | throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
||
173 | e1); |
||
174 | } catch (VisitException e) {
|
||
175 | throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
||
176 | e); |
||
177 | } |
||
178 | 3186 | jmorell | IGeometry[] fgs=ssv.getSelectedGeometries();
|
179 | DxfGisWriter dxfGisWriter = new DxfGisWriter();
|
||
180 | 1668 | jmorell | try {
|
181 | 3436 | jmorell | // map.getLayers() devuelve solo una capa porque la
|
182 | // herramienta est? inhabilitada cuando hay varias capas
|
||
183 | // seleccionadas.
|
||
184 | FLayer layer = map.getLayers().getActives()[0];
|
||
185 | 3442 | jmorell | //dxfGisWriter.write(fgs, layer, file);
|
186 | 1668 | jmorell | } catch (Exception e2) { |
187 | // TODO Auto-generated catch block
|
||
188 | e2.printStackTrace(); |
||
189 | 3186 | jmorell | } |
190 | 1668 | jmorell | /*SelectableDataSource sds=ssv.getSelectableDataSource();
|
191 | BitSet bitset=ssv.getBitSet();
|
||
192 | try {
|
||
193 | sds.start();
|
||
194 | SHP.SHPFileFromGeometries(fgs,bitset,sds,file);
|
||
195 | sds.stop();
|
||
196 | } catch (com.hardcode.gdbms.engine.data.DriverException e2) {
|
||
197 | NotificationManager.addError("No se pudo escribir la capa", e2);
|
||
198 | }*/
|
||
199 | } |
||
200 | } |
||
201 | } |
||
202 | |||
203 | 1219 | vcaballero | /**
|
204 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
205 | 1219 | vcaballero | */
|
206 | public boolean isVisible() { |
||
207 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
208 | 6880 | cesar | .getActiveWindow(); |
209 | 1219 | vcaballero | |
210 | if (f == null) { |
||
211 | return false; |
||
212 | 1169 | vcaballero | } |
213 | 312 | fernando | |
214 | 5900 | jorpiell | if (f instanceof View) { |
215 | 6878 | cesar | MapContext mapa = ((View) f).getModel().getMapContext();
|
216 | 312 | fernando | |
217 | 2421 | caballero | //View v = (View) f;
|
218 | 312 | fernando | |
219 | 1219 | vcaballero | return mapa.getLayers().getLayersCount() > 0; |
220 | } else {
|
||
221 | return false; |
||
222 | } |
||
223 | } |
||
224 | 312 | fernando | |
225 | 1219 | vcaballero | /**
|
226 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
227 | 1219 | vcaballero | */
|
228 | public boolean isEnabled() { |
||
229 | 6880 | cesar | View f = (View) PluginServices.getMDIManager().getActiveWindow(); |
230 | 312 | fernando | |
231 | 1219 | vcaballero | if (f == null) { |
232 | return false; |
||
233 | } |
||
234 | 312 | fernando | |
235 | 1219 | vcaballero | FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
236 | 6778 | jmvivo | if (selected.length == 1 && selected[0] instanceof FLyrVect && selected[0].isAvailable()){ |
237 | 2421 | caballero | return true; |
238 | } |
||
239 | return false; |
||
240 | 1219 | vcaballero | } |
241 | 596 | fernando | |
242 | /**
|
||
243 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
244 | 596 | fernando | */
|
245 | 5005 | jorpiell | public void initialize() { |
246 | 596 | fernando | } |
247 | 312 | fernando | } |