summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java')
-rw-r--r--[-rwxr-xr-x]source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java45
1 files changed, 26 insertions, 19 deletions
diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java
index d77dff3..fabaed8 100755..100644
--- a/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java
+++ b/source/com/c2kernel/gui/tabs/outcome/form/field/DecimalEditField.java
@@ -26,44 +26,50 @@ public class DecimalEditField extends StringEditField {
field.setToolTipText("This field must contains a decimal number e.g. 3.14159265");
}
- public String getText() {
+ @Override
+ public String getText() {
return field.getText();
}
- public void setText(String text) {
+ @Override
+ public void setText(String text) {
field.setText(text);
}
-
- public String getDefaultValue() {
+
+ @Override
+ public String getDefaultValue() {
return "0.0";
- }
-
- public JTextComponent makeTextField() {
+ }
+
+ @Override
+ public JTextComponent makeTextField() {
return new DecimalTextField();
}
-
+
private class DecimalTextField extends JTextField {
public DecimalTextField() {
super();
setHorizontalAlignment(RIGHT);
}
- protected Document createDefaultModel() {
+ @Override
+ protected Document createDefaultModel() {
return new Decimal();
}
}
-
+
private class Decimal extends PlainDocument {
BigDecimal currentVal = new BigDecimal(0.0);
- public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
+ @Override
+ public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
if (str == null || str.equals("")) {
return;
}
-
+
String proposedResult = null;
if (getLength() == 0) {
@@ -73,23 +79,24 @@ public class DecimalEditField extends StringEditField {
currentBuffer.insert(offs, str);
proposedResult = currentBuffer.toString();
}
-
+
try {
currentVal = parse(proposedResult);
super.insertString(offs, str, a);
} catch (Exception e) {
Toolkit.getDefaultToolkit().beep();
}
-
+
}
- public void remove(int offs, int len) throws BadLocationException {
+ @Override
+ public void remove(int offs, int len) throws BadLocationException {
String currentText = this.getText(0, getLength());
String beforeOffset = currentText.substring(0, offs);
String afterOffset = currentText.substring(len + offs, currentText.length());
String proposedResult = beforeOffset + afterOffset;
-
+
if (proposedResult.length() == 0) { // empty is ok
super.remove(offs, len);
return;
@@ -97,17 +104,17 @@ public class DecimalEditField extends StringEditField {
try {
currentVal = parse(proposedResult);
super.remove(offs, len);
- } catch (Exception e) {
+ } catch (Exception e) {
Toolkit.getDefaultToolkit().beep();
}
- }
+ }
public BigDecimal parse(String proposedResult) throws NumberFormatException {
BigDecimal value = new BigDecimal(0);
if ( proposedResult.length() != 0) {
- value = new BigDecimal(proposedResult);
+ value = new BigDecimal(proposedResult);
}
return value;
}