Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / cutting / ui / CuttingPanel.java @ 12284

History | View | Annotate | Download (27.2 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.cutting.ui;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.Insets;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.awt.event.ItemEvent;
29
import java.awt.event.ItemListener;
30
import java.io.File;
31
import java.util.ArrayList;
32

    
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JFileChooser;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
import javax.swing.JTabbedPane;
39
import javax.swing.JTextField;
40

    
41
import org.gvsig.fmap.layers.FLyrRasterSE;
42
import org.gvsig.gui.beans.buttonbar.ButtonBarContainer;
43
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
44
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
45
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
46
import org.gvsig.gui.beans.coorddatainput.CoordDataInputContainer;
47
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
48
import org.gvsig.gui.beans.table.TableContainer;
49
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
50
import org.gvsig.raster.dataset.MultiRasterDataset;
51
import org.gvsig.rastertools.RasterModule;
52
import org.gvsig.rastertools.cutting.ui.listener.CuttingMouseViewListener;
53
import org.gvsig.rastertools.cutting.ui.listener.CuttingPanelListener;
54

    
55
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
56
import com.iver.andami.PluginServices;
57
import com.iver.andami.ui.mdiManager.IWindow;
58
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
59
import com.iver.cit.gvsig.fmap.MapControl;
60
import com.iver.cit.gvsig.fmap.layers.FLayer;
61
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior;
62
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior;
63
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior;
64
import com.iver.cit.gvsig.project.documents.view.gui.View;
65
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener;
66
/**
67
 * <code>CuttingPanel</code>. Interfaz de usuario para el recorte de rasters.
68
 *
69
 * @version 17/04/2007
70
 * @author Borja S?nchez Zamorano (borja.sanchez@iver.es)
71
 */
72
public class CuttingPanel extends DefaultButtonsPanel implements ButtonsPanelListener, ItemListener, ActionListener {
73
        private static final long serialVersionUID = 3078196473228467834L;
74

    
75
        private int                                                wPanel = 400;
76

    
77
        private CuttingDialog                                                cuttingDialog = null;
78

    
79
        private CoordDataInputContainer        coor_pixel = null;
80
        private CoordDataInputContainer        coor_reales = null;
81
        private ButtonBarContainer                        buttonBarContainer = null;
82
        private JPanel                                                                        pSelection = null;
83
        private JPanel                                                                        jOptions = null;
84
        private JPanel                                                                        jPNameFile = null;
85
        private TableContainer                                        tSelection = null;
86
        private ResolutionPanel                                        pResolution = null;
87
        private JCheckBox                                                                jCheckBox = null;
88
        private JCheckBox                                                                jCheckLoadLayerInToc = null;
89
        private JCheckBox                                                                jCheckSaveFile = null;
90
        private JTextField                                                        filenameTextField = null;
91
        private JTabbedPane                                                        jTabbedPane1 = null;
92
        private JPanel                                                                        jPNameDirectory = null;
93
        private JTextField                                                        directoryTextField = null;
94
        private JButton                                                                        jBChooseDirectory = null;
95
        private JLabel                                                                        jLabelDirectory = null;
96

    
97
        private FLayer                                                                        fLayer        = null;
98

    
99
        /**
100
         * Valores reales para el ancho, alto y tama?o de celda. Esto es necesario porque
101
         * en la caja de texto se guardan con decimales recortados y cuando se pide el valor
102
         * se devuelven completos.
103
         */
104
        private double realWidth, realHeight;
105

    
106
        /**
107
         * Relaci?n entre el ancho y alto en pixeles de la imagen
108
         */
109
        private double relWidthHeight = 0;
110

    
111
        /**
112
         * Valores reales para el tama?o de la ventana. Esto es necesario porque
113
         * en la caja de texto se guardan con decimales recortados y cuando se pide el valor
114
         * se devuelven completos.
115
         */
116
        private double                                        wcMinX, wcMinY, wcMaxX, wcMaxY;
117
        private double                                        pxMinX, pxMinY, pxMaxX, pxMaxY;
118

    
119
        CuttingPanelListener cuttingPanelListener = null;
120

    
121
        /**
122
         * Herramienta seleccionada en el momento de la apertura del dialogo
123
         */
124
        private String                                                lastTool = null;
125
        private MapControl                                mapControl = null;
126
        private String                                                viewName = null;
127

    
128
        /**
129
         * Crea un nuevo <code>CuttingPanel</code>
130
         * @param cuttingDialog
131
         */
132
        public CuttingPanel(CuttingDialog cuttingDialog) {
133
                super(ButtonsPanel.BUTTONS_ACCEPTCANCELAPPLY);
134

    
135
                this.cuttingDialog = cuttingDialog;
136
                initialize();
137
                cuttingPanelListener = new CuttingPanelListener(this);
138

    
139
                getCoor_pixel().getPDataInput11().getJTextField().addKeyListener(cuttingPanelListener);
140
                getCoor_pixel().getPDataInput11().getJTextField().addFocusListener(cuttingPanelListener);
141
                getCoor_pixel().getPDataInput12().getJTextField().addKeyListener(cuttingPanelListener);
142
                getCoor_pixel().getPDataInput12().getJTextField().addFocusListener(cuttingPanelListener);
143
                getCoor_pixel().getPDataInput21().getJTextField().addKeyListener(cuttingPanelListener);
144
                getCoor_pixel().getPDataInput21().getJTextField().addFocusListener(cuttingPanelListener);
145
                getCoor_pixel().getPDataInput22().getJTextField().addKeyListener(cuttingPanelListener);
146
                getCoor_pixel().getPDataInput22().getJTextField().addFocusListener(cuttingPanelListener);
147

    
148
                getCoor_reales().getPDataInput11().getJTextField().addKeyListener(cuttingPanelListener);
149
                getCoor_reales().getPDataInput11().getJTextField().addFocusListener(cuttingPanelListener);
150
                getCoor_reales().getPDataInput12().getJTextField().addKeyListener(cuttingPanelListener);
151
                getCoor_reales().getPDataInput12().getJTextField().addFocusListener(cuttingPanelListener);
152
                getCoor_reales().getPDataInput21().getJTextField().addKeyListener(cuttingPanelListener);
153
                getCoor_reales().getPDataInput21().getJTextField().addFocusListener(cuttingPanelListener);
154
                getCoor_reales().getPDataInput22().getJTextField().addKeyListener(cuttingPanelListener);
155
                getCoor_reales().getPDataInput22().getJTextField().addFocusListener(cuttingPanelListener);
156

    
157
                getPResolution().getCCellSize().getJTextField().addKeyListener(cuttingPanelListener);
158
                getPResolution().getCCellSize().getJTextField().addFocusListener(cuttingPanelListener);
159
                getPResolution().getCWidth().getJTextField().addKeyListener(cuttingPanelListener);
160
                getPResolution().getCWidth().getJTextField().addFocusListener(cuttingPanelListener);
161
                getPResolution().getCHeight().getJTextField().addKeyListener(cuttingPanelListener);
162
                getPResolution().getCHeight().getJTextField().addFocusListener(cuttingPanelListener);
163

    
164
                getButtonBarContainer().getButton(0).addActionListener(cuttingPanelListener);
165
                getButtonBarContainer().getButton(1).addActionListener(cuttingPanelListener);
166

    
167
                this.addButtonPressedListener(cuttingPanelListener);
168
        }
169

    
170
        /**
171
         * Obtener el <code>CuttingDialog</code> asociado a este objeto.
172
         * @return CuttingDialog
173
         */
174
        public CuttingDialog getCuttingDialog() {
175
                return cuttingDialog;
176
        }
177

    
178
        /**
179
         * Especificar el nombre de la nueva capa para el recuadro de texto asign?ndo
180
         * en cada llamada un nombre consecutivo.
181
         */
182
        public void setNewLayerText() {
183
                filenameTextField.setText("NewLayer_" + RasterModule.layerCount);
184
                RasterModule.layerCount++;
185
        }
186

    
187
        /**
188
         * Obtener la capa de un raster.
189
         * @return
190
         */
191
        public FLayer getFLayer() {
192
                return fLayer;
193
        }
194

    
195
        /**
196
         * Establecer la capa para usarla en el recorte
197
         * @param fLayer
198
         */
199
        public void setLayer(FLayer fLayer) {
200
                this.fLayer = fLayer;
201
                View view = (View) PluginServices.getMDIManager().getActiveWindow();
202
                viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle();
203
                mapControl = view.getMapControl();
204

    
205
                lastTool = mapControl.getCurrentTool();
206

    
207
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
208
                // la barra de estado
209
                StatusBarListener sbl = new StatusBarListener(mapControl);
210

    
211
                // Cortar Raster
212
                CuttingMouseViewListener cuttingMouseListener = new CuttingMouseViewListener(mapControl, this);
213
                mapControl.addMapTool("cutRaster", new Behavior[] {
214
                                new RectangleBehavior(cuttingMouseListener), new MouseMovementBehavior(sbl)
215
                        }
216
                );
217

    
218
                // Rellenar el arbol de bandas
219
                MultiRasterDataset mDataset = ((FLyrRasterSE) fLayer).getDatasource().getMultiRasterDataset();
220
                for (int i = 0; i < mDataset.getDatasetCount(); i++) {
221
                        String fName = mDataset.getDataset(i).getFName();
222
                        String bandName = new File(fName).getName();
223

    
224
                        if (mDataset.getDataset(i).getBandCount() > 1) {
225
                                for (int b = 0; b < mDataset.getDataset(i).getBandCount(); b++) {
226
                                        Object row[] = { new Boolean(true),
227
                                                        new String("B" + (b + 1) + " - " + bandName) };
228
                                        try {
229
                                                getTSelection().addRow(row);
230
                                        } catch (NotInitializeException e) {
231
                                                e.printStackTrace();
232
                                        }
233
                                }
234
                        } else {
235
                                Object row[] = { new Boolean(true), new String("B - " + bandName) };
236
                                try {
237
                                        getTSelection().addRow(row);
238
                                } catch (NotInitializeException e) {
239
                                        e.printStackTrace();
240
                                }
241
                        }
242
                }
243

    
244
                // Obtener la extension completa de la capa
245
                try {
246
                        cuttingPanelListener.setExtent(fLayer.getFullExtent());
247
                } catch (ExpansionFileReadException e) {
248
                        e.printStackTrace();
249
                } catch (ReadDriverException e) {
250
                        e.printStackTrace();
251
                }
252

    
253
                // Definir el ancho y el alto de la vista en pixeles.
254
                ArrayList attr = ((FLyrRasterSE) fLayer).getAttributes();
255
                for (int i = 0; i < attr.size(); i++) {
256
                        Object[] a = (Object[]) attr.get(i);
257
                        if (a[0].toString().equals("Width"))
258
                                cuttingPanelListener.setWidthPx(((Integer) a[1]).intValue());
259
                        if (a[0].toString().equals("Height"))
260
                                cuttingPanelListener.setHeightPx(((Integer) a[1]).intValue());
261
                }
262
        }
263

    
264
        /**
265
         * Acciones que se realizan para seleccionar la tool CutRaster
266
         */
267
        public void selectToolButton() {
268
                // seleccionamos la vista de gvSIG
269
                com.iver.cit.gvsig.project.documents.view.gui.View theView = null;
270
                try {
271
                        IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
272
                        for (int i = 0; i < allViews.length; i++) {
273
                                if (allViews[i] instanceof com.iver.cit.gvsig.project.documents.view.gui.View
274
                                                && PluginServices.getMDIManager().getWindowInfo((View) allViews[i])
275
                                                                .getTitle().equals(viewName))
276
                                        theView = (com.iver.cit.gvsig.project.documents.view.gui.View) allViews[i];
277
                        }
278
                        if (theView == null)
279
                                return;
280
                } catch (ClassCastException ex) {
281
//                        logger.error(PluginServices.getText(this, "cant_get_view "), ex);
282
                        return;
283
                }
284
                MapControl m_MapControl = theView.getMapControl();
285

    
286
                // Listener de eventos de movimiento que pone las coordenadas del rat?n en
287
                // la barra de estado
288
                StatusBarListener sbl = new StatusBarListener(m_MapControl);
289

    
290
                // Cortar Raster
291
                CuttingMouseViewListener cuttingMouseListener = new CuttingMouseViewListener(m_MapControl, this);
292
                m_MapControl.addMapTool("cutRaster", new Behavior[] {
293
                                new RectangleBehavior(cuttingMouseListener), new MouseMovementBehavior(sbl)
294
                                }
295
                );
296

    
297
                m_MapControl.setTool("cutRaster");
298
        }
299

    
300
        /**
301
         * This method initializes this
302
         */
303
        private void initialize() {
304
                jTabbedPane1 = new JTabbedPane();
305

    
306
                GridBagConstraints gridBagConstraints = new GridBagConstraints();
307
                gridBagConstraints.gridx = 0;
308
                gridBagConstraints.gridy = 0;
309
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
310
                gridBagConstraints.weightx = 1.0;
311
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
312
                gridBagConstraints1.gridx = 0;
313
                gridBagConstraints1.gridy = 1;
314
                gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
315
                gridBagConstraints1.weightx = 1.0;
316

    
317
                GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
318
                gridBagConstraints2.gridx = 0;
319
                gridBagConstraints2.gridy = 2;
320
                gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
321
                gridBagConstraints2.insets = new java.awt.Insets(5, 0, 0, 0);
322

    
323
                JPanel jpanel1 = new JPanel();
324
                jpanel1.setLayout(new GridBagLayout());
325
                jpanel1.add(getCoor_pixel(), gridBagConstraints);
326
                jpanel1.add(getCoor_reales(), gridBagConstraints1);
327
                jpanel1.add(getButtonBarContainer(), gridBagConstraints2);
328

    
329
                jTabbedPane1.addTab(PluginServices.getText(this, "coordenadas_recorte"), jpanel1);
330
                jTabbedPane1.addTab(PluginServices.getText(this, "resolucion_espacial"), getPResolution());
331
                jTabbedPane1.addTab(PluginServices.getText(this, "seleccion_bandas"), getPSelection());
332
                jTabbedPane1.addTab(PluginServices.getText(this, "otras_opciones"), getJOptions());
333

    
334
                this.setLayout(new BorderLayout());
335
                this.add(jTabbedPane1, BorderLayout.CENTER);
336

    
337
                setNewLayerText();
338
        }
339

    
340
        /*
341
         * (non-Javadoc)
342
         * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
343
         */
344
        public void actionButtonPressed(ButtonsPanelEvent e) {
345
        }
346

    
347
        /**
348
         * This method initializes jPanel
349
         *
350
         * @return javax.swing.JPanel
351
         */
352
        public CoordDataInputContainer getCoor_pixel() {
353
                if (coor_pixel == null) {
354
                        coor_pixel = new CoordDataInputContainer();
355
                        coor_pixel.setParameters(PluginServices.getText(this, "coordenadas_pixel"),
356
                                PluginServices.getText(this, "sup_izq"),
357
                                "X" ,"Y",
358
                                PluginServices.getText(this, "inf_der"),
359
                                "X", "Y");
360
                        coor_pixel.setDecimalValues(true);
361
                }
362
                return coor_pixel;
363
        }
364

    
365
        /**
366
         * This method initializes jPanel1
367
         *
368
         * @return javax.swing.JPanel
369
         */
370
        public CoordDataInputContainer getCoor_reales() {
371
                if (coor_reales == null) {
372
                        coor_reales = new CoordDataInputContainer();
373
                        coor_reales.setParameters(PluginServices.getText(this, "coordenadas_reales"),
374
                                PluginServices.getText(this, "sup_izq"),
375
                                "X" ,"Y",
376
                                PluginServices.getText(this, "inf_der"),
377
                                "X", "Y");
378
                        coor_reales.setDecimalValues(true);
379
                }
380
                return coor_reales;
381
        }
382

    
383
        /**
384
         * This method initializes jButton
385
         *
386
         * @return javax.swing.JButton
387
         */
388
        public ButtonBarContainer getButtonBarContainer() {
389
                if (buttonBarContainer == null) {
390
                        buttonBarContainer = new ButtonBarContainer();
391
                        buttonBarContainer.setPreferredSize(new java.awt.Dimension(wPanel - 4, 32));
392
                        buttonBarContainer.addButton("fullExtent.png", PluginServices.getText(this, "fullExtent"), 0);
393
                        buttonBarContainer.addButton("selectTool.png", PluginServices.getText(this, "select_tool"), 1);
394
                        buttonBarContainer.setButtonAlignment("right");
395
                        buttonBarContainer.setComponentBorder(false);
396
                }
397
                return buttonBarContainer;
398
        }
399

    
400
        /**
401
         * This method initializes jPanel
402
         *
403
         * @return javax.swing.JPanel
404
         */
405
        public ResolutionPanel getPResolution() {
406
                if (pResolution == null) {
407
                        pResolution = new ResolutionPanel();
408
                        pResolution.setPreferredSize(new java.awt.Dimension(wPanel, 120));
409
                        pResolution.validate();
410
                }
411
                return pResolution;
412
        }
413

    
414
        /**
415
         * This method initializes jPanel1
416
         *
417
         * @return javax.swing.JPanel
418
         */
419
        private JPanel getPSelection() {
420
                if (pSelection == null) {
421
                        pSelection = new JPanel();
422
                        pSelection.setLayout(new BorderLayout());
423
                        pSelection.setPreferredSize(new java.awt.Dimension(wPanel, 120));
424
                        pSelection.add(getTSelection(), BorderLayout.CENTER);
425

    
426
                }
427
                return pSelection;
428
        }
429

    
430
        /**
431
         * Obtiene la tabla de selecci?n de bandas
432
         * @return Tabla de selecci?n de bandas
433
         */
434
        public TableContainer getTSelection() {
435
                if (tSelection == null) {
436
                        String[] columnNames = {PluginServices.getText(this, "bandas"), PluginServices.getText(this, "nombre")};
437
                        int[] columnWidths = {75, 305};
438
                        tSelection = new TableContainer(columnNames, columnWidths);
439
                        tSelection.setModel("CheckBoxModel");
440
                        tSelection.setControlVisible(false);
441
                        tSelection.initialize();
442
                }
443

    
444
                return tSelection;
445
        }
446

    
447
        /**
448
         * This method initializes jOptions
449
         *
450
         * @return javax.swing.JPanel
451
         */
452
        private JPanel getJOptions() {
453
                if (jOptions == null) {
454
                        jOptions = new JPanel();
455
                        jOptions.setLayout(new GridBagLayout());
456
                        jOptions.add(getJPNameFile(), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
457
                                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
458
                                        new Insets(0, 0, 5, 5), 0, 0));
459
                        jOptions.add(getCbOneLyrPerBand(), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,
460
                                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
461
                                        new Insets(0, 0, 5, 5), 0, 0));
462
                        jOptions.add(getCbLoadLayerInToc(), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
463
                                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
464
                                        new Insets(0, 0, 5, 5), 0, 0));
465
                        jOptions.add(getCbSaveFile(), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
466
                                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
467
                                        new Insets(0, 0, 5, 5), 0, 0));
468
                        jOptions.add(getJPNameDirectory(), new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
469
                                        GridBagConstraints.CENTER, GridBagConstraints.BOTH,
470
                                        new Insets(0, 0, 5, 5), 0, 0));
471
                        jOptions.setPreferredSize(new java.awt.Dimension(wPanel, 135));
472
                }
473
                return jOptions;
474
        }
475

    
476
        /**
477
         * This method initializes jPNameFile
478
         *
479
         * @return javax.swing.JPanel
480
         */
481
        private JPanel getJPNameFile() {
482
                if (jPNameFile == null) {
483
                        jPNameFile = new JPanel();
484
                        jPNameFile.add(new JLabel(PluginServices.getText(this, "nombre_capas") + ":"));
485
                        jPNameFile.add(getFilenameTextField());
486
                }
487
                return jPNameFile;
488
        }
489

    
490
        private JButton getJBChooseDirectory() {
491
                if (jBChooseDirectory == null) {
492
                        jBChooseDirectory = new JButton(PluginServices.getText(this, "cambiar_ruta"));
493
                        jBChooseDirectory.setEnabled(false);
494
                }
495
                return jBChooseDirectory;
496
        }
497
        /**
498
         * This method initializes jPNameFile
499
         *
500
         * @return javax.swing.JPanel
501
         */
502
        private JPanel getJPNameDirectory() {
503
                if (jPNameDirectory == null) {
504
                        jPNameDirectory = new JPanel();
505
                        jPNameDirectory.add(getJLabelDirectory());
506
                        jPNameDirectory.add(getDirectoryTextField());
507
                        jPNameDirectory.add(getJBChooseDirectory());
508
                        getJBChooseDirectory().addActionListener(this);
509
                }
510
                return jPNameDirectory;
511
        }
512

    
513
        private JLabel getJLabelDirectory() {
514
                if (jLabelDirectory == null) {
515
                        jLabelDirectory = new JLabel(PluginServices.getText(this, "ruta") + ":");
516
                        jLabelDirectory.setEnabled(false);
517
                }
518
                return jLabelDirectory;
519
        }
520

    
521
        /**
522
         * This method initializes filenameTextField
523
         *
524
         * @return javax.swing.JTextField
525
         */
526
        public JTextField getFilenameTextField() {
527
                if (filenameTextField == null) {
528
                        filenameTextField = new JTextField();
529
                        filenameTextField.setPreferredSize(new Dimension(150, filenameTextField.getPreferredSize().height));
530
                }
531
                return filenameTextField;
532
        }
533

    
534
        /**
535
         * This method initializes filenameTextField
536
         *
537
         * @return javax.swing.JTextField
538
         */
539
        public JTextField getDirectoryTextField() {
540
                if (directoryTextField == null) {
541
                        directoryTextField = new JTextField();
542
                        directoryTextField.setText(RasterModule.getPath());
543
                        directoryTextField.setEditable(false);
544
                        directoryTextField.setEnabled(false);
545
                        directoryTextField.setPreferredSize(new Dimension(200, directoryTextField.getPreferredSize().height));
546
                }
547
                return directoryTextField;
548
        }
549

    
550
        /**
551
         * This method initializes jCheckSaveFile
552
         *
553
         * @return javax.swing.JCheckBox
554
         */
555
        public JCheckBox getCbSaveFile() {
556
                if (jCheckSaveFile == null) {
557
                        jCheckSaveFile = new JCheckBox();
558
                        jCheckSaveFile.setText(PluginServices.getText(this, "guardar_en_disco"));
559
                        jCheckSaveFile.addItemListener(this);
560
                }
561
                return jCheckSaveFile;
562
        }
563

    
564
        /**
565
         * This method initializes jCheckBox
566
         *
567
         * @return javax.swing.JCheckBox
568
         */
569
        public JCheckBox getCbOneLyrPerBand() {
570
                if (jCheckBox == null) {
571
                        jCheckBox = new JCheckBox();
572
                        jCheckBox.setText(PluginServices.getText(this, "crear_1_capa_por_banda"));
573
                }
574
                return jCheckBox;
575
        }
576

    
577
        /**
578
         * This method initializes jCheckLoadLayerInToc
579
         *
580
         * @return javax.swing.JCheckBox
581
         */
582
        public JCheckBox getCbLoadLayerInToc() {
583
                if (jCheckLoadLayerInToc == null) {
584
                        jCheckLoadLayerInToc = new JCheckBox();
585
                        jCheckLoadLayerInToc.setText(PluginServices.getText(this, "cargar_en_toc"));
586
                        jCheckLoadLayerInToc.setSelected(true);
587
                        jCheckLoadLayerInToc.setEnabled(false);
588
                        jCheckLoadLayerInToc.addItemListener(this);
589
                }
590
                return jCheckLoadLayerInToc;
591
        }
592

    
593
        /**
594
         * Asigna el valor del campo "Ancho" a partir del double que lo representa
595
         * y con el n?mero de decimales que se especifica en el par?metro dec
596
         * @param width Ancho
597
         * @param dec N?mero de decimales
598
         */
599
        public void setWidthText(double width, int dec) {
600
                realWidth = width;
601
                getPResolution().setWidthText(width, dec);
602
        }
603

    
604
        /**
605
         * Obtiene la relaci?n entre el ancho y alto de la imagen
606
         * @return
607
         */
608
        public double getRelWidthHeight() {
609
                return relWidthHeight;
610
        }
611

    
612
        /**
613
         * Asigna el valor del campo "Alto" a partir del double que lo representa
614
         * y con el n?mero de decimales que se especifica en el par?metro dec
615
         * @param height Alto
616
         * @param dec N?mero de decimales
617
         */
618
        public void setHeightText(double height, int dec) {
619
                realHeight = height;
620
                getPResolution().setHeightText(height, dec);
621
        }
622

    
623
        /**
624
         * Asigna el valor del campo "tama?o de celda" a partir del double que lo representa
625
         * y con el n?mero de decimales que se especifica en el par?metro dec
626
         * @param cellSize Tama?o de celda en double
627
         * @param dec N?mero de decimales
628
         */
629
        public void setCellSizeText(double cellSize, int dec) {
630
                getPResolution().setCellSizeText(cellSize, dec);
631
        }
632

    
633
        /**
634
         * Asigna las coordenadas del mundo real a partir de n?meros en coma flotante.
635
         * @param minx coordenada m?nima de X
636
         * @param miny coordenada m?nima de Y
637
         * @param maxx coordenada m?xima de X
638
         * @param maxy coordenada m?xima de Y
639
         * @param dec N?mero de decimales a mostrar en la caja de texto
640
         */
641
        public void setCoorRealFromDouble(double minx, double miny, double maxx, double maxy, int dec) {
642
                wcMinX = minx;
643
                wcMinY = miny;
644
                wcMaxX = maxx;
645
                wcMaxY = maxy;
646
                 setCoordReal(getCoord(minx, miny, maxx, maxy, dec));
647
        }
648

    
649
        /**
650
         * Obtiene un texto con las coordenadas a partir de n?meros en coma flotante.
651
         * @param minx coordenada m?nima de X
652
         * @param miny coordenada m?nima de Y
653
         * @param maxx coordenada m?xima de X
654
         * @param maxy coordenada m?xima de Y
655
         * @param dec N?mero de decimales a mostrar en la caja de texto
656
         */
657
        private String[] getCoord(double minx, double miny, double maxx, double maxy, int dec) {
658
                String[] coordPx = new String[4];
659
                int indexPoint = String.valueOf(minx).indexOf('.');
660
                try {
661
                        coordPx[0] = String.valueOf(minx).substring(0, indexPoint + dec);
662
                } catch (StringIndexOutOfBoundsException ex) {
663
                        coordPx[0] = String.valueOf(minx);
664
                }
665
                indexPoint = String.valueOf(miny).indexOf('.');
666
                try {
667
                        coordPx[1] = String.valueOf(miny).substring(0, indexPoint + dec);
668
                } catch (StringIndexOutOfBoundsException ex) {
669
                        coordPx[1] = String.valueOf(miny);
670
                }
671
                indexPoint = String.valueOf(maxx).indexOf('.');
672
                try {
673
                        coordPx[2] = String.valueOf(maxx).substring(0, indexPoint + dec);
674
                } catch (StringIndexOutOfBoundsException ex) {
675
                        coordPx[2] = String.valueOf(maxx);
676
                }
677
                indexPoint = String.valueOf(maxy).indexOf('.');
678
                try {
679
                        coordPx[3] = String.valueOf(maxy).substring(0, indexPoint + dec);
680
                } catch (StringIndexOutOfBoundsException ex) {
681
                        coordPx[3] = String.valueOf(maxy);
682
                }
683
                return coordPx;
684
        }
685

    
686
        /**
687
         * Asigna los valores de las coordenadas reales.
688
         * @param values
689
         */
690
        private void setCoordReal(String[] values) {
691
                getCoor_reales().setValues(values);
692
        }
693

    
694
        /**
695
         * Asigna las coordenadas pixel a partir de n?meros en coma flotante.
696
         * @param minx coordenada m?nima de X
697
         * @param miny coordenada m?nima de Y
698
         * @param maxx coordenada m?xima de X
699
         * @param maxy coordenada m?xima de Y
700
         * @param dec N?mero de decimales a mostrar en la caja de texto
701
         */
702
        public void setCoorPixelFromDouble(double minx, double miny, double maxx, double maxy, int dec) {
703
                pxMinX = minx;
704
                pxMinY = miny;
705
                pxMaxX = maxx;
706
                pxMaxY = maxy;
707
                setCoordPixel(getCoord(minx, miny, maxx, maxy, dec));
708
        }
709

    
710
        /**
711
         * Asigna los valores de las coordenadas p?xel.
712
         * @return
713
         */
714
        private void setCoordPixel(String[] values) {
715
                this.getCoor_pixel().setValues(values);
716
        }
717

    
718
        /**
719
         * Asigna la relaci?n entre el ancho y alto de la imagen
720
         * @param rel
721
         */
722
        public void setRelWidthHeight(double rel) {
723
                relWidthHeight = rel;
724
        }
725

    
726
        /**
727
         * Obtiene la coordenada de m?xima X en pixel.
728
         * @return Coordenada de m?xima X en pixel
729
         */
730
        public double getPxMaxX() {
731
                return pxMaxX;
732
        }
733

    
734
        /**
735
         * Obtiene la coordenada de m?xima Y en pixel.
736
         * @return Coordenada de m?xima Y en pixel
737
         */
738
        public double getPxMaxY() {
739
                return pxMaxY;
740
        }
741

    
742
        /**
743
         * Obtiene la coordenada de m?nima X en pixel.
744
         * @return Coordenada de m?nima X en pixel
745
         */
746
        public double getPxMinX() {
747
                return pxMinX;
748
        }
749

    
750
        /**
751
         * Obtiene la coordenada de m?nima Y en pixel.
752
         * @return Coordenada de m?nima Y en pixel
753
         */
754
        public double getPxMinY() {
755
                return pxMinY;
756
        }
757

    
758
        /**
759
         * Obtiene la coordenada de m?xima X real.
760
         * @return Coordenada de m?xima X real.
761
         */
762
        public double getWcMaxX() {
763
                return wcMaxX;
764
        }
765

    
766
        /**
767
         * Obtiene la coordenada de m?xima Y real.
768
         * @return Coordenada de m?xima Y real
769
         */
770
        public double getWcMaxY() {
771
                return wcMaxY;
772
        }
773

    
774
        /**
775
         * Obtiene la coordenada de m?nima X real.
776
         * @return Coordenada de m?nima X real
777
         */
778
        public double getWcMinX() {
779
                return wcMinX;
780
        }
781

    
782
        /**
783
         * Obtiene la coordenada de m?nima Y real.
784
         * @return Coordenada de m?nima Y real
785
         */
786
        public double getWcMinY() {
787
                return wcMinY;
788
        }
789

    
790
        /**
791
         * Obtiene el <code>MapControl</code> de gvSIG
792
         * @return <code>MapControl</code>
793
         */
794
        public MapControl getMapControl() {
795
                return mapControl;
796
        }
797

    
798
        /**
799
         * Obtiene la ultima herramienta seleccionada antes de cargar el recorte
800
         * @return
801
         */
802
        public String getLastTool() {
803
                return lastTool;
804
        }
805

    
806
        /**
807
         * Obtiene el nombre de la vista
808
         * @return
809
         */
810
        public String getViewName() {
811
                return viewName;
812
        }
813

    
814
        /**
815
         * Devuelve el valor del campo "tama?o de celda"
816
         * @return
817
         */
818
        public double getWidthText() {
819
                return realWidth;
820
        }
821

    
822
        /**
823
         * Devuelve el valor del campo "tama?o de celda"
824
         * @return
825
         */
826
        public double getHeightText() {
827
                return realHeight;
828
        }
829

    
830
        /**
831
         * Cada vez que cambia un checkbox de cargar en toc o guardar en fichero, nos
832
         * aseguramos de que no pueden estar las dos opciones desmarcadas
833
         */
834
        public void itemStateChanged(ItemEvent e) {
835
                getCbLoadLayerInToc().setEnabled(true);
836
                getCbSaveFile().setEnabled(true);
837
                if (getCbLoadLayerInToc().isSelected() && !getCbSaveFile().isSelected())
838
                        getCbLoadLayerInToc().setEnabled(false);
839
                if (!getCbLoadLayerInToc().isSelected() && getCbSaveFile().isSelected())
840
                        getCbSaveFile().setEnabled(false);
841

    
842
                getJBChooseDirectory().setEnabled(getCbSaveFile().isSelected());
843
                getDirectoryTextField().setEnabled(getCbSaveFile().isSelected());
844
                getJLabelDirectory().setEnabled(getCbSaveFile().isSelected());
845
        }
846

    
847
        /**
848
         * Accion que sucede cuando se pulsa el boton de cambiar directorio
849
         */
850
        public void actionPerformed(ActionEvent e) {
851

    
852
                JFileChooser chooser = new JFileChooser(RasterModule.getPath());
853
                chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
854
                chooser.setDialogTitle(PluginServices.getText(this, "seleccionar_directorio"));
855

    
856
                if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
857
                        return;
858
                String path = chooser.getSelectedFile().toString();
859
                RasterModule.setPath(path);
860
                getDirectoryTextField().setText(path);
861
        }
862
}