Module is.codion.swing.common.ui
Interface ComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>
-
- Type Parameters:
T
- the type of the value the component representsC
- the component typeB
- the builder type
- All Known Subinterfaces:
ButtonBuilder<T,C,B>
,CheckBoxBuilder
,ComboBoxBuilder<T,C,B>
,EntitySearchField.Builder
,FileInputPanelBuilder
,ItemComboBoxBuilder<T>
,ItemSpinnerBuilder<T>
,LabelBuilder<T>
,ListBuilder<T>
,ListSpinnerBuilder<T>
,MaskedTextFieldBuilder
,NumberField.Builder<T>
,NumberSpinnerBuilder<T>
,PanelBuilder
,PasswordFieldBuilder
,ProgressBarBuilder
,RadioButtonBuilder
,ScrollPaneBuilder
,SliderBuilder
,SpinnerBuilder<T,B>
,SplitPaneBuilder
,TabbedPaneBuilder
,TemporalField.Builder<T>
,TemporalInputPanel.Builder<T>
,TextAreaBuilder
,TextComponentBuilder<T,C,B>
,TextFieldBuilder<T,C,B>
,TextInputPanel.Builder
,ToggleButtonBuilder<C,B>
,ToolBarBuilder
- All Known Implementing Classes:
AbstractComponentBuilder
,DefaultComboBoxBuilder
public interface ComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>
Builds a JComponent.
Note that oncebuild()
orbuildValue()
have been called they will return the same instance on subsequent calls until the builder has been cleared by callingclear()
.
-
-
Field Summary
Fields Modifier and Type Field Description static PropertyValue<Boolean>
TRANSFER_FOCUS_ON_ENTER
Specifies whether focus should be transferred from components on enter.
Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwards
Value type: Boolean
Default value: false
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description B
background(Color background)
B
border(Border border)
C
build()
Builds and returns the component, note that subsequent calls return the same component untilclear()
has been called.C
build(Consumer<C> onBuild)
Builds and returns the component, note that subsequent calls return the same component untilclear()
has been called.ComponentValue<T,C>
buildValue()
Builds and returns the component value, note that subsequent calls return the same component value untilclear()
has been called.B
clear()
Clears this builder so that it builds a new instance on next call tobuild()
orbuildValue()
.B
clientProperty(Object key, Object value)
Adds an arbitrary key/value "client property" to the componentB
componentListener(ComponentListener componentListener)
B
componentOrientation(ComponentOrientation orientation)
B
enabled(boolean enabled)
Sets the enabled state of the component, for a dynamic enabled state useenabledState(StateObserver)
.B
enabledState(StateObserver enabledState)
B
focusable(boolean focusable)
B
focusListener(FocusListener focusListener)
B
font(Font font)
B
foreground(Color foreground)
B
initialValue(T initialValue)
Sets the initial value for the component, overridden bylinkedValue(Value)
.B
keyEvent(KeyEvents.Builder keyEventBuilder)
Enables the key event defined by the givenKeyEvents.Builder
on the component.B
keyListener(KeyListener keyListener)
B
label(JLabel label)
B
linkedValue(Value<T> linkedValue)
Creates a bidirectional link to the given value.B
linkedValueObserver(ValueObserver<T> linkedValueObserver)
Creates a read-only link to the givenValueObserver
.B
maximumHeight(int maximumHeight)
B
maximumSize(Dimension maximumSize)
B
maximumWidth(int maximumWidth)
B
minimumHeight(int minimumHeight)
B
minimumSize(Dimension minimumSize)
B
minimumWidth(int minimumWidth)
B
mouseListener(MouseListener mouseListener)
B
mouseMotionListener(MouseMotionListener mouseMotionListener)
B
mouseWheelListener(MouseWheelListener mouseWheelListener)
B
onBuild(Consumer<C> onBuild)
B
onSetVisible(Consumer<C> onSetVisible)
B
opaque(boolean opaque)
B
popupMenu(JPopupMenu popupMenu)
B
popupMenuControl(Control popupMenuControl)
B
popupMenuControls(Controls popupMenuControls)
B
preferredHeight(int preferredHeight)
B
preferredSize(Dimension preferredSize)
B
preferredWidth(int preferredWidth)
ScrollPaneBuilder
scrollPane()
B
toolTipText(String toolTipText)
B
transferFocusOnEnter(boolean transferFocusOnEnter)
Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwardsB
transferHandler(TransferHandler transferHandler)
B
validator(Value.Validator<T> validator)
-
-
-
Field Detail
-
TRANSFER_FOCUS_ON_ENTER
static final PropertyValue<Boolean> TRANSFER_FOCUS_ON_ENTER
Specifies whether focus should be transferred from components on enter.
Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwards
Value type: Boolean
Default value: false
-
-
Method Detail
-
label
B label(JLabel label)
- Parameters:
label
- the label for the component- Returns:
- this builder instance
- See Also:
JLabel.setLabelFor(Component)
-
focusable
B focusable(boolean focusable)
- Parameters:
focusable
- false if the component should not be focusable- Returns:
- this builder instance
- See Also:
Component.setFocusable(boolean)
-
preferredHeight
B preferredHeight(int preferredHeight)
- Parameters:
preferredHeight
- the preferred component height- Returns:
- this builder instance
-
preferredWidth
B preferredWidth(int preferredWidth)
- Parameters:
preferredWidth
- the preferred component width- Returns:
- this builder instance
-
preferredSize
B preferredSize(Dimension preferredSize)
- Parameters:
preferredSize
- the preferred component size- Returns:
- this builder instance
- See Also:
JComponent.setPreferredSize(Dimension)
-
maximumHeight
B maximumHeight(int maximumHeight)
- Parameters:
maximumHeight
- the maximum component height- Returns:
- this builder instance
-
maximumWidth
B maximumWidth(int maximumWidth)
- Parameters:
maximumWidth
- the maximum component width- Returns:
- this builder instance
-
maximumSize
B maximumSize(Dimension maximumSize)
- Parameters:
maximumSize
- the maximum component size- Returns:
- this builder instance
- See Also:
JComponent.setMaximumSize(Dimension)
-
minimumHeight
B minimumHeight(int minimumHeight)
- Parameters:
minimumHeight
- the minimum component height- Returns:
- this builder instance
-
minimumWidth
B minimumWidth(int minimumWidth)
- Parameters:
minimumWidth
- the minimum component width- Returns:
- this builder instance
-
minimumSize
B minimumSize(Dimension minimumSize)
- Parameters:
minimumSize
- the minimum component size- Returns:
- this builder instance
- See Also:
JComponent.setMinimumSize(Dimension)
-
border
B border(Border border)
- Parameters:
border
- the component border- Returns:
- this builder instance
- See Also:
JComponent.setBorder(Border)
-
transferFocusOnEnter
B transferFocusOnEnter(boolean transferFocusOnEnter)
Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwards- Parameters:
transferFocusOnEnter
- if true then the text field transfer focus on enter (shift-enter for backwards)- Returns:
- this builder instance
-
toolTipText
B toolTipText(String toolTipText)
- Parameters:
toolTipText
- the tool tip text- Returns:
- this builder instance
- See Also:
JComponent.setToolTipText(String)
-
enabled
B enabled(boolean enabled)
Sets the enabled state of the component, for a dynamic enabled state useenabledState(StateObserver)
. Overridden byenabledState(StateObserver)
.- Parameters:
enabled
- the enabled state- Returns:
- this builder instance
- See Also:
JComponent.setEnabled(boolean)
-
enabledState
B enabledState(StateObserver enabledState)
- Parameters:
enabledState
- the state controlling the component enabled status- Returns:
- this builder instance
-
popupMenuControl
B popupMenuControl(Control popupMenuControl)
- Parameters:
popupMenuControl
- the control to base a popup menu on- Returns:
- this builder instance
-
popupMenuControls
B popupMenuControls(Controls popupMenuControls)
- Parameters:
popupMenuControls
- the controls to base a popup menu on- Returns:
- this builder instance
-
popupMenu
B popupMenu(JPopupMenu popupMenu)
- Parameters:
popupMenu
- the popup menu- Returns:
- this builder instance
- See Also:
JComponent.setComponentPopupMenu(JPopupMenu)
-
font
B font(Font font)
- Parameters:
font
- the component font- Returns:
- this builder instance
- See Also:
JComponent.setFont(Font)
-
foreground
B foreground(Color foreground)
- Parameters:
foreground
- the foreground color- Returns:
- this builder instance
- See Also:
JComponent.setForeground(Color)
-
background
B background(Color background)
- Parameters:
background
- the background color- Returns:
- this builder instance
- See Also:
JComponent.setBackground(Color)
-
opaque
B opaque(boolean opaque)
- Parameters:
opaque
- true if the component should be opaque- Returns:
- this builder instance
- See Also:
JComponent.setOpaque(boolean)
-
componentOrientation
B componentOrientation(ComponentOrientation orientation)
- Parameters:
orientation
- the component orientation- Returns:
- this builder instance
- See Also:
Component.setComponentOrientation(ComponentOrientation)
-
validator
B validator(Value.Validator<T> validator)
- Parameters:
validator
- the validator to use- Returns:
- this builder instance
-
keyEvent
B keyEvent(KeyEvents.Builder keyEventBuilder)
Enables the key event defined by the givenKeyEvents.Builder
on the component. Note that settingtransferFocusOnEnter(boolean)
to true overrides any conflicting key event based onKeyEvent.VK_ENTER
added via this method.- Parameters:
keyEventBuilder
- a key event builder to enable on the component- Returns:
- this builder instance
-
clientProperty
B clientProperty(Object key, Object value)
Adds an arbitrary key/value "client property" to the component- Parameters:
key
- the keyvalue
- the value- Returns:
- this builder instance
- See Also:
JComponent.putClientProperty(Object, Object)
-
focusListener
B focusListener(FocusListener focusListener)
- Parameters:
focusListener
- the focus listener- Returns:
- this builder instance
- See Also:
Component.addFocusListener(FocusListener)
-
mouseListener
B mouseListener(MouseListener mouseListener)
- Parameters:
mouseListener
- the mouse listener- Returns:
- this builder instance
- See Also:
Component.addMouseListener(MouseListener)
-
mouseMotionListener
B mouseMotionListener(MouseMotionListener mouseMotionListener)
- Parameters:
mouseMotionListener
- the mouse motion listener- Returns:
- this builder instance
- See Also:
Component.addMouseMotionListener(MouseMotionListener)
-
mouseWheelListener
B mouseWheelListener(MouseWheelListener mouseWheelListener)
- Parameters:
mouseWheelListener
- the mouse wheel listener- Returns:
- this builder instance
- See Also:
Component.addMouseWheelListener(MouseWheelListener)
-
keyListener
B keyListener(KeyListener keyListener)
- Parameters:
keyListener
- the key listener- Returns:
- this builder instance
- See Also:
Component.addKeyListener(KeyListener)
-
componentListener
B componentListener(ComponentListener componentListener)
- Parameters:
componentListener
- the component listener- Returns:
- this builder instance
- See Also:
Component.addComponentListener(ComponentListener)
-
transferHandler
B transferHandler(TransferHandler transferHandler)
- Parameters:
transferHandler
- the transfer handler- Returns:
- this builder instance
- See Also:
JComponent.setTransferHandler(TransferHandler)
-
onSetVisible
B onSetVisible(Consumer<C> onSetVisible)
- Parameters:
onSetVisible
- called when the component is made visible for the first time- Returns:
- this builder instance
-
linkedValue
B linkedValue(Value<T> linkedValue)
Creates a bidirectional link to the given value. Overrides any initial value set.- Parameters:
linkedValue
- a value to link to the component value- Returns:
- this builder instance
-
linkedValueObserver
B linkedValueObserver(ValueObserver<T> linkedValueObserver)
Creates a read-only link to the givenValueObserver
.- Parameters:
linkedValueObserver
- a value to link to the component value- Returns:
- this builder instance
-
initialValue
B initialValue(T initialValue)
Sets the initial value for the component, overridden bylinkedValue(Value)
. Note that null is not explicitely set, the component is assumed to represent the null value right after it's been created.- Parameters:
initialValue
- the initial value- Returns:
- this builder instance
-
scrollPane
ScrollPaneBuilder scrollPane()
- Returns:
- a
ScrollPaneBuilder
using this component as the view
-
onBuild
B onBuild(Consumer<C> onBuild)
- Parameters:
onBuild
- called when the component has been built, before any values are linked, not called on subsequent calls untilclear()
has been called.- Returns:
- this builder instance
-
build
C build()
Builds and returns the component, note that subsequent calls return the same component untilclear()
has been called.- Returns:
- the component
-
build
C build(Consumer<C> onBuild)
Builds and returns the component, note that subsequent calls return the same component untilclear()
has been called.- Parameters:
onBuild
- called after the first call when the component is built, before any values are linked, not called on subsequent calls.- Returns:
- the component
-
clear
B clear()
Clears this builder so that it builds a new instance on next call tobuild()
orbuildValue()
.- Returns:
- this builder instance
-
buildValue
ComponentValue<T,C> buildValue()
Builds and returns the component value, note that subsequent calls return the same component value untilclear()
has been called.- Returns:
- the component value
-
-