public void insertString(DocumentFilter.FilterBypass fb, int offs, String str, AttributeSet a)
     throws BadLocationException {
   if (isValidPostiveNumber(true, fb, offs, str, 0)) {
     fb.insertString(offs, str, a);
     doValueUpdate(fb);
   }
 } // End of insert
 public void replace(
     DocumentFilter.FilterBypass fb, int offs, int length, String str, AttributeSet a)
     throws BadLocationException {
   if (isValidPostiveNumber(false, fb, offs, str, length)) {
     fb.replace(offs, length, str, a);
     doValueUpdate(fb);
   }
 } // End of replace
 public void remove(DocumentFilter.FilterBypass fb, int offs, int length)
     throws BadLocationException {
   String str = "";
   if (isValidPostiveNumber(false, fb, offs, str, length)) {
     fb.remove(offs, length);
     doValueUpdate(fb);
   }
 } // End of remove
 /** Overriden to unconditionally allow the replace if ignoreDocumentMutate is true. */
 void replace(
     DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
     throws BadLocationException {
   if (ignoreDocumentMutate) {
     fb.replace(offset, length, text, attrs);
     return;
   }
   super.replace(fb, offset, length, text, attrs);
 }
 public void remove(DocumentFilter.FilterBypass fb, int offs, int length)
     throws BadLocationException {
   // Insertion is just replacement of a 0 lenght string.
   // Delete is a kind of insertion.
   // It's just replacement of non-zero lenght string with a 0 lenght string.
   // So we will insert a 0 length text.
   String str = "";
   // And we pass in false for insertion which means replacement.
   if (isValidTemperature(false, fb, offs, str, length)) {
     fb.remove(offs, length);
     doValueUpdate(fb);
   }
 } // End of remove
示例#6
0
    @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();
    }