Class AbstractValueLayout<T extends Constraints>
java.lang.Object
com.globalmentor.beans.BoundPropertyObject
io.guise.framework.event.GuiseBoundPropertyObject
io.guise.framework.component.layout.AbstractLayout<T>
io.guise.framework.component.layout.AbstractValueLayout<T>
- Type Parameters:
T
- The type of layout constraints associated with each component.
- All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable
,com.globalmentor.beans.PropertyConstrainable
,com.globalmentor.model.MutableValued<Component>
,com.globalmentor.model.Valued<Component>
,Layout<T>
,Model
,ValueModel<Component>
- Direct Known Subclasses:
CardLayout
,TabLayout
public abstract class AbstractValueLayout<T extends Constraints>
extends AbstractLayout<T>
implements ValueModel<Component>
A layout that manages the selection of child components, only one of which can be selected at a time. A value layout can only be used with a
Container
as its owner. The layout maintains its own value model that maintains the current selected component. If a child component implements
Activeable
the child component is set as active when selected and set as inactive when the child component is unselected.- Author:
- Garret Wilson
-
Nested Class Summary
Nested classes/interfaces inherited from class io.guise.framework.component.layout.AbstractLayout
AbstractLayout.ConstraintsPropertyChangeListener
-
Field Summary
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
Fields inherited from interface io.guise.framework.model.ValueModel
VALIDATOR_PROPERTY, VALUE_PROPERTY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addComponent
(Component component) Lays out the associated layout component.void
Clears the value by setting the value tonull
, which may be invalid according to any installed validators.getOwner()
int
getValue()
protected ValueModel<Component>
boolean
Determines whether the value of this model is valid.void
removeComponent
(Component component) Removes a component from the layout.void
Resets the value to a default value, which may be invalid according to any installed validators.void
setOwner
(LayoutComponent newOwner) Sets the layout component that owns this layout This method is managed by layout components, and normally should not be called by applications.void
setSelectedIndex
(int newIndex) Sets the index of the selected component.void
setValidator
(Validator<Component> newValidator) Sets the validator.void
Sets the new value.void
Validates the value of this model, throwing an exception if the model is not valid.Methods inherited from class io.guise.framework.component.layout.AbstractLayout
componentConstraintsChanged, fireConstraintsPropertyChange, getComponentConstraintsChangeListener, getConstraints, getConstraintsPropertyChangeListener
Methods inherited from class io.guise.framework.event.GuiseBoundPropertyObject
getSession
Methods inherited from class com.globalmentor.beans.BoundPropertyObject
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.guise.framework.component.layout.Layout
createDefaultConstraints, getConstraintsClass, getSession
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
Methods inherited from interface com.globalmentor.beans.PropertyConstrainable
addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener
-
Constructor Details
-
AbstractValueLayout
public AbstractValueLayout()Default constructor.
-
-
Method Details
-
getValueModel
- Returns:
- The value model used by this component.
-
getSelectedIndex
public int getSelectedIndex()- Returns:
- The index of the selected component, or -1 if no component is selected.
-
setSelectedIndex
Sets the index of the selected component. If the value change is vetoed by the installed validator, the validation exception will be accessible viaThrowable.getCause()
.- Parameters:
newIndex
- The index of the selected component, or -1 if no component is selected.- Throws:
IllegalStateException
- if this layout has not yet been installed into a container.IndexOutOfBoundsException
- if the index is out of range.PropertyVetoException
- if the component at the given index is not a valid compoment to select or the change has otherwise been vetoed.
-
addComponent
Lays out the associated layout component. This version does nothing.This version updates the new component's active status if the component implements
Activeable
.- Specified by:
addComponent
in interfaceLayout<T extends Constraints>
- Overrides:
addComponent
in classAbstractLayout<T extends Constraints>
- Parameters:
component
- The component to add to the layout.
-
removeComponent
Removes a component from the layout. Called immediately before a component is removed from the associated layout component. This method is called by the associated layout component, and should not be called directly by application code.This implementation updates the selected component if necessary.
- Specified by:
removeComponent
in interfaceLayout<T extends Constraints>
- Overrides:
removeComponent
in classAbstractLayout<T extends Constraints>
- Parameters:
component
- The component to remove from the layout.
-
getOwner
- Specified by:
getOwner
in interfaceLayout<T extends Constraints>
- Overrides:
getOwner
in classAbstractLayout<T extends Constraints>
- Returns:
- The layout component that owns this layout, or
null
if this layout has not been installed into a layout component.
-
setOwner
Description copied from interface:Layout
Sets the layout component that owns this layout This method is managed by layout components, and normally should not be called by applications. A layout cannot be given a layout component if it is already installed in another layout component. Once a layout is installed in a layout component, it cannot be uninstalled. A layout cannot be given a layout component unless that layout component already recognizes this layout as its layout. If a layout is given the same layout component it already has, no action occurs.- Specified by:
setOwner
in interfaceLayout<T extends Constraints>
- Overrides:
setOwner
in classAbstractLayout<T extends Constraints>
- Parameters:
newOwner
- The new layout component for this layout.
-
getDefaultValue
- Specified by:
getDefaultValue
in interfaceValueModel<T extends Constraints>
- Returns:
- The default value.
-
getValue
- Specified by:
getValue
in interfacecom.globalmentor.model.Valued<T extends Constraints>
- Specified by:
getValue
in interfaceValueModel<T extends Constraints>
- Returns:
- The input value, or
null
if there is no input value.
-
setValue
Sets the new value. This is a bound property that only fires a change event when the new value is different via theequals()
method. If a validator is installed, the value will first be validated before the current value is changed. Validation always occurs if a validator is installed, even if the value is not changing. If the value change is vetoed by the installed validator, the validation exception will be accessible viaThrowable.getCause()
.This version makes sure that the given component is contained in the container, and resets the cached selected index so that it can be recalculated. This version updates the active status of the old and new components if the implement
Activeable
.- Specified by:
setValue
in interfacecom.globalmentor.model.MutableValued<T extends Constraints>
- Specified by:
setValue
in interfaceValueModel<T extends Constraints>
- Parameters:
newValue
- The new value.- Throws:
PropertyVetoException
- if the provided value is not valid or the change has otherwise been vetoed.- See Also:
-
clearValue
public void clearValue()Clears the value by setting the value tonull
, which may be invalid according to any installed validators. No validation occurs.This version resets the cached selected index so that it can be recalculated.
- Specified by:
clearValue
in interfaceValueModel<T extends Constraints>
- See Also:
-
resetValue
public void resetValue()Resets the value to a default value, which may be invalid according to any installed validators. No validation occurs.This version resets the cached selected index so that it can be recalculated.
- Specified by:
resetValue
in interfaceValueModel<T extends Constraints>
- See Also:
-
getValidator
- Specified by:
getValidator
in interfaceValueModel<T extends Constraints>
- Returns:
- The validator for this model, or
null
if no validator is installed.
-
setValidator
Description copied from interface:ValueModel
Sets the validator. This is a bound property- Specified by:
setValidator
in interfaceValueModel<T extends Constraints>
- Parameters:
newValidator
- The validator for this model, ornull
if no validator should be used.- See Also:
-
isValidValue
public boolean isValidValue()Description copied from interface:ValueModel
Determines whether the value of this model is valid.- Specified by:
isValidValue
in interfaceValueModel<T extends Constraints>
- Returns:
- Whether the value of this model is valid.
-
validateValue
Description copied from interface:ValueModel
Validates the value of this model, throwing an exception if the model is not valid.- Specified by:
validateValue
in interfaceValueModel<T extends Constraints>
- Throws:
ValidationException
- if the value of this model is not valid.
-
getValueClass
- Specified by:
getValueClass
in interfaceValueModel<T extends Constraints>
- Returns:
- The class representing the type of value this model can hold.
-