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 aContainer
as its owner. The layout maintains its own value model that maintains the current selected component. If a child component implementsActiveable
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
Constructors Constructor Description AbstractValueLayout()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addComponent(Component component)
Lays out the associated layout component.void
clearValue()
Clears the value by setting the value tonull
, which may be invalid according to any installed validators.Component
getDefaultValue()
Container
getOwner()
int
getSelectedIndex()
Validator<Component>
getValidator()
Component
getValue()
java.lang.Class<Component>
getValueClass()
protected ValueModel<Component>
getValueModel()
boolean
isValidValue()
Determines whether the value of this model is valid.void
removeComponent(Component component)
Removes a component from the layout.void
resetValue()
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
setValue(Component newValue)
Sets the new value.void
validateValue()
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
-
-
-
-
Method Detail
-
getValueModel
protected ValueModel<Component> 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
public void setSelectedIndex(int newIndex) throws java.beans.PropertyVetoException
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:
java.lang.IllegalStateException
- if this layout has not yet been installed into a container.java.lang.IndexOutOfBoundsException
- if the index is out of range.java.beans.PropertyVetoException
- if the component at the given index is not a valid compoment to select or the change has otherwise been vetoed.
-
addComponent
public void addComponent(Component component)
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
public void removeComponent(Component component)
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
public Container 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
public void setOwner(LayoutComponent newOwner)
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
public Component getDefaultValue()
- Specified by:
getDefaultValue
in interfaceValueModel<T extends Constraints>
- Returns:
- The default value.
-
getValue
public Component 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
public void setValue(Component newValue) throws java.beans.PropertyVetoException
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:
java.beans.PropertyVetoException
- if the provided value is not valid or the change has otherwise been vetoed.- See Also:
ValueModel.getValidator()
,ValueModel.VALUE_PROPERTY
-
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:
ValueModel.VALUE_PROPERTY
-
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:
ValueModel.VALUE_PROPERTY
-
getValidator
public Validator<Component> getValidator()
- Specified by:
getValidator
in interfaceValueModel<T extends Constraints>
- Returns:
- The validator for this model, or
null
if no validator is installed.
-
setValidator
public void setValidator(Validator<Component> newValidator)
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:
ValueModel.VALIDATOR_PROPERTY
-
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
public void validateValue() throws ValidationException
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
public java.lang.Class<Component> getValueClass()
- Specified by:
getValueClass
in interfaceValueModel<T extends Constraints>
- Returns:
- The class representing the type of value this model can hold.
-
-