Statistics
| Revision:

gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.swing / org.gvsig.raster.georeferencing.swing.impl / src / main / java / org / gvsig / raster / georeferencing / swing / impl / option / CellSizeOptionsPanel.java @ 1752

History | View | Annotate | Download (4.99 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.georeferencing.swing.impl.option;
23

    
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.beans.PropertyChangeEvent;
28
import java.beans.PropertyChangeListener;
29
import java.text.DecimalFormat;
30

    
31
import javax.swing.JFormattedTextField;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34

    
35
import org.gvsig.i18n.Messages;
36

    
37
/**
38
 * Panel de selecci?n del tama?o de pixel en X e Y
39
 * 
40
 * 10/01/2008
41
 * @author Nacho Brodin nachobrodin@gmail.com
42
 */
43
public class CellSizeOptionsPanel extends JPanel {
44
        private static final long     serialVersionUID    = 1L;
45
        
46
        private CellSizeContainer      xCellSize           = null;
47
        private CellSizeContainer      yCellSize           = null;
48
        
49
        public class CellSizeContainer extends JPanel implements PropertyChangeListener {
50
                private static final long      serialVersionUID = 1L;
51
                private JFormattedTextField    box;
52
                private PropertyChangeListener listener            = null;
53
                
54
                public CellSizeContainer(String txt) {
55
                        box = new JFormattedTextField(new DecimalFormat("########.########"));
56
                        box.setValue(0.0);
57
                        box.addPropertyChangeListener("value", this);
58
                        setLayout(new GridBagLayout());
59
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
60
                        gridBagConstraints.insets = new Insets(0, 0, 0, 0);
61
                        add(new JLabel(txt), gridBagConstraints);
62

    
63
                        gridBagConstraints = new GridBagConstraints();
64
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
65
                        gridBagConstraints.weightx = 1.0;
66
                        add(box, gridBagConstraints);
67
                }
68
                
69
                public String getValue() {
70
                        double n = ((Number) box.getValue()).doubleValue();
71
                        return Double.toString(n);
72
                }
73
                
74
                public void setValue(String value) {
75
                        box.setValue(new Double(value));
76
                }
77

    
78
                public void setListener(PropertyChangeListener listener) {
79
                        this.listener = listener;
80
                }
81
                
82
                public void propertyChange(PropertyChangeEvent evt) {
83
                        listener.propertyChange(evt);
84
                }
85
        }
86
                
87
        /**
88
         * Constructor. Asigna la lista de nombres de vistas para el selector. 
89
         * @param viewList
90
         */
91
        public CellSizeOptionsPanel() {
92
                init();
93
        }
94
        
95
        /**
96
         * Acciones de inicializaci?n del panel
97
         */
98
        public void init() {            
99
                GridBagLayout gl = new GridBagLayout();
100
                setLayout(gl);
101
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("cellsize"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
102
                
103
                GridBagConstraints gbc = new GridBagConstraints();
104
                gbc.anchor = GridBagConstraints.WEST;
105
                gbc.insets = new Insets(0, 5, 5, 0);
106
                gbc.weightx = 1.0;
107
                gbc.fill = GridBagConstraints.HORIZONTAL;
108
                
109
                add(getXCellSizeTextField(), gbc);
110

    
111
                gbc.gridy = 1;
112
                add(getYCellSizeTextField(), gbc);
113
        }
114
        
115
        /**
116
         * Obtiene el control para selecci?n de tama?o de pixel en X
117
         * @return DataInputContainer
118
         */
119
        public CellSizeContainer getXCellSizeTextField() {
120
                if(xCellSize == null) {
121
                        xCellSize = new CellSizeContainer("X: ");
122
                }
123
                return xCellSize;
124
        }
125
        
126
        /**
127
         * Obtiene el control para selecci?n de tama?o de pixel en Y
128
         * @return DataInputContainer
129
         */
130
        public CellSizeContainer getYCellSizeTextField() {
131
                if(yCellSize == null) {
132
                        yCellSize = new CellSizeContainer("Y: ");
133
                }
134
                return yCellSize;
135
        }
136
        
137
        /**
138
         * Obtiene el control para selecci?n de tama?o de pixel en X
139
         * @return DataInputContainer
140
         */
141
        public double getXCellSizeValue() {
142
                try {
143
                        return Double.valueOf(xCellSize.getValue()).doubleValue();
144
                } catch(NumberFormatException ex) {
145
                        return -1;
146
                }
147
        }
148
        
149
        /**
150
         * Obtiene el control para selecci?n de tama?o de pixel en Y
151
         * @return DataInputContainer
152
         */
153
        public double getYCellSizeValue() {
154
                try {
155
                        return Double.valueOf(yCellSize.getValue()).doubleValue();
156
                } catch(NumberFormatException ex) {
157
                        return -1;
158
                }
159
        }
160
        
161
        /**
162
         * Asigna el tama?o de pixel en X
163
         * @param dataCellSize
164
         */
165
        public void setXCellSize(double dataCellSize) {
166
                if(xCellSize != null) 
167
                        xCellSize.setValue(dataCellSize + "");
168
        }
169
        
170
        /**
171
         * Asigna el tama?o de pixel en Y
172
         * @param dataCellSize
173
         */
174
        public void setYCellSize(double dataCellSize) {
175
                if(yCellSize != null) 
176
                        yCellSize.setValue(dataCellSize + "");
177
        }
178
                
179
}
180