Class FormatterFactory
java.lang.Object
net.sf.basedb.clients.web.formatter.FormatterFactory
Factory class for creating formatters for various data types. Some formatters
are affected by user settings on the session control. For example, the number
of decimals to display by a number formatter or the date format of a date
formatter.
- Version:
- 2.2
- Author:
- nicklas
- Last modified
- $Date: 2023-12-06 08:50:30 +0100 (Wed, 06 Dec 2023) $
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Formatter<T>
getAnnotationFormatter
(SessionControl sc, Annotation a, Unit unit) Get a formatter for nice formatting of annotation values, including units.Get the logged in user's formatter for boolean values.getColorFormatter
(SessionControl sc, Coloring coloring, Formatter<Number> valueFormatter) Get a formatter that adds a color box to the display which is a visual representation of the value.Get the logged in user's date formatter.Get the logged in user's datetime formatter.Get the logged in user's number formatter for double values.static <T> Formatter<T>
Get a formatter for an extended property.static <T> Formatter<T>
getFormulaFormatter
(SessionControl sc, Formula formula) Get a formatter that knows how to format results from formulas.Get the logged in user's formatter for integral numbers.Get the logged in user's formatter for long numbers.Get the logged in user's number formatter for float values.Get a formattater that is encoding strings for HTML output.getStringFormatter
(SessionControl sc, boolean encodeTagsInStrings) Get the logged in user's formatter for strings.static <T> Formatter<T>
getTypeFormatter
(SessionControl sc, Type type) Get a formattater that is encoding strings for HTML output.static <T> Formatter<T>
getTypeFormatter
(SessionControl sc, Type type, boolean encodeTagsInStrings) Get a formatter suitable for displaying values of the given type.
-
Constructor Details
-
FormatterFactory
public FormatterFactory()
-
-
Method Details
-
getNumberFormatter
Get the logged in user's number formatter for float values. The number of decimals to display is configured by the user settingformatter.number.decimals
. The default number of decimals is two.- Parameters:
sc
- The session control of the logged in user- Returns:
- A number formatter
- See Also:
-
getDoubleFormatter
Get the logged in user's number formatter for double values. The number of decimals to display is configured by the user settingformatter.number.decimals
. The default number of decimals is two.- Parameters:
sc
- The session control of the logged in user- Returns:
- A number formatter
- See Also:
-
getIntFormatter
Get the logged in user's formatter for integral numbers. This formatter has no configuration options.- Parameters:
sc
- The session control of the logged in user- Returns:
- A number formatter
- See Also:
-
getLongFormatter
Get the logged in user's formatter for long numbers. This formatter has no configuration options.- Parameters:
sc
- The session control of the logged in user- Returns:
- A number formatter
- See Also:
-
getDateFormatter
Get the logged in user's date formatter. How the date is displayed is configured by the user settingformatter.date.formatstring
. The default date format isyyyy-MM-dd
.- Parameters:
sc
- The session control of the logged in user- Returns:
- A date formatter
- See Also:
-
getDateTimeFormatter
Get the logged in user's datetime formatter. How the date and time is displayed is configured by the user settingformatter.datetime.formatstring
. The default format isyyyy-MM-dd HH:nn:ss
.- Parameters:
sc
- The session control of the logged in user- Returns:
- A date and time formatter
- See Also:
-
getStringFormatter
Get a formattater that is encoding strings for HTML output. -
getStringFormatter
Get the logged in user's formatter for strings. This formatter has no configuration options.- Parameters:
sc
- The session control of the logged in userencodeTagsInStrings
- If TRUE, text values are encoded withHTML.encodeTags(String)
- Returns:
- A string formatter
- Since:
- 3.19.10
- See Also:
-
getBooleanFormatter
Get the logged in user's formatter for boolean values. This formatter has no configuration options.- Parameters:
sc
- The session control of the logged in user- Returns:
- A boolean formatter
- See Also:
-
getTypeFormatter
Get a formattater that is encoding strings for HTML output. -
getTypeFormatter
public static <T> Formatter<T> getTypeFormatter(SessionControl sc, Type type, boolean encodeTagsInStrings) Get a formatter suitable for displaying values of the given type. If type isFLOAT
orDOUBLE
agetNumberFormatter(SessionControl)
is returned. If type isLONG
orINT
agetIntFormatter(SessionControl)
is returned. If type isSTRING
orTEXT
agetStringFormatter(SessionControl)
is returned. If type isDATE
agetDateFormatter(SessionControl)
is returned. If type isBOOLEAN
agetBooleanFormatter(SessionControl)
is returned. Otherwise null is returned.- Parameters:
sc
- The logged in user's session controltype
- The type to get a formatter forencodeTagsInStrings
- If TRUE, text values are encoded withHTML.encodeTags(String)
- Returns:
- A formatter or null if no suitable formatter could be found
- Since:
- 3.19.10
-
getExtendedPropertyFormatter
Get a formatter for an extended property. This formatter will check theExtendedProperty.getUrl(Object)
if the property value should be linked and create a link if needed. The actual value is formatted by creating a formatter based on the type of the extended property using thegetTypeFormatter(SessionControl, Type)
method.- Parameters:
sc
- The logged in user's session controlep
- The extended property- Returns:
- A formatter for the extended property
- See Also:
-
getColorFormatter
public static Formatter<Number> getColorFormatter(SessionControl sc, Coloring coloring, Formatter<Number> valueFormatter) Get a formatter that adds a color box to the display which is a visual representation of the value. AColorGenerator
is created based on theColoring
information. The color generator is used to create the color for a specific value. The value is formatted by the supplied formatter and is not affected by the color formatter. If theColoring.isUsingColors()
returns false no color formatter is created and the orginal formatter is returned.- Parameters:
sc
- The logged in user's session controlcoloring
- The coloring object that keeps information about how to generate colorsvalueFormatter
- A formatter for the actual values- Returns:
- A formatter that adds color to the values
- See Also:
-
getAnnotationFormatter
Get a formatter for nice formatting of annotation values, including units. A base formatter is created bygetTypeFormatter(SessionControl, Type)
using the value type of the annotation. This formatter is wrapped by aPrefixSuffixFormatter
if a unit is supplied or the annotation has a unit.- Parameters:
sc
- The logged in user's session controla
- The annotation to get a formatter forunit
- The unit, or null to use the unit from the annotation (Annotation.getUnit()
.- Returns:
- A formatter object
- Since:
- 2.9
-
getFormulaFormatter
Get a formatter that knows how to format results from formulas. This method uses the value type of the formula (Formula.getValueType()
) andgetTypeFormatter(SessionControl, Type)
to create the basic formatter. If the formula is numerical and uses coloring information the formatter is wrapped in a color formattergetColorFormatter(SessionControl, Coloring, Formatter)
. If the value type of the formula can't be determined aToStringFormatter
is used.- Parameters:
sc
- The logged in user's session controlformula
- The formula- Returns:
- A formatter object
- Since:
- 2.16
-