public class PercentFormatter extends NumberFormatter
This formatter extends the NumberFormatter
:
- add the percent symbol in the suffix area.
- convert the number value in a percent : multiply by 100 on setValue() and
divide by 100 on getValue().
alwaysShowDec, cachedPatterns, decimalLen, editPattern, editValue, fixedDec, fixedInt, groupLen, intCount, intLen, locale, minus, modified, nbspSeparator, negative, nfDisplay, nfEdit, prefixLen, suffixLen, symbols, value, zeroDecimalLen, zeroIntLen
EMPTY, ignore, SPACE, text
Constructor and Description |
---|
PercentFormatter()
Constructs a new instance with all defaults :
edit mask from NumberPatterns for the default locale
display mask identical to the edit mask
default locale
|
PercentFormatter(java.util.Locale loc)
Constructs a new instance with default edit and display masks for the given
locale.
|
PercentFormatter(java.lang.String editPattern)
Constructs a new instance with the given edit mask.
|
PercentFormatter(java.lang.String editPattern,
java.util.Locale loc)
Constructs a new instance with the given edit mask and locale.
|
PercentFormatter(java.lang.String editPattern,
java.lang.String displayPattern)
Constructs a new instance with the given edit and display masks.
|
PercentFormatter(java.lang.String editPattern,
java.lang.String displayPattern,
java.util.Locale loc)
Constructs a new instance with the given masks and locale.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getValue()
Returns the current value of the text control if it is a valid
Number . |
protected void |
setPatterns(java.lang.String edit,
java.lang.String display,
java.util.Locale loc)
Sets the patterns and initializes the technical attributes used to manage
the operations.
|
void |
setValue(java.lang.Object value)
Sets the value to edit.
|
clearText, format, getDefaultPattern, getDisplayString, getEditString, getValueType, isEmpty, isValid, setDecimalSeparatorAlwaysShown, setFixedLengths, setPrefix, setSuffix, verifyText
beep, detach, setIgnore, setText, updateText, updateText
public PercentFormatter()
public PercentFormatter(java.util.Locale loc)
loc
- localepublic PercentFormatter(java.lang.String editPattern, java.util.Locale loc)
editPattern
- edit maskloc
- localepublic PercentFormatter(java.lang.String editPattern, java.lang.String displayPattern, java.util.Locale loc)
editPattern
- edit maskdisplayPattern
- display maskloc
- localepublic PercentFormatter(java.lang.String editPattern, java.lang.String displayPattern)
editPattern
- edit maskdisplayPattern
- display maskpublic PercentFormatter(java.lang.String editPattern)
editPattern
- edit maskpublic java.lang.Object getValue()
Number
.
If the buffer is flagged as modified, the value is recalculated by parsing
with the nfEdit
initialized with the edit pattern. If the
number is not valid, returns null
.getValue
in interface ITextFormatter
getValue
in class NumberFormatter
null
elseITextFormatter.getValue()
protected void setPatterns(java.lang.String edit, java.lang.String display, java.util.Locale loc)
Override the NumberFormatter implementation to add the percent symbol to the masks.
setPatterns
in class NumberFormatter
edit
- edit patterndisplay
- display patternloc
- Locale to usejava.lang.IllegalArgumentException
- if a pattern is invalidcom.wdev91.comp4swt.core.NumberFormatter#setPatterns(java.lang.String, java.lang.String, java.util.Locale)
public void setValue(java.lang.Object value)
Number
.
The value provided is multiplied by 100.setValue
in interface ITextFormatter
setValue
in class NumberFormatter
value
- number valuejava.lang.IllegalArgumentException
- if not a numberITextFormatter.setValue(java.lang.Object)