Module is.codion.swing.common.ui
Class AbstractComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>
java.lang.Object
is.codion.swing.common.ui.component.builder.AbstractComponentBuilder<T,C,B>
- All Implemented Interfaces:
ComponentBuilder<T,
C, B>
- Direct Known Subclasses:
DefaultComboBoxBuilder
public abstract class AbstractComponentBuilder<T,C extends JComponent,B extends ComponentBuilder<T,C,B>>
extends Object
implements ComponentBuilder<T,C,B>
-
Field Summary
Fields inherited from interface is.codion.swing.common.ui.component.builder.ComponentBuilder
TRANSFER_FOCUS_ON_ENTER
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
AbstractComponentBuilder
(Value<T> linkedValue) Note that when a linked value is set via the constructor, it is considered locked and cannot be changed. -
Method Summary
Modifier and TypeMethodDescriptionfinal B
background
(Color background) final B
final C
build()
Builds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()
has been called.final C
Builds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()
has been called.final ComponentValue<T,
C> Builds and returns the component value, note that subsequent calls return the same component value untilComponentBuilder.clear()
has been called.final B
clear()
Clears this builder so that it builds a new instance on next call toComponentBuilder.build()
orComponentBuilder.buildValue()
.final B
clientProperty
(Object key, Object value) Adds an arbitrary key/value "client property" to the componentfinal B
componentListener
(ComponentListener componentListener) final B
componentOrientation
(ComponentOrientation componentOrientation) protected abstract C
Creates the component.protected abstract ComponentValue<T,
C> createComponentValue
(C component) Creates the component valuefinal B
enabled
(boolean enabled) Sets the enabled state of the component, for a dynamic enabled state useComponentBuilder.enabled(StateObserver)
.final B
enabled
(StateObserver enabled) protected void
enableTransferFocusOnEnter
(C component) Enables focus transfer on Enter, override for special handlingfinal B
focusable
(boolean focusable) final B
focusCycleRoot
(boolean focusCycleRoot) final B
focusListener
(FocusListener focusListener) final B
final B
foreground
(Color foreground) final B
initialValue
(T initialValue) Sets the initial value for the component, overridden byComponentBuilder.linkedValue(Value)
.final B
keyEvent
(KeyEvents.Builder keyEventBuilder) Enables the key event defined by the givenKeyEvents.Builder
on the component.final B
keyListener
(KeyListener keyListener) final B
final B
linkedValue
(Value<T> linkedValue) Creates a bidirectional link to the given value.final B
linkedValue
(ValueObserver<T> linkedValueObserver) Creates a read-only link to the givenValueObserver
.final B
maximumHeight
(int maximumHeight) final B
maximumSize
(Dimension maximumSize) final B
maximumWidth
(int maximumWidth) final B
minimumHeight
(int minimumHeight) final B
minimumSize
(Dimension minimumSize) final B
minimumWidth
(int minimumWidth) final B
mouseListener
(MouseListener mouseListener) final B
mouseMotionListener
(MouseMotionListener mouseMotionListener) final B
mouseWheelListener
(MouseWheelListener mouseWheelListener) final B
final B
onSetVisible
(Consumer<C> onSetVisible) final B
opaque
(boolean opaque) final B
popupMenu
(Function<C, JPopupMenu> popupMenu) final B
popupMenuControl
(Function<C, Control> popupMenuControl) final B
popupMenuControls
(Function<C, Controls> popupMenuControls) final B
preferredHeight
(int preferredHeight) final B
preferredSize
(Dimension preferredSize) final B
preferredWidth
(int preferredWidth) final B
propertyChangeListener
(PropertyChangeListener propertyChangeListener) final B
propertyChangeListener
(String propertyName, PropertyChangeListener propertyChangeListener) final ScrollPaneBuilder
protected abstract void
setInitialValue
(C component, T initialValue) Sets the initial value in the component, only called for non-null values.protected boolean
final B
toolTipText
(String toolTipText) final B
transferFocusOnEnter
(boolean transferFocusOnEnter) Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwardsfinal B
transferHandler
(TransferHandler transferHandler) final B
validator
(Value.Validator<T> validator) final B
visible
(boolean visible)
-
Constructor Details
-
AbstractComponentBuilder
protected AbstractComponentBuilder() -
AbstractComponentBuilder
Note that when a linked value is set via the constructor, it is considered locked and cannot be changed.- Parameters:
linkedValue
- the linked value, may be null
-
-
Method Details
-
label
- Specified by:
label
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
label
- the label for the component- Returns:
- this builder instance
- See Also:
-
focusable
- Specified by:
focusable
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
focusable
- false if the component should not be focusable- Returns:
- this builder instance
- See Also:
-
preferredHeight
- Specified by:
preferredHeight
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
preferredHeight
- the preferred component height- Returns:
- this builder instance
-
preferredWidth
- Specified by:
preferredWidth
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
preferredWidth
- the preferred component width- Returns:
- this builder instance
-
preferredSize
- Specified by:
preferredSize
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
preferredSize
- the preferred component size- Returns:
- this builder instance
- See Also:
-
maximumHeight
- Specified by:
maximumHeight
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
maximumHeight
- the maximum component height- Returns:
- this builder instance
-
maximumWidth
- Specified by:
maximumWidth
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
maximumWidth
- the maximum component width- Returns:
- this builder instance
-
maximumSize
- Specified by:
maximumSize
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
maximumSize
- the maximum component size- Returns:
- this builder instance
- See Also:
-
minimumHeight
- Specified by:
minimumHeight
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
minimumHeight
- the minimum component height- Returns:
- this builder instance
-
minimumWidth
- Specified by:
minimumWidth
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
minimumWidth
- the minimum component width- Returns:
- this builder instance
-
minimumSize
- Specified by:
minimumSize
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
minimumSize
- the minimum component size- Returns:
- this builder instance
- See Also:
-
border
- Specified by:
border
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
border
- the component border- Returns:
- this builder instance
- See Also:
-
transferFocusOnEnter
Description copied from interface:ComponentBuilder
Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwards- Specified by:
transferFocusOnEnter
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
transferFocusOnEnter
- if true then the text field transfer focus on enter (shift-enter for backwards)- Returns:
- this builder instance
- See Also:
-
enabled
Description copied from interface:ComponentBuilder
Sets the enabled state of the component, for a dynamic enabled state useComponentBuilder.enabled(StateObserver)
. Overridden byComponentBuilder.enabled(StateObserver)
.- Specified by:
enabled
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
enabled
- the enabled state- Returns:
- this builder instance
- See Also:
-
enabled
- Specified by:
enabled
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
enabled
- the state observer controlling the component enabled status- Returns:
- this builder instance
-
popupMenuControl
- Specified by:
popupMenuControl
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
popupMenuControl
- a function, receiving the component being built, providing the control to base a popup menu on- Returns:
- this builder instance
-
popupMenuControls
- Specified by:
popupMenuControls
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
popupMenuControls
- a function, receiving the component being built, providing the controls to base a popup menu on- Returns:
- this builder instance
-
popupMenu
- Specified by:
popupMenu
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
popupMenu
- a function, receiving the component being built, providing the popup menu- Returns:
- this builder instance
- See Also:
-
toolTipText
- Specified by:
toolTipText
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
toolTipText
- the tool tip text- Returns:
- this builder instance
- See Also:
-
font
- Specified by:
font
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
font
- the component font- Returns:
- this builder instance
- See Also:
-
foreground
- Specified by:
foreground
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
foreground
- the foreground color- Returns:
- this builder instance
- See Also:
-
background
- Specified by:
background
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
background
- the background color- Returns:
- this builder instance
- See Also:
-
opaque
- Specified by:
opaque
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
opaque
- true if the component should be opaque- Returns:
- this builder instance
- See Also:
-
visible
- Specified by:
visible
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
visible
- the initial component visibility, default true- Returns:
- this builder instance
- See Also:
-
componentOrientation
- Specified by:
componentOrientation
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
componentOrientation
- the component orientation- Returns:
- this builder instance
- See Also:
-
validator
- Specified by:
validator
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
validator
- the validator to use- Returns:
- this builder instance
-
keyEvent
Description copied from interface:ComponentBuilder
Enables the key event defined by the givenKeyEvents.Builder
on the component. Note that settingComponentBuilder.transferFocusOnEnter(boolean)
to true overrides any conflicting key event based onKeyEvent.VK_ENTER
added via this method.- Specified by:
keyEvent
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
keyEventBuilder
- a key event builder to enable on the component- Returns:
- this builder instance
-
clientProperty
Description copied from interface:ComponentBuilder
Adds an arbitrary key/value "client property" to the component- Specified by:
clientProperty
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
key
- the keyvalue
- the value- Returns:
- this builder instance
- See Also:
-
focusListener
- Specified by:
focusListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
focusListener
- the focus listener- Returns:
- this builder instance
- See Also:
-
mouseListener
- Specified by:
mouseListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
mouseListener
- the mouse listener- Returns:
- this builder instance
- See Also:
-
mouseMotionListener
- Specified by:
mouseMotionListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
mouseMotionListener
- the mouse motion listener- Returns:
- this builder instance
- See Also:
-
mouseWheelListener
- Specified by:
mouseWheelListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
mouseWheelListener
- the mouse wheel listener- Returns:
- this builder instance
- See Also:
-
keyListener
- Specified by:
keyListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
keyListener
- the key listener- Returns:
- this builder instance
- See Also:
-
componentListener
- Specified by:
componentListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
componentListener
- the component listener- Returns:
- this builder instance
- See Also:
-
propertyChangeListener
- Specified by:
propertyChangeListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
propertyChangeListener
- the property change listener- Returns:
- this builder instance
- See Also:
-
propertyChangeListener
public final B propertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener) - Specified by:
propertyChangeListener
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
propertyName
- the name of the property to listen forpropertyChangeListener
- the property change listener- Returns:
- this builder instance
- See Also:
-
transferHandler
- Specified by:
transferHandler
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
transferHandler
- the transfer handler- Returns:
- this builder instance
- See Also:
-
focusCycleRoot
- Specified by:
focusCycleRoot
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
focusCycleRoot
- true if the component should be the root of a focus traversal cycle- Returns:
- this builder instance
- See Also:
-
onSetVisible
- Specified by:
onSetVisible
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
onSetVisible
- called when the component is made visible for the first time- Returns:
- this builder instance
-
linkedValue
Description copied from interface:ComponentBuilder
Creates a bidirectional link to the given value. Overrides any initial value set.- Specified by:
linkedValue
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
linkedValue
- a value to link to the component value- Returns:
- this builder instance
-
linkedValue
Description copied from interface:ComponentBuilder
Creates a read-only link to the givenValueObserver
.- Specified by:
linkedValue
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
linkedValueObserver
- a value to link to the component value- Returns:
- this builder instance
-
initialValue
Description copied from interface:ComponentBuilder
Sets the initial value for the component, overridden byComponentBuilder.linkedValue(Value)
. Note that null is not explicitely set, the component is assumed to represent the null value right after it's been created.- Specified by:
initialValue
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
initialValue
- the initial value- Returns:
- this builder instance
-
scrollPane
- Specified by:
scrollPane
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- a
ScrollPaneBuilder
using this component as the view
-
onBuild
- Specified by:
onBuild
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
onBuild
- called when the component has been built, not called on subsequent calls untilComponentBuilder.clear()
has been called.- Returns:
- this builder instance
-
build
Description copied from interface:ComponentBuilder
Builds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()
has been called.- Specified by:
build
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- the component
-
build
Description copied from interface:ComponentBuilder
Builds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()
has been called.- Specified by:
build
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
onBuild
- called after the first call when the component is built, not called on subsequent calls.- Returns:
- the component
-
buildValue
Description copied from interface:ComponentBuilder
Builds and returns the component value, note that subsequent calls return the same component value untilComponentBuilder.clear()
has been called.- Specified by:
buildValue
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- the component value
-
clear
Description copied from interface:ComponentBuilder
Clears this builder so that it builds a new instance on next call toComponentBuilder.build()
orComponentBuilder.buildValue()
.- Specified by:
clear
in interfaceComponentBuilder<T,
C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- this builder instance
-
createComponent
Creates the component.- Returns:
- a new component instance
-
createComponentValue
Creates the component value- Parameters:
component
- the component- Returns:
- a component value based on the component
-
setInitialValue
Sets the initial value in the component, only called for non-null values.- Parameters:
component
- the componentinitialValue
- the initial value, not null
-
supportsNull
protected boolean supportsNull()- Returns:
- true if this component can be linked with a nullable value
-
enableTransferFocusOnEnter
Enables focus transfer on Enter, override for special handling- Parameters:
component
- the component
-