org.crosswire.common.swing.desktop

## Class AbstractViewLayout

- java.lang.Object
- - org.crosswire.common.swing.desktop.AbstractViewLayout

- All Implemented Interfaces:
    Iterable<Component>, Viewable
  Direct Known Subclasses:
    MDIViewLayout, TDIViewLayout

      public abstract class AbstractViewLayout
      extends Object
      implements Viewable

  Abstract manager of how we layout views.
  Author:
    Joe Walker, DM Smith
  See Also:
    `The GNU General Public License for details.`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static int` | `base` A shared counter for creating unknown titles.
    `private EventListenerList` | `listenerList` The listeners for handling ViewEvent Listeners
    `private static int` | `MAX_TITLE_LEN` The maximum length of a title before it is abbreviated
    `private JPanel` | `panel` The panel into which all components are placed.
    `private List<Component>` | `views` The list of views.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractViewLayout()` This constructor is protected because it only needs to be seen by the sub classes

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addView(Component component)` Add a view to the set.
    `void` | `addViewEventListener(ViewEventListener listener)` Adds a view event listener for notification of any changes to the view.
    `void` | `closeAll()` Close all the views.
    `void` | `closeOthers(Component component)` Close all the views but the one provided.
    `void` | `fireViewRemoved(ViewEvent e)` Notify the listeners that the view has been removed.
    `protected void` | `forceRemoveView(Component component)` Unconditionally remove a view from the set.
    `private String` | `generateTitle()` Generates a generic title
    `protected Object` | `getConstraint()` A constraint that allows the panel to be filled up, stretching horizontally and vertically.
    `protected JPanel` | `getPanel()` All parts are put into a panel.
    `abstract Component` | `getSelected()` Returns the top view.
    `protected String` | `getTitle(Component component)` Get the title from the component, truncating it if necessary.
    `Component` | `getView(int i)` Get the view by position.
    `int` | `getViewCount()` The number of views held by this layout.
    `Collection<Component>` | `getViews()` Get a snapshot of the views as a collection.
    `Iterator<Component>` | `iterator()` Get an iterator of a snapshot of views.
    `void` | `moveTo(AbstractViewLayout other)` Copies all the views from the one layout to the other
    `void` | `removeView(Component component)` Remove a view from the set.
    `void` | `removeViewEventListener(ViewEventListener listener)` Removes a view event listener.
    `abstract void` | `select(Component component)` Find the view and select it.
    `abstract void` | `updateTitle(Component component)` Update the title of the view.
    `void` | `visit(ViewVisitor visitor)` Visit every view in the order that they were added.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### views

          private List<Component> views

      The list of views.

    - #### listenerList

          private EventListenerList listenerList

      The listeners for handling ViewEvent Listeners

    - #### MAX_TITLE_LEN

          private static final int MAX_TITLE_LEN

      The maximum length of a title before it is abbreviated
      See Also:
        Constant Field Values

    - #### base

          private static int base

      A shared counter for creating unknown titles.

    - #### panel

          private JPanel panel

      The panel into which all components are placed.

  - ### Constructor Detail

    - #### AbstractViewLayout

          protected AbstractViewLayout()

      This constructor is protected because it only needs to be seen by the sub classes

  - ### Method Detail

    - #### addView

          public void addView(Component component)

      Add a view to the set.
      Specified by:
        `addView` in interface `Viewable`

    - #### removeView

          public void removeView(Component component)

      Remove a view from the set.
      Specified by:
        `removeView` in interface `Viewable`

    - #### forceRemoveView

          protected void forceRemoveView(Component component)

      Unconditionally remove a view from the set.

    - #### getViews

          public Collection<Component> getViews()

      Get a snapshot of the views as a collection.
      Specified by:
        `getViews` in interface `Viewable`
      Returns:
        the views

    - #### iterator

          public Iterator<Component> iterator()

      Get an iterator of a snapshot of views.
      Specified by:
        `iterator` in interface `Iterable<Component>`
      Returns:
        an iterator over the views.

    - #### moveTo

          public void moveTo(AbstractViewLayout other)

      Copies all the views from the one layout to the other
      Specified by:
        `moveTo` in interface `Viewable`
      Parameters:
        `other` - the other layout

    - #### closeAll

          public void closeAll()

      Close all the views. Note the policy is enforced that one view is kept. This will keep the last one added.
      Specified by:
        `closeAll` in interface `Viewable`

    - #### closeOthers

          public void closeOthers(Component component)

      Close all the views but the one provided.
      Specified by:
        `closeOthers` in interface `Viewable`
      Parameters:
        `component` - the view that is to remain open.

    - #### visit

          public void visit(ViewVisitor visitor)

      Visit every view in the order that they were added.
      Specified by:
        `visit` in interface `Viewable`
      Parameters:
        `visitor` - The visitor for the view

    - #### updateTitle

          public abstract void updateTitle(Component component)

      Update the title of the view. If the component does not implement Titleable, then a generated title will be used.
      Specified by:
        `updateTitle` in interface `Viewable`
      Parameters:
        `component` - the component whose title is to be used

    - #### getSelected

          public abstract Component getSelected()

      Returns the top view. If no view is the top, it returns the first one added.
      Specified by:
        `getSelected` in interface `Viewable`

    - #### select

          public abstract void select(Component component)

      Find the view and select it.
      Specified by:
        `select` in interface `Viewable`
      Parameters:
        `component` -

    - #### getViewCount

          public int getViewCount()

      The number of views held by this layout.
      Specified by:
        `getViewCount` in interface `Viewable`
      Returns:
        the number of views held by this layout

    - #### getView

          public Component getView(int i)

      Get the view by position. Note that adding and removing views changes the indexes of the views. Do not use this for iteration as it is not thread safe.
      Specified by:
        `getView` in interface `Viewable`
      Parameters:
        `i` - the index of the view
      Returns:
        the requested view.

    - #### getTitle

          protected String getTitle(Component component)

      Get the title from the component, truncating it if necessary. If the component does not implement Titleable of if the title is empty, then titles are generated.
      Parameters:
        `component` - from whom the title is gotten
      Returns:
        the title, possibly truncated or generated

    - #### generateTitle

          private String generateTitle()

      Generates a generic title
      Returns:
        the generated title

    - #### getPanel

          protected JPanel getPanel()

      All parts are put into a panel. This prevents the programmer from having to change containers.
      Returns:
        Returns the panel.

    - #### getConstraint

          protected Object getConstraint()

      A constraint that allows the panel to be filled up, stretching horizontally and vertically.
      Returns:
        the constraint

    - #### addViewEventListener

          public void addViewEventListener(ViewEventListener listener)

      Adds a view event listener for notification of any changes to the view.
      Specified by:
        `addViewEventListener` in interface `Viewable`
      Parameters:
        `listener` - the listener

    - #### removeViewEventListener

          public void removeViewEventListener(ViewEventListener listener)

      Removes a view event listener.
      Specified by:
        `removeViewEventListener` in interface `Viewable`
      Parameters:
        `listener` - the listener

    - #### fireViewRemoved

          public void fireViewRemoved(ViewEvent e)

      Notify the listeners that the view has been removed.
      Parameters:
        `e` - the event
      See Also:
        `EventListenerList`