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