コード例 #1
1
ファイル: FormatTest.java プロジェクト: hwp0710/javabread
 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
     throws BadLocationException {
   StringBuilder builder = new StringBuilder(string);
   for (int i = builder.length() - 1; i >= 0; i--) {
     int cp = builder.codePointAt(i);
     if (!Character.isDigit(cp) && cp != '-') {
       builder.deleteCharAt(i);
       if (Character.isSupplementaryCodePoint(cp)) {
         i--;
         builder.deleteCharAt(i);
       }
     }
   }
   super.insertString(fb, offset, builder.toString(), attr);
 }
コード例 #2
0
 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
     throws BadLocationException {
   StringBuilder builder = new StringBuilder(string);
   // 过滤用户输入的所有字符
   filterInt(builder);
   super.insertString(fb, offset, builder.toString(), attr);
 }
コード例 #3
0
 public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr)
     throws BadLocationException {
   if (string != null) {
     StringBuilder builder = new StringBuilder(string);
     // 过滤用户替换的所有字符
     filterInt(builder);
     string = builder.toString();
   }
   super.replace(fb, offset, length, string, attr);
 }
コード例 #4
0
    public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a)
        throws BadLocationException {
      if ("\n".equals(str)) str = addWhiteSpace(fb.getDocument(), offs);

      super.replace(fb, offs, length, str, a);
    }