Class AbstractCompositeComponent

All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, io.clogr.Clogged, Component, CompositeComponent, Displayable, InfoModel, LabelModel, Model, PresentationModel, DepictedObject
Direct Known Subclasses:
AbstractMultipleCompositeComponent, AbstractSingleCompositeComponent

public abstract class AbstractCompositeComponent extends AbstractComponent implements CompositeComponent, io.clogr.Clogged
An abstract implementation of a composite component. Every child component must be added or removed using AbstractListCompositeComponent.addComponent(Component) and AbstractLayoutComponent.removeComponent(Component), although other actions may take place. This version listens for the Component.VALID_PROPERTY of each child component and updates the valid status of this component in response. This version listens for child notifications and fires a copy of the NotificationEvent, retaining the original event target. This version listens for child components being added or removed and fires a copy of the ComponentEvent, retaining the original event target.
Author:
Garret Wilson
  • Constructor Details

    • AbstractCompositeComponent

      public AbstractCompositeComponent(InfoModel infoModel)
      Info model constructor.
      Parameters:
      infoModel - The component info model.
      Throws:
      NullPointerException - if the given info model is null.
  • Method Details

    • initializeChildComponent

      protected void initializeChildComponent(Component childComponent)
      Initializes a component to be added as a child component of this composite component. This method should be called for every child component added to this composite component. This version installs a listener for the component's valid status. This version installs a listener to refire copies of notification events. This version installs a listener to refire copies of composite component events. This version loads the preferences of the child component, but not its descendants.
      Parameters:
      childComponent - The component to add to this component.
      See Also:
    • uninitializeChildComponent

      protected void uninitializeChildComponent(Component childComponent)
      Uninitializes a comopnent to be removed as a child comopnent of this composite component. This method should be called for every child component removed from this composite component. This version uninstalls a listener for the component's valid status. This version uninstalls a listener to refire copies of notification events. This version uninstalls a listener to refire copies of composite component events. This version saves any preferences of the child component and any descendants.
      Parameters:
      childComponent - The component to remove from this component.
      See Also:
    • childComponentValidPropertyChanged

      protected void childComponentValidPropertyChanged(Component childComponent, boolean oldValid, boolean newValid)
      Called when the Component.VALID_PROPERTY of a child component changes. Every child version should call this version. This version updates the composite component's valid state by calling AbstractComponent.updateValid().
      Parameters:
      childComponent - The child component the valid property of which changed.
      oldValid - The old valid property.
      newValid - The new valid property.
    • determineValid

      protected boolean determineValid()
      Checks the state of the component for validity. This version returns true.

      This version calls determineChildrenValid().

      Overrides:
      determineValid in class AbstractComponent
      Returns:
      true if the component and all children passes all validity tests, else false.
    • determineChildrenValid

      protected boolean determineChildrenValid()
      Checks the state of child components for validity. This version checks all child components for validity using the current Component.isValid(); child component are not asked to update their valid state. Children that are not visible and/or not displayed are not taken into account.
      Returns:
      true if the relevant children pass all validity tests.
    • validate

      public boolean validate()
      Validates the user input of this component and all child components. The component will be updated with error information.

      This version clears all notifications. This version calls AbstractComponent.updateValid().

      This version first calls validateChildren() so that all children will be validated before checks are performed on this component.

      Specified by:
      validate in interface Component
      Overrides:
      validate in class AbstractComponent
      Returns:
      The current state of Component.isValid() as a convenience.
    • validateChildren

      protected boolean validateChildren()
      Validates the user input of child components. Children that are not visible and/or not displayed are not taken into account.
      Returns:
      true if all child validations return true.
    • resetTheme

      public void resetTheme()
      Resets this object's theme. This method sets to false the state of whether a theme has been applied to this object. This method is called for any child components resetting its own theme. No new theme is actually loaded. There is normally no need to override this method or to call this method directly by applications.

      This version recursively calls the resetTheme() method of all child components before resetting the theme of this component.

      Specified by:
      resetTheme in interface Component
      Overrides:
      resetTheme in class AbstractComponent
      See Also:
    • updateTheme

      public void updateTheme() throws IOException
      Updates this object's theme. This method checks whether a theme has been applied to this object. If a theme has not been applied to this object this method calls Component.applyTheme(). This method is called for any child components before applying the theme to the component itself, to assure that child theme updates have already occurred before theme updates occur for this component. There is normally no need to override this method or to call this method directly by applications.

      This version recursively calls the updateTheme() method of all child components before updating the theme of this component.

      Specified by:
      updateTheme in interface Component
      Overrides:
      updateTheme in class AbstractComponent
      Throws:
      IOException - if there was an error loading or applying a theme.
      See Also:
    • loadPreferences

      public void loadPreferences(boolean includeDescendants) throws IOException
      Loads the preferences for this component and optionally any descendant components. Any preferences returned from Component.getPreferenceProperties() will be loaded automatically.

      This version loads the preferences of child components if descendants should be included.

      Specified by:
      loadPreferences in interface Component
      Overrides:
      loadPreferences in class AbstractComponent
      Parameters:
      includeDescendants - true if preferences of any descendant components should also be loaded, else false.
      Throws:
      IOException - if there is an error loading preferences.
    • savePreferences

      public void savePreferences(boolean includeDescendants) throws IOException
      Saves the preferences for this component and optionally any descendant components. Any preferences returned from Component.getPreferenceProperties() will be saved automatically.

      This version loads the preferences of child components if descendants should be included.

      Specified by:
      savePreferences in interface Component
      Overrides:
      savePreferences in class AbstractComponent
      Parameters:
      includeDescendants - true if preferences of any descendant components should also be saved, else false.
      Throws:
      IOException - if there is an error saving preferences.
    • dispatchInputEvent

      public void dispatchInputEvent(InputEvent inputEvent)
      Description copied from class: AbstractComponent
      Dispatches an input event to this component and all child components, if any. If this is a FocusedInputEvent, the event will be directed towards the branch in which lies the focused component of any InputFocusGroupComponent ancestor of this component (or this component, if it is a focus group). If this is instead a TargetedEvent, the event will be directed towards the branch in which lies the target component of the event. Otherwise, the event will be dispatched to all child components. Only after the event has been dispatched to any children will the event be fired to any event listeners and then passed to the installed input strategy, if any. Once the event is consumed, no further processing takes place.

      This version fires all events that are not consumed.

      Specified by:
      dispatchInputEvent in interface Component
      Overrides:
      dispatchInputEvent in class AbstractComponent
      Parameters:
      inputEvent - The input event to dispatch.
      See Also:
    • dispatchInputEvent

      protected void dispatchInputEvent(InputEvent inputEvent, Component target)
      Dispatches an input event to the specified target child hierarchy. If the given target is not a descendant of this component, or if the target is this component, no action occurs.
      Parameters:
      inputEvent - The input event to dispatch.
      target - The target indicating the child hierarchy to which this event should be directed.
      Throws:
      NullPointerException - if the given event and/or target is null.
      See Also:
    • addCompositeComponentListener

      public void addCompositeComponentListener(CompositeComponentListener compositeComponentListener)
      Description copied from interface: CompositeComponent
      Adds a composite component listener. An event will be fired for each descendant component added or removed, with the event target indicating the parent composite component of the change.
      Specified by:
      addCompositeComponentListener in interface CompositeComponent
      Parameters:
      compositeComponentListener - The composite component listener to add.
    • removeCompositeComponentListener

      public void removeCompositeComponentListener(CompositeComponentListener compositeComponentListener)
      Description copied from interface: CompositeComponent
      Removes a composite component listener. An event will be fired for each descendant component added or removed, with the event target indicating the parent composite component of the change.
      Specified by:
      removeCompositeComponentListener in interface CompositeComponent
      Parameters:
      compositeComponentListener - The composite component listener to remove.
    • fireChildComponentAdded

      protected void fireChildComponentAdded(Component childComponent)
      Fires a component added event to all registered composite component listeners. This method delegates to fireChildComponentAdded(ComponentEvent).
      Parameters:
      childComponent - The child component added.
      See Also:
    • fireChildComponentAdded

      protected void fireChildComponentAdded(ComponentEvent childComponentEvent)
      Fires a given component added event to all registered composite component listeners.
      Parameters:
      childComponentEvent - The child component event to fire.
    • fireChildComponentRemoved

      protected void fireChildComponentRemoved(Component childComponent)
      Fires a component removed event to all registered composite component listeners. This method delegates to fireChildComponentRemoved(ComponentEvent).
      Parameters:
      childComponent - The child component removed.
      See Also:
    • fireChildComponentRemoved

      protected void fireChildComponentRemoved(ComponentEvent childComponentEvent)
      Fires a given component removed event to all registered composite component listeners.
      Parameters:
      childComponentEvent - The child component event to fire.
      See Also: