Моя проблема заключается в следующем:
У меня есть:
public class WWFormattedTextField extends JFormattedTextField implements FocusListener {
Все отформатированные текстовые поля на всех экранах всегда будут в верхнем регистре. Мы хотим, чтобы они отображались в верхнем регистре при наборе текста и т. д. Итак, вот что мы для этого сделали:
public class WWFormattedTextField extends JFormattedTextField implements FocusListener {
private DocumentFilter filter = new UppercaseDocumentFilter();
private boolean isEmail = false;
public WWFormattedTextField() {
super();
init();
}
private void init() {
addFocusListener(this);
((AbstractDocument) this.getDocument()).setDocumentFilter(filter);
}
public void setIsEmail(boolean email) {
//Normally this is where I would put something like
//if email is true - allow mixed case characters
this.isEmail = email;
}
public boolean getIsEmail() {
return isEmail;
}
Теперь все поля WWFormattedTextField на всех экранах печатаются в верхнем регистре. Вот упомянутый выше UppercaseDocumentFilter():
public class UppercaseDocumentFilter extends DocumentFilter{
@Override
public void insertString(DocumentFilter.FilterBypass fb, int offset, String text, AttributeSet attr) throws BadLocationException {
fb.insertString(offset, text.toUpperCase(), attr);
}
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
fb.replace(offset, length, text.toUpperCase(), attrs);
}
}
Как видите, это FormattedTextField также имеет свойство isEmail. Когда это значение истинно, я хочу разрешить пользователю вводить в поле символы смешанного регистра, но только этот конкретный.
Любые подсказки/предложения о том, как я могу это сделать?