Class AbstractValueLayout<T extends Constraints>

  • 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
    • Field Summary

      • Fields inherited from class com.globalmentor.beans.BoundPropertyObject

        NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
    • 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 to null, 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 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 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 Detail

      • AbstractValueLayout

        public AbstractValueLayout()
        Default constructor.
    • 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 via Throwable.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 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.
      • 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.
      • 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 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 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:
        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 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:
        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 interface ValueModel<T extends Constraints>
        See Also:
        ValueModel.VALUE_PROPERTY
      • 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.