コード例 #1
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);
 }
コード例 #2
0
ファイル: FormatTest.java プロジェクト: hwp0710/javabread
 public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr)
     throws BadLocationException {
   if (string != null) {
     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);
         }
       }
     }
     string = builder.toString();
   }
   super.replace(fb, offset, length, string, attr);
 }
コード例 #3
0
ファイル: NumbrixGUI.java プロジェクト: rainerlg90/Numbrix
    @Override
    public void replace(
        DocumentFilter.FilterBypass fp, int offset, int length, String string, AttributeSet aset)
        throws BadLocationException {
      Document doc = fp.getDocument();
      String oldText = doc.getText(0, doc.getLength());
      StringBuilder sb = new StringBuilder(oldText);
      sb.replace(offset, offset + length, oldText);

      int len = string.length();
      boolean isValidInteger = true;

      for (int i = 0; i < len; i++) {
        if (!Character.isDigit(string.charAt(i))) {
          isValidInteger = false;
          break;
        }
      }
      if (isValidInteger && verifyText(sb.toString())) {
        super.replace(fp, offset, length, string, aset);
      } else Toolkit.getDefaultToolkit().beep();
    }
コード例 #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);
    }