Statistics
| Revision:

root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / coordDataInput / CoordDataInputContainer.java @ 8026

History | View | Annotate | Download (8.74 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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.gui.beans.coordDataInput;
20

    
21
import java.awt.FlowLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24

    
25
import javax.swing.JLabel;
26
import javax.swing.JPanel;
27

    
28
import org.gvsig.gui.beans.BaseComponent;
29
import org.gvsig.gui.beans.dataInput.DataInputContainer;
30

    
31
public class CoordDataInputContainer extends BaseComponent{
32
        private int                                        MARGIN = 12;
33
        private int                                        wComp = 350, hComp = 80;
34
        private int                                        hPanel = 24;
35
        private int                                        wLabels = 60, hLabels = 22;
36
        private int                                        wData = 152, hData = 24;
37
        
38
        private JPanel pCoord = null;
39
        private JPanel pData1 = null;
40
        private JPanel pData2 = null;
41
        private JLabel lTitulo1 = null;
42
        private JLabel lTitulo2 = null;
43
        private DataInputContainer pDataInput11 = null;
44
        private DataInputContainer pDataInput12 = null;
45
        private DataInputContainer pDataInput21 = null;
46
        private DataInputContainer pDataInput22 = null;
47
        
48
        private String                                tituloPanel = "Title";
49

    
50
        /**
51
         * This is the default constructor
52
         */
53
        public CoordDataInputContainer(int w, int h) {
54
                super();
55
                this.wComp = w;
56
                setComponentSize(wComp, hComp);
57
                initialize();
58
        }
59

    
60
        /**
61
         * This method initializes this
62
         * 
63
         * @return void
64
         */
65
        private void initialize() {
66
                FlowLayout flowLayout = new FlowLayout();
67
                flowLayout.setHgap(0);
68
                flowLayout.setVgap(0);
69
                this.setLayout(flowLayout);
70
                this.setPreferredSize(new java.awt.Dimension(wComp, hComp));
71
                this.add(getPCoord(), null);
72
        }
73

    
74
        /**
75
         * This method initializes jPanel        
76
         *         
77
         * @return javax.swing.JPanel        
78
         */
79
        private JPanel getPCoord() {
80
                if (pCoord == null) {
81
                        GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
82
                        gridBagConstraints2.gridx = 0;
83
                        gridBagConstraints2.gridy = 1;
84
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
85
                        gridBagConstraints.gridx = 0;
86
                        gridBagConstraints.gridy = 0;
87
                        pCoord = new JPanel();
88
                        pCoord.setLayout(new GridBagLayout());
89
                        pCoord.setBorder(javax.swing.BorderFactory.createTitledBorder(null, tituloPanel, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10), null));
90
                        pCoord.add(getPData1(), gridBagConstraints);
91
                        pCoord.add(getPData2(), gridBagConstraints2);
92
                }
93
                return pCoord;
94
        }
95

    
96
        /**
97
         * This method initializes jPanel        
98
         *         
99
         * @return javax.swing.JPanel        
100
         */
101
        private JPanel getPData1() {
102
                if (pData1 == null) {
103
                        FlowLayout flowLayout1 = new FlowLayout();
104
                        flowLayout1.setHgap(0);
105
                        flowLayout1.setAlignment(java.awt.FlowLayout.LEFT);
106
                        flowLayout1.setVgap(0);
107
                        pData1 = new JPanel();
108
                        pData1.setLayout(flowLayout1);
109
                        pData1.add(getLTitulo1(), null);
110
                        pData1.add(getPDataInput11(), null);
111
                        pData1.add(getPDataInput12(), null);
112
                        //pData1.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
113
                }
114
                return pData1;
115
        }
116

    
117
        private JLabel getLTitulo1(){
118
                if (lTitulo1 == null){
119
                        lTitulo1 = new JLabel();
120
                        lTitulo1.setText("JLabel");
121
                }
122
                return lTitulo1;
123
        }
124
        
125
        /**
126
         * This method initializes jPanel1        
127
         *         
128
         * @return javax.swing.JPanel        
129
         */
130
        private JPanel getPData2() {
131
                if (pData2 == null) {
132
                        FlowLayout flowLayout2 = new FlowLayout();
133
                        flowLayout2.setHgap(0);
134
                        flowLayout2.setAlignment(java.awt.FlowLayout.LEFT);
135
                        flowLayout2.setVgap(0);
136
                        pData2 = new JPanel();
137
                        pData2.setLayout(flowLayout2);
138
                        pData2.add(getLTitulo2(), null);
139
                        pData2.add(getPDataInput21(), null);
140
                        pData2.add(getPDataInput22(), null);
141
                        //pData2.setBorder(javax.swing.BorderFactory.createLineBorder(java.awt.Color.gray,1));
142
                }
143
                return pData2;
144
        }
145

    
146
        private JLabel getLTitulo2(){
147
                if (lTitulo2 == null){
148
                        lTitulo2 = new JLabel();
149
                        lTitulo2.setText("JLabel");
150
                }
151
                return lTitulo2;
152
        }
153

    
154
        /**
155
         * This method initializes jPanel        
156
         *         
157
         * @return javax.swing.JPanel        
158
         */
159
        public DataInputContainer getPDataInput11() {
160
                if (pDataInput11 == null) {
161
                        pDataInput11 = new DataInputContainer(0);
162
                }
163
                return pDataInput11;
164
        }
165

    
166
        /**
167
         * This method initializes jPanel1        
168
         *         
169
         * @return javax.swing.JPanel        
170
         */
171
        public DataInputContainer getPDataInput12() {
172
                if (pDataInput12 == null) {
173
                        pDataInput12 = new DataInputContainer(0);
174
                }
175
                return pDataInput12;
176
        }
177

    
178
        /**
179
         * This method initializes jPanel2        
180
         *         
181
         * @return javax.swing.JPanel        
182
         */
183
        public DataInputContainer getPDataInput21() {
184
                if (pDataInput21 == null) {
185
                        pDataInput21 = new DataInputContainer(0);
186
                }
187
                return pDataInput21;
188
        }
189

    
190
        /**
191
         * This method initializes jPanel3        
192
         *         
193
         * @return javax.swing.JPanel        
194
         */
195
        public DataInputContainer getPDataInput22() {
196
                if (pDataInput22 == null) {
197
                        pDataInput22 = new DataInputContainer(0);
198
                }
199
                return pDataInput22;
200
        }
201
        
202
        /**
203
         * M?todo para introducir los campos del componente. Por orden de
204
         * arriba a abajo se introducen las cadenas que tienen que ir en el panel.
205
         * @param tPanel
206
         * @param titulo1
207
         * @param celda11
208
         * @param celda12
209
         * @param titulo2
210
         * @param celda21
211
         * @param celda22
212
         */
213
        public void setParameters(String tPanel, String titulo1, String celda11, String celda12, String titulo2, String celda21, String celda22){
214
                this.tituloPanel = tPanel;
215
                this.lTitulo1.setText(titulo1);
216
                this.pDataInput11.setLabelText(celda11);
217
                this.pDataInput12.setLabelText(celda12);
218
                this.lTitulo2.setText(titulo2);
219
                this.pDataInput21.setLabelText(celda21);
220
                this.pDataInput22.setLabelText(celda22);
221
                pCoord.setBorder(javax.swing.BorderFactory.createTitledBorder(null, tituloPanel, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", java.awt.Font.PLAIN, 10), null));
222
                
223
        }
224
        
225
        /**
226
         * Modifica el tama?o del componente.
227
         * @param w
228
         * @param h
229
         */
230
        public void setComponentSize(int w, int h){
231
                wComp = w;
232
                this.getPCoord().setPreferredSize(new java.awt.Dimension(wComp, hComp));
233
                this.getLTitulo1().setPreferredSize(new java.awt.Dimension(wLabels,hLabels));
234
                this.getLTitulo2().setPreferredSize(new java.awt.Dimension(wLabels,hLabels));
235
                this.getPData1().setPreferredSize(new java.awt.Dimension(wComp - MARGIN, hPanel));
236
                this.getPData2().setPreferredSize(new java.awt.Dimension(wComp - MARGIN, hPanel));
237
                
238
                wData = (int)Math.floor((wComp - wLabels - 10) >> 1);
239
                int MARG = 2;
240
                this.getPDataInput11().setPreferredSize(new java.awt.Dimension(wData,hData));
241
                this.pDataInput11.setComponentSize(wData - MARG, hData - MARG);
242
                this.getPDataInput12().setPreferredSize(new java.awt.Dimension(wData,hData));
243
                this.pDataInput12.setComponentSize(wData - MARG, hData - MARG);
244
                this.getPDataInput21().setPreferredSize(new java.awt.Dimension(wData,hData));
245
                this.pDataInput21.setComponentSize(wData - MARG, hData - MARG);
246
                this.getPDataInput22().setPreferredSize(new java.awt.Dimension(wData,hData));
247
                this.pDataInput22.setComponentSize(wData - MARG, hData - MARG);
248
        }
249
        
250
        /**
251
         * Indica si los campos de texto admiten valores
252
         * decimales o no.
253
         * @param dec
254
         */
255
        public void setDecimalValues(boolean dec){
256
                this.pDataInput11.setDecimal(dec);
257
                this.pDataInput12.setDecimal(dec);
258
                this.pDataInput21.setDecimal(dec);
259
                this.pDataInput22.setDecimal(dec);
260
        }
261
        
262
        
263
        /**
264
         * Indica si los campos de texto admiten cadenas de
265
         * de caracteres.
266
         * @param car
267
         */
268
        public void setCaracterValues(boolean car){
269
                this.pDataInput11.setCaracter(car);
270
                this.pDataInput12.setCaracter(car);
271
                this.pDataInput21.setCaracter(car);
272
                this.pDataInput22.setCaracter(car);
273
        }
274
        
275
        
276
        /**
277
         * Devuelve los valores del panel por orden de izquierda a derecha
278
         * y de arriba a bajo.
279
         * @return
280
         */
281
        public String[] getValues(){
282
                String[] values = {this.pDataInput11.getValue(),
283
                                        this.pDataInput12.getValue(),
284
                                        this.pDataInput21.getValue(),
285
                                        this.pDataInput22.getValue()
286
                };
287
                return values;
288
        }
289
        
290
        /**
291
         * Asigna los valores del panel por orden de izquierda a derecha
292
         * y de arriba a bajo.
293
         * @return
294
         */
295
        public void setValues(String[] values){
296
                this.pDataInput11.setValue(values[0]);
297
                this.pDataInput12.setValue(values[1]);
298
                this.pDataInput21.setValue(values[2]);
299
                this.pDataInput22.setValue(values[3]);
300
        }
301
}