svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / datainput / DataInputContainer.java @ 40561
History | View | Annotate | Download (4.59 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.gui.beans.datainput; |
25 |
|
26 |
import java.awt.ComponentOrientation; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
import java.awt.event.KeyListener; |
31 |
|
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
/**
|
35 |
* Campo de texto que controla el contenido de datos del componente y solo
|
36 |
* dispara un evento cuando realmente ha cambiado su valor. Contiene un
|
37 |
* label para ponerle un nombre.<p>
|
38 |
*
|
39 |
* <b>RECOMENDABLE:</b> Usar JFormattedTextFields<p>
|
40 |
*
|
41 |
* Ejemplo de Sun:<br>
|
42 |
* <a href="http://java.sun.com/docs/books/tutorial/uiswing/examples/components/FormatterFactoryDemoProject/src/components/FormatterFactoryDemo.java">FormatterFactoryDemo.java</a>
|
43 |
*
|
44 |
* @version 06/09/2007
|
45 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
46 |
*/
|
47 |
public class DataInputContainer extends JPanel { |
48 |
private static final long serialVersionUID = 7084105134015956663L; |
49 |
|
50 |
private JLabel jLabel = null; |
51 |
private DataInputField dataInputField = null; |
52 |
private int maximumFractionDigits = 3; |
53 |
|
54 |
/**
|
55 |
* This is the default constructor
|
56 |
*/
|
57 |
public DataInputContainer(int maximumFractionDigits) { |
58 |
this.maximumFractionDigits = maximumFractionDigits;
|
59 |
initialize(); |
60 |
} |
61 |
|
62 |
/**
|
63 |
* This is the default constructor
|
64 |
*/
|
65 |
public DataInputContainer() {
|
66 |
initialize(); |
67 |
} |
68 |
|
69 |
/**
|
70 |
* This method initializes this
|
71 |
* @return void
|
72 |
*/
|
73 |
private void initialize() { |
74 |
setLayout(new GridBagLayout()); |
75 |
|
76 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
77 |
gridBagConstraints.insets = new Insets(0, 0, 0, 0); |
78 |
add(getLText(), gridBagConstraints); |
79 |
|
80 |
gridBagConstraints = new GridBagConstraints(); |
81 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
82 |
gridBagConstraints.weightx = 1.0;
|
83 |
add(getDataInputField(), gridBagConstraints); |
84 |
} |
85 |
|
86 |
private JLabel getLText() { |
87 |
if (jLabel == null) { |
88 |
jLabel = new JLabel(); |
89 |
jLabel.setText("JLabel");
|
90 |
jLabel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
|
91 |
} |
92 |
return jLabel;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Da nombre al campo de texto del componente.
|
97 |
* @param text
|
98 |
*/
|
99 |
public void setLabelText(String text){ |
100 |
getLText().setText(text + ":");
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* This method initializes jTextField
|
105 |
*
|
106 |
* @return javax.swing.JTextField
|
107 |
*/
|
108 |
public DataInputField getDataInputField() {
|
109 |
if (dataInputField == null) { |
110 |
dataInputField = new DataInputField(maximumFractionDigits);
|
111 |
} |
112 |
return dataInputField;
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* Devuelve el valor del campo de texto.
|
117 |
* @return
|
118 |
*/
|
119 |
public String getValue() { |
120 |
return getDataInputField().getValue();
|
121 |
} |
122 |
|
123 |
/**
|
124 |
* Habilita o deshabilita el control
|
125 |
* @param en
|
126 |
*/
|
127 |
public void setControlEnabled(boolean en){ |
128 |
getLText().setEnabled(en); |
129 |
getDataInputField().setControlEnabled(en); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Asigna el valor al campo de texto.
|
134 |
* @return
|
135 |
*/
|
136 |
public void setValue(String value) { |
137 |
getDataInputField().setValue(value); |
138 |
} |
139 |
|
140 |
/**
|
141 |
* A?adir un listener a la lista de eventos
|
142 |
* @param listener
|
143 |
*/
|
144 |
public void addValueChangedListener(DataInputContainerListener listener) { |
145 |
getDataInputField().addValueChangedListener(listener); |
146 |
} |
147 |
|
148 |
/**
|
149 |
* A?adir un listener a la lista de eventos
|
150 |
* @param listener
|
151 |
*/
|
152 |
public void addKeyListener(KeyListener listener) { |
153 |
getDataInputField().addKeyListener(listener); |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Borrar un listener de la lista de eventos
|
158 |
* @param listener
|
159 |
*/
|
160 |
public void removeValueChangedListener(DataInputContainerListener listener) { |
161 |
getDataInputField().removeValueChangedListener(listener); |
162 |
} |
163 |
|
164 |
/**
|
165 |
* Borrar un listener de la lista de eventos
|
166 |
* @param listener
|
167 |
*/
|
168 |
public void removeKeyListener(KeyListener listener) { |
169 |
getDataInputField().removeKeyListener(listener); |
170 |
} |
171 |
} |