svn-gvsig-desktop / tags / Root_gvSIG_CAD_Layout_version / applications / appgvSIG / src / com / iver / cit / gvsig / ThemeControls.java @ 1648
History | View | Annotate | Download (7.87 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 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.andami.messages.NotificationManager; |
60 |
import com.iver.andami.plugins.Extension; |
61 |
import com.iver.cit.gvsig.fmap.DriverException; |
62 |
import com.iver.cit.gvsig.fmap.FMap; |
63 |
import com.iver.cit.gvsig.fmap.MapControl; |
64 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
65 |
import com.iver.cit.gvsig.fmap.drivers.dxf.write.DxfWriter; |
66 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
67 |
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource; |
68 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
70 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
71 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer; |
72 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable; |
73 |
import com.iver.cit.gvsig.fmap.operations.strategies.SelectedShapeVisitor; |
74 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
75 |
import com.iver.cit.gvsig.gui.View; |
76 |
import com.iver.cit.gvsig.project.ProjectView; |
77 |
import com.iver.utiles.GenericFileFilter; |
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().getMapControl(); |
96 |
logger.debug("Comand : " + s);
|
97 |
|
98 |
if (s.compareTo("PROPERTIES") == 0) { |
99 |
vista.openThemeProperties(); |
100 |
} else 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 |
BitSet bitset = ((Selectable) mapa.getLayers().getLayer(i)).getSelection();
|
111 |
|
112 |
if (bitset.cardinality() != 0) { |
113 |
refresh = true;
|
114 |
} |
115 |
|
116 |
bitset.clear(); |
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
if (refresh) {
|
122 |
mapCtrl.drawMap(false);
|
123 |
} |
124 |
} else if (s.compareTo("ZOOM_SELECT") == 0) { |
125 |
Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
126 |
|
127 |
if (selectedExtent != null) { |
128 |
mapa.getViewPort().setExtent(selectedExtent); |
129 |
} |
130 |
} |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Crea un nuevo shape.
|
135 |
*
|
136 |
* @param map FMap de donde coger las capas a copiar.
|
137 |
*/
|
138 |
private void createShape(FMap map) { |
139 |
if (map.getSelectionBounds() != null) { |
140 |
JFileChooser jfc = new JFileChooser(); |
141 |
jfc.addChoosableFileFilter(new GenericFileFilter("shp", |
142 |
PluginServices.getText(this, "ShapeFile"))); |
143 |
|
144 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
145 |
File file=jfc.getSelectedFile();
|
146 |
if (!(file.getPath().endsWith(".shp") || file.getPath().endsWith(".SHP"))){ |
147 |
file=new File(file.getPath()+".shp"); |
148 |
} |
149 |
//SHP.SHPFileFromSelected(map, file);
|
150 |
SelectedShapeVisitor ssv=new SelectedShapeVisitor();
|
151 |
try {
|
152 |
map.getLayers().process(ssv); |
153 |
} catch (DriverException e1) {
|
154 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
155 |
e1); |
156 |
} catch (VisitException e) {
|
157 |
throw new RuntimeException("No se espera que SelectByPointVisitor lance esta excepci?n", |
158 |
e); |
159 |
} |
160 |
IGeometry[] fgs=ssv.getSelectedGeometries();
|
161 |
SelectableDataSource sds=ssv.getSelectableDataSource(); |
162 |
BitSet bitset=ssv.getBitSet();
|
163 |
try {
|
164 |
sds.start(); |
165 |
SHP.SHPFileFromGeometries(fgs,bitset,sds,file); |
166 |
sds.stop(); |
167 |
} catch (com.hardcode.gdbms.engine.data.DriverException e2) {
|
168 |
NotificationManager.addError("No se pudo escribir la capa", e2);
|
169 |
} |
170 |
} |
171 |
} // else {
|
172 |
|
173 |
//}
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Crea un DXF2000 partiendo de los objetos seleccionados.
|
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 |
DxfWriter dxfWriter = new DxfWriter();
|
204 |
try {
|
205 |
dxfWriter.write(fgs, file); |
206 |
} catch (Exception e2) { |
207 |
// TODO Auto-generated catch block
|
208 |
e2.printStackTrace(); |
209 |
} |
210 |
/*SelectableDataSource sds=ssv.getSelectableDataSource();
|
211 |
BitSet bitset=ssv.getBitSet();
|
212 |
try {
|
213 |
sds.start();
|
214 |
SHP.SHPFileFromGeometries(fgs,bitset,sds,file);
|
215 |
sds.stop();
|
216 |
} catch (com.hardcode.gdbms.engine.data.DriverException e2) {
|
217 |
NotificationManager.addError("No se pudo escribir la capa", e2);
|
218 |
}*/
|
219 |
} |
220 |
} |
221 |
} |
222 |
|
223 |
/**
|
224 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
225 |
*/
|
226 |
public boolean isVisible() { |
227 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
228 |
.getActiveView(); |
229 |
|
230 |
if (f == null) { |
231 |
return false; |
232 |
} |
233 |
|
234 |
if (f.getClass() == View.class) { |
235 |
FMap mapa = ((View) f).getModel().getMapContext();
|
236 |
|
237 |
View v = (View) f; |
238 |
|
239 |
return mapa.getLayers().getLayersCount() > 0; |
240 |
} else {
|
241 |
return false; |
242 |
} |
243 |
} |
244 |
|
245 |
/**
|
246 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
247 |
*/
|
248 |
public boolean isEnabled() { |
249 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
250 |
|
251 |
if (f == null) { |
252 |
return false; |
253 |
} |
254 |
|
255 |
FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
256 |
|
257 |
return selected.length > 0; |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
262 |
*/
|
263 |
public void inicializar() { |
264 |
} |
265 |
} |