diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2012-05-30 08:37:45 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2012-05-30 08:37:45 +0200 |
| commit | b086f57f56bf0eb9dab9cf321a0f69aaaae84347 (patch) | |
| tree | 8e6e26e8b7eed6abad7a17b093bdbb55c5e6b1ba /source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java | |
| parent | 22088ae8d2d5ff390518dbe1c4372325ffb3a647 (diff) | |
Initial Maven Conversion
Diffstat (limited to 'source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java')
| -rw-r--r-- | source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java b/source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java deleted file mode 100644 index e2c3df4..0000000 --- a/source/com/c2kernel/gui/tabs/outcome/form/field/IntegerEditField.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.c2kernel.gui.tabs.outcome.form.field;
-
-import java.awt.Toolkit;
-import java.math.BigInteger;
-
-import javax.swing.JTextField;
-import javax.swing.text.AttributeSet;
-import javax.swing.text.BadLocationException;
-import javax.swing.text.Document;
-import javax.swing.text.JTextComponent;
-import javax.swing.text.PlainDocument;
-
-/**************************************************************************
- *
- * $Revision: 1.4 $
- * $Date: 2005/08/16 13:59:56 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-public class IntegerEditField extends StringEditField {
-
- public IntegerEditField() {
- super();
- field.setToolTipText("This field must contains a whole number e.g. 3");
- }
-
- @Override
- public String getText() {
- return field.getText();
- }
-
- @Override
- public void setText(String text) {
- field.setText(text);
- }
-
- @Override
- public String getDefaultValue() {
- return "0";
- }
-
- @Override
- public JTextComponent makeTextField() {
- return new IntegerTextField();
- }
-
- private class IntegerTextField extends JTextField {
-
- public IntegerTextField() {
- super();
- setHorizontalAlignment(RIGHT);
- }
- @Override
- protected Document createDefaultModel() {
- return new IntegerDocument();
- }
- }
-
- private class IntegerDocument extends PlainDocument {
-
- BigInteger currentVal = new BigInteger("0");
-
- @Override
- public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
-
- if (str == null || str.equals("")) {
- return;
- }
-
- String proposedResult = null;
-
- if (getLength() == 0) {
- proposedResult = str;
- } else {
- StringBuffer currentBuffer = new StringBuffer( this.getText(0, getLength()) );
- currentBuffer.insert(offs, str);
- proposedResult = currentBuffer.toString();
- }
-
- try {
- currentVal = parse(proposedResult);
- super.insertString(offs, str, a);
- } catch (Exception e) {
- Toolkit.getDefaultToolkit().beep();
- }
-
- }
-
- @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;
- }
-
- try {
- currentVal = parse(proposedResult);
- super.remove(offs, len);
- } catch (Exception e) {
- Toolkit.getDefaultToolkit().beep();
- }
-
- }
-
- public BigInteger parse(String proposedResult) throws NumberFormatException {
-
- BigInteger value = new BigInteger("0");
- if ( proposedResult.length() != 0) {
- value = new BigInteger(proposedResult);
- }
- return value;
- }
- }
-}
|
