uk.co.prosperosoftware.pspnum
Class PSPNum

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.TextComponent
              |
              +--java.awt.TextField
                    |
                    +--uk.co.prosperosoftware.pspnum.PSPNum
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.datatransfer.ClipboardOwner, java.util.EventListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class PSPNum
extends java.awt.TextField
implements java.io.Serializable, java.awt.datatransfer.ClipboardOwner, java.awt.event.FocusListener

The PSPNum class supports regular decimal numbers which may be viewed/revised in an edit box. You can set a mask for each PSPNum to control how numeric values are displayed and which keystrokes are recognised.

Each PSPNum has an exact decimal size i.e. you set the number of digits you want either side of the decimal place. The internal numeric value is exact (no degrees of precision) within these limits. You access the numeric value as an unformatted string (the Value property) or as a formatted Text property. PSPNum supports a number of common arithmetic and logical operations for which you can specify both overflow and rounding behaviour. PSPNum also triggers events which your applet/application can listen for.

Apart from operations it provides directly, PSPNum also provides operations indirectly through inheritance. You will probably find the following inherited operations most useful: From TextComponent: select() and other operations dealing with a range of selected Text, also setEditable(..) and isEditable(). From Component: Appearance operations such as those for Font, Background/Foreground color and size.

Click here for index to more PSPNum online documentation.

Version:
4.4 05Jun2003
Author:
www.prosperosoftware.co.uk
See Also:
Serialized Form

Field Summary
static int CARET_POSITION_DECIMAL
          The caret is positioned to the digit nearest the decimal place.
static int CARET_POSITION_DEFAULT
          The caret is positioned by default (per the parent TextField object which PSPNum extends).
static int CARET_POSITION_FIRSTDIGIT
          The caret is positioned to the first digit in the displayed Text.
static int MAX_DIGITS_AFTER
          Maximum number (50) of digits after decimal place for PSPNum.
static int MAX_DIGITS_BEFORE
          Maximum number (50) of digits before decimal place for PSPNum.
static int OVERFLOW_BUMP_BEFOREDP
          When overflow occurs, PSPNum automatically increments DigitsBeforeDP to accommodate the new value.
static int OVERFLOW_EXCEPTION
          When overflow occurs, PSPNum throws an PSPException error for which the getErrNum() function returns PSPException.NumOverflow.
static int OVERFLOW_IGNORE
          When overflow occurs, PSPNum silently ignores the new value.
static int OVERFLOW_IGNORE_BEEP
          When overflow occurs, PSPNum ignores the new value and beeps.
static int OVERFLOW_TRUNCATE
          When overflow occurs, PSPNum silently truncates excess high-order digits.
static int OVERFLOW_TRUNCATE_BEEP
          When overflow occurs, PSPNum truncates excess high-order digits and beeps.
static int TEXT_ALIGN_CENTER
          Text displayed in Text box is centrally aligned (positioned in middle of Text box).
static int TEXT_ALIGN_LEFT
          Text displayed in Text box is left aligned (this is the default for each new PSPNum).
static int TEXT_ALIGN_RIGHT
          Text displayed in Text box is right aligned.
 
Fields inherited from class java.awt.TextComponent
textListener
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PSPNum()
          Default constructor - no parameters.
PSPNum(int cols)
          Simplest constructor - size of edit box only.
PSPNum(int cols, int DigitsBeforeDP, int DigitsAfterDP)
          Constructor with size of edit box and size of number.
PSPNum(int cols, int DigitsBeforeDP, int DigitsAfterDP, java.lang.String Value)
          Constructor with sizes of edit box, number; also initial numeric value.
 
Method Summary
 void add(PSPNum addNum)
          Add decimal value of parameter PSPNum to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 void add(java.lang.String addValue)
          Add parameter decimal value to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          The propertyChange method of the specified (parameter) PropertyChangeListener will be called each time the value of any bound property is changed.
 void divide(PSPNum divNum)
          Divide decimal value of parameter PSPNum into this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 void divide(java.lang.String divValue)
          Divide parameter decimal value into this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 void dump()
          Utility function to dump PSPNum persistent property values to 'stdout' via 'System.out.println' call.
 void focusGained(java.awt.event.FocusEvent evt)
          Method invoked when PSPNum gains input focus.
 void focusLost(java.awt.event.FocusEvent evt)
          Method invoked when PSPNum loses input focus.
 java.awt.Color getActiveBackColor()
          Returns active background color.
 int getCaretPosition()
          Gets the position of the text insertion caret for this PSPNum.
protected  int getColumnWidth()
          Gets the column width.
 int getDigitsAfterDP()
          Returns number of digits after decimal place.
 int getDigitsBeforeDP()
          Returns number of digits before decimal place.
 java.lang.String getMask()
          Returns all components of edit mask.
 java.lang.String getMaskUsed()
          Returns used components of edit mask.
 int getOverflowCode()
          Returns current OverflowCode flag setting for overflow following program operations.
 int getOverflowKey()
          Returns current OverflowKey flag setting for overflow following user keying.
 java.awt.Dimension getPreferredSize()
          Gets the preferred size of this PSPNum.
 boolean getRound()
          Returns setting (true/false) for arithmetic rounding.
 java.lang.String getText()
          Returns the Text for this PSPNum (trimmed to remove leading/trailing whitespace).
 int getTextAlign()
          Returns current TextAlign flag setting.
 boolean getTextRefresh()
          Get current state of TextRefresh boolean variable.
 java.lang.String getValue()
          Returns unformatted decimal numeric value.
 boolean isEQ(PSPNum compareNum)
          Checks if this PSPNum is EQ another PSPNum.
 boolean isEQ(java.lang.String compareValue)
          Checks if this PSPNum is EQ a particular numeric value.
 boolean isGE(PSPNum compareNum)
          Checks if this PSPNum is GE another PSPNum.
 boolean isGE(java.lang.String compareValue)
          Checks if this PSPNum is GE a particular numeric value.
 boolean isGT(PSPNum compareNum)
          Checks if this PSPNum is GT another PSPNum.
 boolean isGT(java.lang.String compareValue)
          Checks if this PSPNum is GT a particular numeric value.
 boolean isLE(PSPNum compareNum)
          Checks if this PSPNum is LE another PSPNum.
 boolean isLE(java.lang.String compareValue)
          Checks if this PSPNum is LE a particular numeric value.
 boolean isLT(PSPNum compareNum)
          Checks if this PSPNum is LT another PSPNum.
 boolean isLT(java.lang.String compareValue)
          Checks if this PSPNum is LT a particular numeric value.
 boolean isNE(PSPNum compareNum)
          Checks if this PSPNum is NE another PSPNum.
 boolean isNE(java.lang.String compareValue)
          Checks if this PSPNum is NE a particular numeric value.
 boolean isNegative()
          Check if the number is negative.
 boolean isPositive()
          Check if the number is positive.
 boolean isZero()
          Check if the number is zero.
 void lostOwnership(java.awt.datatransfer.Clipboard cb, java.awt.datatransfer.Transferable data)
          method required to be present only for system Clipboard Interface support - does nothing for PSPNum.
 void multiply(PSPNum multNum)
          Multiply this PSPNum by decimal value of parameter PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively
 void multiply(java.lang.String multValue)
          Multiply this PSPNum by parameter decimal value with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
protected  void processKeyEvent(java.awt.event.KeyEvent evt)
          Keystroke processing - filters out keys inapplicable to decimal numbers.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Remove specified (parameter) PropertyChangeListener from the PSPNum's internal list of PropertyChangeListeners.
 void select(int selectionStart, int selectionEnd)
          Selects the text between the specified start and end positions.
 void selectAll()
          Selects all the text in this text component.
 void setActiveBackColor(java.awt.Color newBackColor)
          Set background color for PSPNum when it has the input focus (is the active control).
 void setCaretPosition(int newPosition)
          Sets the position of the text insertion caret for this PSPNum.
 void setCaretRelativePosition(int newRelativePosition)
          Set caret position for this PSPNum (not for entire class) to relative position given by either CARET_POSITION_FIRSTDIGIT or CARET_POSITION_DECIMAL.
 void setDigitsAfterDP(int newDigitsAfterDP)
          Resets number of digits after decimal place (revise number of digits set initially when PSPNum constructed).
 void setDigitsBeforeDP(int newDigitsBeforeDP)
          Reset number of digits before decimal place (revise number of digits set initially when PSPNum constructed).
 void setFocusCaretRelativePosition(int newRelativePosition)
          Set desired relative positioning of caret for this PSPNum (not for entire class) when it gains the input focus.
 void setFont(java.awt.Font f)
          Sets the current font.
 void setMask(java.lang.String newMask)
          Resets edit mask controlling display of formatted value in text box and the keystrokes recognised for input.
 void setOverflowCode(int newCode)
          Set flag for this PSPNum (not for entire class) to control response to numeric overflow when new value set by program operations.
 void setOverflowDefault(byte overflowDefault)
          Set flag for PSPNum class (default applied to new PSPNum's) to control response to numeric overflow when new value set by program operations or user keying.
 void setOverflowKey(int newKey)
          Set flag for this PSPNum (not for entire class) to control response to numeric overflow when user keys new value.
 void setRound(boolean newRound)
          Set default true/false value for arithmetic rounding of new numeric values assigned in code (does not apply to keystrokes).
 void setText(java.lang.String newText)
          Dummy function to reset Text for PSPNum; deliberately does nothing - PSPNum value must be reset using setValue().
 void setTextAlign(int newAlign)
          Set alignment for Text displayed in Text box for this PSPNum (not for entire class).
 void setTextRefresh(boolean refresh)
          Controls whether Text is refreshed whenever the underlying Value - per getValue() function - changes.
 void setValue(PSPNum assnNum)
          Assigns decimal value of parameter PSPNum to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively
 void setValue(PSPNum assnNum, int Overflow, boolean Round)
          Assigns decimal value of parameter PSPNum to this PSPNum with treatment of overflow and rounding determined by last two parameters (temporary override values set by preceding setOverflowCode() and setRound() methods).
 void setValue(java.lang.String assnValue)
          Assign parameter decimal value to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 void setValue(java.lang.String assnValue, int Overflow, boolean Round)
          Assign parameter decimal value to this PSPNum with treatment of overflow and rounding determined by last two parameters.
 int signum()
          Returns the signum function of this number
 void subtract(PSPNum subNum)
          Subtract decimal value of parameter PSPNum from this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 void subtract(java.lang.String subValue)
          Subtract parameter decimal value from this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.
 java.lang.String toString()
          Returns a String object representing this PSPNum's value - which is the decimal value also returned by the getValue() method.
 
Methods inherited from class java.awt.TextField
addActionListener, addNotify, echoCharIsSet, getAccessibleContext, getActionListeners, getColumns, getEchoChar, getListeners, getMinimumSize, getMinimumSize, getPreferredSize, minimumSize, minimumSize, paramString, preferredSize, preferredSize, processActionEvent, processEvent, removeActionListener, setColumns, setEchoChar, setEchoCharacter
 
Methods inherited from class java.awt.TextComponent
addTextListener, enableInputMethods, getBackground, getSelectedText, getSelectionEnd, getSelectionStart, getTextListeners, isEditable, processTextEvent, removeNotify, removeTextListener, setBackground, setEditable, setSelectionEnd, setSelectionStart
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_DIGITS_BEFORE

public static final int MAX_DIGITS_BEFORE
Maximum number (50) of digits before decimal place for PSPNum.

See Also:
Constant Field Values

MAX_DIGITS_AFTER

public static final int MAX_DIGITS_AFTER
Maximum number (50) of digits after decimal place for PSPNum.

See Also:
Constant Field Values

OVERFLOW_BUMP_BEFOREDP

public static final int OVERFLOW_BUMP_BEFOREDP
When overflow occurs, PSPNum automatically increments DigitsBeforeDP to accommodate the new value. This is the default for all new PSPNum's unless you execute the setOverflowDefault() function.

See Also:
Constant Field Values

OVERFLOW_EXCEPTION

public static final int OVERFLOW_EXCEPTION
When overflow occurs, PSPNum throws an PSPException error for which the getErrNum() function returns PSPException.NumOverflow. This error is also thrown if MAX_DIGITS_BEFORE limit is reached when OVERFLOW_BUMP_BEFOREDP is set.

See Also:
Constant Field Values

OVERFLOW_IGNORE

public static final int OVERFLOW_IGNORE
When overflow occurs, PSPNum silently ignores the new value.

See Also:
Constant Field Values

OVERFLOW_IGNORE_BEEP

public static final int OVERFLOW_IGNORE_BEEP
When overflow occurs, PSPNum ignores the new value and beeps.

See Also:
Constant Field Values

OVERFLOW_TRUNCATE

public static final int OVERFLOW_TRUNCATE
When overflow occurs, PSPNum silently truncates excess high-order digits.

See Also:
Constant Field Values

OVERFLOW_TRUNCATE_BEEP

public static final int OVERFLOW_TRUNCATE_BEEP
When overflow occurs, PSPNum truncates excess high-order digits and beeps.

See Also:
Constant Field Values

TEXT_ALIGN_RIGHT

public static final int TEXT_ALIGN_RIGHT
Text displayed in Text box is right aligned. Note that right alignment is only correct if a monospace font is used. The default font is Monospaced plain.

See Also:
Constant Field Values

TEXT_ALIGN_CENTER

public static final int TEXT_ALIGN_CENTER
Text displayed in Text box is centrally aligned (positioned in middle of Text box). Note that center alignment is only correct if a monospace font is used. The default font is Monospaced plain.

See Also:
Constant Field Values

TEXT_ALIGN_LEFT

public static final int TEXT_ALIGN_LEFT
Text displayed in Text box is left aligned (this is the default for each new PSPNum).

See Also:
Constant Field Values

CARET_POSITION_DEFAULT

public static final int CARET_POSITION_DEFAULT
The caret is positioned by default (per the parent TextField object which PSPNum extends). When the PSPNum first gets the input focus, the caret is positioned before the first character (digit or other) in the displayed Text. Thereafter when the PSPNum gets the input focus, the caret is positioned to the position the caret was at when the PSPNum previously lost the input focus.

See Also:
Constant Field Values

CARET_POSITION_FIRSTDIGIT

public static final int CARET_POSITION_FIRSTDIGIT
The caret is positioned to the first digit in the displayed Text.

See Also:
Constant Field Values

CARET_POSITION_DECIMAL

public static final int CARET_POSITION_DECIMAL
The caret is positioned to the digit nearest the decimal place. If the PSPNum has decimal places (DigitsAfterDP is positive), the caret is positioned to just before the decimal place in the displayed Text. Otherwise the caret is positioned to the first digit in the displayed Text.

See Also:
Constant Field Values
Constructor Detail

PSPNum

public PSPNum()
Default constructor - no parameters. Size (number of columns) of edit box defaults to 40. Digits before decimal place defaults to 9. Digits after decimal place defaults to 2. This constructor is typically required for tools that must construct PSPNum's before allowing you to edit their properties. If you can use another constructor (with parameters) directly, we recommend you do so.


PSPNum

public PSPNum(int cols)
Simplest constructor - size of edit box only. Digits before decimal place defaults to 9. Digits after decimal place defaults to 2.

Parameters:
cols - The size (number of columns) of the edit box.

PSPNum

public PSPNum(int cols,
              int DigitsBeforeDP,
              int DigitsAfterDP)
Constructor with size of edit box and size of number.

Parameters:
cols - The size (number of columns) of the edit box.
DigitsBeforeDP - Number of digits before decimal place.
DigitsAfterDP - Number of digits after decimal place.

PSPNum

public PSPNum(int cols,
              int DigitsBeforeDP,
              int DigitsAfterDP,
              java.lang.String Value)
Constructor with sizes of edit box, number; also initial numeric value. Note that the constructor throws no error if the initial numeric value is invalid - it is quietly ignored and the PSPNum simply gets an initial value of zero.

Parameters:
cols - The size (number of columns) of the edit box.
DigitsBeforeDP - Number of digits before decimal place.
DigitsAfterDP - Number of digits after decimal place.
Value - Initial decimal numeric value for PSPNum.
Method Detail

getColumnWidth

protected int getColumnWidth()
Gets the column width. The meaning of what a column is can be considered a fairly weak notion for some fonts. This method is used to define the width of a column. By default this is defined to be the width of the character m for the font used. This method can be redefined to be some alternative amount

Returns:
the column width >= 1

setFont

public void setFont(java.awt.Font f)
Sets the current font. The cached column width value is removed.

Overrides:
setFont in class java.awt.Component
Parameters:
f - the new font

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
The propertyChange method of the specified (parameter) PropertyChangeListener will be called each time the value of any bound property is changed. The PropertyListener object is added to a list of PropertyChangeListeners managed by this PSPNum. It can be removed with removePropertyChangeListener.

Overrides:
addPropertyChangeListener in class java.awt.Component
Parameters:
l - the PropertyChangeListener
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove specified (parameter) PropertyChangeListener from the PSPNum's internal list of PropertyChangeListeners. If the parameter PropertyChangeListener isn't on the list, method silently does nothing.

Overrides:
removePropertyChangeListener in class java.awt.Component
Parameters:
l - the PropertyChangeListener
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

getDigitsBeforeDP

public final int getDigitsBeforeDP()
Returns number of digits before decimal place.

Returns:
Number of digits before decimal place.

setDigitsBeforeDP

public final void setDigitsBeforeDP(int newDigitsBeforeDP)
Reset number of digits before decimal place (revise number of digits set initially when PSPNum constructed).

Parameters:
newDigitsBeforeDP - New digits before decimal place.

getDigitsAfterDP

public final int getDigitsAfterDP()
Returns number of digits after decimal place.

Returns:
Number of digits after decimal place.

setDigitsAfterDP

public final void setDigitsAfterDP(int newDigitsAfterDP)
Resets number of digits after decimal place (revise number of digits set initially when PSPNum constructed).

Parameters:
newDigitsAfterDP - New digits after decimal place.

getTextAlign

public final int getTextAlign()
Returns current TextAlign flag setting.

Returns:
Value for TextAlign flag (integer value corresponding to TEXT_ALIGN_xxx value set by preceding setTextAlign() operation).

setTextAlign

public final void setTextAlign(int newAlign)
                        throws java.lang.IllegalArgumentException
Set alignment for Text displayed in Text box for this PSPNum (not for entire class). New setting must be one of TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER or TEXT_ALIGN_RIGHT.

Parameters:
newAlign - Flag controlling Text alignment.
Throws:
java.lang.IllegalArgumentException - if parameter newAlign is not one of valid TEXT_ALIGN_xxx values.

setText

public final void setText(java.lang.String newText)
Dummy function to reset Text for PSPNum; deliberately does nothing - PSPNum value must be reset using setValue().

Overrides:
setText in class java.awt.TextField
Parameters:
newText - New text (ignored).

getText

public final java.lang.String getText()
Returns the Text for this PSPNum (trimmed to remove leading/trailing whitespace).

Overrides:
getText in class java.awt.TextComponent
Returns:
trimmed Text for this PSPNum.

setTextRefresh

public final void setTextRefresh(boolean refresh)
Controls whether Text is refreshed whenever the underlying Value - per getValue() function - changes. You may, for example, want to set TextRefresh to false while you perform intermediate calculations on the numeric value, then reset TextRefresh to true again to show the final result. Setting TextRefresh to true always results in an immediate refresh.

Parameters:
refresh - true/false if Text to be refreshed when underlying decimal numeric value changes.

getTextRefresh

public final boolean getTextRefresh()
Get current state of TextRefresh boolean variable.

Returns:
Current state of TextRefresh variable.

getMaskUsed

public final java.lang.String getMaskUsed()
Returns used components of edit mask.

Returns:
Edit mask - used components only.

getMask

public final java.lang.String getMask()
Returns all components of edit mask.

Returns:
Edit mask - all components (both used and unused).

setMask

public final void setMask(java.lang.String newMask)
Resets edit mask controlling display of formatted value in text box and the keystrokes recognised for input. Mask component values remain in effect until reset, so only changed component values need to be set each time.

Parameters:
newMask - New mask values (changed components)

getActiveBackColor

public final java.awt.Color getActiveBackColor()
Returns active background color.

Returns:
Color in effect when PSPNum has input focus.

setActiveBackColor

public final void setActiveBackColor(java.awt.Color newBackColor)
Set background color for PSPNum when it has the input focus (is the active control).

Parameters:
newBackColor - New active background color.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Gets the preferred size of this PSPNum. Returns exactly the same value as the underlying TextField.getPreferredSize() method, but is overridden here so PSPNum can verify/establish fonts.

Overrides:
getPreferredSize in class java.awt.TextField
Returns:
the preferred dimensions for displaying this PSPNum.

focusGained

public void focusGained(java.awt.event.FocusEvent evt)
Method invoked when PSPNum gains input focus. This method processes the event completely for the PSPNum - it does not pass the event up to parent objects. The method is not declared final, which means you can override it in any class which extends PSPNum. If you do this, you must invoke 'super.focusGained(evt)' as the first step within your overriding method.

Specified by:
focusGained in interface java.awt.event.FocusListener
Parameters:
evt - FocusEvent generated for receipt of input focus.

focusLost

public void focusLost(java.awt.event.FocusEvent evt)
Method invoked when PSPNum loses input focus. This method processes the event completely for the PSPNum - it does not pass the event up to parent objects. The method is not declared final, which means you can override it in any class which extends PSPNum. If you do this, you must invoke 'super.focusLost(evt)' as the first step within your overriding method.

Specified by:
focusLost in interface java.awt.event.FocusListener
Parameters:
evt - FocusEvent generated for loss of input focus.

getCaretPosition

public final int getCaretPosition()
Gets the position of the text insertion caret for this PSPNum.

Overrides:
getCaretPosition in class java.awt.TextComponent
Returns:
the position of the text insertion caret where zero denotes first position of displayed Text.

setCaretPosition

public void setCaretPosition(int newPosition)
                      throws java.lang.IllegalArgumentException
Sets the position of the text insertion caret for this PSPNum.

Overrides:
setCaretPosition in class java.awt.TextComponent
Parameters:
newPosition - the position of the text insertion caret where zero denotes first position of displayed Text.
Throws:
java.lang.IllegalArgumentException - if the value supplied for newPosition is less than zero.

setCaretRelativePosition

public final void setCaretRelativePosition(int newRelativePosition)
                                    throws java.lang.IllegalArgumentException
Set caret position for this PSPNum (not for entire class) to relative position given by either CARET_POSITION_FIRSTDIGIT or CARET_POSITION_DECIMAL. PSPNum must currently have the input focus. New caret position must be one of CARET_POSITION_FIRSTDIGIT or CARET_POSITION_DECIMAL. If the PSPNum does not have the input focus when this method is called, the method call is ignored.

Parameters:
newRelativePosition - Flag controlling relative position caret to be set to now.
Throws:
java.lang.IllegalArgumentException - if parameter newRelativePosition is not one of the valid CARET_POSITION_xxx values.

setFocusCaretRelativePosition

public final void setFocusCaretRelativePosition(int newRelativePosition)
                                         throws java.lang.IllegalArgumentException
Set desired relative positioning of caret for this PSPNum (not for entire class) when it gains the input focus. New relative caret setting must be one of CARET_POSITION_DEFAULT, CARET_POSITION_FIRSTDIGIT or CARET_POSITION_DECIMAL.

Throws:
java.lang.IllegalArgumentException - if parameter newCaretPosition is not one of the valid CARET_POSITION_xxx values.

getRound

public final boolean getRound()
Returns setting (true/false) for arithmetic rounding.

Returns:
true/false value for arithmetic rounding.

setRound

public final void setRound(boolean newRound)
Set default true/false value for arithmetic rounding of new numeric values assigned in code (does not apply to keystrokes).


getOverflowCode

public final int getOverflowCode()
Returns current OverflowCode flag setting for overflow following program operations.

Returns:
Value for OverflowCode flag (integer value corresponding to OVERFLOW_xxx value set by preceding setOverflowCode() operation).

setOverflowCode

public final void setOverflowCode(int newCode)
                           throws java.lang.IllegalArgumentException
Set flag for this PSPNum (not for entire class) to control response to numeric overflow when new value set by program operations. New flag setting must be one of OVERFLOW_TRUNCATE_BEEP, OVERFLOW_TRUNCATE, OVERFLOW_IGNORE_BEEP, OVERFLOW_IGNORE, OVERFLOW_BUMP_BEFOREDP or OVERFLOW_EXCEPTION.

Parameters:
newCode - Flag controlling overflow response.
Throws:
java.lang.IllegalArgumentException - if parameter newCode is not one of the valid OVERFLOW_xxx values.

getOverflowKey

public final int getOverflowKey()
Returns current OverflowKey flag setting for overflow following user keying.

Returns:
Value for OverflowKey flag (integer value corresponding to OVERFLOW_xxx value set by preceding setOverflowKey() operation).

setOverflowKey

public final void setOverflowKey(int newKey)
                          throws java.lang.IllegalArgumentException
Set flag for this PSPNum (not for entire class) to control response to numeric overflow when user keys new value. New flag setting must be one of OVERFLOW_TRUNCATE_BEEP, OVERFLOW_TRUNCATE, OVERFLOW_IGNORE_BEEP, OVERFLOW_IGNORE or OVERFLOW_BUMP_BEFOREDP.

Parameters:
newKey - Flag controlling overflow response.
Throws:
java.lang.IllegalArgumentException - if parameter newKey is not one of the valid OVERFLOW_xxx values.

setOverflowDefault

public void setOverflowDefault(byte overflowDefault)
Set flag for PSPNum class (default applied to new PSPNum's) to control response to numeric overflow when new value set by program operations or user keying. New flag setting must be one of OVERFLOW_TRUNCATE_BEEP, OVERFLOW_TRUNCATE, OVERFLOW_IGNORE_BEEP, OVERFLOW_IGNORE or OVERFLOW_BUMP_BEFOREDP. Until this function is called, the default is OVERFLOW_BUMP_BEFOREDP.

Parameters:
overflowDefault - Flag controlling default overflow response.

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent evt)
Keystroke processing - filters out keys inapplicable to decimal numbers. Allowable keystrokes are 0-9, +/- and new decimal place per DI component of PSPNum edit mask. All other visible keystrokes are ignored.

Overrides:
processKeyEvent in class java.awt.Component
Parameters:
evt - Event generated for keying.

lostOwnership

public final void lostOwnership(java.awt.datatransfer.Clipboard cb,
                                java.awt.datatransfer.Transferable data)
method required to be present only for system Clipboard Interface support - does nothing for PSPNum.

Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner
Parameters:
cb - Object representing the system clipboard.
data - Contents of the clipboard.

select

public void select(int selectionStart,
                   int selectionEnd)
Selects the text between the specified start and end positions. This method overrides the equivalent method in the base TextField class because of the special treatement PSPNum requires for right-aligned or centre-aligned text.

This method sets the start and end positions of the selected text, enforcing the restriction that the start position must be greater than or equal to zero. The end position must be greater than or equal to the start position, and less than or equal to the length of the text component's text. The character positions are indexed starting with zero. The length of the selection is endPosition-startPosition, so the character at endPosition is not selected. If the start and end positions of the selected text are equal, all text is deselected.

If the caller supplies values that are inconsistent or out of bounds, the method enforces these constraints silently, and without failure. Specifically, if the start position or end position is greater than the length of the text, it is reset to equal the text length. If the start position is less than zero, it is reset to zero, and if the end position is less than the start position, it is reset to the start position.

Overrides:
select in class java.awt.TextComponent
Parameters:
selectionStart - the zero-based index of the first character to be selected.
selectionEnd - the zero-based end position of the text to be selected. The character at selectionEnd is not selected.
See Also:
TextComponent.setSelectionStart(int), TextComponent.setSelectionEnd(int), TextComponent.selectAll()

selectAll

public void selectAll()
Selects all the text in this text component. This method overrides the equivalent method in the base TextField class because of the special treatement PSPNum requires for right-aligned or centre-aligned text.

Overrides:
selectAll in class java.awt.TextComponent
See Also:
TextComponent.select(int, int)

toString

public final java.lang.String toString()
Returns a String object representing this PSPNum's value - which is the decimal value also returned by the getValue() method.

Overrides:
toString in class java.awt.Component
Returns:
Current decimal numeric value - unformatted.

getValue

public final java.lang.String getValue()
Returns unformatted decimal numeric value.

Returns:
Current decimal numeric value - unformatted.

setValue

public final void setValue(java.lang.String assnValue)
                    throws PSPException
Assign parameter decimal value to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
assnValue - New decimal numeric value.
Throws:
PSPException - if parameter assnValue (after trimming) has extraneous character.
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

setValue

public final void setValue(java.lang.String assnValue,
                           int Overflow,
                           boolean Round)
                    throws java.lang.IllegalArgumentException,
                           PSPException
Assign parameter decimal value to this PSPNum with treatment of overflow and rounding determined by last two parameters.

Parameters:
assnValue - New decimal numeric value.
Overflow - One of OVERFLOW_xxx field values for treatment of overflow.
Round - true/false for arithmetic rounding.
Throws:
java.lang.IllegalArgumentException - if Overflow parameter is not one of the valid OVERFLOW_xxx values.
PSPException - if parameter assnValue (after trimming) has extraneous character.
PSPException - if overflow occurs and Overflow parameter set to OVERFLOW_EXCEPTION.

setValue

public final void setValue(PSPNum assnNum)
                    throws PSPException
Assigns decimal value of parameter PSPNum to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively

Parameters:
assnNum - Number whose value to be assigned.
Throws:
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

setValue

public final void setValue(PSPNum assnNum,
                           int Overflow,
                           boolean Round)
                    throws java.lang.IllegalArgumentException,
                           PSPException
Assigns decimal value of parameter PSPNum to this PSPNum with treatment of overflow and rounding determined by last two parameters (temporary override values set by preceding setOverflowCode() and setRound() methods).

Parameters:
assnNum - Number whose value to be assigned.
Overflow - One of OVERFLOW_xxx field values for treatment of overflow.
Round - true/false for arithmetic rounding.
Throws:
java.lang.IllegalArgumentException - if Overflow parameter is not one of the valid OVERFLOW_xxx values.
PSPException - if overflow occurs and Overflow parameter set to OVERFLOW_EXCEPTION.

add

public final void add(PSPNum addNum)
               throws PSPException
Add decimal value of parameter PSPNum to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
addNum - Number whose value to be added.
Throws:
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

add

public final void add(java.lang.String addValue)
               throws PSPException
Add parameter decimal value to this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
addValue - Value to be added.
Throws:
PSPException - if parameter addValue (after trimming) has extraneous character.
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

subtract

public final void subtract(PSPNum subNum)
                    throws PSPException
Subtract decimal value of parameter PSPNum from this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
subNum - Number whose value to be subtracted.
Throws:
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

subtract

public final void subtract(java.lang.String subValue)
                    throws PSPException
Subtract parameter decimal value from this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
subValue - Value to be subtracted.
Throws:
PSPException - if parameter subValue (after trimming) has extraneous character.
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

multiply

public final void multiply(PSPNum multNum)
                    throws PSPException
Multiply this PSPNum by decimal value of parameter PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively

Parameters:
multNum - Number whose value to be multiplied by.
Throws:
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

multiply

public final void multiply(java.lang.String multValue)
                    throws PSPException
Multiply this PSPNum by parameter decimal value with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
multValue - Value to be multiplied by.
Throws:
PSPException - if parameter multValue (after trimming) has extraneous character.
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

divide

public final void divide(PSPNum divNum)
                  throws java.lang.ArithmeticException,
                         PSPException
Divide decimal value of parameter PSPNum into this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
divNum - Number whose value to be divided by.
Throws:
java.lang.ArithmeticException - if parameter divNum has zero value.
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

divide

public final void divide(java.lang.String divValue)
                  throws java.lang.ArithmeticException,
                         PSPException
Divide parameter decimal value into this PSPNum with treatment of overflow and rounding determined by OverflowCode and Round properties respectively.

Parameters:
divValue - Value to be divided by.
Throws:
PSPException - if parameter divValue (after trimming) has extraneous character.
java.lang.ArithmeticException - if parameter divValue has zero value.
PSPException - if overflow occurs and OverflowCode property set to OVERFLOW_EXCEPTION.

signum

public final int signum()
Returns the signum function of this number

Returns:
-1, 0 or 1 as the value of this number is negative, zero or positive.

isPositive

public final boolean isPositive()
Check if the number is positive.

Returns:
True if numeric value positive.

isNegative

public final boolean isNegative()
Check if the number is negative.

Returns:
True if numeric value is negative.

isZero

public final boolean isZero()
Check if the number is zero.

Returns:
True if numeric value is zero.

isEQ

public final boolean isEQ(PSPNum compareNum)
Checks if this PSPNum is EQ another PSPNum.

Returns:
True if this PSPNum has decimal numeric value equal to that of parameter PSPNum.

isEQ

public final boolean isEQ(java.lang.String compareValue)
                   throws PSPException
Checks if this PSPNum is EQ a particular numeric value.

Returns:
True if this PSPNum has decimal numeric value equal to parameter value.
Throws:
PSPException - if parameter compareValue (after trimming) has extraneous character.

isNE

public final boolean isNE(PSPNum compareNum)
Checks if this PSPNum is NE another PSPNum.

Returns:
True if this PSPNum has decimal numeric value not equal to that of parameter PSPNum.

isNE

public final boolean isNE(java.lang.String compareValue)
                   throws PSPException
Checks if this PSPNum is NE a particular numeric value.

Returns:
True if this PSPNum has decimal numeric value not equal to parameter value.
Throws:
PSPException - if parameter compareValue (after trimming) has extraneous character.

isGT

public final boolean isGT(PSPNum compareNum)
Checks if this PSPNum is GT another PSPNum.

Returns:
True if this PSPNum has decimal numeric value greater than that of parameter PSPNum.

isGT

public final boolean isGT(java.lang.String compareValue)
                   throws PSPException
Checks if this PSPNum is GT a particular numeric value.

Returns:
True if this PSPNum has decimal numeric value greater than parameter value.
Throws:
PSPException - if parameter compareValue (after trimming) has extraneous character.

isLT

public final boolean isLT(PSPNum compareNum)
Checks if this PSPNum is LT another PSPNum.

Returns:
True if this PSPNum has decimal numeric value less than that of parameter PSPNum.

isLT

public final boolean isLT(java.lang.String compareValue)
                   throws PSPException
Checks if this PSPNum is LT a particular numeric value.

Returns:
True if this PSPNum has decimal numeric value less than parameter value.
Throws:
PSPException - if parameter compareValue (after trimming) has extraneous character.

isGE

public final boolean isGE(PSPNum compareNum)
Checks if this PSPNum is GE another PSPNum.

Returns:
True if this PSPNum has decimal numeric value greater than or equal to that of parameter PSPNum.

isGE

public final boolean isGE(java.lang.String compareValue)
                   throws PSPException
Checks if this PSPNum is GE a particular numeric value.

Returns:
True if this PSPNum has decimal numeric value greater than or equal to parameter value.
Throws:
PSPException - if parameter compareValue (after trimming) has extraneous character.

isLE

public final boolean isLE(PSPNum compareNum)
Checks if this PSPNum is LE another PSPNum.

Returns:
True if this PSPNum has decimal numeric value less than or equal to that of parameter PSPNum.

isLE

public final boolean isLE(java.lang.String compareValue)
                   throws PSPException
Checks if this PSPNum is LE a particular numeric value.

Returns:
True if this PSPNum has decimal numeric value less than or equal to parameter value.
Throws:
PSPException - if parameter compareValue (after trimming) has extraneous character.

dump

public void dump()
Utility function to dump PSPNum persistent property values to 'stdout' via 'System.out.println' call. Use only for debugging e.g. if we ask you to do so to help us resolve any problem you may be having with PSPNum. Do not call this function in your production code.