1 19 24 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards; 25 26 import javax.swing.text.PlainDocument ; 27 import javax.swing.text.AttributeSet ; 28 import javax.swing.text.BadLocationException ; 29 import java.awt.Toolkit ; 30 31 32 36 public class Util { 37 38 39 public Util() { 40 } 41 42 public static NumericDocument getNumericDocument(){ 44 return new NumericDocument(); 45 } 46 public static class NumericDocument extends PlainDocument { 47 private Toolkit toolkit = Toolkit.getDefaultToolkit(); 48 49 public void insertString(int offs, String str, AttributeSet a) 50 throws BadLocationException { 51 char[] s = str.toCharArray(); 52 char[] r = new char[s.length]; 53 int j = 0; 54 for (int i = 0; i < r.length; i++) { 55 if (Character.isDigit(s[i])) { 56 r[j++] = s[i]; 57 } else { 58 toolkit.beep(); 59 } 60 } 61 super.insertString(offs, new String (r, 0, j), a); 62 } 63 } 65 66 } 67 | Popular Tags |