01: /*
02: * Copyright 2004 JETA Software, Inc. All rights reserved.
03: * JETA SOFTWARE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
04: */
05:
06: package com.jeta.swingbuilder.gui.components;
07:
08: import javax.swing.text.AttributeSet;
09: import javax.swing.text.BadLocationException;
10: import javax.swing.text.PlainDocument;
11:
12: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
13:
14: /**
15: * This class implements a text Document that only takes digits and a '-' sign
16: *
17: * @author Jeff Tassin
18: */
19: public class IntegerDocument extends PlainDocument {
20: private boolean m_allow_signed = true;
21:
22: public IntegerDocument() {
23: this (true);
24: }
25:
26: public IntegerDocument(boolean bsigned) {
27: m_allow_signed = bsigned;
28: }
29:
30: public void insertString(int offs, String str, AttributeSet a)
31: throws BadLocationException {
32: if (str == null) {
33: return;
34: }
35:
36: str = FormDesignerUtils.fastTrim(str);
37: for (int index = 0; index < str.length(); index++) {
38: char c = str.charAt(index);
39: if (!Character.isDigit(c)) {
40: if (c == '-' && m_allow_signed)
41: continue;
42:
43: // Toolkit toolkit = Toolkit.getDefaultToolkit() ;
44: // toolkit.beep();
45: return;
46: }
47: }
48: super.insertString(offs, str, a);
49: }
50: }
|