root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeControls.java @ 2981
History | View | Annotate | Download (7.76 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.FLyrVect; |
60 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
61 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
62 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
63 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
64 |
import com.iver.cit.gvsig.gui.View; |
65 |
import com.iver.cit.gvsig.project.ProjectView; |
66 |
|
67 |
import com.iver.utiles.GenericFileFilter; |
68 |
|
69 |
import org.apache.log4j.Logger; |
70 |
|
71 |
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 |
/**
|
81 |
* Extensi?n de operaciones sobre el tema.
|
82 |
*
|
83 |
* @author Vicente Caballero Navarro
|
84 |
*/
|
85 |
public class ThemeControls implements Extension { |
86 |
private static Logger logger = Logger.getLogger(ThemeControls.class.getName()); |
87 |
|
88 |
/**
|
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 |
FMap mapa = model.getMapContext(); |
95 |
MapControl mapCtrl = vista.getMapControl(); |
96 |
logger.debug("Comand : " + s);
|
97 |
|
98 |
if (s.compareTo("SHAPE_SELECTED") == 0) { |
99 |
createShape(mapa); |
100 |
} else if (s.compareTo("DXF_SELECTED") == 0) { |
101 |
createDxf(mapa); |
102 |
} 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 |
Selectable selectable = (Selectable) mapa.getLayers().getLayer(i); |
109 |
|
110 |
if (selectable.getSelection().cardinality() != 0) { |
111 |
refresh = true;
|
112 |
} |
113 |
selectable.clearSelection(); |
114 |
} |
115 |
} |
116 |
} |
117 |
|
118 |
if (refresh) {
|
119 |
mapCtrl.drawMap(false);
|
120 |
} |
121 |
} else if (s.compareTo("ZOOM_SELECT") == 0) { |
122 |
Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
123 |
|
124 |
if (selectedExtent != null) { |
125 |
mapa.getViewPort().setExtent(selectedExtent); |
126 |
} |
127 |
} |
128 |
} |
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 |
if (map.getSelectionBounds() != null) { |
137 |
JFileChooser jfc = new JFileChooser(); |
138 |
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 |
//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 |
try {
|
161 |
sds.start(); |
162 |
SHP.SHPFileFromGeometries(fgs,bitset,sds,file); |
163 |
sds.stop(); |
164 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e2) {
|
165 |
NotificationManager.addError("No se pudo escribir la capa", e2);
|
166 |
} |
167 |
} |
168 |
} // else {
|
169 |
|
170 |
//}
|
171 |
} |
172 |
|
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 |
|
184 |
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 |
//IGeometry[] fgs=ssv.getSelectedGeometries();
|
201 |
/*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 |
/**
|
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 |
} |
231 |
|
232 |
if (f.getClass() == View.class) { |
233 |
FMap mapa = ((View) f).getModel().getMapContext();
|
234 |
|
235 |
//View v = (View) f;
|
236 |
|
237 |
return mapa.getLayers().getLayersCount() > 0; |
238 |
} else {
|
239 |
return false; |
240 |
} |
241 |
} |
242 |
|
243 |
/**
|
244 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
245 |
*/
|
246 |
public boolean isEnabled() { |
247 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
248 |
|
249 |
if (f == null) { |
250 |
return false; |
251 |
} |
252 |
|
253 |
FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
254 |
if (selected.length == 1 && selected[0] instanceof FLyrVect){ |
255 |
return true; |
256 |
} |
257 |
return false; |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
262 |
*/
|
263 |
public void inicializar() { |
264 |
} |
265 |
} |