1 package com.instantbank.common.uiutils;
2
3 import java.awt.Toolkit;
4 import javax.swing.text.PlainDocument;
5 import javax.swing.text.AttributeSet;
6 import javax.swing.text.BadLocationException;
7
8
16 public class DoubleDocument extends PlainDocument {
17
18 public DoubleDocument() { }
19
20
21
29 public void insertString(int offset, String s, AttributeSet attributeSet)
30 throws BadLocationException {
31 try {
32 String saux;
33 if(s.endsWith(".")) {
34 saux = s + "0";
35 }
36 else {
37 saux = s;
38 }
39
40 Double.parseDouble(saux);
41 }
42 catch(Exception ex) {
43 Toolkit.getDefaultToolkit().beep();
44 return;
45 }
46 super.insertString(offset, s, attributeSet);
47 }
48 }
49