private class NumberFormat.NumberBuf extends DisplayFormat.Presentation
Modifier and Type | Class and Description |
---|---|
private class |
NumberFormat.NumberBuf.ScreenCharInfo
Additional info about character in screen value.
|
Modifier and Type | Field and Description |
---|---|
private byte[] |
digits
Array of digits.
|
private boolean |
extra
If extra char is possible due to certain format sign options.
|
private boolean |
justActivated
Flags if activation just occurred (flag resets on any input).
|
private static byte |
LEADING_ZERO
Special "digit" for explicit leading zero.
|
private boolean |
negative
Does number contain negative sign.
|
private boolean |
overflow
Has an overflow (number too big to fit in format) occurred?
|
private int |
scale
Current decimal scale for
digits array. |
private java.lang.String |
screen
Cached screen value.
|
private java.lang.StringBuilder |
screenBuf
Buffer for screen value.
|
private NumberFormat.NumberBuf.ScreenCharInfo[] |
screenInfo
Cached screen rendering info.
|
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 non digit char to screen cache buffer.
|
private void |
addScreenChar(char ch,
int type,
int digitPos)
Appends digit char to screen cache buffer.
|
private void |
addScreenString(java.lang.String str,
int type)
Appends non digit char to screen cache buffer.
|
private int |
calcDigitIndex(int digitPos)
Calculates an index in the digits array corresponding to the given
digit decimal position.
|
void |
checkFormat()
Checks format rules.
|
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 |
finishEdit()
Indicates completion of an edit.
|
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()
Perform common initialization of the byte array.
|
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.
|
private void |
invalidateScreen()
Clears screen cache so it will be refilled on the next reading.
|
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").
|
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.
|
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 |
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 boolean |
overwrite(char ch)
Inputs character in overwrite mode.
|
private void |
overwriteDigit(int index,
char ch)
Overwrites digit at given index with given char.
|
private void |
renderScreen()
Fills screen cache accordingly to current internal values.
|
int |
rightSignSize()
Returns the size of the right side sign formatting characters in the
format.
|
private void |
toDecimalVar(decimal var)
Places current value into a
decimal variable. |
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.
|
private void |
validateScreen()
Refills screen cache if it is invalid.
|
getCursorPos, getInsertMode, isLastCharEntered, setCursorPos, setInsertMode, setLastCharEntered, toScreenValue, validateFormat
private static final byte LEADING_ZERO
private 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
.private int scale
digits
array. May be changed
during edit if format includes '<' elements.private boolean negative
private boolean overflow
private boolean extra
private boolean justActivated
private NumberFormat.NumberBuf.ScreenCharInfo[] screenInfo
private java.lang.String screen
private java.lang.StringBuilder screenBuf
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 boolean isFixedFont()
isFixedFont
in class DisplayFormat.Presentation
true
.public int getLastPos()
getLastPos
in class DisplayFormat.Presentation
public boolean isNegative()
isNegative
in class DisplayFormat.Presentation
true
if the value is negative.public boolean isOptionalLeftSign()
isOptionalLeftSign
in class DisplayFormat.Presentation
true
if the format has an optional sign
character.public boolean isFixedNumeric()
isFixedNumeric
in class DisplayFormat.Presentation
true
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.Presentation
public int getInitialCursorPos()
getInitialCursorPos
in class DisplayFormat.Presentation
public 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.Presentation
public 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.Presentation
true
if this is unknown
.public boolean deleteBack()
deleteBack
in class DisplayFormat.Presentation
true
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean deleteCurrent()
deleteCurrent
in class DisplayFormat.Presentation
true
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean input(char ch)
input
in class DisplayFormat.Presentation
ch
- Input charactertrue
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorLeft()
moveCursorLeft
in class DisplayFormat.Presentation
true
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorRight()
moveCursorRight
in class DisplayFormat.Presentation
true
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorBegin()
moveCursorBegin
in class DisplayFormat.Presentation
true
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean moveCursorEnd()
moveCursorEnd
in class DisplayFormat.Presentation
true
if input is accepted (nevertheless it
may be silently ignored in reality).public boolean finishEdit()
finishEdit
in class DisplayFormat.Presentation
true
if rendering is necessary.public java.lang.String toScreenValue()
toScreenValue
in class DisplayFormat.Presentation
public void toVar(BaseDataType var)
toVar
in class DisplayFormat.Presentation
var
- A variable which must be compatible with the format.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 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)
decimal
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.private void renderScreen()
private boolean isExplicitZero()
true
for an explicit zero, false
for a leading zero or any other digit.private int numIntegerChars(java.lang.String text)
text
- The formatted number as a string.private 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. Always
ScreenCharInfo.DIGIT
.digitPos
- Position of this digit.private void addScreenString(java.lang.String str, int type)
str
- String.type
- Type of this string. It will be type for each character from
it. Constant from ScreenCharInfo
class.private void invalidateScreen()
private void validateScreen()
private void initArray()