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