summaryrefslogtreecommitdiff
path: root/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java
diff options
context:
space:
mode:
Diffstat (limited to 'BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java')
-rw-r--r--BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java28
1 files changed, 23 insertions, 5 deletions
diff --git a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java
index 2054ae86..87b636f0 100644
--- a/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java
+++ b/BKUCommonGUI/src/main/java/at/gv/egiz/bku/gui/PinDocument.java
@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
import javax.swing.JButton;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
import javax.swing.text.PlainDocument;
/**
@@ -30,9 +31,10 @@ import javax.swing.text.PlainDocument;
*/
class PINDocument extends PlainDocument {
- private PINSpec pinSpec;
- private Pattern pinPattern;
- private JButton enterButton;
+ protected PINSpec pinSpec;
+ protected Pattern pinPattern;
+ protected JButton enterButton;
+ protected Document compareTo;
public PINDocument(PINSpec pinSpec, JButton enterButton) {
this.pinSpec = pinSpec;
@@ -44,6 +46,11 @@ class PINDocument extends PlainDocument {
this.enterButton = enterButton;
}
+ public PINDocument(PINSpec pinSpec, JButton enterButton, Document compareTo) {
+ this(pinSpec, enterButton);
+ this.compareTo = compareTo;
+ }
+
@Override
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
if (pinSpec.getMaxLength() < 0 || pinSpec.getMaxLength() >= (getLength() + str.length())) {
@@ -58,12 +65,23 @@ class PINDocument extends PlainDocument {
super.insertString(offs, str, a);
}
}
- enterButton.setEnabled(getLength() >= pinSpec.getMinLength());
+ if (enterButton != null) {
+ enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare());
+ }
}
@Override
public void remove(int offs, int len) throws BadLocationException {
super.remove(offs, len);
- enterButton.setEnabled(getLength() >= pinSpec.getMinLength());
+ if (enterButton != null) {
+ enterButton.setEnabled(getLength() >= pinSpec.getMinLength() && compare());
+ }
+ }
+
+ private boolean compare() throws BadLocationException {
+ if (compareTo == null) {
+ return true;
+ }
+ return compareTo.getText(0, compareTo.getLength()).equals(getText(0, getLength()));
}
} \ No newline at end of file