2.17.2: 2011-06-17

net.sf.basedb.clients.web.formatter
Class FormatterFactory

java.lang.Object
  extended by net.sf.basedb.clients.web.formatter.FormatterFactory

public class FormatterFactory
extends Object

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: 2010-10-04 12:59:36 +0200 (Mon, 04 Oct 2010) $

Constructor Summary
FormatterFactory()
           
 
Method Summary
static Formatter<?> getAnnotationFormatter(SessionControl sc, Annotation a, Unit unit)
          Get a formatter for nice formatting of annotation values, including units.
static Formatter<Boolean> getBooleanFormatter(SessionControl sc)
          Get the logged in user's formatter for boolean values.
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.
static Formatter<Date> getDateFormatter(SessionControl sc)
          Get the logged in user's date formatter.
static Formatter<Date> getDateTimeFormatter(SessionControl sc)
          Get the logged in user's datetime formatter.
static Formatter<Number> getDoubleFormatter(SessionControl sc)
          Get the logged in user's number formatter for double values.
static Formatter<?> getExtendedPropertyFormatter(SessionControl sc, ExtendedProperty ep)
          Get a formatter for an extended property.
static Formatter<?> getFormulaFormatter(SessionControl sc, Formula formula)
          Get a formatter that knows how to format results from formulas.
static Formatter<Number> getIntFormatter(SessionControl sc)
          Get the logged in user's formatter for integral numbers.
static Formatter<Number> getLongFormatter(SessionControl sc)
          Get the logged in user's formatter for long numbers.
static Formatter<Number> getNumberFormatter(SessionControl sc)
          Get the logged in user's number formatter for float values.
static Formatter<String> getStringFormatter(SessionControl sc)
          Get the logged in user's formatter for strings.
static Formatter<?> getTypeFormatter(SessionControl sc, Type type)
          Get a formatter suitable for displaying values of the given type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormatterFactory

public FormatterFactory()
Method Detail

getNumberFormatter

public static Formatter<Number> getNumberFormatter(SessionControl sc)
Get the logged in user's number formatter for float values. The number of decimals to display is configured by the user setting formatter.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:
FormatterSettings.getNumDecimals(SessionControl), FormatterSettings.setNumDecimals(SessionControl, int), NumberFormatter

getDoubleFormatter

public static Formatter<Number> getDoubleFormatter(SessionControl sc)
Get the logged in user's number formatter for double values. The number of decimals to display is configured by the user setting formatter.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:
FormatterSettings.getNumDecimals(SessionControl), FormatterSettings.setNumDecimals(SessionControl, int), NumberFormatter

getIntFormatter

public static Formatter<Number> getIntFormatter(SessionControl sc)
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:
IntegerFormatter

getLongFormatter

public static Formatter<Number> getLongFormatter(SessionControl sc)
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:
IntegerFormatter

getDateFormatter

public static Formatter<Date> getDateFormatter(SessionControl sc)
Get the logged in user's date formatter. How the date is displayed is configured by the user setting formatter.date.formatstring. The default date format is yyyy-MM-dd.

Parameters:
sc - The session control of the logged in user
Returns:
A date formatter
See Also:
FormatterSettings.getDateFormat(SessionControl), FormatterSettings.setDateFormat(SessionControl, String), DateFormatter

getDateTimeFormatter

public static Formatter<Date> getDateTimeFormatter(SessionControl sc)
Get the logged in user's datetime formatter. How the date and time is displayed is configured by the user setting formatter.datetime.formatstring. The default format is yyyy-MM-dd HH:nn:ss.

Parameters:
sc - The session control of the logged in user
Returns:
A date and time formatter
See Also:
FormatterSettings.getDateTimeFormat(SessionControl), FormatterSettings.setDateTimeFormat(SessionControl, String), DateFormatter

getStringFormatter

public static Formatter<String> getStringFormatter(SessionControl sc)
Get the logged in user's formatter for strings. This formatter has no configuration options.

Parameters:
sc - The session control of the logged in user
Returns:
A string formatter
See Also:
StringFormatter

getBooleanFormatter

public static Formatter<Boolean> getBooleanFormatter(SessionControl sc)
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:
BooleanFormatter

getTypeFormatter

public static Formatter<?> getTypeFormatter(SessionControl sc,
                                            Type type)
Get a formatter suitable for displaying values of the given type. If type is FLOAT or DOUBLE a getNumberFormatter(SessionControl) is returned. If type is LONG or INT a getIntFormatter(SessionControl) is returned. If type is STRING or TEXT a getStringFormatter(SessionControl) is returned. If type is DATE a getDateFormatter(SessionControl) is returned. If type is BOOLEAN a getBooleanFormatter(SessionControl) is returned. Otherwise null is returned.

Parameters:
sc - The logged in user's session control
type - The type to get a formatter for
Returns:
A formatter or null if no suitable formatter could be found

getExtendedPropertyFormatter

public static Formatter<?> getExtendedPropertyFormatter(SessionControl sc,
                                                        ExtendedProperty ep)
Get a formatter for an extended property. This formatter will check the ExtendedProperty.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 the getTypeFormatter(SessionControl, Type) method.

Parameters:
sc - The logged in user's session control
ep - The extended property
Returns:
A formatter for the extended property
See Also:
ExtendedPropertyFormatter

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. A ColorGenerator is created based on the Coloring 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 the Coloring.isUsingColors() returns false no color formatter is created and the orginal formatter is returned.

Parameters:
sc - The logged in user's session control
coloring - The coloring object that keeps information about how to generate colors
valueFormatter - A formatter for the actual values
Returns:
A formatter that adds color to the values
See Also:
ColorFormatter

getAnnotationFormatter

public static Formatter<?> getAnnotationFormatter(SessionControl sc,
                                                  Annotation a,
                                                  Unit unit)
Get a formatter for nice formatting of annotation values, including units. A base formatter is created by getTypeFormatter(SessionControl, Type) using the value type of the annotation. This formatter is wrapped by a PrefixSuffixFormatter if a unit is supplied or the annotation has a unit.

Parameters:
sc - The logged in user's session control
a - The annotation to get a formatter for
unit - The unit, or null to use the unit from the annotation (Annotation.getUnit().
Returns:
A formatter object
Since:
2.9

getFormulaFormatter

public static Formatter<?> getFormulaFormatter(SessionControl sc,
                                               Formula formula)
Get a formatter that knows how to format results from formulas. This method uses the value type of the formula (Formula.getValueType()) and getTypeFormatter(SessionControl, Type) to create the basic formatter. If the formula is numerical and uses coloring information the formatter is wrapped in a color formatter getColorFormatter(SessionControl, Coloring, Formatter). If the value type of the formula can't be determined a ToStringFormatter is used.

Parameters:
sc - The logged in user's session control
formula - The formula
Returns:
A formatter object
Since:
2.16

2.17.2: 2011-06-17