Statistics
| Revision:

root / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Dialogs / GeoreferencingDialog.java @ 3023

History | View | Annotate | Download (12 KB)

1 2844 nacho
package com.iver.cit.gvsig.gui.Dialogs;
2
3
import java.awt.BorderLayout;
4 3014 nacho
import java.awt.Dimension;
5 2844 nacho
import java.awt.FlowLayout;
6 3009 nacho
import java.awt.event.ActionListener;
7 2945 nacho
import java.beans.PropertyVetoException;
8 2844 nacho
9
import javax.swing.JButton;
10
import javax.swing.JFileChooser;
11 2945 nacho
import javax.swing.JInternalFrame;
12 2844 nacho
import javax.swing.JPanel;
13
14
import org.cresques.cts.IProjection;
15
16
import com.iver.andami.PluginServices;
17 2854 nacho
import com.iver.cit.gvsig.fmap.MapControl;
18 2947 nacho
import com.iver.cit.gvsig.fmap.layers.FLayer;
19
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster;
20 2987 nacho
import com.iver.cit.gvsig.fmap.layers.FLyrPoints;
21 2854 nacho
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener;
22
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
23 2894 nacho
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoMoveBehavior;
24
import com.iver.cit.gvsig.fmap.tools.Behavior.GeoRedimBehavior;
25 2854 nacho
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
26
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior;
27 2947 nacho
import com.iver.cit.gvsig.gui.View;
28 3014 nacho
import com.iver.cit.gvsig.gui.Panels.ConectorPanel;
29 2844 nacho
import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel;
30 2854 nacho
import com.iver.cit.gvsig.gui.toolListeners.GeorefPanListener;
31 2958 nacho
import com.iver.cit.gvsig.gui.toolListeners.GeorefPointerListener;
32 2854 nacho
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener;
33 2894 nacho
import com.iver.cit.gvsig.gui.toolListeners.ZoomGeorefListener;
34 2844 nacho
import com.iver.cit.gvsig.gui.wizards.WizardListener;
35
import com.iver.cit.gvsig.project.Project;
36
37
/**
38
 * Panel que contiene el Wizard de georeferenciaci?n con los tabs
39
 * interiores
40
 *
41
 * @author Nacho Brodin (brodin_ign@gva.es)
42
 */
43 3009 nacho
public class GeoreferencingDialog extends JPanel implements ActionListener {
44 2844 nacho
45 2945 nacho
46 2844 nacho
        static private IProjection proj = Project.getProjection();
47
    private JFileChooser fileChooser;
48 2958 nacho
        private JPanel pBotones = null;  //  @jve:decl-index=0:
49
        private JButton bProcesar = null;  //  @jve:decl-index=0:
50
        private JButton bCancelar = null;  //  @jve:decl-index=0:
51 2844 nacho
        private WizardListener wizardListener = new DialogWizardListener();
52 2958 nacho
        private JButton bSave = null;  //  @jve:decl-index=0:
53 2894 nacho
        private GeoRedimBehavior rb = null;
54
        private GeoMoveBehavior mb = null;
55 2854 nacho
        private static boolean loadTools = false;
56 2945 nacho
        private JInternalFrame frame = null;
57 3014 nacho
58
        private ConectorPanel        conectorPanel = null;
59 3012 nacho
60 3014 nacho
        private boolean enlarge = false;
61
        private int normalWidth = 410;
62
        private int normalHeight = 315;
63
        private int enlargeHeight = 600;
64 2844 nacho
65 2987 nacho
        private JButton bAceptar = null;
66 3014 nacho
        private JPanel pGeneral = null;
67 3012 nacho
68 2844 nacho
    /**
69
     * Constructor.
70
     */
71 2945 nacho
    public GeoreferencingDialog(JInternalFrame f) {
72
            frame = f;
73 2844 nacho
            initialize();
74
    }
75
76
    /**
77 2993 nacho
     * Asigna el frame
78
     * @param f
79
     */
80
    public void setFrame(JInternalFrame f){
81
            frame = f;
82
    }
83
84
    /**
85 2893 nacho
     * En la inicializaci?n de la ventana a?adimos los tags de est? y cargamos
86
     * ls herramientas para manejar las imagenes a georeferenciar.
87 2844 nacho
     */
88
    private void initialize() {
89 2931 nacho
            //Cargamos las herramientas la primera vez que abrimos la ventana
90 2854 nacho
        if(!loadTools){
91
                GeoreferencingDialog.loadTools = true;
92
                com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
93
                MapControl mapCtrl = vista.getMapControl();
94
95
                        StatusBarListener sbl = new StatusBarListener(mapCtrl);
96
97
                        ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(mapCtrl);
98 2894 nacho
                        ZoomGeorefListener zigl = new ZoomGeorefListener(mapCtrl);
99 2903 nacho
                        rb = new GeoRedimBehavior(zigl, this);
100 2893 nacho
                        mapCtrl.addMapTool("geoZoom", new Behavior[]{rb,
101 2854 nacho
                                                new PointBehavior(zoil), new MouseMovementBehavior(sbl)});
102
103
                        GeorefPanListener pl = new GeorefPanListener(mapCtrl);
104 2903 nacho
                        mb = new GeoMoveBehavior(pl, this);
105 2894 nacho
                        mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)});
106 2958 nacho
107
                        //Seleccion de un punto sobre la vista
108
                GeorefPointerListener psl = new GeorefPointerListener(this);
109
                mapCtrl.addMapTool("pointLyrSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)});
110
111 2854 nacho
        }
112 2931 nacho
113
        this.setLayout(new BorderLayout());
114 3014 nacho
        if(!enlarge){
115
                this.setPreferredSize(new java.awt.Dimension(normalWidth, normalHeight));
116
                this.setSize(new java.awt.Dimension(normalWidth, normalHeight));
117 3023 nacho
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(false);
118
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(false);
119 3014 nacho
        }else{
120
                this.setPreferredSize(new java.awt.Dimension(normalWidth, enlargeHeight));
121
                this.setSize(new java.awt.Dimension(normalWidth, enlargeHeight));
122 3023 nacho
                this.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().setVisible(true);
123
                this.getConectorPanel().getAdjustGeorefPanel().getZoomRight().setVisible(true);
124 3014 nacho
        }
125 2931 nacho
        this.setLocation(new java.awt.Point(0,0));
126 3014 nacho
127
        this.add(this.getPBotones(), BorderLayout.SOUTH);
128
        this.add(this.getConectorPanel(), BorderLayout.NORTH);
129
130 2964 nacho
131 2844 nacho
    }
132 2987 nacho
133 3014 nacho
134
    public ConectorPanel getConectorPanel() {
135
            if (conectorPanel == null) {
136
                    conectorPanel = new ConectorPanel(this);
137 3012 nacho
            }
138
139 3014 nacho
            return conectorPanel;
140 2844 nacho
    }
141 3014 nacho
142
143 2844 nacho
        /**
144
         * This method initializes jPanel
145
         *
146
         * @return javax.swing.JPanel
147
         */
148
        private JPanel getPBotones() {
149
                if (pBotones == null) {
150
                        FlowLayout flowLayout1 = new FlowLayout();
151
                        pBotones = new JPanel();
152
                        pBotones.setLayout(flowLayout1);
153 2987 nacho
                        flowLayout1.setHgap(10);
154 2844 nacho
                        pBotones.add(getBProcesar(), null);
155
                        pBotones.add(getBSave(), null);
156 2987 nacho
                        pBotones.add(getBAceptar(), null);
157 2844 nacho
                        pBotones.add(getBCancelar(), null);
158
                }
159
                return pBotones;
160
        }
161
162 2993 nacho
163
164 2844 nacho
        public class DialogWizardListener implements WizardListener {
165
166
                /**
167
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#error(java.lang.Exception)
168
                 */
169
                public void error(Exception e) {
170
                }
171
172
                /**
173
                 * @see com.iver.cit.gvsig.gui.wms.WizardListener#wizardStateChanged(boolean)
174
                 */
175
                public void wizardStateChanged(boolean finishable) {
176
                        getBProcesar().setEnabled(finishable);
177
                }
178
179
        }
180
        public static IProjection getLastProjection() {
181
                return proj;
182
        }
183
        public static void setLastProjection(IProjection proj) {
184
                GeoreferencingDialog.proj = proj;
185
        }
186
187 2893 nacho
188 2993 nacho
189 2893 nacho
        /**
190 2894 nacho
         * @return Returns the GeoRedimBehavior.
191 2893 nacho
         */
192 2903 nacho
        public GeoRedimBehavior getGeoRedimBehavior() {
193 2893 nacho
                return rb;
194
        }
195
196
        /**
197 2894 nacho
         * @param rb The GeoRedimBehavior to set.
198 2893 nacho
         */
199 2903 nacho
        public void setGeoRedimBehavior(GeoRedimBehavior rb) {
200 2893 nacho
                this.rb = rb;
201
        }
202 2894 nacho
203
        /**
204
         * @return Returns the GeoMoveBehavior
205
         */
206
        public GeoMoveBehavior getGeoMoveBehavior() {
207
                return mb;
208
        }
209
210
        /**
211
         * @param mb The GeoMoveBehavior to set.
212
         */
213
        public void setGeoMoveBehavior(GeoMoveBehavior mb) {
214
                this.mb = mb;
215
        }
216 2945 nacho
217
218
        /* (non-Javadoc)
219
         * @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
220
         */
221
        /*public ViewInfo getViewInfo() {
222
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.MODELESSDIALOG |
223
                                ViewInfo.RESIZABLE);
224
                m_viewinfo.setWidth(this.getWidth());
225
                m_viewinfo.setHeight(this.getHeight());
226
                m_viewinfo.setTitle(PluginServices.getText(this,
227
                                "cargar_sin_georef"));
228

229
                return m_viewinfo;
230
        }*/
231
232
        /**
233
         * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
234
         */
235
        /*public Object getViewModel() {
236
                return "GeoreferencingDialog";
237
        }*/
238 2958 nacho
239 3014 nacho
240 2958 nacho
        /**
241 2987 nacho
         * This method initializes jButton
242
         *
243
         * @return javax.swing.JButton
244
         */
245
        private JButton getBAceptar() {
246
                if (bAceptar == null) {
247
                        bAceptar = new JButton();
248
                        bAceptar.setText("aceptar");
249 3009 nacho
                        bAceptar.addActionListener(this);
250
                }
251
                return bAceptar;
252
        }
253
254 3012 nacho
        /**
255
         * Acci?n cuando se pulsa el bot?n de aceptar en el dialogo.
256
         * <UL>
257
         * <LI>Cambiamos el nombre a la capa georraster</LI>
258
         * <LI>A la capa Georraster le asignamos la capa de puntos para poder recuperarla</LI>
259
         * <LI>Cerramos la ventana</LI>
260
         * </UL>
261
         */
262 3009 nacho
        public void actionPerformed(java.awt.event.ActionEvent e) {
263
                if(e.getSource() == bAceptar){
264
                        View theView = (View) PluginServices.getMDIManager().getActiveView();
265
                        FLyrGeoRaster lyrGeoRaster = null;
266
                        FLyrPoints lyrPoints = null;
267
268
                        for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){
269
                                FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i);
270
                                if(        lyr instanceof FLyrGeoRaster &&
271
                                        lyr.getName().startsWith("*") &&
272
                                        lyr.isActive()){
273 3012 nacho
274
                                        //Campbiamos el nombre a la capa GeoRaster
275 3009 nacho
                                        lyr.setName(lyr.getName().substring(1, lyr.getName().length()));
276
                                        lyr.setActive(false);
277
                                        lyrGeoRaster = (FLyrGeoRaster)lyr;
278
                                }
279 2987 nacho
280 3009 nacho
                                if(        lyr instanceof FLyrPoints)
281
                                        lyrPoints = (FLyrPoints)lyr;
282
                        }
283
284 3012 nacho
                        //A la capa Georraster le asignamos la capa de puntos para poder recuperarla
285
                        if(lyrGeoRaster != null)
286 3009 nacho
                                lyrGeoRaster.setFLyrPoints(lyrPoints);
287 3012 nacho
288 3009 nacho
289
                        theView.getMapControl().setTool("zoomIn");
290
291
                        //Cerramos la ventana
292
                        //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
293
                        try{
294
                                frame.setClosed(true);
295
                        }catch(PropertyVetoException exc){}
296 2987 nacho
                }
297 3009 nacho
298 2987 nacho
        }
299 2993 nacho
300
        /**
301
         * This method initializes bProcesar
302
         *
303
         * @return javax.swing.JButton
304
         */
305
        private JButton getBProcesar() {
306
                if (bProcesar == null) {
307
                        bProcesar = new JButton();
308
                        bProcesar.setText(PluginServices.getText(this,"procesar"));
309
                        bProcesar.setEnabled(false);
310
                        bProcesar.setPreferredSize(new java.awt.Dimension(87,25));
311
                        bProcesar.addActionListener(new java.awt.event.ActionListener() {
312
                                public void actionPerformed(java.awt.event.ActionEvent e) {
313
                    /*if (PluginServices.getMainFrame() == null) {
314
                        ((JDialog) (getParent().getParent().getParent()
315
                                .getParent())).dispose();
316
                    } else {
317
                        PluginServices.getMDIManager().closeView((com.iver.andami.ui.mdiManager.View) GeoreferencingDialog.this);
318
                    }*/
319
                                }
320
                        });
321
                }
322
                return bProcesar;
323
        }
324
325
        /**
326
         * El bot?n cancelar restaura el extent con el que se carg? la imagen a georreferenciar
327
         * y cierra la ventana.
328
         *
329
         * @return javax.swing.JButton
330
         */
331
        private JButton getBCancelar() {
332
                if (bCancelar == null) {
333
                        bCancelar = new JButton();
334
                        bCancelar.setText(PluginServices.getText(this,"cancelar"));
335
                        bCancelar.addActionListener(new java.awt.event.ActionListener() {
336 2998 nacho
                                public void actionPerformed(java.awt.event.ActionEvent e) {
337
                                        //Cerramos la ventana
338
                                        //(se ejecuta el evento internalFrameClosing de GeoRasterFrameListener)
339 2993 nacho
                                        try{
340
                                                frame.setClosed(true);
341
                                        }catch(PropertyVetoException exc){}
342
                                }
343
                        });
344
                }
345
                return bCancelar;
346
        }
347
348
        /**
349
         * This method initializes jButton
350
         *
351
         * @return javax.swing.JButton
352
         */
353
        private JButton getBSave() {
354
                if (bSave == null) {
355
                        bSave = new JButton();
356
                        bSave.setText(PluginServices.getText(this,"guardar"));
357
                        bSave.setEnabled(false);
358
                }
359
                return bSave;
360
        }
361 3014 nacho
362
        /**
363
         * @return Returns the extended.
364
         */
365
        public boolean isEnlarge() {
366
                return enlarge;
367
        }
368
369
        /**
370
         * @param extended The extended to set.
371
         */
372
        public void setEnlarge(boolean enlarge) {
373
                this.enlarge = enlarge;
374
                if(!enlarge){
375
                        this.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight));
376
                        this.setSize(new Dimension(this.normalWidth, this.normalHeight));
377
                        frame.setSize(new Dimension(this.normalWidth, this.normalHeight + 10));
378
                        frame.setPreferredSize(new Dimension(this.normalWidth, this.normalHeight + 10));
379
                        this.getConectorPanel().setCanvasVisible(false);
380
                }else{
381
                        this.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight));
382
                        this.setSize(new Dimension(this.normalWidth, this.enlargeHeight));
383
                        frame.setSize(new Dimension(this.normalWidth, this.enlargeHeight + 10));
384
                        frame.setPreferredSize(new Dimension(this.normalWidth, this.enlargeHeight + 10));
385
                        this.getConectorPanel().setCanvasVisible(true);
386
                }
387
                frame.pack();
388
        }
389
390
        public SelectPointsPanel getSelectPointsPanel(){
391
                return this.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel();
392
        }
393
394 2844 nacho
   }  //  @jve:decl-index=0:visual-constraint="10,10"
395
 //  @jve:visual-info  decl-index=0 visual-constraint="10,10"
396
//  @jve:visual-info  decl-index=0 visual-constraint="10,10"