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