root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Dialogs / GeoreferencingDialog.java @ 2998
History | View | Annotate | Download (11.7 KB)
1 | 2844 | nacho | package com.iver.cit.gvsig.gui.Dialogs; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | import java.awt.FlowLayout; |
||
5 | 2945 | nacho | import java.beans.PropertyVetoException; |
6 | 2844 | nacho | |
7 | import javax.swing.JButton; |
||
8 | import javax.swing.JFileChooser; |
||
9 | 2945 | nacho | import javax.swing.JInternalFrame; |
10 | 2844 | nacho | 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 | 2947 | nacho | import org.cresques.px.Extent; |
17 | 2844 | nacho | |
18 | import com.iver.andami.PluginServices; |
||
19 | 2854 | nacho | import com.iver.cit.gvsig.fmap.MapControl; |
20 | 2947 | nacho | import com.iver.cit.gvsig.fmap.layers.FLayer; |
21 | import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
||
22 | 2987 | nacho | import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
23 | 2854 | nacho | import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener; |
24 | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
||
25 | 2894 | nacho | import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior; |
26 | import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior; |
||
27 | 2854 | nacho | import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
28 | import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
||
29 | 2947 | nacho | import com.iver.cit.gvsig.gui.View; |
30 | 2844 | nacho | import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
31 | import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel; |
||
32 | 2854 | nacho | import com.iver.cit.gvsig.gui.toolListeners.GeorefPanListener; |
33 | 2958 | nacho | import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener; |
34 | 2854 | nacho | import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
35 | 2894 | nacho | import com.iver.cit.gvsig.gui.toolListeners.ZoomGeorefListener; |
36 | 2844 | nacho | 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 | 2945 | nacho | public class GeoreferencingDialog extends JPanel { |
46 | 2844 | nacho | |
47 | 2945 | nacho | |
48 | 2844 | nacho | static private IProjection proj = Project.getProjection(); |
49 | private javax.swing.JTabbedPane tabPanel = null;; |
||
50 | private JFileChooser fileChooser; |
||
51 | 2958 | nacho | 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 | 2844 | nacho | private WizardListener wizardListener = new DialogWizardListener(); |
55 | 2958 | nacho | private JButton bSave = null; // @jve:decl-index=0: |
56 | 2894 | nacho | private GeoRedimBehavior rb = null; |
57 | private GeoMoveBehavior mb = null; |
||
58 | 2854 | nacho | private static boolean loadTools = false; |
59 | 2945 | nacho | private JInternalFrame frame = null; |
60 | 2958 | nacho | private SelectFilePanel selectFilePanel = null; |
61 | private SelectPointsPanel selectPointsPanel = null; |
||
62 | 2844 | nacho | |
63 | 2987 | nacho | private JButton bAceptar = null; |
64 | 2844 | nacho | /**
|
65 | * Constructor.
|
||
66 | */
|
||
67 | 2945 | nacho | public GeoreferencingDialog(JInternalFrame f) { |
68 | frame = f; |
||
69 | 2844 | nacho | initialize(); |
70 | } |
||
71 | |||
72 | /**
|
||
73 | 2993 | nacho | * Asigna el frame
|
74 | * @param f
|
||
75 | */
|
||
76 | public void setFrame(JInternalFrame f){ |
||
77 | frame = f; |
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | 2893 | nacho | * 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 | 2844 | nacho | */
|
84 | private void initialize() { |
||
85 | 2931 | nacho | //Cargamos las herramientas la primera vez que abrimos la ventana
|
86 | 2854 | nacho | 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 | 2894 | nacho | ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
|
95 | 2903 | nacho | rb = new GeoRedimBehavior(zigl, this); |
96 | 2893 | nacho | mapCtrl.addMapTool("geoZoom", new Behavior[]{rb, |
97 | 2854 | nacho | new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
98 | |||
99 | GeorefPanListener pl = new GeorefPanListener(mapCtrl);
|
||
100 | 2903 | nacho | mb = new GeoMoveBehavior(pl, this); |
101 | 2894 | nacho | mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)}); |
102 | 2958 | nacho | |
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 | 2854 | nacho | } |
108 | 2931 | nacho | |
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 | 2958 | nacho | selectFilePanel = new SelectFilePanel(this); |
116 | selectPointsPanel = new SelectPointsPanel();
|
||
117 | 2993 | nacho | //this.addTab(PluginServices.getText(this, "cargar_fichero"), selectFilePanel);
|
118 | 2958 | nacho | this.addTab(PluginServices.getText(this, "seleccionar_puntos"), selectPointsPanel); |
119 | 2964 | nacho | |
120 | 2844 | nacho | } |
121 | 2987 | nacho | |
122 | 2844 | nacho | |
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 | 2987 | nacho | flowLayout1.setHgap(10);
|
171 | 2844 | nacho | pBotones.add(getBProcesar(), null);
|
172 | pBotones.add(getBSave(), null);
|
||
173 | 2987 | nacho | pBotones.add(getBAceptar(), null);
|
174 | 2844 | nacho | pBotones.add(getBCancelar(), null);
|
175 | } |
||
176 | return pBotones;
|
||
177 | } |
||
178 | |||
179 | 2993 | nacho | |
180 | |||
181 | 2844 | nacho | 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 | 2893 | nacho | |
205 | 2993 | nacho | |
206 | 2893 | nacho | /**
|
207 | 2894 | nacho | * @return Returns the GeoRedimBehavior.
|
208 | 2893 | nacho | */
|
209 | 2903 | nacho | public GeoRedimBehavior getGeoRedimBehavior() {
|
210 | 2893 | nacho | return rb;
|
211 | } |
||
212 | |||
213 | /**
|
||
214 | 2894 | nacho | * @param rb The GeoRedimBehavior to set.
|
215 | 2893 | nacho | */
|
216 | 2903 | nacho | public void setGeoRedimBehavior(GeoRedimBehavior rb) { |
217 | 2893 | nacho | this.rb = rb;
|
218 | } |
||
219 | 2894 | nacho | |
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 | 2945 | nacho | |
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 | 2958 | nacho | |
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 | 2987 | nacho | /**
|
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 | 2993 | nacho | //Obtenemos la capa de georaster y le cambiamos el nombre
|
297 | 2987 | nacho | FLyrGeoRaster lyrGeoRaster = null;
|
298 | 2993 | nacho | FLyrPoints lyrPoints = null;
|
299 | 2987 | nacho | for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
300 | FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
||
301 | 2993 | nacho | if( lyr instanceof FLyrGeoRaster && |
302 | lyr.getName().startsWith("*")){
|
||
303 | 2987 | nacho | lyrGeoRaster = (FLyrGeoRaster)lyr; |
304 | lyrGeoRaster.setName(lyrGeoRaster.getName().substring(1, lyrGeoRaster.getName().length()));
|
||
305 | } |
||
306 | 2993 | nacho | if( lyr instanceof FLyrPoints){ |
307 | lyrPoints = (FLyrPoints)lyr; |
||
308 | theView.getMapControl().getMapContext().getLayers().removeLayer(i); |
||
309 | } |
||
310 | 2987 | nacho | } |
311 | |||
312 | 2993 | nacho | //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 | 2987 | nacho | //Cerramos la ventana
|
318 | try{
|
||
319 | frame.setClosed(true);
|
||
320 | }catch(PropertyVetoException exc){} |
||
321 | } |
||
322 | }); |
||
323 | } |
||
324 | return bAceptar;
|
||
325 | } |
||
326 | 2993 | nacho | |
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 | 2998 | nacho | public void actionPerformed(java.awt.event.ActionEvent e) { |
364 | //Cerramos la ventana
|
||
365 | //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
|
||
366 | 2993 | nacho | 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 | 2844 | nacho | } // @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" |