Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2059 / libraries / libUIComponent / src / org / gvsig / gui / beans / datainput / DataInputContainer.java @ 39319

History | View | Annotate | Download (4.49 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.datainput;
20

    
21
import java.awt.ComponentOrientation;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.Insets;
25
import java.awt.event.KeyListener;
26

    
27
import javax.swing.JLabel;
28
import javax.swing.JPanel;
29
/**
30
 * Campo de texto que controla el contenido de datos del componente y solo
31
 * dispara un evento cuando realmente ha cambiado su valor. Contiene un
32
 * label para ponerle un nombre.<p>
33
 * 
34
 * <b>RECOMENDABLE:</b> Usar JFormattedTextFields<p>
35
 * 
36
 * Ejemplo de Sun:<br>
37
 * &nbsp;&nbsp;<a href="http://java.sun.com/docs/books/tutorial/uiswing/examples/components/FormatterFactoryDemoProject/src/components/FormatterFactoryDemo.java">FormatterFactoryDemo.java</a>
38
 * 
39
 * @version 06/09/2007
40
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
41
 */
42
public class DataInputContainer extends JPanel {
43
        private static final long serialVersionUID = 7084105134015956663L;
44

    
45
        private JLabel          jLabel                = null;
46
        private DataInputField  dataInputField        = null;
47
        private int             maximumFractionDigits = 3;
48

    
49
        /**
50
         * This is the default constructor
51
         */
52
        public DataInputContainer(int maximumFractionDigits) {
53
                this.maximumFractionDigits = maximumFractionDigits;
54
                initialize();
55
        }
56
        
57
        /**
58
         * This is the default constructor
59
         */
60
        public DataInputContainer() {
61
                initialize();
62
        }
63

    
64
        /**
65
         * This method initializes this
66
         * @return void
67
         */
68
        private void initialize() {
69
                setLayout(new GridBagLayout());
70

    
71
                GridBagConstraints gridBagConstraints = new GridBagConstraints();
72
                gridBagConstraints.insets = new Insets(0, 0, 0, 0);
73
                add(getLText(), gridBagConstraints);
74

    
75
                gridBagConstraints = new GridBagConstraints();
76
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
77
                gridBagConstraints.weightx = 1.0;
78
                add(getDataInputField(), gridBagConstraints);
79
        }
80

    
81
        private JLabel getLText() {
82
                if (jLabel == null) {
83
                        jLabel = new JLabel();
84
                        jLabel.setText("JLabel");
85
                        jLabel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
86
                }
87
                return jLabel;
88
        }
89

    
90
        /**
91
         * Da nombre al campo de texto del componente.
92
         * @param text
93
         */
94
        public void setLabelText(String text){
95
                getLText().setText(text + ":");
96
        }
97

    
98
        /**
99
         * This method initializes jTextField
100
         *
101
         * @return javax.swing.JTextField
102
         */
103
        public DataInputField getDataInputField() {
104
                if (dataInputField == null) {
105
                        dataInputField = new DataInputField(maximumFractionDigits);
106
                }
107
                return dataInputField;
108
        }
109

    
110
        /**
111
         * Devuelve el valor del campo de texto.
112
         * @return
113
         */
114
        public String getValue() {
115
                return getDataInputField().getValue();
116
        }
117

    
118
        /**
119
         * Habilita o deshabilita el control
120
         * @param en
121
         */
122
        public void setControlEnabled(boolean en){
123
                getLText().setEnabled(en);
124
                getDataInputField().setControlEnabled(en);
125
        }
126

    
127
        /**
128
         * Asigna el valor al campo de texto.
129
         * @return
130
         */
131
        public void setValue(String value) {
132
                getDataInputField().setValue(value);
133
        }
134

    
135
        /**
136
         * A?adir un listener a la lista de eventos
137
         * @param listener
138
         */
139
        public void addValueChangedListener(DataInputContainerListener listener) {
140
                getDataInputField().addValueChangedListener(listener);
141
        }
142
        
143
        /**
144
         * A?adir un listener a la lista de eventos
145
         * @param listener
146
         */
147
        public void addKeyListener(KeyListener listener) {
148
                getDataInputField().addKeyListener(listener);
149
        }
150

    
151
        /**
152
         * Borrar un listener de la lista de eventos
153
         * @param listener
154
         */
155
        public void removeValueChangedListener(DataInputContainerListener listener) {
156
                getDataInputField().removeValueChangedListener(listener);
157
        }
158
        
159
        /**
160
         * Borrar un listener de la lista de eventos
161
         * @param listener
162
         */
163
        public void removeKeyListener(KeyListener listener) {
164
                getDataInputField().removeKeyListener(listener);
165
        }
166
}