Ejemplo n.º 1
0
 @Override
 public void replace(FilterBypass fb, int i, int i1, String string, AttributeSet as)
     throws BadLocationException {
   for (int n = string.length(); n > 0; n--) {
     char c = string.charAt(n - 1);
     switch (filterType) {
       case ALPHA:
         if ((Character.isAlphabetic(c))
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case NUMERIC:
         if ((Character.isDigit(c))
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case ALPHANUMERIC:
         if ((Character.isAlphabetic(c) || Character.isDigit(c))
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case ALPHA_SPACE:
         if ((Character.isAlphabetic(c) || c == ' ')
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case NUMERIC_SPACE:
         if ((Character.isDigit(c) || c == ' ')
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case ALPHANUMERIC_SPACE:
         if ((Character.isAlphabetic(c) || Character.isDigit(c) || c == ' ')
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case NO_HTML:
         if ((!isOneOfChars(c, '<', '>', '&'))
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case EMAIL:
         if ((Character.isAlphabetic(c)
                 || Character.isDigit(c)
                 || isOneOfChars(
                     c, '.', '!', '@', '_', '-', '+', '#', '$', '?', '=', '%', '\'', '*', '^',
                     '`', '{', '|', '}', '~'))
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       case FILENAME:
         if ((Character.isAlphabetic(c) || Character.isDigit(c) || isOneOfChars(c, '_', '-'))
             && (maxLength < 0 || this.textComponent.getText().length() < maxLength))
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
       default:
         if (maxLength < 0 || this.textComponent.getText().length() < maxLength)
           super.replace(fb, i, i1, String.valueOf(c), as);
         break;
     }
   }
   if (listener != null) listener.lengthChanged(textComponent.getText().length(), textComponent);
 }
Ejemplo n.º 2
0
    @Override
    public void remove(FilterBypass fb, int i, int i1) throws BadLocationException {
      super.remove(fb, i, i1);

      if (listener != null) listener.lengthChanged(textComponent.getText().length(), textComponent);
    }