svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / DEMO / ComandosListener.java @ 645
History | View | Annotate | Download (9.07 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.Color; |
16 |
import java.awt.event.ActionEvent; |
17 |
import java.awt.event.ActionListener; |
18 |
import java.io.File; |
19 |
import java.io.FileNotFoundException; |
20 |
import java.io.IOException; |
21 |
|
22 |
import javax.swing.JDialog; |
23 |
|
24 |
import org.cresques.cts.IProjection; |
25 |
import org.cresques.cts.ProjectionPool; |
26 |
import org.geotools.data.DataSourceException; |
27 |
import org.geotools.data.DataStore; |
28 |
import org.geotools.data.FeatureSource; |
29 |
import org.geotools.map.DefaultMapLayer; |
30 |
import org.geotools.map.MapLayer; |
31 |
import org.geotools.styling.Style; |
32 |
import org.geotools.styling.StyleBuilder; |
33 |
|
34 |
import com.hardcode.driverManager.DriverLoadException; |
35 |
import com.hardcode.gdbms.engine.data.DBDriver; |
36 |
import com.iver.cit.gvsig.fmap.FMap; |
37 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
38 |
import com.iver.cit.gvsig.fmap.ViewPort; |
39 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
40 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
41 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
43 |
import com.iver.cit.gvsig.fmap.layers.FLyrGT2; |
44 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
45 |
import com.iver.cit.gvsig.gui.DataBaseOpenDialog; |
46 |
import com.iver.cit.gvsig.gui.FOpenDialog; |
47 |
import com.iver.cit.gvsig.gui.FPanelLocConfig; |
48 |
import com.iver.cit.gvsig.gui.FileOpenDialog; |
49 |
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow; |
50 |
import com.vividsolutions.jts.geom.LineString; |
51 |
import com.vividsolutions.jts.geom.MultiLineString; |
52 |
import com.vividsolutions.jts.geom.MultiPoint; |
53 |
import com.vividsolutions.jts.geom.Point; |
54 |
|
55 |
|
56 |
|
57 |
//import java.awt.Frame;
|
58 |
|
59 |
/**
|
60 |
* @author Administrador
|
61 |
*
|
62 |
* To change the template for this generated type comment go to
|
63 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
64 |
*/
|
65 |
public class ComandosListener implements ActionListener { |
66 |
private NewMapControl m_MapControl;
|
67 |
private FMap m_Mapa;
|
68 |
private SingleView theView;
|
69 |
|
70 |
private static final boolean WKB_ENABLED = true; |
71 |
|
72 |
PruebasGT2 pruebasGT2 = new PruebasGT2();
|
73 |
|
74 |
public ComandosListener(NewMapControl mapa, SingleView Owner) { |
75 |
m_Mapa = mapa.getMapContext(); |
76 |
theView = Owner;
|
77 |
m_MapControl = mapa; |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Load the data from the specified dataStore and construct a {@linkPlain Context context} with
|
82 |
* a default style.
|
83 |
*
|
84 |
* @param url The url of the shapefile to load.
|
85 |
* @param name DOCUMENT ME!
|
86 |
*
|
87 |
* @throws IOException is a I/O error occured.
|
88 |
* @throws DataSourceException if an error occured while reading the data source.
|
89 |
* @throws FileNotFoundException DOCUMENT ME!
|
90 |
*/
|
91 |
protected void loadLayer(DataStore store, String layerName) |
92 |
throws IOException, DataSourceException { |
93 |
final FeatureSource features = store.getFeatureSource(layerName);
|
94 |
|
95 |
// Create the style
|
96 |
final StyleBuilder builder = new StyleBuilder(); |
97 |
final Style style; |
98 |
Class geometryClass = features.getSchema().getDefaultGeometry().getType();
|
99 |
|
100 |
if (LineString.class.isAssignableFrom(geometryClass)
|
101 |
|| MultiLineString.class.isAssignableFrom(geometryClass)) { |
102 |
style = builder.createStyle(builder.createLineSymbolizer()); |
103 |
} else if (Point.class.isAssignableFrom(geometryClass) |
104 |
|| MultiPoint.class.isAssignableFrom(geometryClass)) { |
105 |
style = builder.createStyle(builder.createPointSymbolizer()); |
106 |
} else {
|
107 |
style = builder.createStyle(builder.createPolygonSymbolizer(Color.ORANGE, Color.BLACK, 1)); |
108 |
} |
109 |
|
110 |
final MapLayer layer = new DefaultMapLayer(features, style); |
111 |
layer.setTitle(layerName); |
112 |
|
113 |
FLyrGT2 lyrGT2 = new FLyrGT2(layer);
|
114 |
try {
|
115 |
m_Mapa.getLayers().addLayer(lyrGT2); |
116 |
m_Mapa.fireInvalidEvent(); |
117 |
} catch (CancelationException e) {
|
118 |
// TODO Auto-generated catch block
|
119 |
e.printStackTrace(); |
120 |
} |
121 |
|
122 |
} |
123 |
|
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
127 |
*/
|
128 |
public void actionPerformed(ActionEvent e) { |
129 |
// TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
|
130 |
IProjection proj = ProjectionPool.get("ed50utm30");
|
131 |
ViewPort vp = m_Mapa.getViewPort(); |
132 |
|
133 |
if (e.getActionCommand() == "ZOOM_TODO") { |
134 |
try {
|
135 |
vp.setExtent(m_Mapa.getFullExtent()); |
136 |
m_MapControl.drawMap(); |
137 |
} catch (DriverIOException e1) {
|
138 |
// TODO Auto-generated catch block
|
139 |
e1.printStackTrace(); |
140 |
} |
141 |
m_MapControl.drawMap(); |
142 |
} |
143 |
if (e.getActionCommand() == "ZOOM_PREVIO") { |
144 |
vp.setExtentPrev(); |
145 |
} |
146 |
if (e.getActionCommand().indexOf("GT2") != -1 && pruebasGT2 != null) |
147 |
pruebasGT2.setMapContext(m_Mapa); |
148 |
pruebasGT2.actionPerformed(e); |
149 |
|
150 |
if (e.getActionCommand() == "OPEN_LOCATOR") { |
151 |
//Set up the dialog that the button brings up.
|
152 |
JDialog dialog = new JDialog(); |
153 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(theView.getMapOverview());
|
154 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
155 |
dialog.getContentPane().add(m_panelLoc); |
156 |
dialog.setModal(true);
|
157 |
dialog.pack(); |
158 |
dialog.show(); |
159 |
} |
160 |
|
161 |
if (e.getActionCommand() == "PRUEBA") { |
162 |
int i;
|
163 |
double valor;
|
164 |
FLegendManagerWindow dlg = new FLegendManagerWindow();
|
165 |
|
166 |
dlg.show(); |
167 |
} |
168 |
|
169 |
if (e.getActionCommand() == "ZOOM_MAS") { |
170 |
m_MapControl.setTool("zoomrect");
|
171 |
} |
172 |
|
173 |
if (e.getActionCommand() == "ZOOM_MENOS") { |
174 |
m_MapControl.setTool("zoomout");
|
175 |
} |
176 |
|
177 |
if (e.getActionCommand() == "PAN") { |
178 |
m_MapControl.setTool("pan");
|
179 |
} |
180 |
|
181 |
if (e.getActionCommand() == "INFO") { |
182 |
m_MapControl.setTool("info");
|
183 |
} |
184 |
if (e.getActionCommand() == "MEDICION") { |
185 |
m_MapControl.setTool("medicion");
|
186 |
} |
187 |
if (e.getActionCommand() == "MEDIRAREA") { |
188 |
m_MapControl.setTool("area");
|
189 |
} |
190 |
|
191 |
if ((e.getActionCommand() == "ADD_LAYER") || (e.getActionCommand() == "ADD_MEMORY_LAYER")) { |
192 |
JDialog dlg = new JDialog(); |
193 |
dlg.setModal(true);
|
194 |
FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class}); |
195 |
DataBaseOpenDialog dbop = new DataBaseOpenDialog();
|
196 |
try {
|
197 |
dbop.setClasses(new Class[]{DBDriver.class}); |
198 |
} catch (DriverLoadException e1) {
|
199 |
e1.printStackTrace(); |
200 |
return;
|
201 |
} |
202 |
|
203 |
FOpenDialog fopen = new FOpenDialog();
|
204 |
fopen.addTab("Fichero", fileDlg);
|
205 |
fopen.addTab("Base de datos", dbop);
|
206 |
// fileDlg.setPreferredSize(fopen.getSize());
|
207 |
dlg.setSize(fopen.getSize()); |
208 |
dlg.getContentPane().add(fopen); |
209 |
dlg.pack(); |
210 |
dlg.show(); |
211 |
|
212 |
|
213 |
// TODO: Hacer lo de la capa WMS tambi?n.
|
214 |
if (fileDlg.getFiles() == null) return; |
215 |
FLayer lyr = null;
|
216 |
File[] files = fileDlg.getFiles(); |
217 |
for (int iFile=0; iFile < files.length; iFile++) |
218 |
{ |
219 |
File fich = files[iFile];
|
220 |
String layerName = fich.getName();
|
221 |
String layerPath = fich.getAbsolutePath();
|
222 |
|
223 |
try {
|
224 |
lyr = LayerFactory.createLayer(layerName, fileDlg.getDriverName(), fich, proj); |
225 |
|
226 |
lyr.setVisible(true);
|
227 |
lyr.setName(layerName); |
228 |
if (lyr != null ) |
229 |
{ |
230 |
try {
|
231 |
theView.getMapControl().getMapContext().getLayers().addLayer(lyr); |
232 |
} catch (CancelationException ex) {
|
233 |
// TODO Auto-generated catch block
|
234 |
ex.printStackTrace(); |
235 |
} |
236 |
// TODO: Poner una variable y dibujar solo cuando
|
237 |
// todas las capas hayan sido cargadas.
|
238 |
theView.getMapControl().drawMap(); |
239 |
theView.getTOC().refresh(); |
240 |
} |
241 |
|
242 |
} catch (DriverLoadException ex) {
|
243 |
ex.printStackTrace(); |
244 |
} catch (DriverIOException ex) {
|
245 |
// TODO Auto-generated catch block
|
246 |
ex.printStackTrace(); |
247 |
} |
248 |
} // for
|
249 |
return;
|
250 |
|
251 |
} |
252 |
|
253 |
/**
|
254 |
|
255 |
String pathFich = fc.getDirectory() + fc.getFile();
|
256 |
|
257 |
|
258 |
System.out.println(pathFich);
|
259 |
FLyrVect lyr = new FLyrVect(fc.getFile(),pathFich);
|
260 |
|
261 |
m_Mapa.AddLayer(lyr);
|
262 |
m_Owner.jLeyenda.Refresh();
|
263 |
|
264 |
}
|
265 |
|
266 |
**/
|
267 |
if (e.getActionCommand() == "EXPORT") { |
268 |
// Export jExport = new Export(m_MapControl);
|
269 |
} |
270 |
|
271 |
if (e.getActionCommand() == "VIEW_TABLE") { |
272 |
/* FLyrVect lyrSelec = m_Owner.getTOC().getFirstLyrVectSelected();
|
273 |
Table nuevaTabla = new Table();
|
274 |
nuevaTabla.setModel(new FTable(lyrSelec.getRecordset()));
|
275 |
JDialog myDialog = new JDialog(m_Owner, "Tabla de Atributos ("
|
276 |
+ nuevaTabla.getModel().getRecordsCount() + " registros)" );
|
277 |
myDialog.setContentPane(nuevaTabla);
|
278 |
|
279 |
// myViewer.addAttributeTableViewerListener(m_Owner);
|
280 |
myDialog.pack();
|
281 |
myDialog.show(); */
|
282 |
} |
283 |
} |
284 |
} |