Revision 11087
branches/v10/libraries/libUI/src/de/ios/framework/swing/NumberField.java | ||
---|---|---|
1 |
|
|
2 |
|
|
3 |
/* |
|
4 |
* $Id$ |
|
5 |
* |
|
6 |
* (c)1997 IoS Gesellschaft fr innovative Softwareentwicklung mbH |
|
7 |
* http://www.IoS-Online.de mailto:info@IoS-Online.de |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License as |
|
11 |
* published by the Free Software Foundation; either version 2 of |
|
12 |
* the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
* General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
|
|
26 |
package de.ios.framework.swing; |
|
27 |
|
|
28 |
import java.math.BigInteger; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.text.*; |
|
31 |
|
|
32 |
import de.ios.framework.basic.*; |
|
33 |
|
|
34 |
|
|
35 |
/** |
|
36 |
* Input-Field for Numbers, supported Objects: BigInteger, Long, Integer, (long) |
|
37 |
* Implementation of several Listener-Interfaces by the Basic-Class only for internal use! |
|
38 |
* For further description |
|
39 |
* @see IoSTextField |
|
40 |
* @version $Id$ |
|
41 |
*/ |
|
42 |
public class NumberField extends IoSTextField { |
|
43 |
|
|
44 |
|
|
45 |
/** Input-Field-Size in Columns. */ |
|
46 |
public final static int DEFAULT_LENGTH = 10; |
|
47 |
|
|
48 |
/** Limited Character-Set of this Field. */ |
|
49 |
private static final String NUMBER_CHARSET = "-0123456789TMtm"; |
|
50 |
|
|
51 |
/** The Decimal-Format. */ |
|
52 |
protected DecimalFormat decimalFormat = null; |
|
53 |
|
|
54 |
/** The Decimal-Format-Pattern. */ |
|
55 |
protected String dformat = "0"; |
|
56 |
|
|
57 |
|
|
58 |
/** |
|
59 |
* Default Constructor |
|
60 |
*/ |
|
61 |
public NumberField() { |
|
62 |
this( DEFAULT_LENGTH ); |
|
63 |
} |
|
64 |
|
|
65 |
|
|
66 |
/** |
|
67 |
* Constructor |
|
68 |
* @param cols columns of textfield |
|
69 |
*/ |
|
70 |
public NumberField( int cols ) { |
|
71 |
super( cols, NUMBER_CHARSET ); |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
/** |
|
76 |
* Constructor |
|
77 |
* @param _autoFormat if true use the special character set, ignore invalid characters |
|
78 |
*/ |
|
79 |
public NumberField( boolean _autoFormat ) { |
|
80 |
this( DEFAULT_LENGTH, _autoFormat ); |
|
81 |
} |
|
82 |
|
|
83 |
|
|
84 |
/** |
|
85 |
* Constructor |
|
86 |
* @param cols columns of textfield |
|
87 |
* @param _autoFormat |
|
88 |
*/ |
|
89 |
public NumberField( int cols, boolean _autoFormat ) { |
|
90 |
this( cols ); |
|
91 |
setAutoFormat( _autoFormat ); |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
/** |
|
96 |
* Constructor defining the auto-formating and illegal-value-focus-keeping. |
|
97 |
*/ |
|
98 |
public NumberField( boolean _autoFormat, boolean _keepFocus ) { |
|
99 |
this( DEFAULT_LENGTH, _autoFormat, _keepFocus ); |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
/** |
|
104 |
* Constructor defining the auto-formating and illegal-value-focus-keeping. |
|
105 |
*/ |
|
106 |
public NumberField( int cols, boolean _autoFormat, boolean _keepFocus ) { |
|
107 |
super( cols, NUMBER_CHARSET, _autoFormat, _keepFocus ); |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* Set the value |
|
113 |
* @param value The value to set. |
|
114 |
*/ |
|
115 |
public void setValue( BigInteger value ) { |
|
116 |
defineDecimalFormat(); |
|
117 |
setText( (value == null) ? |
|
118 |
null : |
|
119 |
( (decimalFormat == null) ? |
|
120 |
value.toString() : |
|
121 |
decimalFormat.format( value.longValue() ) ) ); |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
/** |
|
126 |
* Set the value |
|
127 |
* @param value The value to set. |
|
128 |
*/ |
|
129 |
public void setValue( Integer value ) { |
|
130 |
defineDecimalFormat(); |
|
131 |
setText( (value == null) ? |
|
132 |
null : |
|
133 |
( (decimalFormat == null) ? |
|
134 |
value.toString() : |
|
135 |
decimalFormat.format( value.longValue() ) ) ); |
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
/** |
|
140 |
* Set the value |
|
141 |
* @param value The value to set. |
|
142 |
*/ |
|
143 |
public void setValue( Long value ) { |
|
144 |
defineDecimalFormat(); |
|
145 |
setText( (value == null) ? |
|
146 |
null : |
|
147 |
( (decimalFormat == null) ? |
|
148 |
value.toString() : |
|
149 |
decimalFormat.format( value.longValue() ) ) ); |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
/** |
|
154 |
* Set the value |
|
155 |
* @param value The value to set. |
|
156 |
*/ |
|
157 |
public void setValue( long value ) { |
|
158 |
defineDecimalFormat(); |
|
159 |
setText( (decimalFormat == null) ? |
|
160 |
String.valueOf( value ) : |
|
161 |
decimalFormat.format( value ) ); |
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
/** |
|
166 |
* Set the format for display (WARNING: Can't be used with BigInteger!). |
|
167 |
* @param formater New formater or null. |
|
168 |
* @see java.text.DecimalFormat |
|
169 |
*/ |
|
170 |
public void setDecimalFormat( DecimalFormat formater ) |
|
171 |
throws IllegalArgumentException { |
|
172 |
decimalFormat = (formater == null) ? null : (DecimalFormat)formater.clone(); |
|
173 |
dformat = null; |
|
174 |
} |
|
175 |
|
|
176 |
|
|
177 |
/** |
|
178 |
* Set the format-pattern for display (WARNING: Can't be used with BigInteger!). |
|
179 |
* @param pattern New pattern or null. |
|
180 |
* @see java.text.DecimalFormat |
|
181 |
*/ |
|
182 |
public NumberField showTPoints( boolean b ) { |
|
183 |
dformat = (b ? ",##0" : "0"); |
|
184 |
return this; |
|
185 |
} |
|
186 |
|
|
187 |
|
|
188 |
/** |
|
189 |
* Internal Method for setting the DecimalFormat. |
|
190 |
*/ |
|
191 |
protected void defineDecimalFormat() { |
|
192 |
DecimalFormatSymbols decFormSym; |
|
193 |
|
|
194 |
if (dformat != null) { |
|
195 |
try { |
|
196 |
decimalFormat = new DecimalFormat( dformat ); |
|
197 |
decFormSym = decimalFormat.getDecimalFormatSymbols(); |
|
198 |
setCharSet( getCharSet()+ |
|
199 |
decFormSym.getGroupingSeparator() ); |
|
200 |
} catch (IllegalArgumentException e) { |
|
201 |
e.printStackTrace(); |
|
202 |
} |
|
203 |
dformat = null; |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
/** |
|
209 |
* Get the current value as BigInteger. |
|
210 |
* @return The current value. |
|
211 |
*/ |
|
212 |
public BigInteger getValue() { |
|
213 |
String bi = getFormatedText(); |
|
214 |
try { |
|
215 |
defineDecimalFormat(); |
|
216 |
return ( (bi == null) ? |
|
217 |
null : |
|
218 |
( (decimalFormat == null) ? |
|
219 |
new BigInteger(bi) : |
|
220 |
BigInteger.valueOf( decimalFormat.parse( bi ).longValue() ) ) ); |
|
221 |
} catch ( ParseException p ) { // If this happens, the formatValue()-Method is buggy! |
|
222 |
p.printStackTrace(); |
|
223 |
return null; |
|
224 |
} catch ( NumberFormatException e ) { // If this happens, the formatValue()-Method is buggy! |
|
225 |
e.printStackTrace(); |
|
226 |
return null; |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
|
|
231 |
/** |
|
232 |
* Get the current value as Long. |
|
233 |
* @return The current value. |
|
234 |
*/ |
|
235 |
public Long getLongValue() { |
|
236 |
BigInteger bi = getValue(); |
|
237 |
return (bi == null) ? null : new Long( bi.longValue() ); |
|
238 |
} |
|
239 |
|
|
240 |
|
|
241 |
/** |
|
242 |
* Get the current value as Integer. |
|
243 |
* @return The current value. |
|
244 |
*/ |
|
245 |
public Integer getIntegerValue() { |
|
246 |
BigInteger bi = getValue(); |
|
247 |
return (bi == null) ? null : new Integer( bi.intValue() ); |
|
248 |
} |
|
249 |
|
|
250 |
|
|
251 |
/** |
|
252 |
* Format the Value (automatically called on lostFocus, manually called on getValue/Date()). |
|
253 |
* @return false, if formating fails due to an illegal Value |
|
254 |
* (results in keeping the Focus, if requested by setKeepFocusOnIllegalValue). |
|
255 |
*/ |
|
256 |
public boolean formatValue() { |
|
257 |
String bi = getNullText(); |
|
258 |
try { |
|
259 |
defineDecimalFormat(); |
|
260 |
if (bi != null) |
|
261 |
if ( bi.trim().length() == 0 ) |
|
262 |
setText( null ); |
|
263 |
else { |
|
264 |
bi = bi.toUpperCase(); |
|
265 |
if (bi.endsWith("T")) |
|
266 |
bi = bi.substring(0, bi.length()-1)+"000"; |
|
267 |
else if (bi.endsWith("M")) |
|
268 |
bi = bi.substring(0, bi.length()-1)+"000000"; |
|
269 |
setValue( (decimalFormat == null) ? |
|
270 |
new BigInteger(bi) : |
|
271 |
BigInteger.valueOf( decimalFormat.parse( bi ).longValue() ) ); |
|
272 |
} |
|
273 |
return true; |
|
274 |
} catch ( ParseException p ) { // If this happens, the formatValue()-Method is buggy! |
|
275 |
return false; |
|
276 |
} catch ( NumberFormatException e ) { // If this happens, the formatValue()-Method is buggy! |
|
277 |
return false; |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
|
|
282 |
/** |
|
283 |
* Implements KeyListener. |
|
284 |
* Invoked when a key has been typed. Replaces manualy handled Characters. |
|
285 |
*/ |
|
286 |
public synchronized void keyTyped(KeyEvent evt ) { |
|
287 |
defineDecimalFormat(); |
|
288 |
super.keyTyped( evt ); |
|
289 |
} |
|
290 |
|
|
291 |
} |
|
292 |
|
|
293 |
/* |
|
294 |
* $Log$ |
|
295 |
* Revision 1.1.2.1 2007-01-19 13:42:54 caballero |
|
296 |
* NumericField |
|
297 |
* |
|
298 |
* Revision 1.1.1.1 2001/02/07 15:23:12 rtfm |
|
299 |
* initial |
|
300 |
* |
|
301 |
* Revision 1.17 1999/12/15 09:08:45 fw |
|
302 |
* allowed also small 't/m' |
|
303 |
* |
|
304 |
* Revision 1.16 1999/12/03 10:00:52 js |
|
305 |
* comment fix |
|
306 |
* |
|
307 |
* Revision 1.15 1999/04/22 11:47:33 fw |
|
308 |
* added xxxT & xxxM Support |
|
309 |
* |
|
310 |
* Revision 1.14 1999/04/15 15:50:09 fw |
|
311 |
* using Formaters |
|
312 |
* |
|
313 |
* Revision 1.13 1999/04/09 15:36:27 fw |
|
314 |
* extended Formater-Support |
|
315 |
* |
|
316 |
* Revision 1.12 1998/12/08 18:26:10 fw |
|
317 |
* *Field: cleanup; autoFormat-, keepFocus-, limited-Charset-Support for all Fields (enabled by default) |
|
318 |
* ViewLayout: Litle change due to changes at the *Fields |
|
319 |
* DBListRow: toString()-Method for BigDecimals exchanging the '.' by ',' |
|
320 |
* |
|
321 |
* Revision 1.11 1998/12/02 11:27:43 js |
|
322 |
* Modifications for changes in IoSText (special character sets). |
|
323 |
* |
|
324 |
* Revision 1.10 1998/11/30 12:01:26 bw |
|
325 |
* Support for DecimalFormat added (automatic formating by java.text.DecimalFormat). |
|
326 |
* Not tested!!!! |
|
327 |
* |
|
328 |
* Revision 1.9 1998/06/30 12:18:30 bw |
|
329 |
* Bugfix (keyTyped now set Caret-Position and can handle empty fields). |
|
330 |
* |
|
331 |
* Revision 1.8 1998/05/13 11:55:38 fw |
|
332 |
* Added new basic TextField-Component IoSTextField (ExtendedTextField |
|
333 |
* with JDK 1.1 Event-Handling), replaced the Base-Class ExtendedTextField |
|
334 |
* of all other 'Fields' by IoSTextField |
|
335 |
* ExtendedTextField uses now the JDK 1.0 Event-Handling again (due to massive |
|
336 |
* Problems with blocked 1.0-Event-Handling at older Projects) - from now |
|
337 |
* on the complete Class is DEPRECATED. |
|
338 |
* |
|
339 |
* Revision 1.7 1998/04/28 13:21:41 js |
|
340 |
* bugfix in constructor |
|
341 |
* |
|
342 |
* Revision 1.6 1998/04/28 12:56:26 bw |
|
343 |
* Automativ supression of non-digits added. |
|
344 |
* |
|
345 |
* Revision 1.5 1998/04/08 11:58:49 fw |
|
346 |
* bugfix / extension |
|
347 |
* |
|
348 |
* Revision 1.4 1998/04/08 09:01:22 fw |
|
349 |
* bugfix: Standard-Default-Value is null |
|
350 |
* |
|
351 |
* Revision 1.3 1998/04/07 11:44:48 fw |
|
352 |
* *** empty log message *** |
|
353 |
* |
|
354 |
* Revision 1.2 1998/03/18 01:15:24 fw |
|
355 |
* added some Methods |
|
356 |
* |
|
357 |
* Revision 1.1 1998/03/15 15:40:09 mh |
|
358 |
* added new fields DateField, DecimalField and NumberField |
|
359 |
* |
|
360 |
*/ |
|
361 |
|
branches/v10/libraries/libUI/src/de/ios/framework/swing/NumberRange.java | ||
---|---|---|
35 | 35 |
public static final boolean debug = false; |
36 | 36 |
|
37 | 37 |
/** TextField to hold the current value */ |
38 |
protected NumberField value = null; |
|
38 |
protected JNumberField value = null;
|
|
39 | 39 |
/** Button to increment the current value */ |
40 | 40 |
protected Button plusB = new Button("+");; |
41 | 41 |
/** Button to decrement the current value */ |
... | ... | |
103 | 103 |
* Arranges the GUI components |
104 | 104 |
*/ |
105 | 105 |
protected void createDialog() { |
106 |
value = new NumberField( digits ); |
|
106 |
value = new JNumberField( digits );
|
|
107 | 107 |
value.setEditable( false ); |
108 | 108 |
setLayout( new FlowLayout( FlowLayout.LEFT, 1, 1) ); |
109 | 109 |
add( value ); |
... | ... | |
161 | 161 |
|
162 | 162 |
/* |
163 | 163 |
* $Log$ |
164 |
* Revision 1.1.2.1 2007-01-19 13:42:54 caballero |
|
164 |
* Revision 1.1.2.2 2007-04-10 08:15:10 jmvivo |
|
165 |
* Por compatibilidad con la v1_0_1 se vuelve a usar JNumberField |
|
166 |
* |
|
167 |
* Revision 1.1.2.1 2007/01/19 13:42:54 caballero |
|
165 | 168 |
* NumericField |
166 | 169 |
* |
167 | 170 |
* Revision 1.1.1.1 2001/02/07 15:24:01 rtfm |
branches/v10/libraries/libUI/src/de/ios/framework/swing/JNumberField.java | ||
---|---|---|
1 |
|
|
2 |
|
|
3 |
/* |
|
4 |
* $Id$ |
|
5 |
* |
|
6 |
* (c)1997 IoS Gesellschaft fr innovative Softwareentwicklung mbH |
|
7 |
* http://www.IoS-Online.de mailto:info@IoS-Online.de |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License as |
|
11 |
* published by the Free Software Foundation; either version 2 of |
|
12 |
* the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 |
* General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
22 |
* |
|
23 |
*/ |
|
24 |
|
|
25 |
|
|
26 |
package de.ios.framework.swing; |
|
27 |
|
|
28 |
import java.math.BigInteger; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.text.*; |
|
31 |
|
|
32 |
import de.ios.framework.basic.*; |
|
33 |
|
|
34 |
|
|
35 |
/** |
|
36 |
* Input-Field for Numbers, supported Objects: BigInteger, Long, Integer, (long) |
|
37 |
* Implementation of several Listener-Interfaces by the Basic-Class only for internal use! |
|
38 |
* For further description |
|
39 |
* @see IoSTextField |
|
40 |
* @version $Id$ |
|
41 |
* @deprecated |
|
42 |
*/ |
|
43 |
public class JNumberField extends IoSTextField { |
|
44 |
|
|
45 |
|
|
46 |
/** Input-Field-Size in Columns. */ |
|
47 |
public final static int DEFAULT_LENGTH = 10; |
|
48 |
|
|
49 |
/** Limited Character-Set of this Field. */ |
|
50 |
private static final String NUMBER_CHARSET = "-0123456789TMtm"; |
|
51 |
|
|
52 |
/** The Decimal-Format. */ |
|
53 |
protected DecimalFormat decimalFormat = null; |
|
54 |
|
|
55 |
/** The Decimal-Format-Pattern. */ |
|
56 |
protected String dformat = "0"; |
|
57 |
|
|
58 |
|
|
59 |
/** |
|
60 |
* Default Constructor |
|
61 |
*/ |
|
62 |
public JNumberField() { |
|
63 |
this( DEFAULT_LENGTH ); |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
/** |
|
68 |
* Constructor |
|
69 |
* @param cols columns of textfield |
|
70 |
*/ |
|
71 |
public JNumberField( int cols ) { |
|
72 |
super( cols, NUMBER_CHARSET ); |
|
73 |
} |
|
74 |
|
|
75 |
|
|
76 |
/** |
|
77 |
* Constructor |
|
78 |
* @param _autoFormat if true use the special character set, ignore invalid characters |
|
79 |
*/ |
|
80 |
public JNumberField( boolean _autoFormat ) { |
|
81 |
this( DEFAULT_LENGTH, _autoFormat ); |
|
82 |
} |
|
83 |
|
|
84 |
|
|
85 |
/** |
|
86 |
* Constructor |
|
87 |
* @param cols columns of textfield |
|
88 |
* @param _autoFormat |
|
89 |
*/ |
|
90 |
public JNumberField( int cols, boolean _autoFormat ) { |
|
91 |
this( cols ); |
|
92 |
setAutoFormat( _autoFormat ); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
/** |
|
97 |
* Constructor defining the auto-formating and illegal-value-focus-keeping. |
|
98 |
*/ |
|
99 |
public JNumberField( boolean _autoFormat, boolean _keepFocus ) { |
|
100 |
this( DEFAULT_LENGTH, _autoFormat, _keepFocus ); |
|
101 |
} |
|
102 |
|
|
103 |
|
|
104 |
/** |
|
105 |
* Constructor defining the auto-formating and illegal-value-focus-keeping. |
|
106 |
*/ |
|
107 |
public JNumberField( int cols, boolean _autoFormat, boolean _keepFocus ) { |
|
108 |
super( cols, NUMBER_CHARSET, _autoFormat, _keepFocus ); |
|
109 |
} |
|
110 |
|
|
111 |
|
|
112 |
/** |
|
113 |
* Set the value |
|
114 |
* @param value The value to set. |
|
115 |
*/ |
|
116 |
public void setValue( BigInteger value ) { |
|
117 |
defineDecimalFormat(); |
|
118 |
setText( (value == null) ? |
|
119 |
null : |
|
120 |
( (decimalFormat == null) ? |
|
121 |
value.toString() : |
|
122 |
decimalFormat.format( value.longValue() ) ) ); |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
/** |
|
127 |
* Set the value |
|
128 |
* @param value The value to set. |
|
129 |
*/ |
|
130 |
public void setValue( Integer value ) { |
|
131 |
defineDecimalFormat(); |
|
132 |
setText( (value == null) ? |
|
133 |
null : |
|
134 |
( (decimalFormat == null) ? |
|
135 |
value.toString() : |
|
136 |
decimalFormat.format( value.longValue() ) ) ); |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
/** |
|
141 |
* Set the value |
|
142 |
* @param value The value to set. |
|
143 |
*/ |
|
144 |
public void setValue( Long value ) { |
|
145 |
defineDecimalFormat(); |
|
146 |
setText( (value == null) ? |
|
147 |
null : |
|
148 |
( (decimalFormat == null) ? |
|
149 |
value.toString() : |
|
150 |
decimalFormat.format( value.longValue() ) ) ); |
|
151 |
} |
|
152 |
|
|
153 |
|
|
154 |
/** |
|
155 |
* Set the value |
|
156 |
* @param value The value to set. |
|
157 |
*/ |
|
158 |
public void setValue( long value ) { |
|
159 |
defineDecimalFormat(); |
|
160 |
setText( (decimalFormat == null) ? |
|
161 |
String.valueOf( value ) : |
|
162 |
decimalFormat.format( value ) ); |
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
/** |
|
167 |
* Set the format for display (WARNING: Can't be used with BigInteger!). |
|
168 |
* @param formater New formater or null. |
|
169 |
* @see java.text.DecimalFormat |
|
170 |
*/ |
|
171 |
public void setDecimalFormat( DecimalFormat formater ) |
|
172 |
throws IllegalArgumentException { |
|
173 |
decimalFormat = (formater == null) ? null : (DecimalFormat)formater.clone(); |
|
174 |
dformat = null; |
|
175 |
} |
|
176 |
|
|
177 |
|
|
178 |
/** |
|
179 |
* Set the format-pattern for display (WARNING: Can't be used with BigInteger!). |
|
180 |
* @param pattern New pattern or null. |
|
181 |
* @see java.text.DecimalFormat |
|
182 |
*/ |
|
183 |
public JNumberField showTPoints( boolean b ) { |
|
184 |
dformat = (b ? ",##0" : "0"); |
|
185 |
return this; |
|
186 |
} |
|
187 |
|
|
188 |
|
|
189 |
/** |
|
190 |
* Internal Method for setting the DecimalFormat. |
|
191 |
*/ |
|
192 |
protected void defineDecimalFormat() { |
|
193 |
DecimalFormatSymbols decFormSym; |
|
194 |
|
|
195 |
if (dformat != null) { |
|
196 |
try { |
|
197 |
decimalFormat = new DecimalFormat( dformat ); |
|
198 |
decFormSym = decimalFormat.getDecimalFormatSymbols(); |
|
199 |
setCharSet( getCharSet()+ |
|
200 |
decFormSym.getGroupingSeparator() ); |
|
201 |
} catch (IllegalArgumentException e) { |
|
202 |
e.printStackTrace(); |
|
203 |
} |
|
204 |
dformat = null; |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
/** |
|
210 |
* Get the current value as BigInteger. |
|
211 |
* @return The current value. |
|
212 |
*/ |
|
213 |
public BigInteger getValue() { |
|
214 |
String bi = getFormatedText(); |
|
215 |
try { |
|
216 |
defineDecimalFormat(); |
|
217 |
return ( (bi == null) ? |
|
218 |
null : |
|
219 |
( (decimalFormat == null) ? |
|
220 |
new BigInteger(bi) : |
|
221 |
BigInteger.valueOf( decimalFormat.parse( bi ).longValue() ) ) ); |
|
222 |
} catch ( ParseException p ) { // If this happens, the formatValue()-Method is buggy! |
|
223 |
p.printStackTrace(); |
|
224 |
return null; |
|
225 |
} catch ( NumberFormatException e ) { // If this happens, the formatValue()-Method is buggy! |
|
226 |
e.printStackTrace(); |
|
227 |
return null; |
|
228 |
} |
|
229 |
} |
|
230 |
|
|
231 |
|
|
232 |
/** |
|
233 |
* Get the current value as Long. |
|
234 |
* @return The current value. |
|
235 |
*/ |
|
236 |
public Long getLongValue() { |
|
237 |
BigInteger bi = getValue(); |
|
238 |
return (bi == null) ? null : new Long( bi.longValue() ); |
|
239 |
} |
|
240 |
|
|
241 |
|
|
242 |
/** |
|
243 |
* Get the current value as Integer. |
|
244 |
* @return The current value. |
|
245 |
*/ |
|
246 |
public Integer getIntegerValue() { |
|
247 |
BigInteger bi = getValue(); |
|
248 |
return (bi == null) ? null : new Integer( bi.intValue() ); |
|
249 |
} |
|
250 |
|
|
251 |
|
|
252 |
/** |
|
253 |
* Format the Value (automatically called on lostFocus, manually called on getValue/Date()). |
|
254 |
* @return false, if formating fails due to an illegal Value |
|
255 |
* (results in keeping the Focus, if requested by setKeepFocusOnIllegalValue). |
|
256 |
*/ |
|
257 |
public boolean formatValue() { |
|
258 |
String bi = getNullText(); |
|
259 |
try { |
|
260 |
defineDecimalFormat(); |
|
261 |
if (bi != null) |
|
262 |
if ( bi.trim().length() == 0 ) |
|
263 |
setText( null ); |
|
264 |
else { |
|
265 |
bi = bi.toUpperCase(); |
|
266 |
if (bi.endsWith("T")) |
|
267 |
bi = bi.substring(0, bi.length()-1)+"000"; |
|
268 |
else if (bi.endsWith("M")) |
|
269 |
bi = bi.substring(0, bi.length()-1)+"000000"; |
|
270 |
setValue( (decimalFormat == null) ? |
|
271 |
new BigInteger(bi) : |
|
272 |
BigInteger.valueOf( decimalFormat.parse( bi ).longValue() ) ); |
|
273 |
} |
|
274 |
return true; |
|
275 |
} catch ( ParseException p ) { // If this happens, the formatValue()-Method is buggy! |
|
276 |
return false; |
|
277 |
} catch ( NumberFormatException e ) { // If this happens, the formatValue()-Method is buggy! |
|
278 |
return false; |
|
279 |
} |
|
280 |
} |
|
281 |
|
|
282 |
|
|
283 |
/** |
|
284 |
* Implements KeyListener. |
|
285 |
* Invoked when a key has been typed. Replaces manualy handled Characters. |
|
286 |
*/ |
|
287 |
public synchronized void keyTyped(KeyEvent evt ) { |
|
288 |
defineDecimalFormat(); |
|
289 |
super.keyTyped( evt ); |
|
290 |
} |
|
291 |
|
|
292 |
} |
|
293 |
|
|
294 |
/* |
|
295 |
* $Log$ |
|
296 |
* Revision 1.2.2.4 2007-04-10 08:15:10 jmvivo |
|
297 |
* Por compatibilidad con la v1_0_1 se vuelve a usar JNumberField |
|
298 |
* |
|
299 |
* Revision 1.1.2.1 2007/01/19 13:42:54 caballero |
|
300 |
* NumericField |
|
301 |
* |
|
302 |
* Revision 1.1.1.1 2001/02/07 15:23:12 rtfm |
|
303 |
* initial |
|
304 |
* |
|
305 |
* Revision 1.17 1999/12/15 09:08:45 fw |
|
306 |
* allowed also small 't/m' |
|
307 |
* |
|
308 |
* Revision 1.16 1999/12/03 10:00:52 js |
|
309 |
* comment fix |
|
310 |
* |
|
311 |
* Revision 1.15 1999/04/22 11:47:33 fw |
|
312 |
* added xxxT & xxxM Support |
|
313 |
* |
|
314 |
* Revision 1.14 1999/04/15 15:50:09 fw |
|
315 |
* using Formaters |
|
316 |
* |
|
317 |
* Revision 1.13 1999/04/09 15:36:27 fw |
|
318 |
* extended Formater-Support |
|
319 |
* |
|
320 |
* Revision 1.12 1998/12/08 18:26:10 fw |
|
321 |
* *Field: cleanup; autoFormat-, keepFocus-, limited-Charset-Support for all Fields (enabled by default) |
|
322 |
* ViewLayout: Litle change due to changes at the *Fields |
|
323 |
* DBListRow: toString()-Method for BigDecimals exchanging the '.' by ',' |
|
324 |
* |
|
325 |
* Revision 1.11 1998/12/02 11:27:43 js |
|
326 |
* Modifications for changes in IoSText (special character sets). |
|
327 |
* |
|
328 |
* Revision 1.10 1998/11/30 12:01:26 bw |
|
329 |
* Support for DecimalFormat added (automatic formating by java.text.DecimalFormat). |
|
330 |
* Not tested!!!! |
|
331 |
* |
|
332 |
* Revision 1.9 1998/06/30 12:18:30 bw |
|
333 |
* Bugfix (keyTyped now set Caret-Position and can handle empty fields). |
|
334 |
* |
|
335 |
* Revision 1.8 1998/05/13 11:55:38 fw |
|
336 |
* Added new basic TextField-Component IoSTextField (ExtendedTextField |
|
337 |
* with JDK 1.1 Event-Handling), replaced the Base-Class ExtendedTextField |
|
338 |
* of all other 'Fields' by IoSTextField |
|
339 |
* ExtendedTextField uses now the JDK 1.0 Event-Handling again (due to massive |
|
340 |
* Problems with blocked 1.0-Event-Handling at older Projects) - from now |
|
341 |
* on the complete Class is DEPRECATED. |
|
342 |
* |
|
343 |
* Revision 1.7 1998/04/28 13:21:41 js |
|
344 |
* bugfix in constructor |
|
345 |
* |
|
346 |
* Revision 1.6 1998/04/28 12:56:26 bw |
|
347 |
* Automativ supression of non-digits added. |
|
348 |
* |
|
349 |
* Revision 1.5 1998/04/08 11:58:49 fw |
|
350 |
* bugfix / extension |
|
351 |
* |
|
352 |
* Revision 1.4 1998/04/08 09:01:22 fw |
|
353 |
* bugfix: Standard-Default-Value is null |
|
354 |
* |
|
355 |
* Revision 1.3 1998/04/07 11:44:48 fw |
|
356 |
* *** empty log message *** |
|
357 |
* |
|
358 |
* Revision 1.2 1998/03/18 01:15:24 fw |
|
359 |
* added some Methods |
|
360 |
* |
|
361 |
* Revision 1.1 1998/03/15 15:40:09 mh |
|
362 |
* added new fields DateField, DecimalField and NumberField |
|
363 |
* |
|
364 |
*/ |
|
365 |
|
|
0 | 366 |
branches/v10/extensions/extGraph_predes/src/com/iver/cit/gvsig/gvsig/gui/styling/SymbolSelector.java | ||
---|---|---|
90 | 90 |
import com.iver.utiles.XMLEntity; |
91 | 91 |
|
92 | 92 |
import de.ios.framework.swing.JDecimalField; |
93 |
import de.ios.framework.swing.NumberField; |
|
93 |
import de.ios.framework.swing.JNumberField;
|
|
94 | 94 |
|
95 | 95 |
/** |
96 | 96 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
... | ... | |
112 | 112 |
private JPanel northPanel; |
113 | 113 |
private ColorChooserPanel jcc1; |
114 | 114 |
private ColorChooserPanel jcc2; |
115 |
private NumberField txtSize; |
|
115 |
private JNumberField txtSize;
|
|
116 | 116 |
private JDecimalField txtAngle; |
117 | 117 |
private JPanel jPanelButtons; |
118 | 118 |
private JButton btnProperties; |
... | ... | |
500 | 500 |
PluginServices.getText(this, "color")+":", jcc1); |
501 | 501 |
jPanelOptions.addComponent( |
502 | 502 |
PluginServices.getText(this, "size")+":", |
503 |
txtSize = new NumberField()); |
|
503 |
txtSize = new JNumberField());
|
|
504 | 504 |
jPanelOptions.addComponent( |
505 | 505 |
PluginServices.getText(this, "angle")+":", |
506 | 506 |
txtAngle = new JDecimalField()); |
... | ... | |
509 | 509 |
PluginServices.getText(this, "color")+":", jcc1); |
510 | 510 |
jPanelOptions.addComponent( |
511 | 511 |
PluginServices.getText(this, "width")+":", |
512 |
txtSize = new NumberField()); |
|
512 |
txtSize = new JNumberField());
|
|
513 | 513 |
jPanelOptions.addComponent(new JLabel("AQUI VA EL COMBO DE PATTERN DE LINEA")); |
514 | 514 |
} else if (shapeType == FShape.POLYGON) { |
515 | 515 |
jPanelOptions.addComponent( |
Also available in: Unified diff