com.guiseframework.component.layout
Class AbstractValueLayout<T extends Constraints>

java.lang.Object
  extended by com.globalmentor.beans.BoundPropertyObject
      extended by com.guiseframework.event.GuiseBoundPropertyObject
          extended by com.guiseframework.component.layout.AbstractLayout<T>
              extended by com.guiseframework.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, Layout<T>, Model, Valued<Component>, 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 com.guiseframework.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 com.guiseframework.model.ValueModel
VALIDATOR_PROPERTY, VALUE_PROPERTY
 
Fields inherited from interface com.guiseframework.model.Model
PLAIN_TEXT_CONTENT_TYPE, XHTML_CONTENT_TYPE, XHTML_FRAGMENT_CONTENT_TYPE
 
Constructor Summary
AbstractValueLayout()
          Default constructor.
 
Method Summary
 void addComponent(Component component)
          Adds a component to the layout.
 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 container that owns this layout This method is managed by containers, 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 input value.
 void validateValue()
          Validates the value of this model, throwing an exception if the model is not valid.
 
Methods inherited from class com.guiseframework.component.layout.AbstractLayout
componentConstraintsChanged, fireConstraintsPropertyChange, getComponentConstraintsChangeListener, getConstraints, getConstraintsPropertyChangeListener
 
Methods inherited from class com.guiseframework.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 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
 
Methods inherited from interface com.guiseframework.component.layout.Layout
createDefaultConstraints, getConstraintsClass, getSession
 

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)
Adds a component to the layout. Called immediately after a component is added to the associated container. This method is called by the associated container, and should not be called directly by application code. This version selects a component if none is selected. 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.
Throws:
java.lang.IllegalStateException - if this layout has not yet been installed into a container.

removeComponent

public void removeComponent(Component component)
Removes a component from the layout. Called immediately before a component is removed from the associated container. This method is called by the associated container, 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 container that owns this layout, or null if this layout has not been installed into a container.

setOwner

public void setOwner(LayoutComponent newOwner)
Sets the container that owns this layout This method is managed by containers, and normally should not be called by applications. //TODO del A layout cannot be given a container if it is already installed in another container. Once a layout is installed in a container, it cannot be uninstalled. A layout cannot be given a container if it is already installed in another container. A layout cannot be given a container unless that container already recognizes this layout as its layout. If a layout is given the same container 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 container for this layout. //TODO del @exception NullPointerException if the given container is null.
Throws:
java.lang.IllegalStateException - if a different container is provided and this layout already has a container.
java.lang.ClassCastException - if the given layout component is not a Container.
java.lang.IllegalArgumentException - if a different container is provided and the given container does not already recognize this layout as its layout.

getDefaultValue

public Component getDefaultValue()
Specified by:
getDefaultValue in interface ValueModel<Component>
Returns:
The default value.

getValue

public Component getValue()
Specified by:
getValue in interface Valued<Component>
Specified by:
getValue in interface ValueModel<Component>
Returns:
The input value, or null if there is no input value.

setValue

public void setValue(Component newValue)
              throws java.beans.PropertyVetoException
Sets the input 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 Valued<Component>
Specified by:
setValue in interface ValueModel<Component>
Parameters:
newValue - The input value of the model.
Throws:
java.beans.PropertyVetoException - if the provided value is not valid or the change has otherwise been vetoed.
See Also:
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<Component>
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<Component>
See Also:
ValueModel.VALUE_PROPERTY

getValidator

public Validator<Component> getValidator()
Specified by:
getValidator in interface ValueModel<Component>
Returns:
The validator for this model, or null if no validator is installed.

setValidator

public void setValidator(Validator<Component> newValidator)
Sets the validator. This is a bound property

Specified by:
setValidator in interface ValueModel<Component>
Parameters:
newValidator - The validator for this model, or null if no validator should be used.
See Also:
ValueModel.VALIDATOR_PROPERTY

isValidValue

public boolean isValidValue()
Determines whether the value of this model is valid.

Specified by:
isValidValue in interface ValueModel<Component>
Returns:
Whether the value of this model is valid.

validateValue

public void validateValue()
                   throws ValidationException
Validates the value of this model, throwing an exception if the model is not valid.

Specified by:
validateValue in interface ValueModel<Component>
Throws:
ValidationException - if the value of this model is not valid.

getValueClass

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


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.