Class PercentFormatter
java.lang.Object
org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
org.eclipse.nebula.widgets.formattedtext.NumberFormatter
org.eclipse.nebula.widgets.formattedtext.PercentFormatter
- All Implemented Interfaces:
java.util.EventListener
,ITextFormatter
,org.eclipse.swt.events.VerifyListener
,org.eclipse.swt.internal.SWTEventListener
public class PercentFormatter extends NumberFormatter
Formatter for percent values.
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().
-
Field Summary
Fields inherited from class org.eclipse.nebula.widgets.formattedtext.NumberFormatter
alwaysShowDec, cachedPatterns, decimalLen, editPattern, editValue, fixedDec, fixedInt, groupLen, intCount, intLen, locale, minus, modified, nbspSeparator, negative, nfDisplay, nfEdit, prefixLen, suffixLen, symbols, value, zeroDecimalLen, zeroIntLen
Fields inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
EMPTY, ignore, SPACE, text
-
Constructor Summary
Constructors Constructor 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 localePercentFormatter(java.lang.String editPattern)
Constructs a new instance with the given edit mask.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.PercentFormatter(java.lang.String editPattern, java.util.Locale loc)
Constructs a new instance with the given edit mask and locale.PercentFormatter(java.util.Locale loc)
Constructs a new instance with default edit and display masks for the given locale. -
Method Summary
Modifier and Type Method Description java.lang.Object
getValue()
Returns the current value of the text control if it is a validNumber
.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.Methods inherited from class org.eclipse.nebula.widgets.formattedtext.NumberFormatter
clearText, format, getDefaultPattern, getDisplayString, getEditString, getValueType, isEmpty, isValid, setDecimalSeparatorAlwaysShown, setFixedLengths, setPrefix, setSuffix, verifyText
Methods inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
beep, detach, setIgnore, setText, updateText, updateText
-
Constructor Details
-
PercentFormatter
public 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
public PercentFormatter(java.util.Locale loc)Constructs a new instance with default edit and display masks for the given locale.- Parameters:
loc
- locale
-
PercentFormatter
public PercentFormatter(java.lang.String editPattern, java.util.Locale loc)Constructs a new instance with the given edit mask and locale. Display mask is identical to the edit mask.- Parameters:
editPattern
- edit maskloc
- locale
-
PercentFormatter
public PercentFormatter(java.lang.String editPattern, java.lang.String displayPattern, java.util.Locale loc)Constructs a new instance with the given masks and locale.- Parameters:
editPattern
- edit maskdisplayPattern
- display maskloc
- locale
-
PercentFormatter
public PercentFormatter(java.lang.String editPattern, java.lang.String displayPattern)Constructs a new instance with the given edit and display masks. Uses the default locale.- Parameters:
editPattern
- edit maskdisplayPattern
- display mask
-
PercentFormatter
public PercentFormatter(java.lang.String editPattern)Constructs a new instance with the given edit mask. Display mask is identical to the edit mask, and locale is the default one.- Parameters:
editPattern
- edit mask
-
-
Method Details
-
getValue
public java.lang.Object getValue()Returns the current value of the text control if it is a validNumber
. If the buffer is flagged as modified, the value is recalculated by parsing with thenfEdit
initialized with the edit pattern. If the number is not valid, returnsnull
.- Specified by:
getValue
in interfaceITextFormatter
- Overrides:
getValue
in classNumberFormatter
- Returns:
- current number value if valid,
null
else - See Also:
ITextFormatter.getValue()
-
setPatterns
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.Override the NumberFormatter implementation to add the percent symbol to the masks.
- Overrides:
setPatterns
in classNumberFormatter
- Parameters:
edit
- edit patterndisplay
- display patternloc
- Locale to use- Throws:
java.lang.IllegalArgumentException
- if a pattern is invalid- See Also:
com.wdev91.comp4swt.core.NumberFormatter#setPatterns(java.lang.String, java.lang.String, java.util.Locale)
-
setValue
public void setValue(java.lang.Object value)Sets the value to edit. The value provided must be aNumber
. The value provided is multiplied by 100.- Specified by:
setValue
in interfaceITextFormatter
- Overrides:
setValue
in classNumberFormatter
- Parameters:
value
- number value- Throws:
java.lang.IllegalArgumentException
- if not a number- See Also:
ITextFormatter.setValue(java.lang.Object)
-