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
ConstructorsModifierConstructorDescriptionprotectedprotectedAbstractComponentBuilder(is.codion.common.value.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 Bbackground(Color background) final Bfinal Cbuild()Builds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()has been called.final CBuilds 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 Bclear()Clears this builder so that it builds a new instance on next call toComponentBuilder.build()orComponentBuilder.buildValue().final BclientProperty(Object key, Object value) Adds an arbitrary key/value "client property" to the componentfinal BcomponentListener(ComponentListener componentListener) final BcomponentOrientation(ComponentOrientation componentOrientation) protected abstract CCreates the component.protected abstract ComponentValue<T,C> createComponentValue(C component) Creates the component valuefinal Benabled(boolean enabled) Sets the enabled state of the component, for a dynamic enabled state useComponentBuilder.enabled(StateObserver).final Benabled(is.codion.common.state.StateObserver enabled) protected voidenableTransferFocusOnEnter(C component) Enables focus transfer on Enter, override for special handlingfinal Bfocusable(boolean focusable) final BfocusListener(FocusListener focusListener) final Bfinal Bforeground(Color foreground) final BinitialValue(T initialValue) Sets the initial value for the component, overridden byComponentBuilder.linkedValue(Value).final BkeyEvent(KeyEvents.Builder keyEventBuilder) Enables the key event defined by the givenKeyEvents.Builderon the component.final BkeyListener(KeyListener keyListener) final Bfinal BlinkedValue(is.codion.common.value.Value<T> linkedValue) Creates a bidirectional link to the given value.final BlinkedValue(is.codion.common.value.ValueObserver<T> linkedValueObserver) Creates a read-only link to the givenValueObserver.final BmaximumHeight(int maximumHeight) final BmaximumSize(Dimension maximumSize) final BmaximumWidth(int maximumWidth) final BminimumHeight(int minimumHeight) final BminimumSize(Dimension minimumSize) final BminimumWidth(int minimumWidth) final BmouseListener(MouseListener mouseListener) final BmouseMotionListener(MouseMotionListener mouseMotionListener) final BmouseWheelListener(MouseWheelListener mouseWheelListener) final Bfinal BonSetVisible(Consumer<C> onSetVisible) final Bopaque(boolean opaque) final BpopupMenu(Function<C, JPopupMenu> popupMenu) final BpopupMenuControl(Function<C, Control> popupMenuControl) final BpopupMenuControls(Function<C, Controls> popupMenuControls) final BpreferredHeight(int preferredHeight) final BpreferredSize(Dimension preferredSize) final BpreferredWidth(int preferredWidth) final BpropertyChangeListener(PropertyChangeListener propertyChangeListener) final BpropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener) final ScrollPaneBuilderprotected abstract voidsetInitialValue(C component, T initialValue) Sets the initial value in the component, only called for non-null values.protected booleanfinal BtoolTipText(String toolTipText) final BtransferFocusOnEnter(boolean transferFocusOnEnter) Note that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwardsfinal BtransferHandler(TransferHandler transferHandler) final Bfinal Bvisible(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:
labelin 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:
focusablein 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:
preferredHeightin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
preferredHeight- the preferred component height- Returns:
- this builder instance
-
preferredWidth
- Specified by:
preferredWidthin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
preferredWidth- the preferred component width- Returns:
- this builder instance
-
preferredSize
- Specified by:
preferredSizein 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:
maximumHeightin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
maximumHeight- the maximum component height- Returns:
- this builder instance
-
maximumWidth
- Specified by:
maximumWidthin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
maximumWidth- the maximum component width- Returns:
- this builder instance
-
maximumSize
- Specified by:
maximumSizein 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:
minimumHeightin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
minimumHeight- the minimum component height- Returns:
- this builder instance
-
minimumWidth
- Specified by:
minimumWidthin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
minimumWidth- the minimum component width- Returns:
- this builder instance
-
minimumSize
- Specified by:
minimumSizein 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:
borderin 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:ComponentBuilderNote that for JTextArea CTRL is added to move focus forward and CTRL + SHIFT to move it backwards- Specified by:
transferFocusOnEnterin 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:ComponentBuilderSets the enabled state of the component, for a dynamic enabled state useComponentBuilder.enabled(StateObserver). Overridden byComponentBuilder.enabled(StateObserver).- Specified by:
enabledin 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:
enabledin 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:
popupMenuControlin 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:
popupMenuControlsin 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:
popupMenuin 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:
toolTipTextin 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:
fontin 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:
foregroundin 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:
backgroundin 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:
opaquein 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:
visiblein 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:
componentOrientationin 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:
validatorin 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:ComponentBuilderEnables the key event defined by the givenKeyEvents.Builderon the component. Note that settingComponentBuilder.transferFocusOnEnter(boolean)to true overrides any conflicting key event based onKeyEvent.VK_ENTERadded via this method.- Specified by:
keyEventin 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:ComponentBuilderAdds an arbitrary key/value "client property" to the component- Specified by:
clientPropertyin 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:
focusListenerin 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:
mouseListenerin 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:
mouseMotionListenerin 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:
mouseWheelListenerin 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:
keyListenerin 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:
componentListenerin 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:
propertyChangeListenerin 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:
propertyChangeListenerin 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:
transferHandlerin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
transferHandler- the transfer handler- Returns:
- this builder instance
- See Also:
-
onSetVisible
- Specified by:
onSetVisiblein 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:ComponentBuilderCreates a bidirectional link to the given value. Overrides any initial value set.- Specified by:
linkedValuein 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:ComponentBuilderCreates a read-only link to the givenValueObserver.- Specified by:
linkedValuein 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:ComponentBuilderSets 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:
initialValuein interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Parameters:
initialValue- the initial value- Returns:
- this builder instance
-
scrollPane
- Specified by:
scrollPanein interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- a
ScrollPaneBuilderusing this component as the view
-
onBuild
- Specified by:
onBuildin 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:ComponentBuilderBuilds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()has been called.- Specified by:
buildin interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- the component
-
build
Description copied from interface:ComponentBuilderBuilds and returns the component, note that subsequent calls return the same component untilComponentBuilder.clear()has been called.- Specified by:
buildin 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:ComponentBuilderBuilds and returns the component value, note that subsequent calls return the same component value untilComponentBuilder.clear()has been called.- Specified by:
buildValuein interfaceComponentBuilder<T,C extends JComponent, B extends ComponentBuilder<T, C, B>> - Returns:
- the component value
-
clear
Description copied from interface:ComponentBuilderClears this builder so that it builds a new instance on next call toComponentBuilder.build()orComponentBuilder.buildValue().- Specified by:
clearin 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
-