svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / DEMO / ComandosListener.java @ 312
History | View | Annotate | Download (11.3 KB)
1 |
/*
|
---|---|
2 |
* Created on 17-jun-2003
|
3 |
*
|
4 |
* Copyright (c) 2003
|
5 |
* Francisco Jos?Pearrubia Mart?ez
|
6 |
* IVER Tecnolog?s de la Informacin S.A.
|
7 |
* Salamanca 50
|
8 |
* 46005 Valencia ( SPAIN )
|
9 |
* +34 963163400
|
10 |
* mailto:fran@iver.es
|
11 |
* http://www.iver.es
|
12 |
*/
|
13 |
package com.iver.cit.gvsig.DEMO; |
14 |
|
15 |
import java.awt.event.ActionEvent; |
16 |
import java.awt.event.ActionListener; |
17 |
|
18 |
import javax.swing.JDialog; |
19 |
|
20 |
import org.cresques.cts.IProjection; |
21 |
import org.cresques.cts.ProjectionPool; |
22 |
|
23 |
import com.iver.cit.gvsig.fmap.FLyrDgnG; |
24 |
import com.iver.cit.gvsig.fmap.FLyrDxfG; |
25 |
import com.iver.cit.gvsig.fmap.FLyrRaster; |
26 |
import com.iver.cit.gvsig.fmap.FLyrShp; |
27 |
import com.iver.cit.gvsig.fmap.FLyrVect; |
28 |
import com.iver.cit.gvsig.fmap.FMap; |
29 |
import com.iver.cit.gvsig.fmap.FTable; |
30 |
import com.iver.cit.gvsig.fmap.IFLayer; |
31 |
import com.iver.cit.gvsig.fmap.IView; |
32 |
import com.iver.cit.gvsig.fmap.MapControl; |
33 |
import com.iver.cit.gvsig.gui.FLegendManagerWindow; |
34 |
import com.iver.cit.gvsig.gui.FOpenDialog; |
35 |
import com.iver.cit.gvsig.gui.FPanelLocConfig; |
36 |
import com.iver.cit.gvsig.gui.Table; |
37 |
|
38 |
|
39 |
|
40 |
//import java.awt.Frame;
|
41 |
|
42 |
/**
|
43 |
* @author Administrador
|
44 |
*
|
45 |
* To change the template for this generated type comment go to
|
46 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
47 |
*/
|
48 |
public class ComandosListener implements ActionListener { |
49 |
private MapControl m_MapControl;
|
50 |
private FMap m_Mapa;
|
51 |
private SingleView m_Owner;
|
52 |
|
53 |
public ComandosListener(MapControl mapa, SingleView Owner) { |
54 |
m_Mapa = mapa.getMapContext(); |
55 |
m_Owner = Owner;
|
56 |
m_MapControl = mapa; |
57 |
} |
58 |
|
59 |
/* (non-Javadoc)
|
60 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
61 |
*/
|
62 |
public void actionPerformed(ActionEvent e) { |
63 |
// TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
|
64 |
IProjection proj = ProjectionPool.get("ed50utm30");
|
65 |
|
66 |
if (e.getActionCommand() == "ZOOM_TODO") { |
67 |
m_Mapa.setExtent(m_Mapa.getFullExtent()); |
68 |
m_MapControl.drawMap(); |
69 |
} |
70 |
if (e.getActionCommand() == "ZOOM_PREVIO") { |
71 |
m_MapControl.setExtentPrev(); |
72 |
} |
73 |
|
74 |
if (e.getActionCommand() == "OPEN_LOCATOR") { |
75 |
//Set up the dialog that the button brings up.
|
76 |
JDialog dialog = new JDialog(); |
77 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(m_Owner);
|
78 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
79 |
dialog.getContentPane().add(m_panelLoc); |
80 |
dialog.setModal(true);
|
81 |
dialog.pack(); |
82 |
dialog.show(); |
83 |
} |
84 |
|
85 |
if (e.getActionCommand() == "PRUEBA") { |
86 |
int i;
|
87 |
double valor;
|
88 |
FLegendManagerWindow dlg = new FLegendManagerWindow();
|
89 |
|
90 |
dlg.show(); |
91 |
} |
92 |
|
93 |
if (e.getActionCommand() == "ZOOM_MAS") { |
94 |
m_MapControl.setTool(MapControl.ZOOM_MAS); |
95 |
} |
96 |
|
97 |
if (e.getActionCommand() == "ZOOM_MENOS") { |
98 |
m_MapControl.setTool(MapControl.ZOOM_MENOS); |
99 |
} |
100 |
|
101 |
if (e.getActionCommand() == "PAN") { |
102 |
m_MapControl.setTool(MapControl.PAN); |
103 |
} |
104 |
|
105 |
if (e.getActionCommand() == "INFO") { |
106 |
m_MapControl.setTool(MapControl.INFO); |
107 |
} |
108 |
if (e.getActionCommand() == "MEDICION") { |
109 |
m_MapControl.setTool(MapControl.MEDICION); |
110 |
} |
111 |
if (e.getActionCommand() == "MEDIRAREA") { |
112 |
m_MapControl.setTool(MapControl.AREA); |
113 |
} |
114 |
|
115 |
if ((e.getActionCommand() == "ADD_LAYER") || (e.getActionCommand() == "ADD_MEMORY_LAYER")) { |
116 |
JDialog dlg = new JDialog(); |
117 |
FOpenDialog fopen = new FOpenDialog((IView) m_Owner, m_Owner.getMapControl());
|
118 |
dlg.setModal(true);
|
119 |
fopen.setPreferredSize(fopen.getSize()); |
120 |
dlg.setSize(fopen.getSize()); |
121 |
dlg.getContentPane().add(fopen); |
122 |
dlg.pack(); |
123 |
dlg.show(); |
124 |
/* fopen.setTitle("Abrir una capa");
|
125 |
fopen.setModal(true);
|
126 |
fopen.pack();
|
127 |
fopen.show(); */
|
128 |
IFLayer lyr = null;
|
129 |
// IFLayer lyrLoc = null;
|
130 |
if (fopen.getFiles() == null) return; // Es posible que hayamos a?adido una |
131 |
// capa WMS, o WFS, etc.
|
132 |
for (int iFile=0; iFile < fopen.getFiles().length; iFile++) |
133 |
{ |
134 |
String layerName = fopen.getFiles()[iFile].getName();
|
135 |
String layerPath = fopen.getFiles()[iFile].getAbsolutePath();
|
136 |
// Capas Raster
|
137 |
if (layerName.endsWith(".ecw") || layerName.endsWith(".ECW") || |
138 |
layerName.endsWith(".jpg") ||
|
139 |
layerName.endsWith(".png") ||
|
140 |
layerName.endsWith(".tif")) {
|
141 |
|
142 |
// Miramos por si es un ecwp:
|
143 |
int test = layerPath.indexOf("ecwp:"); |
144 |
if (test != -1) { |
145 |
String urlECW = layerPath.substring(test + 6); |
146 |
urlECW.replaceAll("/", "//"); |
147 |
layerPath = "ecwp://" + urlECW;
|
148 |
} |
149 |
|
150 |
// TODO LWS solo crea la capa raster si no hay o la ?ltima creada (activa) ...
|
151 |
// TODO LWS ... no es raster. as? metemos varios raster en una sola capa
|
152 |
// TODO LWS deber?a guardar la capa raster activa para crearla solo cuando no exista
|
153 |
// TODO LWS (en la primera carga de raster; las siguientes van en la actual, de momento)
|
154 |
if (lyr == null || !(lyr instanceof FLyrRaster)) |
155 |
lyr = new FLyrRaster(proj, layerName, true); |
156 |
((FLyrRaster) lyr).addRasterFile(layerName, layerPath); |
157 |
} else { // Capas vectoriales |
158 |
if (layerName.endsWith(".shp") || (layerName.endsWith(".SHP"))){ |
159 |
lyr = new FLyrShp(proj, layerName, layerPath, true); |
160 |
// lyrLoc = new FLyrShp(fopen.getText(), fopen.getText());
|
161 |
} else if ((layerName.endsWith(".dgn")) || (layerName.endsWith(".DGN"))) { |
162 |
lyr = new FLyrDgnG(proj, layerName, layerPath, true); |
163 |
} else if (layerName.endsWith(".dxf") || layerName.endsWith(".DXF") || layerName.endsWith(".gml") || layerName.endsWith(".GML")){ |
164 |
lyr = new FLyrDxfG(proj, layerName, layerPath, true); |
165 |
//lyr = new FLyrDxf(layerName, layerPath);
|
166 |
}/* else if (layerName.endsWith(".gml") || layerName.endsWith(".GML")){
|
167 |
lyr = new FLyrGml(proj, layerName, layerPath);
|
168 |
}*/
|
169 |
if (e.getActionCommand() == "ADD_MEMORY_LAYER") |
170 |
((FLyrVect) lyr).copyToMemory(); |
171 |
|
172 |
} |
173 |
if (lyr != null && (lyr.getMapa() == null)) |
174 |
{ |
175 |
m_Mapa.getLayers().addLayer(lyr); |
176 |
m_Owner.getTOC().refresh(); |
177 |
m_MapControl.drawMap(); |
178 |
/* if (lyrLoc != null)
|
179 |
{
|
180 |
m_Owner.getMapOverview().getMapContext().getLayers().addLayer(lyrLoc);
|
181 |
m_Owner.getMapOverview().drawMap();
|
182 |
} */
|
183 |
} |
184 |
} // for
|
185 |
return;
|
186 |
|
187 |
/* JFileChooser tempChooser = new JFileChooser();
|
188 |
|
189 |
//tempChooser.setFileSelectionMode(tempChooser.FILES_ONLY);
|
190 |
// A?ade filtro para raster (de momento ecw)
|
191 |
tempChooser.addChoosableFileFilter(new FileFilter() {
|
192 |
public boolean accept(File f) {
|
193 |
String extension = "";
|
194 |
|
195 |
if (f.isDirectory()) { return true; }
|
196 |
|
197 |
int i = f.getName().lastIndexOf('.');
|
198 |
|
199 |
if (i > 0) {
|
200 |
extension = f.getName().substring(i + 1)
|
201 |
.toLowerCase();
|
202 |
}
|
203 |
|
204 |
if (extension.equals("ecw")) {
|
205 |
return true;
|
206 |
} else {
|
207 |
return false;
|
208 |
}
|
209 |
}
|
210 |
|
211 |
public String getDescription() {
|
212 |
return "Raster Files (*.ecw)";
|
213 |
}
|
214 |
});
|
215 |
// filtro para DXF
|
216 |
tempChooser.addChoosableFileFilter(new FileFilter() {
|
217 |
public boolean accept(File f) {
|
218 |
String extension = "";
|
219 |
|
220 |
if (f.isDirectory()) { return true; }
|
221 |
|
222 |
int i = f.getName().lastIndexOf('.');
|
223 |
|
224 |
if (i > 0) {
|
225 |
extension = f.getName().substring(i + 1)
|
226 |
.toLowerCase();
|
227 |
}
|
228 |
|
229 |
if (extension.equals("dxf")) {
|
230 |
return true;
|
231 |
} else {
|
232 |
return false;
|
233 |
}
|
234 |
}
|
235 |
|
236 |
public String getDescription() {
|
237 |
return "Autocad DXF Files (*.dxf)";
|
238 |
}
|
239 |
});
|
240 |
// A?ade filtro para DGN
|
241 |
tempChooser.addChoosableFileFilter(new FileFilter() {
|
242 |
public boolean accept(File f) {
|
243 |
String extension = "";
|
244 |
|
245 |
if (f.isDirectory()) { return true; }
|
246 |
|
247 |
int i = f.getName().lastIndexOf('.');
|
248 |
|
249 |
if (i > 0) {
|
250 |
extension = f.getName().substring(i + 1)
|
251 |
.toLowerCase();
|
252 |
}
|
253 |
|
254 |
if (extension.equals("dgn")) {
|
255 |
return true;
|
256 |
} else {
|
257 |
return false;
|
258 |
}
|
259 |
}
|
260 |
|
261 |
public String getDescription() {
|
262 |
return "Microstation Files (*.dgn)";
|
263 |
}
|
264 |
});
|
265 |
// Archivos .shp
|
266 |
tempChooser.addChoosableFileFilter(new FileFilter() {
|
267 |
public boolean accept(File f) {
|
268 |
String extension = "";
|
269 |
|
270 |
if (f.isDirectory()) { return true; }
|
271 |
|
272 |
int i = f.getName().lastIndexOf('.');
|
273 |
|
274 |
if (i > 0) {
|
275 |
extension = f.getName().substring(i + 1)
|
276 |
.toLowerCase();
|
277 |
}
|
278 |
|
279 |
if (extension.equals("shp")) {
|
280 |
return true;
|
281 |
} else {
|
282 |
return false;
|
283 |
}
|
284 |
}
|
285 |
|
286 |
public String getDescription() {
|
287 |
return "Shapes Files (*.shp)";
|
288 |
}
|
289 |
});
|
290 |
|
291 |
int result = tempChooser.showOpenDialog(m_Owner);
|
292 |
if (result == JFileChooser.APPROVE_OPTION) {
|
293 |
File tempFile = tempChooser.getSelectedFile();
|
294 |
IFLayer lyr = null;
|
295 |
|
296 |
//System.out.println(pathFich);
|
297 |
if ((e.getActionCommand() == "ADD_LAYER") || (e.getActionCommand() == "ADD_MEMORY_LAYER"))
|
298 |
{
|
299 |
if (tempFile.getName().endsWith(".ecw")) {
|
300 |
// TODO debe guardar la capa raster activa para crearla solo cuando no exista
|
301 |
// (en la primera carga de raster; las siguientes van en la actual, de momento)
|
302 |
lyr = new FLyrRaster("Pruebas de raster");
|
303 |
((FLyrRaster) lyr).addRasterFile(tempFile.getName(), tempFile.getPath());
|
304 |
} else { // Capas vectoriales
|
305 |
if (tempFile.getName().endsWith(".shp")){
|
306 |
lyr = new FLyrShp(tempFile.getName(), tempFile.getPath());
|
307 |
} else if ((tempFile.getName().endsWith(".dgn")) || (tempFile.getName().endsWith(".DGN"))) {
|
308 |
lyr = new FLyrDgnG(tempFile.getName(), tempFile.getPath());
|
309 |
} else if (tempFile.getName().endsWith(".dxf")){
|
310 |
lyr = new FLyrDxfG(tempFile.getName(), tempFile.getPath());
|
311 |
}
|
312 |
if (e.getActionCommand() == "ADD_MEMORY_LAYER")
|
313 |
((FLyrVect) lyr).copyToMemory();
|
314 |
|
315 |
}
|
316 |
if (lyr != null)
|
317 |
m_Mapa.getLayers().addLayer(lyr);
|
318 |
|
319 |
}
|
320 |
|
321 |
|
322 |
m_Owner.getTOC().refresh();
|
323 |
m_MapControl.drawMap();
|
324 |
} */
|
325 |
} |
326 |
|
327 |
/**
|
328 |
|
329 |
String pathFich = fc.getDirectory() + fc.getFile();
|
330 |
|
331 |
|
332 |
System.out.println(pathFich);
|
333 |
FLyrVect lyr = new FLyrVect(fc.getFile(),pathFich);
|
334 |
|
335 |
m_Mapa.AddLayer(lyr);
|
336 |
m_Owner.jLeyenda.Refresh();
|
337 |
|
338 |
}
|
339 |
|
340 |
**/
|
341 |
if (e.getActionCommand() == "EXPORT") { |
342 |
// Export jExport = new Export(m_MapControl);
|
343 |
} |
344 |
|
345 |
if (e.getActionCommand() == "VIEW_TABLE") { |
346 |
FLyrVect lyrSelec = m_Owner.getTOC().getFirstLyrVectSelected(); |
347 |
Table nuevaTabla = new Table();
|
348 |
nuevaTabla.setModel(new FTable(lyrSelec.getRecordset()));
|
349 |
JDialog myDialog = new JDialog(m_Owner, "Tabla de Atributos (" |
350 |
+ nuevaTabla.getModel().getRecordsCount() + " registros)" );
|
351 |
myDialog.setContentPane(nuevaTabla); |
352 |
|
353 |
// myViewer.addAttributeTableViewerListener(m_Owner);
|
354 |
myDialog.pack(); |
355 |
myDialog.show(); |
356 |
} |
357 |
} |
358 |
} |