Class AbstractValueLayout<T extends Constraints>

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
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
  • Constructor Details

    • AbstractValueLayout

      public AbstractValueLayout()
      Default constructor.
  • Method Details

    • 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 PropertyVetoException
      Sets the index of the selected component. If the value change is vetoed by the installed validator, the validation exception will be accessible via Throwable.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

      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 interface Layout<T extends Constraints>
      Overrides:
      addComponent in class AbstractLayout<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 interface Layout<T extends Constraints>
      Overrides:
      removeComponent in class AbstractLayout<T extends Constraints>
      Parameters:
      component - The component to remove from the layout.
    • getOwner

      public Container getOwner()
      Specified by:
      getOwner in interface Layout<T extends Constraints>
      Overrides:
      getOwner in class AbstractLayout<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 interface Layout<T extends Constraints>
      Overrides:
      setOwner in class AbstractLayout<T extends Constraints>
      Parameters:
      newOwner - The new layout component for this layout.
    • getDefaultValue

      public Component getDefaultValue()
      Specified by:
      getDefaultValue in interface ValueModel<T extends Constraints>
      Returns:
      The default value.
    • getValue

      public Component getValue()
      Specified by:
      getValue in interface com.globalmentor.model.Valued<T extends Constraints>
      Specified by:
      getValue in interface ValueModel<T extends Constraints>
      Returns:
      The input value, or null if there is no input value.
    • setValue

      public void setValue(Component newValue) throws PropertyVetoException
      Sets the new value. This is a bound property that only fires a change event when the new value is different via the equals() 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 via Throwable.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 interface com.globalmentor.model.MutableValued<T extends Constraints>
      Specified by:
      setValue in interface ValueModel<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 to null, 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 interface ValueModel<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 interface ValueModel<T extends Constraints>
      See Also:
    • getValidator

      public Validator<Component> getValidator()
      Specified by:
      getValidator in interface ValueModel<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 interface ValueModel<T extends Constraints>
      Parameters:
      newValidator - The validator for this model, or null 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 interface ValueModel<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 interface ValueModel<T extends Constraints>
      Throws:
      ValidationException - if the value of this model is not valid.
    • getValueClass

      public Class<Component> getValueClass()
      Specified by:
      getValueClass in interface ValueModel<T extends Constraints>
      Returns:
      The class representing the type of value this model can hold.