public class SwingComponentManager extends Object implements ComponentManager
The Swing specific implementation of the ComponentManager
interface.
This class implements the methods of the ComponentManager
interface in a way that standard Swing components are created.
Modifier and Type | Field and Description |
---|---|
static String |
BUILDER_NAME
Constant for the Swing form builder name.
|
Constructor and Description |
---|
SwingComponentManager()
Creates a new instance of
SwingComponentManager . |
Modifier and Type | Method and Description |
---|---|
void |
addContainerComponent(Object container,
Object component,
Object constraints)
Adds the specified component to a container using the given constraints.
|
Object |
createBorderLayout(BorderLayoutTag tag)
Creates a border layout with the information from the passed in tag.
|
ComponentHandler<Boolean> |
createButton(ButtonTag tag,
boolean create)
Creates a component handler for a command button, which is specified by
the given tag.
|
protected ComponentHandler<Boolean> |
createButtonHandler(AbstractButton button,
InputComponentTag tag,
TextIconData data,
String command)
Initializes a button component and creates a component handler for it.
|
Object |
createButtonLayout(ButtonLayoutTag tag)
Creates a button layout with the information from the passed in tag.
|
ComponentHandler<Boolean> |
createCheckbox(CheckboxTag tag,
boolean create)
Creates a component handler for a checkbox, which is specified by the
given tag.
|
ComponentHandler<Object> |
createComboBox(ComboBoxTag tag,
boolean create)
Creates a component handler for a combo box, which is specified by the
given tag.
|
protected Border |
createDefaultBorder()
Creates a default border.
|
Object |
createDesktopPanel(DesktopPanelTag tag,
boolean create)
Creates a desktop panel with the information obtained from the passed in
tag.
|
PlatformEventManager |
createEventManager()
Creates the Swing specific platform event manager.
|
Object |
createFont(FontTag tag)
Creates a font based on the data provided by the given
FontTag . |
Object |
createIcon(Locator locator)
Creates an icon with the information obtained from the given locator.
|
Object |
createLabel(LabelTag tag,
boolean create)
Creates a label component with the information obtained from the given
tag.
|
ComponentHandler<Object> |
createListBox(ListBoxTag tag,
boolean create)
Creates a component handler for a list, which is specified by the given
tag.
|
Object |
createPanel(PanelTag tag,
boolean create)
Creates a panel with the information obtained from the passed in tag.
|
ComponentHandler<String> |
createPasswordField(PasswordFieldTag tag,
boolean create)
Creates a component handler for a password text field which is specified
by the given tag.
|
Object |
createPercentLayout(PercentLayoutTag tag)
Creates a percent layout with the information from the passed in tag.
|
ComponentHandler<Integer> |
createProgressBar(ProgressBarTag tag,
boolean create)
Creates a component handler for a progress bar, which is specified by the
given tag.
|
ComponentHandler<Boolean> |
createRadioButton(RadioButtonTag tag,
boolean create)
Creates a component handler for a radio button, which is specified by the
given tag.
|
ButtonGroup |
createRadioGroup(Map<String,Object> radios)
Creates a radio group, which contains the specified radio buttons.
|
ComponentHandler<Integer> |
createSlider(SliderTag tag,
boolean create)
Creates a component handler for a slider, which is specified by the given
tag.
|
Object |
createSplitter(SplitterTag tag,
boolean create)
Creates a splitter component from the information contained in the passed
in tag.
|
ComponentHandler<StaticTextData> |
createStaticText(StaticTextTag tag,
boolean create)
Creates a component handler for a static text, which is specified by the
given tag.
|
ComponentHandler<Integer> |
createTabbedPane(TabbedPaneTag tag,
boolean create)
Creates a component handler for a tabbed pane, which is specified by the
given tag.
|
ComponentHandler<Object> |
createTable(TableTag tag,
boolean create)
Creates a component handler for a table specified by the given tag.
|
ComponentHandler<String> |
createTextArea(TextAreaTag tag,
boolean create)
Creates a component handler for a text area which is specified by the
given tag.
|
ComponentHandler<String> |
createTextField(TextFieldTag tag,
boolean create)
Creates a component handler for a text field which is specified by the
given tag.
|
ComponentHandler<Boolean> |
createToggleButton(ToggleButtonTag tag,
boolean create)
Creates a component handler for a toggle button, which is specified by
the given tag.
|
ComponentHandler<Object> |
createTree(TreeTag tag,
boolean create)
Creates a component handler for a tree specified by the given tag.
|
WidgetHandler |
getWidgetHandlerFor(Object component)
Returns a
WidgetHandler for the specified component. |
protected void |
initButton(AbstractButton button,
InputComponentTag tag,
TextIconData data,
String command)
Initializes a button component like a toggle button or a checkbox.
|
protected void |
initComponent(JComponent component,
ComponentBaseTag tag)
Initializes the given component from the specified tag.
|
protected void |
initLabel(JLabel label,
ComponentBaseTag tag,
TextIconData data)
Initializes a label from a
TextIconData object. |
protected void |
initTableColumnWidths(TableTag tag,
JTable table)
Initializes the widths of the columns of the specified table.
|
protected void |
initText(JTextComponent text,
InputComponentTag tag,
int maxlen)
Initializes a text component.
|
void |
linkLabel(Object label,
Object component,
String text)
Associates a label with another component.
|
protected void |
registerTableListener(TableTag tag,
net.sf.jguiraffe.gui.platform.swing.builder.components.SwingTableComponentHandler handler)
Registers a specialized listener for resizing table columns if required.
|
void |
setContainerLayout(Object container,
Object layout)
Sets the layout manager for the specified container.
|
public static final String BUILDER_NAME
public SwingComponentManager()
SwingComponentManager
.public void addContainerComponent(Object container, Object component, Object constraints)
java.awt.Container
and the component of type
java.awt.Component
. The constraints may be undefined.addContainerComponent
in interface ComponentManager
container
- the containercomponent
- the componentconstraints
- the layout constrainspublic void setContainerLayout(Object container, Object layout)
java.awt.Container
,
the layout manager object must implement the
java.awt.LayoutManager
interface.setContainerLayout
in interface ComponentManager
container
- the containerlayout
- the layout managerpublic PlatformEventManager createEventManager()
SwingEventManager
class.createEventManager
in interface ComponentManager
public WidgetHandler getWidgetHandlerFor(Object component)
WidgetHandler
for the specified component. This
implementation expects that the passed in component is either derived
from javax.swing.JComponent
or is a javax.swing.ButtonGroup
. It will then return a Swing-specific handler
implementation, which allows manipulation of this component. Some
components created by SwingComponentManager
are wrapped inside a
JScrollPane
. If the component passed in happens to be a scroll
pane, the WidgetHandler
is therefore created for the viewport
component.getWidgetHandlerFor
in interface ComponentManager
component
- the affected componentWidgetHandler
for this componentFormBuilderRuntimeException
- if the component is a ButtonGroup
and does not contain any elementspublic Object createLabel(LabelTag tag, boolean create)
JLabel
object if the
create
parameter is false.createLabel
in interface ComponentManager
tag
- the label tagcreate
- the create flagpublic void linkLabel(Object label, Object component, String text) throws FormBuilderException
javax.swing.JLabel
, the component must be of type
java.awt.Component
.linkLabel
in interface ComponentManager
label
- the labelcomponent
- the componenttext
- the text for the labelFormBuilderException
- if an error occurspublic Object createIcon(Locator locator) throws FormBuilderException
ImageIcon
object will be returned.createIcon
in interface ComponentManager
locator
- the Locator
pointing to the icon's dataFormBuilderException
- if the icon cannot be loadedpublic Object createFont(FontTag tag) throws FormBuilderException
FontTag
.
This implementation creates a java.awt.Font
object using the
constructor that takes a map with attributes. The default font attributes
specified by the tag are mapped to corresponding constants of the TextAttribute
class. For the map with extended attributes two kinds of
keys are supported:
TextAttribute
are used directly.String
, it is checked whether it is the
name of a constant in the TextAttribute
class. In this case the
key is accepted.createFont
in interface ComponentManager
tag
- the FontTag
FormBuilderException
- if an error occurspublic Object createPercentLayout(PercentLayoutTag tag) throws FormBuilderException
createPercentLayout
in interface ComponentManager
tag
- the percent layout tagFormBuilderException
- if an error occurspublic Object createButtonLayout(ButtonLayoutTag tag) throws FormBuilderException
createButtonLayout
in interface ComponentManager
tag
- the button layout tagFormBuilderException
- if an error occurspublic Object createBorderLayout(BorderLayoutTag tag) throws FormBuilderException
createBorderLayout
in interface ComponentManager
tag
- the border layout tagFormBuilderException
- if an error occurspublic Object createPanel(PanelTag tag, boolean create) throws FormBuilderException
javax.swing.JPanel
. If a text is
defined or the border
attribute is true, a border
will be added. This implementation also supports border objects that have
been placed into the Jelly context and that are referenced by the
borderref
attribute.createPanel
in interface ComponentManager
tag
- the panel tagcreate
- the create flagFormBuilderException
- if an error occurspublic Object createDesktopPanel(DesktopPanelTag tag, boolean create) throws FormBuilderException
JDesktopPane
class.createDesktopPanel
in interface ComponentManager
tag
- the desktop panel tagcreate
- the create flagFormBuilderException
- if an error occurspublic Object createSplitter(SplitterTag tag, boolean create) throws FormBuilderException
JSplitPane
class.createSplitter
in interface ComponentManager
tag
- the splitter tagcreate
- the create flagFormBuilderException
- if an error occurspublic ButtonGroup createRadioGroup(Map<String,Object> radios) throws FormBuilderException
javax.swing.AbstractButton
.
The button group must not be empty.createRadioGroup
in interface ComponentManager
radios
- a collection with the radio buttons to addFormBuilderException
- if an error occurspublic ComponentHandler<Boolean> createButton(ButtonTag tag, boolean create) throws FormBuilderException
createButton
in interface ComponentManager
tag
- the button tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Boolean> createToggleButton(ToggleButtonTag tag, boolean create) throws FormBuilderException
createToggleButton
in interface ComponentManager
tag
- the toggle button tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<String> createTextField(TextFieldTag tag, boolean create) throws FormBuilderException
createTextField
in interface ComponentManager
tag
- the text field tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<String> createTextArea(TextAreaTag tag, boolean create) throws FormBuilderException
createTextArea
in interface ComponentManager
tag
- the text area tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<String> createPasswordField(PasswordFieldTag tag, boolean create) throws FormBuilderException
createPasswordField
in interface ComponentManager
tag
- the password tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Boolean> createCheckbox(CheckboxTag tag, boolean create) throws FormBuilderException
createCheckbox
in interface ComponentManager
tag
- the checkbox tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Boolean> createRadioButton(RadioButtonTag tag, boolean create) throws FormBuilderException
createRadioButton
in interface ComponentManager
tag
- the radio button tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Object> createComboBox(ComboBoxTag tag, boolean create) throws FormBuilderException
createComboBox
in interface ComponentManager
tag
- the combo box tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Object> createListBox(ListBoxTag tag, boolean create) throws FormBuilderException
createListBox
in interface ComponentManager
tag
- the list box tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Integer> createTabbedPane(TabbedPaneTag tag, boolean create) throws FormBuilderException
createTabbedPane
in interface ComponentManager
tag
- the tabbed pane tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<StaticTextData> createStaticText(StaticTextTag tag, boolean create) throws FormBuilderException
createStaticText
in interface ComponentManager
tag
- the static text tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Integer> createProgressBar(ProgressBarTag tag, boolean create) throws FormBuilderException
createProgressBar
in interface ComponentManager
tag
- the progress bar tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Integer> createSlider(SliderTag tag, boolean create) throws FormBuilderException
createSlider
in interface ComponentManager
tag
- the slider tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Object> createTable(TableTag tag, boolean create) throws FormBuilderException
createTable
in interface ComponentManager
tag
- the tagcreate
- the create flagFormBuilderException
- if an error occurspublic ComponentHandler<Object> createTree(TreeTag tag, boolean create) throws FormBuilderException
createTree
in interface ComponentManager
tag
- the tagcreate
- the create flagFormBuilderException
- if an error occursprotected void initComponent(JComponent component, ComponentBaseTag tag)
component
- the component to initializetag
- the tagprotected void initLabel(JLabel label, ComponentBaseTag tag, TextIconData data)
TextIconData
object.label
- the label to be initializedtag
- the tag with the label definitiondata
- the text icon data objectprotected void initButton(AbstractButton button, InputComponentTag tag, TextIconData data, String command)
button
- the button to initializetag
- the tag for the buttondata
- the text icon data objectcommand
- the button's command (can be null)protected ComponentHandler<Boolean> createButtonHandler(AbstractButton button, InputComponentTag tag, TextIconData data, String command)
initButton()
and then creates a
SwingButtonHandler
that wraps the button.button
- the button to initializetag
- the tag for the buttondata
- the text icon data objectcommand
- the button's command (can be null)protected void initText(JTextComponent text, InputComponentTag tag, int maxlen)
text
- the text componenttag
- the input component tagmaxlen
- the maximum text lengthprotected Border createDefaultBorder()
protected void initTableColumnWidths(TableTag tag, JTable table) throws FormBuilderException
tag
- the tag defining the tabletable
- the tableFormBuilderException
- if an error occursprotected void registerTableListener(TableTag tag, net.sf.jguiraffe.gui.platform.swing.builder.components.SwingTableComponentHandler handler) throws FormBuilderException
tag
- the table taghandler
- the handler for the tableFormBuilderException
- if an error occursCopyright © 2016 The JGUIraffe Team. All rights reserved.