root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Dialogs / GeoreferencingDialog.java @ 3012
History | View | Annotate | Download (11.3 KB)
1 |
package com.iver.cit.gvsig.gui.Dialogs; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.FlowLayout; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.beans.PropertyVetoException; |
7 |
|
8 |
import javax.swing.JButton; |
9 |
import javax.swing.JFileChooser; |
10 |
import javax.swing.JInternalFrame; |
11 |
import javax.swing.JPanel; |
12 |
|
13 |
import org.cresques.cts.IProjection; |
14 |
|
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.cit.gvsig.fmap.MapControl; |
17 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
18 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
19 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
20 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener; |
21 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
22 |
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior; |
23 |
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior; |
24 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
25 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
26 |
import com.iver.cit.gvsig.gui.View; |
27 |
import com.iver.cit.gvsig.gui.Panels.DataPointsTabPanel; |
28 |
import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
29 |
import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel; |
30 |
import com.iver.cit.gvsig.gui.Panels.TablePointsPanel; |
31 |
import com.iver.cit.gvsig.gui.toolListeners.GeorefPanListener; |
32 |
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener; |
33 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
34 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomGeorefListener; |
35 |
import com.iver.cit.gvsig.gui.wizards.WizardListener; |
36 |
import com.iver.cit.gvsig.project.Project; |
37 |
|
38 |
/**
|
39 |
* Panel que contiene el Wizard de georeferenciaci?n con los tabs
|
40 |
* interiores
|
41 |
*
|
42 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
43 |
*/
|
44 |
public class GeoreferencingDialog extends JPanel implements ActionListener { |
45 |
|
46 |
|
47 |
static private IProjection proj = Project.getProjection(); |
48 |
private JFileChooser fileChooser; |
49 |
private JPanel pBotones = null; // @jve:decl-index=0: |
50 |
private JButton bProcesar = null; // @jve:decl-index=0: |
51 |
private JButton bCancelar = null; // @jve:decl-index=0: |
52 |
private WizardListener wizardListener = new DialogWizardListener(); |
53 |
private JButton bSave = null; // @jve:decl-index=0: |
54 |
private GeoRedimBehavior rb = null; |
55 |
private GeoMoveBehavior mb = null; |
56 |
private static boolean loadTools = false; |
57 |
private JInternalFrame frame = null; |
58 |
|
59 |
private SelectFilePanel selectFilePanel = null; |
60 |
private SelectPointsPanel selectPointsPanel = null; |
61 |
private TablePointsPanel tablePointsPanel = null; |
62 |
private DataPointsTabPanel dataPointsTabPanel = null; |
63 |
|
64 |
private JButton bAceptar = null; |
65 |
|
66 |
/**
|
67 |
* Constructor.
|
68 |
*/
|
69 |
public GeoreferencingDialog(JInternalFrame f) { |
70 |
frame = f; |
71 |
initialize(); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Asigna el frame
|
76 |
* @param f
|
77 |
*/
|
78 |
public void setFrame(JInternalFrame f){ |
79 |
frame = f; |
80 |
} |
81 |
|
82 |
/**
|
83 |
* En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos
|
84 |
* ls herramientas para manejar las imagenes a georeferenciar.
|
85 |
*/
|
86 |
private void initialize() { |
87 |
//Cargamos las herramientas la primera vez que abrimos la ventana
|
88 |
if(!loadTools){
|
89 |
GeoreferencingDialog.loadTools = true;
|
90 |
com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
91 |
MapControl mapCtrl = vista.getMapControl(); |
92 |
|
93 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
94 |
|
95 |
ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
|
96 |
ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
|
97 |
rb = new GeoRedimBehavior(zigl, this); |
98 |
mapCtrl.addMapTool("geoZoom", new Behavior[]{rb, |
99 |
new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
100 |
|
101 |
GeorefPanListener pl = new GeorefPanListener(mapCtrl);
|
102 |
mb = new GeoMoveBehavior(pl, this); |
103 |
mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)}); |
104 |
|
105 |
//Seleccion de un punto sobre la vista
|
106 |
GeorefPointerListener psl = new GeorefPointerListener(this); |
107 |
mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)}); |
108 |
|
109 |
} |
110 |
|
111 |
this.setLayout(new BorderLayout()); |
112 |
this.setPreferredSize(new java.awt.Dimension(400,315)); |
113 |
this.setSize(new java.awt.Dimension(400,315)); |
114 |
this.setLocation(new java.awt.Point(0,0)); |
115 |
this.add(getPBotones(), java.awt.BorderLayout.SOUTH);
|
116 |
tablePointsPanel = new TablePointsPanel();
|
117 |
selectPointsPanel = new SelectPointsPanel();
|
118 |
this.add(this.getDataPointsPanel(), null); |
119 |
|
120 |
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Obtiene el panel que contiene los tabs de selecci?n de puntos y tabla de puntos.
|
125 |
* @return
|
126 |
*/
|
127 |
public DataPointsTabPanel getDataPointsPanel() {
|
128 |
if (dataPointsTabPanel == null) { |
129 |
dataPointsTabPanel = new DataPointsTabPanel(this.selectPointsPanel, this.tablePointsPanel); |
130 |
dataPointsTabPanel.setBounds(0, 0, 519, 352); |
131 |
} |
132 |
|
133 |
return dataPointsTabPanel;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* This method initializes jPanel
|
138 |
*
|
139 |
* @return javax.swing.JPanel
|
140 |
*/
|
141 |
private JPanel getPBotones() { |
142 |
if (pBotones == null) { |
143 |
FlowLayout flowLayout1 = new FlowLayout(); |
144 |
pBotones = new JPanel(); |
145 |
pBotones.setLayout(flowLayout1); |
146 |
flowLayout1.setHgap(10);
|
147 |
pBotones.add(getBProcesar(), null);
|
148 |
pBotones.add(getBSave(), null);
|
149 |
pBotones.add(getBAceptar(), null);
|
150 |
pBotones.add(getBCancelar(), null);
|
151 |
} |
152 |
return pBotones;
|
153 |
} |
154 |
|
155 |
|
156 |
|
157 |
public class DialogWizardListener implements WizardListener { |
158 |
|
159 |
/**
|
160 |
* @see com.iver.cit.gvsig.gui.wms.WizardListener#error(java.lang.Exception)
|
161 |
*/
|
162 |
public void error(Exception e) { |
163 |
} |
164 |
|
165 |
/**
|
166 |
* @see com.iver.cit.gvsig.gui.wms.WizardListener#wizardStateChanged(boolean)
|
167 |
*/
|
168 |
public void wizardStateChanged(boolean finishable) { |
169 |
getBProcesar().setEnabled(finishable); |
170 |
} |
171 |
|
172 |
} |
173 |
public static IProjection getLastProjection() { |
174 |
return proj;
|
175 |
} |
176 |
public static void setLastProjection(IProjection proj) { |
177 |
GeoreferencingDialog.proj = proj; |
178 |
} |
179 |
|
180 |
|
181 |
|
182 |
/**
|
183 |
* @return Returns the GeoRedimBehavior.
|
184 |
*/
|
185 |
public GeoRedimBehavior getGeoRedimBehavior() {
|
186 |
return rb;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* @param rb The GeoRedimBehavior to set.
|
191 |
*/
|
192 |
public void setGeoRedimBehavior(GeoRedimBehavior rb) { |
193 |
this.rb = rb;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @return Returns the GeoMoveBehavior
|
198 |
*/
|
199 |
public GeoMoveBehavior getGeoMoveBehavior() {
|
200 |
return mb;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* @param mb The GeoMoveBehavior to set.
|
205 |
*/
|
206 |
public void setGeoMoveBehavior(GeoMoveBehavior mb) { |
207 |
this.mb = mb;
|
208 |
} |
209 |
|
210 |
|
211 |
/* (non-Javadoc)
|
212 |
* @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
213 |
*/
|
214 |
/*public ViewInfo getViewInfo() {
|
215 |
ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODELESSDIALOG |
|
216 |
ViewInfo.RESIZABLE);
|
217 |
m_viewinfo.setWidth(this.getWidth());
|
218 |
m_viewinfo.setHeight(this.getHeight());
|
219 |
m_viewinfo.setTitle(PluginServices.getText(this,
|
220 |
"cargar_sin_georef"));
|
221 |
|
222 |
return m_viewinfo;
|
223 |
}*/
|
224 |
|
225 |
/**
|
226 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
|
227 |
*/
|
228 |
/*public Object getViewModel() {
|
229 |
return "GeoreferencingDialog";
|
230 |
}*/
|
231 |
|
232 |
/**
|
233 |
* @return Returns the selectFilePanel.
|
234 |
*/
|
235 |
public SelectFilePanel getSelectFilePanel() {
|
236 |
return selectFilePanel;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
* @param selectFilePanel The selectFilePanel to set.
|
241 |
*/
|
242 |
public void setSelectFilePanel(SelectFilePanel selectFilePanel) { |
243 |
this.selectFilePanel = selectFilePanel;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* @return Returns the selectPointsPanel.
|
248 |
*/
|
249 |
public SelectPointsPanel getSelectPointsPanel() {
|
250 |
return selectPointsPanel;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* @param selectPointsPanel The selectPointsPanel to set.
|
255 |
*/
|
256 |
public void setSelectPointsPanel(SelectPointsPanel selectPointsPanel) { |
257 |
this.selectPointsPanel = selectPointsPanel;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* This method initializes jButton
|
262 |
*
|
263 |
* @return javax.swing.JButton
|
264 |
*/
|
265 |
private JButton getBAceptar() { |
266 |
if (bAceptar == null) { |
267 |
bAceptar = new JButton(); |
268 |
bAceptar.setText("aceptar");
|
269 |
bAceptar.addActionListener(this);
|
270 |
} |
271 |
return bAceptar;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
|
276 |
* <UL>
|
277 |
* <LI>Cambiamos el nombre a la capa georraster</LI>
|
278 |
* <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
|
279 |
* <LI>Cerramos la ventana</LI>
|
280 |
* </UL>
|
281 |
*/
|
282 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
283 |
if(e.getSource() == bAceptar){
|
284 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
285 |
FLyrGeoRaster lyrGeoRaster = null;
|
286 |
FLyrPoints lyrPoints = null;
|
287 |
|
288 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
289 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
290 |
if( lyr instanceof FLyrGeoRaster && |
291 |
lyr.getName().startsWith("*") &&
|
292 |
lyr.isActive()){ |
293 |
|
294 |
//Campbiamos el nombre a la capa GeoRaster
|
295 |
lyr.setName(lyr.getName().substring(1, lyr.getName().length()));
|
296 |
lyr.setActive(false);
|
297 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
298 |
} |
299 |
|
300 |
if( lyr instanceof FLyrPoints) |
301 |
lyrPoints = (FLyrPoints)lyr; |
302 |
} |
303 |
|
304 |
//A la capa Georraster le asignamos la capa de puntos para poder recuperarla
|
305 |
if(lyrGeoRaster != null) |
306 |
lyrGeoRaster.setFLyrPoints(lyrPoints); |
307 |
|
308 |
|
309 |
theView.getMapControl().setTool("zoomIn");
|
310 |
|
311 |
//Cerramos la ventana
|
312 |
//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
|
313 |
try{
|
314 |
frame.setClosed(true);
|
315 |
}catch(PropertyVetoException exc){} |
316 |
} |
317 |
|
318 |
} |
319 |
|
320 |
/**
|
321 |
* This method initializes bProcesar
|
322 |
*
|
323 |
* @return javax.swing.JButton
|
324 |
*/
|
325 |
private JButton getBProcesar() { |
326 |
if (bProcesar == null) { |
327 |
bProcesar = new JButton(); |
328 |
bProcesar.setText(PluginServices.getText(this,"procesar")); |
329 |
bProcesar.setEnabled(false);
|
330 |
bProcesar.setPreferredSize(new java.awt.Dimension(87,25)); |
331 |
bProcesar.addActionListener(new java.awt.event.ActionListener() {
|
332 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
333 |
/*if (PluginServices.getMainFrame() == null) {
|
334 |
((JDialog) (getParent().getParent().getParent()
|
335 |
.getParent())).dispose();
|
336 |
} else {
|
337 |
PluginServices.getMDIManager().closeView((com.iver.andami.ui.mdiManager.View) GeoreferencingDialog.this);
|
338 |
}*/
|
339 |
} |
340 |
}); |
341 |
} |
342 |
return bProcesar;
|
343 |
} |
344 |
|
345 |
/**
|
346 |
* El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
|
347 |
* y cierra la ventana.
|
348 |
*
|
349 |
* @return javax.swing.JButton
|
350 |
*/
|
351 |
private JButton getBCancelar() { |
352 |
if (bCancelar == null) { |
353 |
bCancelar = new JButton(); |
354 |
bCancelar.setText(PluginServices.getText(this,"cancelar")); |
355 |
bCancelar.addActionListener(new java.awt.event.ActionListener() {
|
356 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
357 |
//Cerramos la ventana
|
358 |
//(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
|
359 |
try{
|
360 |
frame.setClosed(true);
|
361 |
}catch(PropertyVetoException exc){} |
362 |
} |
363 |
}); |
364 |
} |
365 |
return bCancelar;
|
366 |
} |
367 |
|
368 |
/**
|
369 |
* This method initializes jButton
|
370 |
*
|
371 |
* @return javax.swing.JButton
|
372 |
*/
|
373 |
private JButton getBSave() { |
374 |
if (bSave == null) { |
375 |
bSave = new JButton(); |
376 |
bSave.setText(PluginServices.getText(this,"guardar")); |
377 |
bSave.setEnabled(false);
|
378 |
} |
379 |
return bSave;
|
380 |
} |
381 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
382 |
// @jve:visual-info decl-index=0 visual-constraint="10,10"
|
383 |
// @jve:visual-info decl-index=0 visual-constraint="10,10"
|