mainPanel.add(gridPanel);
octalPermTextField = new JTextField(3);
// Constrains text field to 3 digits, from 0 to 7 (octal base)
Document doc = new SizeConstrainedDocument(3) {
@Override
public void insertString(int offset, String str, AttributeSet attributeSet) throws BadLocationException {
int strLen = str.length();
char c;
for(int i=0; i<strLen; i++) {
c = str.charAt(i);
if(c<'0' || c>'7')
return;
}
super.insertString(offset, str, attributeSet);
}
};
octalPermTextField.setDocument(doc);
// Initializes the field's value
updateOctalPermTextField();
if(canSetPermission) {
doc.addDocumentListener(this);
}
// Disable text field if no permission bit can be set
else {
octalPermTextField.setEnabled(false);
}