private abstract class NumberFormat.NumberBuf extends DisplayFormat.Presentation
| Modifier and Type | Class and Description |
|---|---|
protected class |
NumberFormat.NumberBuf.FindHelperIterator
Implements a find helper iterator to find the current cursor position after the current
digit has been deleted.
|
protected class |
NumberFormat.NumberBuf.ScreenCharInfo
Additional info about a character in screen value.
|
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
digits
Array of digits.
|
protected boolean |
extra
If extra char is possible due to certain format sign options.
|
protected boolean |
justActivated
Flags if activation just occurred (flag resets on any input).
|
protected static byte |
LEADING_ZERO
Special "digit" for explicit leading zero.
|
protected boolean |
negative
Does number contain negative sign.
|
protected boolean |
overflow
Has an overflow (number too big to fit in format) occurred?
|
protected boolean |
rightAlignedGuiFillIn
Flag indicating we have right aligned fill-in as front end representation.
|
protected int |
scale
Current decimal scale for
digits array. |
protected java.lang.String |
screen
Cached screen value.
|
protected java.lang.StringBuilder |
screenBuf
Buffer for screen value.
|
protected NumberFormat.NumberBuf.ScreenCharInfo[] |
screenInfo
Cached screen rendering info.
|
forFieldValue, presCursorPos, presInsertMode| Constructor and Description |
|---|
NumberBuf()
Constructs default presentation used for clear operation.
|
NumberBuf(NumberType var)
Constructs presentation initialized with given
decimal, int64
or integer. |
| Modifier and Type | Method and Description |
|---|---|
void |
activate()
Performs the necessary initialization for a widget which is
activated by a focus change (using a tab).
|
private void |
addScreenChar(char ch,
int type)
Appends a char to screen cache buffer, which is not a real digit character.
|
private void |
addScreenChar(char ch,
int type,
int digitPos)
Appends a char to screen cache buffer.
|
private int |
calcDigitIndex(int digitPos)
Calculates an index in the digits array corresponding to the given
digit decimal position.
|
protected abstract boolean |
checkCursorPosition()
Returns true if the new cursor position must be recalculated.
|
void |
checkFormat()
Checks format rules.
|
void |
clear()
Delete the screen value.
|
private int |
decimalSeparatorScreenIndex()
Find the screen decimal separator index.
|
boolean |
deleteBack()
Performs BACKSPACE function which consists of deleting one character
at the cursor and then moving the cursor one position to the left,
if possible.
|
boolean |
deleteCurrent()
Erases one symbol in the cursor position.
|
boolean |
deleteRegion(int start,
int end)
Erases a region.
|
private int |
digitsIndexOf(int from)
Scan the screen info forward, starting from the given index.
|
private int |
digitsLastIndexOf(int from)
Scan the screen info backward, starting from the given index.
|
boolean |
finishEdit()
Indicates completion of an edit.
|
private int |
getCursorByDigitPosition(int digitPos)
Calculates new cursor position by the given digit position of the deleted character.
|
protected abstract NumberFormat.NumberBuf.FindHelperIterator |
getFindHelperIterator(int digitPos)
Returns the find iterator to help to recalculate the current cursor position after
delete action has been completed.
|
int |
getInitialCursorPos()
Get initial cursor position which will be set during activation.
|
int |
getLastPos()
Returns the last valid cursor position in the current data.
|
private void |
init()
Common part in constructors.
|
private void |
initArray()
|
private void |
initClear()
Resets content to zero value and sets cursor to the first zero digit.
|
boolean |
input(char ch)
Inputs character.
|
private boolean |
insert(char ch)
Inputs a character in insert mode.
|
private int |
insertLeadingPlace()
Calculates index where new leading digit may be placed.
|
protected void |
invalidateScreen()
Clears screen cache so it will be refilled on the next reading.
|
protected boolean |
isAllDigitsFilled()
Tests if it is possible to insert a new digit.
|
private boolean |
isExplicitZero()
Determines if the rightmost integer digit (just to the left of any
decimal point) is an explicit zero.
|
boolean |
isFixedFont()
Determine if this format must use the DEFAULT-FIXED-FONT, if no font is specified.
|
boolean |
isFixedNumeric()
Detects if the numeric format is comprised of digits that always
output (like "-99,999").
|
protected abstract boolean |
isFixedNumericInGui()
Returns
TRUE if having fixed numeric in GUI mode. |
private boolean |
isLeftOnly()
Determines if there are no digits on the right of any decimal point.
|
boolean |
isNegative()
Returns the sign state of the numeric value.
|
boolean |
isOptionalLeftSign()
Detects if the numeric sign formatting character exists on the left
in the format and if it is optional.
|
private boolean |
isRealDigit(int idx)
Test if a character at the given screen index is a 'real'
digit: its type in
screenInfo is NumberFormat.NumberBuf.ScreenCharInfo.DIGIT
and the screen character is a digit. |
boolean |
isUnknown()
Returns if the presentation currently represents the
unknown value. |
private boolean |
isZeroSuppressed()
Determines if the format string has all integer digits (digits to
the right of the decimal point) that are zero-suppressed (as a
'z' or 'Z' or '*' or '>').
|
boolean |
moveCursorBegin()
Moves cursor to the beginning of the field.
|
boolean |
moveCursorEnd()
Moves cursor to the end of the field.
|
boolean |
moveCursorLeft()
Moves cursor one character to the left.
|
boolean |
moveCursorRight()
Moves cursor one character to the right.
|
private int |
numFractionalIntegerChars(java.lang.String text)
Calculate the number of digits to the right of the decimal point
|
private int |
numIntegerChars(java.lang.String text)
Calculate the number of digits to the left of the decimal point
(this is the same as the total number of digits for any number
that has no decimal point or no digits to the right of the decimal
point).
|
private int |
numIntegerChars(java.lang.String text,
boolean excludeLeadingZero)
Calculate the number of digits to the left of the decimal point
(this is the same as the total number of digits for any number
that has no decimal point or no digits to the right of the decimal
point).
|
private boolean |
overwrite(char ch)
Inputs character in overwrite mode.
|
private void |
overwriteDigit(int index,
char ch)
Overwrites digit at given index with given char.
|
protected abstract boolean |
preprocessDeleteAction()
Returns true if the delete action is completed.
|
protected abstract void |
processDeleteAction(int digitPos,
int digitIndex)
Process the main delete action for the given symbol.
|
protected void |
renderScreen()
Fills screen cache accordingly to current internal values:
digits and overflow, negative,
and rightAlignedGuiFillIn. |
int |
rightSignSize()
Returns the size of the right side sign formatting characters in the
format.
|
protected void |
shiftDigits(int digitIndex)
Shifts symbols right one step starting from the given symbol index.
|
private int |
skipDigitsLeft(int start,
int digits)
Scan a string in backward direction, try to skip the given number of digits,
|
private int |
skipDigitsRight(int start,
int digits)
Scan a string in forward direction, try to skip the given number of digits.
|
private void |
toDecimalVar(decimal var)
|
private void |
toInt64Var(int64 var)
Places current value into a
int64 variable. |
private void |
toIntegerVar(integer var)
Places current value into a
integer variable. |
java.lang.String |
toScreenValue()
Formats the data as a string that is ready for display.
|
void |
toVar(BaseDataType var)
Instantiates a variable that is equivalent to the presentation's
internal representation.
|
protected void |
validateScreen()
Refills screen cache if it is invalid.
|
private void |
validateScreen(java.lang.String screenValue)
Fixed the internal screen buffer according to the given screen value.
|
forFieldValue, getCursorPos, getInsertMode, isLastCharEntered, setCursorPos, setInsertMode, setLastCharEntered, toScreenValue, validateFormatprotected static final byte LEADING_ZERO
protected byte[] digits
scale of them are after decimal
point. Several first bytes may have value LEADING_ZERO.
This special value is necessary to show something like " 00023" or
"0" with "z(8)" format. May be null which means the
unknown value.protected int scale
digits array. May be changed
during edit if format includes '<' elements.protected boolean negative
protected boolean overflow
protected boolean extra
protected boolean justActivated
protected NumberFormat.NumberBuf.ScreenCharInfo[] screenInfo
protected java.lang.String screen
protected java.lang.StringBuilder screenBuf
protected boolean rightAlignedGuiFillIn
public NumberBuf()
public NumberBuf(NumberType var)
decimal, int64
or integer.var - Wrapper containing our initial value and which will be
used to format and parse the data.public void clear()
clear in class DisplayFormat.Presentationpublic boolean isFixedFont()
isFixedFont in class DisplayFormat.Presentationtrue.public int getLastPos()
getLastPos in class DisplayFormat.Presentationpublic boolean isNegative()
isNegative in class DisplayFormat.Presentationtrue if the value is negative.public boolean isOptionalLeftSign()
isOptionalLeftSign in class DisplayFormat.Presentationtrue if the format has an optional sign
character.public boolean isFixedNumeric()
isFixedNumeric in class DisplayFormat.Presentationtrue if all digits in on the left or right
of the decimal point always generate a corresponding
character in the output. This means that no ">" or
"<" characters exist in the format.public int rightSignSize()
public void activate()
activate in class DisplayFormat.Presentationpublic int getInitialCursorPos()
getInitialCursorPos in class DisplayFormat.Presentationpublic void checkFormat()
This is a no-operation method in this class. It is not needed since a number presentation is always maintained in the correct state.
checkFormat in class DisplayFormat.Presentationpublic boolean isUnknown()
unknown value. If any editing has occurred, then this
will return false even if the editing is not complete.isUnknown in class DisplayFormat.Presentationtrue if this is unknown.public boolean deleteBack()
deleteBack in class DisplayFormat.Presentationtrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean deleteCurrent()
deleteCurrent in class DisplayFormat.Presentationtrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean input(char ch)
input in class DisplayFormat.Presentationch - Input charactertrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorLeft()
moveCursorLeft in class DisplayFormat.Presentationtrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorRight()
moveCursorRight in class DisplayFormat.Presentationtrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorBegin()
moveCursorBegin in class DisplayFormat.Presentationtrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorEnd()
moveCursorEnd in class DisplayFormat.Presentationtrue if input is accepted (nevertheless it
may be silently ignored in reality).public boolean finishEdit()
finishEdit in class DisplayFormat.Presentationtrue if rendering is necessary.public java.lang.String toScreenValue()
toScreenValue in class DisplayFormat.Presentationpublic void toVar(BaseDataType var)
toVar in class DisplayFormat.Presentationvar - A variable which must be compatible with the format.protected abstract boolean preprocessDeleteAction()
protected abstract void processDeleteAction(int digitPos,
int digitIndex)
digitPos - The given symbol positiondigitIndex - The given symbol indexprotected abstract boolean checkCursorPosition()
protected void shiftDigits(int digitIndex)
digitIndex - The given symbolprotected abstract NumberFormat.NumberBuf.FindHelperIterator getFindHelperIterator(int digitPos)
digitPos - The given symbol positionprotected abstract boolean isFixedNumericInGui()
TRUE if having fixed numeric in GUI mode.TRUE if GUI mode and fixed numeric format, FALSE otherwise.protected boolean isAllDigitsFilled()
private void init()
private void initClear()
private boolean isZeroSuppressed()
true if all left digits are zero-suppressed.private boolean isLeftOnly()
true if there are no digits on the right of
the decimal point.private final int calcDigitIndex(int digitPos)
digitPos - Digit position i.e. decimal shiftprivate void toIntegerVar(integer var)
integer variable.var - Target variable.private void toInt64Var(int64 var)
int64 variable.var - Target variable.private void toDecimalVar(decimal var)
digits, scale and negative
fields to a decimal value and assign the variable.var - Target variable.private boolean insert(char ch)
ch - Input charactertrue if input is accepted (note that it
may be silently ignored in reality).private boolean overwrite(char ch)
ch - Input charactertrue if input is accepted (nevertheless it
may be silently ignored in reality).private int insertLeadingPlace()
private void overwriteDigit(int index,
char ch)
lastCharEntered flag if this
state is detected.index - Index in digits[] array.ch - Char which must be decimal digit.protected final void renderScreen()
digits and overflow, negative,
and rightAlignedGuiFillIn.
This includes not only displayed chars but their types (digit, sign etc.)
also.private boolean isExplicitZero()
true for an explicit zero, false
for a leading zero or any other digit.private int numIntegerChars(java.lang.String text,
boolean excludeLeadingZero)
text - The formatted number as a string.excludeLeadingZero - This flag value indicates if the leading zeros should be excluded.private int numIntegerChars(java.lang.String text)
text - The formatted number as a string.private int numFractionalIntegerChars(java.lang.String text)
text - The formatted number as a string.private final void addScreenChar(char ch,
int type)
ch - Character.type - Type of this character. Constant from
ScreenCharInfo class.private void addScreenChar(char ch,
int type,
int digitPos)
ch - Character.type - Type of this character.digitPos - for digits, the position of the digit.protected void invalidateScreen()
protected void validateScreen()
private final void validateScreen(java.lang.String screenValue)
screenValue - The given screen value, not nullprivate void initArray()
private final int getCursorByDigitPosition(int digitPos)
digitPos - The digit position given by the internal number model.public boolean deleteRegion(int start,
int end)
deleteRegion in class DisplayFormat.Presentationstart - region start index inclusiveend - region end index exclusivetrue is something was changedprivate final int decimalSeparatorScreenIndex()
private final boolean isRealDigit(int idx)
screenInfo is NumberFormat.NumberBuf.ScreenCharInfo.DIGIT
and the screen character is a digit.idx - the index into screenInfo and/or screen.private final int skipDigitsRight(int start,
int digits)
start - the start index to test characters, inclusivedigits - the number of digits to skipprivate final int skipDigitsLeft(int start,
int digits)
start - a start index to test characters, exclusivedigits - the number of digits to skipprivate final int digitsIndexOf(int from)
from - the start screen index to search, inclusiveprivate final int digitsLastIndexOf(int from)
from - the start screen index to search, inclusive