org.springframework.richclient.factory
Class DefaultComponentFactory

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.factory.DefaultComponentFactory
All Implemented Interfaces:
MessageSourceAware, ComponentFactory

public class DefaultComponentFactory
extends Object
implements ComponentFactory, MessageSourceAware

Default component factory implementation that delegates to JGoodies component factory.

Author:
Keith Donald

Constructor Summary
DefaultComponentFactory()
           
 
Method Summary
 void addConfiguredTab(JTabbedPane tabbedPane, String labelKey, JComponent tabComponent)
          Adds a tab to the provided tabbed pane, configuring the tab's appearance from information retrieved using the labelKey property.
 void configureForEnum(JComboBox comboBox, Class enumType)
          Configure a combo box to be populated with all enums of the specified enumeration type.
protected  void configureTextField(JTextField textField)
          Configures the text field.
 JButton createButton(String labelKey)
          Create and configure a button with the specified label key.
 JCheckBox createCheckBox(String labelKey)
          Create a configured checkbox.
 JCheckBox createCheckBox(String[] labelKeys)
          Create a configured checkbox.
 JComboBox createComboBox()
          Create a combo box using this component factory.
 JComboBox createComboBox(Class enumType)
          Create a combo box using this component factory, to be populated by the list of all enums of the specified type, resolved using this factory's enum resolver.
 JFormattedTextField createFormattedTextField(JFormattedTextField.AbstractFormatterFactory formatterFactory)
          Create a formatted text field using this component factory.
 JLabel createLabel(String labelKey)
          Create and configure a label with the specified label key.
 JLabel createLabel(String[] labelKeys)
          Create and configure a label with the specified label key.
 JLabel createLabel(String labelKey, Object[] arguments)
          Creates and configure a label with the specified label key and parameterized arguments.
 JLabel createLabel(String labelKey, ValueModel[] argumentValueHolders)
          Creates and configure a label with the specified label key and parameterized arguments.
 JComponent createLabeledSeparator(String labelKey)
          Create and configure an left-aligned label acting as a form dividing separator; that is, a control that displays a label and a separator immediately underneath it.
 JComponent createLabeledSeparator(String labelKey, Alignment alignment)
          Create and configure an aligned label acting as a form dividing separator; that is, a control that displays a label and a separator immediately underneath it.
 JLabel createLabelFor(String[] labelKeys, JComponent component)
          Create and configure a label for the provided component.
 JLabel createLabelFor(String labelKey, JComponent component)
          Create and configure a label for the provided component.
 JList createList()
          Create a list using this component factory.
 JComboBox createListValueModelComboBox(ValueModel selectedItemValueModel, ValueModel selectableItemsListHolder, String renderedPropertyPath)
          Create a combo box using this component factory.
 JMenuItem createMenuItem(String labelKey)
          Create a configured menu item.
protected  JCheckBox createNewCheckBox()
           
protected  JLabel createNewLabel()
           
protected  JRadioButton createNewRadioButton()
           
protected  AbstractButton createNewToggleButton()
           
 JPanel createPanel()
          Creates a panel using this component factory.
 JPanel createPanel(LayoutManager layoutManager)
          Creates a panel with the supplied LayoutManager using this component factory.
 JPasswordField createPasswordField()
          Create a standard password field using this component factory.
 JRadioButton createRadioButton(String labelKey)
          Create a configured radio button.
 JRadioButton createRadioButton(String[] labelKeys)
          Create a configured radio button.
 JScrollPane createScrollPane()
          Create a scroll pane using this component factory.
 JScrollPane createScrollPane(Component view)
          Create a scroll pane using this component factory, with the specified component as the viewport view.
 JScrollPane createScrollPane(Component view, int vsbPolicy, int hsbPolicy)
          Create a scroll pane using this component factory, with the specified component as the viewport view and with the specified vertical and horizontal scrollbar policies.
 JTabbedPane createTabbedPane()
          Create and return a new tabbed pane.
 JTable createTable()
          Construct a JTable with a default model It will delegate the creation to a TableFactory if it exists.
 JTable createTable(TableModel model)
          Construct a JTable with the specified table model.
 JTextArea createTextArea()
          Create a text area using this component factory.
 JTextArea createTextArea(int rows, int columns)
          Create a text area using this component factory.
 JTextArea createTextAreaAsLabel()
          Create a text area that looks like a label (but with cut/copy/paste enabled!) using this component factory.
 JTextField createTextField()
          Create a standard text field using this component factory.
 JComponent createTitledBorderFor(String labelKey, JComponent component)
          Creates a titled border for the specified component.
 JLabel createTitleLabel(String labelKey)
          Create and configure a title label with the specified label key.
 JToggleButton createToggleButton(String labelKey)
          Create a configured toggle button.
 JToggleButton createToggleButton(String[] labelKeys)
          Create a configured toggle button.
 JComponent createToolBar()
          Construct a JToolBar.
protected  ButtonFactory getButtonFactory()
           
protected  CommandButtonLabelInfo getButtonLabelInfo(String label)
           
protected  LabeledEnumResolver getEnumResolver()
          Returns the resolver used for enumerations.
protected  LabelInfo getLabelInfo(String label)
          Parse the given label to create a LabelInfo.
protected  MenuFactory getMenuFactory()
           
protected  String getOptionalMessage(String messageKey)
           
protected  String getRequiredMessage(String messageKey)
          Get the message for the given key.
protected  String getRequiredMessage(String[] messageKeys)
          Get the message for the given key.
 int getTextFieldColumns()
          Returns the default column count for new text fields (including formatted text and password fields)
 void setButtonFactory(ButtonFactory buttonFactory)
          Set the button factory.
 void setEnumResolver(LabeledEnumResolver enumResolver)
          Set the resolver used to create messages for enumerations.
 void setIconSource(IconSource iconSource)
          Set the source for retrieving icons.
 void setMenuFactory(MenuFactory menuFactory)
          Set the menu factory.
 void setMessageSource(MessageSource messageSource)
          
 void setTableFactory(TableFactory tableFactory)
          Allow configuration via XML of a table factory.
 void setTextFieldColumns(int columns)
          Defines the default column count for new text fields (including formatted text and password fields)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultComponentFactory

public DefaultComponentFactory()
Method Detail

setMessageSource

public void setMessageSource(MessageSource messageSource)

Specified by:
setMessageSource in interface MessageSourceAware

setIconSource

public void setIconSource(IconSource iconSource)
Set the source for retrieving icons.


setButtonFactory

public void setButtonFactory(ButtonFactory buttonFactory)
Set the button factory.


setMenuFactory

public void setMenuFactory(MenuFactory menuFactory)
Set the menu factory.


setEnumResolver

public void setEnumResolver(LabeledEnumResolver enumResolver)
Set the resolver used to create messages for enumerations.

See Also:
LabeledEnum

getEnumResolver

protected LabeledEnumResolver getEnumResolver()
Returns the resolver used for enumerations. Uses the ApplicationServicesLocator to find one if no resolver is explicitly set.


createLabel

public JLabel createLabel(String labelKey)
Create and configure a label with the specified label key. For example: "&My Control Label:", where the '&' marks a positional mnemonic.

Specified by:
createLabel in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The configured label.

createLabel

public JLabel createLabel(String[] labelKeys)
Create and configure a label with the specified label key. For example: "&My Control Label:", where the '&' marks a positional mnemonic.

Specified by:
createLabel in interface ComponentFactory
Returns:
The configured label.

createLabel

public JLabel createLabel(String labelKey,
                          Object[] arguments)
Creates and configure a label with the specified label key and parameterized arguments. Argument values are resolved to {digit placeholder} characters in the resolved message string.

Specified by:
createLabel in interface ComponentFactory
Returns:
The configured label.

getLabelInfo

protected LabelInfo getLabelInfo(String label)
Parse the given label to create a LabelInfo.

Parameters:
label - The label to parse.
Returns:
a LabelInfo representing the label.
See Also:
LabelInfo.valueOf(String)

getRequiredMessage

protected String getRequiredMessage(String messageKey)
Get the message for the given key. Don't throw an exception if it's not found but return a default value.

Parameters:
messageKey - Key to lookup the message.
Returns:
the message found in the resources or a default message.

getRequiredMessage

protected String getRequiredMessage(String[] messageKeys)
Get the message for the given key. Don't throw an exception if it's not found but return a default value.

Parameters:
messageKeys - The keys to use when looking for the message.
Returns:
the message found in the resources or a default message.

createLabel

public JLabel createLabel(String labelKey,
                          ValueModel[] argumentValueHolders)
Creates and configure a label with the specified label key and parameterized arguments. Argument values are resolved to {digit placeholder} characters in the resolved message string. Argument values are pulled from the provided value model, and this component factory will auto-subscribe for changes, dynamically updating the label when underlying arguments change.

Specified by:
createLabel in interface ComponentFactory
argumentValueHolders - The value model of the arguments;
Returns:
The configured label.

createTitleLabel

public JLabel createTitleLabel(String labelKey)
Description copied from interface: ComponentFactory
Create and configure a title label with the specified label key. A title label's text matches that of a titled border title (bold, highlighted.)

Specified by:
createTitleLabel in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The configured label.

createTitledBorderFor

public JComponent createTitledBorderFor(String labelKey,
                                        JComponent component)
Description copied from interface: ComponentFactory
Creates a titled border for the specified component.

Specified by:
createTitledBorderFor in interface ComponentFactory
Parameters:
labelKey - the title label message code.
component - the component to attach a titled border to.
Returns:
the configured component.

createLabelFor

public JLabel createLabelFor(String labelKey,
                             JComponent component)
Description copied from interface: ComponentFactory
Create and configure a label for the provided component. Associating a label with a component ensures when the mnemonic is selected the component is given focus.

Specified by:
createLabelFor in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
component - the labeled component
Returns:
The configured label.

createLabelFor

public JLabel createLabelFor(String[] labelKeys,
                             JComponent component)
Description copied from interface: ComponentFactory
Create and configure a label for the provided component. Associating a label with a component ensures when the mnemonic is selected the component is given focus.

Specified by:
createLabelFor in interface ComponentFactory
component - the labeled component
Returns:
The configured label.

createNewLabel

protected JLabel createNewLabel()

createButton

public JButton createButton(String labelKey)
Description copied from interface: ComponentFactory
Create and configure a button with the specified label key. The button will be configured with the appropriate mnemonic and accelerator. Note: if you find yourself duplicating the same handler logic accross different buttons, maybe its time to use a Command.

Specified by:
createButton in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The configured button.

getButtonLabelInfo

protected CommandButtonLabelInfo getButtonLabelInfo(String label)

getButtonFactory

protected ButtonFactory getButtonFactory()

createLabeledSeparator

public JComponent createLabeledSeparator(String labelKey)
Description copied from interface: ComponentFactory
Create and configure an left-aligned label acting as a form dividing separator; that is, a control that displays a label and a separator immediately underneath it.

Specified by:
createLabeledSeparator in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The configured labeled separator.

createCheckBox

public JCheckBox createCheckBox(String labelKey)
Description copied from interface: ComponentFactory
Create a configured checkbox.

Specified by:
createCheckBox in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The checkbox.

createCheckBox

public JCheckBox createCheckBox(String[] labelKeys)
Description copied from interface: ComponentFactory
Create a configured checkbox.

Specified by:
createCheckBox in interface ComponentFactory
Parameters:
labelKeys - The label message codes; may also be the label text if no message source is configured.
Returns:
The checkbox.

createNewCheckBox

protected JCheckBox createNewCheckBox()

createToggleButton

public JToggleButton createToggleButton(String labelKey)
Description copied from interface: ComponentFactory
Create a configured toggle button.

Specified by:
createToggleButton in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The toggle button.

createToggleButton

public JToggleButton createToggleButton(String[] labelKeys)
Description copied from interface: ComponentFactory
Create a configured toggle button.

Specified by:
createToggleButton in interface ComponentFactory
Parameters:
labelKeys - The label message codes; may also be the label text if no message source is configured.
Returns:
The toggle button.

createNewToggleButton

protected AbstractButton createNewToggleButton()

createRadioButton

public JRadioButton createRadioButton(String labelKey)
Description copied from interface: ComponentFactory
Create a configured radio button.

Specified by:
createRadioButton in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The radio button.

createNewRadioButton

protected JRadioButton createNewRadioButton()

createRadioButton

public JRadioButton createRadioButton(String[] labelKeys)
Description copied from interface: ComponentFactory
Create a configured radio button.

Specified by:
createRadioButton in interface ComponentFactory
Parameters:
labelKeys - The label message codes; may also be the label text if no message source is configured.
Returns:
The radio button.

createMenuItem

public JMenuItem createMenuItem(String labelKey)
Description copied from interface: ComponentFactory
Create a configured menu item.

Specified by:
createMenuItem in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
Returns:
The menu item.

getMenuFactory

protected MenuFactory getMenuFactory()

createLabeledSeparator

public JComponent createLabeledSeparator(String labelKey,
                                         Alignment alignment)
Description copied from interface: ComponentFactory
Create and configure an aligned label acting as a form dividing separator; that is, a control that displays a label and a separator immediately underneath it.

Specified by:
createLabeledSeparator in interface ComponentFactory
Parameters:
labelKey - The label message code; may also be the label text if no message source is configured.
alignment - The label's alignment.
Returns:
The configured labeled separator.

createList

public JList createList()
Description copied from interface: ComponentFactory
Create a list using this component factory.

Specified by:
createList in interface ComponentFactory
Returns:
The new list.

createComboBox

public JComboBox createComboBox()
Description copied from interface: ComponentFactory
Create a combo box using this component factory.

Specified by:
createComboBox in interface ComponentFactory
Returns:
The new combo box.

createComboBox

public JComboBox createComboBox(Class enumType)
Description copied from interface: ComponentFactory
Create a combo box using this component factory, to be populated by the list of all enums of the specified type, resolved using this factory's enum resolver.

Specified by:
createComboBox in interface ComponentFactory
Returns:
The new combo box.

createListValueModelComboBox

public JComboBox createListValueModelComboBox(ValueModel selectedItemValueModel,
                                              ValueModel selectableItemsListHolder,
                                              String renderedPropertyPath)
Description copied from interface: ComponentFactory
Create a combo box using this component factory. The list of selectable items is populated from the provided value model, which provides access to a list. When an item is selected in the list, the selectedItemValueModel is set.

Specified by:
createListValueModelComboBox in interface ComponentFactory
Returns:
The new combo box.

configureForEnum

public void configureForEnum(JComboBox comboBox,
                             Class enumType)
Description copied from interface: ComponentFactory
Configure a combo box to be populated with all enums of the specified enumeration type. The type must be resolvable by this factory's enum resolver.

Specified by:
configureForEnum in interface ComponentFactory
enumType - The enumeration type.

getTextFieldColumns

public int getTextFieldColumns()
Returns the default column count for new text fields (including formatted text and password fields)

Returns:
the default column count. Must not be lower than 0
See Also:
JTextField

setTextFieldColumns

public void setTextFieldColumns(int columns)
Defines the default column count for new text fields (including formatted text and password fields)

Parameters:
the - default column count. Must not be lower than 0
See Also:
JTextField

createFormattedTextField

public JFormattedTextField createFormattedTextField(JFormattedTextField.AbstractFormatterFactory formatterFactory)
Description copied from interface: ComponentFactory
Create a formatted text field using this component factory.

Specified by:
createFormattedTextField in interface ComponentFactory
Parameters:
formatterFactory - AbstractFormatterFactory used for formatting.
Returns:
The new formatted text field

createTextField

public JTextField createTextField()
Description copied from interface: ComponentFactory
Create a standard text field using this component factory.

Specified by:
createTextField in interface ComponentFactory
Returns:
the new text field.

configureTextField

protected void configureTextField(JTextField textField)
Configures the text field.

Parameters:
textField - the field to configure. Must not be null

createPasswordField

public JPasswordField createPasswordField()
Description copied from interface: ComponentFactory
Create a standard password field using this component factory.

Specified by:
createPasswordField in interface ComponentFactory
Returns:
the new password field.

createTextArea

public JTextArea createTextArea()
Description copied from interface: ComponentFactory
Create a text area using this component factory.

Specified by:
createTextArea in interface ComponentFactory
Returns:
The new text area.

createTextArea

public JTextArea createTextArea(int rows,
                                int columns)
Description copied from interface: ComponentFactory
Create a text area using this component factory.

Specified by:
createTextArea in interface ComponentFactory
Returns:
The new text area.

createTextAreaAsLabel

public JTextArea createTextAreaAsLabel()
Description copied from interface: ComponentFactory
Create a text area that looks like a label (but with cut/copy/paste enabled!) using this component factory.

Specified by:
createTextAreaAsLabel in interface ComponentFactory
Returns:
The new text area.

createTabbedPane

public JTabbedPane createTabbedPane()
Description copied from interface: ComponentFactory
Create and return a new tabbed pane.

Specified by:
createTabbedPane in interface ComponentFactory
Returns:
a new tabbed pane.

addConfiguredTab

public void addConfiguredTab(JTabbedPane tabbedPane,
                             String labelKey,
                             JComponent tabComponent)
Description copied from interface: ComponentFactory
Adds a tab to the provided tabbed pane, configuring the tab's appearance from information retrieved using the labelKey property. The tab title text, icon, mnemonic, and mnemonic index are all configurable.

Specified by:
addConfiguredTab in interface ComponentFactory

createScrollPane

public JScrollPane createScrollPane()
Description copied from interface: ComponentFactory
Create a scroll pane using this component factory.

Specified by:
createScrollPane in interface ComponentFactory
Returns:
empty scroll pane.
See Also:
JScrollPane.JScrollPane()

createScrollPane

public JScrollPane createScrollPane(Component view)
Description copied from interface: ComponentFactory
Create a scroll pane using this component factory, with the specified component as the viewport view.

Specified by:
createScrollPane in interface ComponentFactory
Parameters:
view - the component to display in the scrollpane's viewport
Returns:
scroll pane with specified view
See Also:
JScrollPane.JScrollPane(java.awt.Component)

createScrollPane

public JScrollPane createScrollPane(Component view,
                                    int vsbPolicy,
                                    int hsbPolicy)
Description copied from interface: ComponentFactory
Create a scroll pane using this component factory, with the specified component as the viewport view and with the specified vertical and horizontal scrollbar policies.

Specified by:
createScrollPane in interface ComponentFactory
Parameters:
view - the component to display in the scrollpane's viewport
vsbPolicy - set the vertical scrollbar policy.
hsbPolicy - set the horizontal scrollbar policy.
Returns:
scroll pane with specified view and scrolling policies
See Also:
JScrollPane.JScrollPane(java.awt.Component, int, int)

createPanel

public JPanel createPanel()
Description copied from interface: ComponentFactory
Creates a panel using this component factory.

Specified by:
createPanel in interface ComponentFactory
Returns:
the panel
See Also:
JPanel

createPanel

public JPanel createPanel(LayoutManager layoutManager)
Description copied from interface: ComponentFactory
Creates a panel with the supplied LayoutManager using this component factory.

Specified by:
createPanel in interface ComponentFactory
Parameters:
layoutManager - the LayoutManager that will be used by the returned panel
Returns:
a panel
See Also:
JPanel.JPanel(java.awt.LayoutManager)

getOptionalMessage

protected String getOptionalMessage(String messageKey)

createTable

public JTable createTable()
Construct a JTable with a default model It will delegate the creation to a TableFactory if it exists.

Specified by:
createTable in interface ComponentFactory
Parameters:
model - the table model
Returns:
The new table.

createTable

public JTable createTable(TableModel model)
Construct a JTable with the specified table model. It will delegate the creation to a TableFactory if it exists.

Specified by:
createTable in interface ComponentFactory
Parameters:
model - the table model
Returns:
The new table.

setTableFactory

public void setTableFactory(TableFactory tableFactory)
Allow configuration via XML of a table factory. A simple interface for creating JTable object, this allows the developer to create an application specific table factory where, say, each tables have a set of renderers installed, are sortable, etc.

Parameters:
tableFactory - the table factory to use

createToolBar

public JComponent createToolBar()
Construct a JToolBar.

Specified by:
createToolBar in interface ComponentFactory
Returns:
new toolbar instance


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.