Class AbstractLocationMode<A extends ModeArea>

java.lang.Object
bibliothek.gui.dock.facile.mode.AbstractLocationMode<A>
Type Parameters:
A - the values managed by this mode
All Implemented Interfaces:
LocationMode, Mode<Location>, Iterable<A>
Direct Known Subclasses:
DefaultLocationMode, MaximizedMode

public abstract class AbstractLocationMode<A extends ModeArea> extends Object implements Iterable<A>, LocationMode
This abstract class offers various properties that may be useful for any implementation of LocationMode. It also allows to store a set of ModeAreas. Basic methods to verify and change the Mode of a Dockable are implemented too.
Author:
Benjamin Sigg
  • Constructor Details

    • AbstractLocationMode

      public AbstractLocationMode()
  • Method Details

    • setActionProvider

      public void setActionProvider(LocationModeActionProvider actionProvider)
      Sets the LocationModeActionProvider for this mode.
      Parameters:
      actionProvider - the provider, not null
      Throws:
      IllegalArgumentException - if actionProvider is null
      IllegalStateException - if there are already Dockables which show actions that are provided by the current LocationModeActionProvider
    • setManager

      public void setManager(LocationModeManager<?> manager)
      Description copied from interface: LocationMode
      Sets the manager which is using this mode.
      Specified by:
      setManager in interface LocationMode
      Parameters:
      manager - the manager or null
    • getManager

      public LocationModeManager<?> getManager()
      Gets the owner of this mode.
      Specified by:
      getManager in interface LocationMode
      Returns:
      the owner, not null
    • setController

      public void setController(DockController controller)
      Description copied from interface: LocationMode
      Connects this mode with a controller. It is up to the mode to add or remove listeners if necessary. This mode should also forward the controller to its ModeAreas.
      Specified by:
      setController in interface LocationMode
      Parameters:
      controller - the new controller or null
    • getController

      public DockController getController()
      Gets the controller in whose realm this mode works.
      Returns:
      the controller or null
    • addLocationModeListener

      public void addLocationModeListener(LocationModeListener listener)
      Description copied from interface: LocationMode
      Adds a listener to this mode. The listener is to be called if apply starts or finishes.
      Specified by:
      addLocationModeListener in interface LocationMode
      Parameters:
      listener - the new listener
    • removeLocationModeListener

      public void removeLocationModeListener(LocationModeListener listener)
      Description copied from interface: LocationMode
      Removes listener from this mode.
      Specified by:
      removeLocationModeListener in interface LocationMode
      Parameters:
      listener - the listener to remove
    • listeners

      protected LocationModeListener[] listeners()
      Gets all the listeners that are currently registered at this mode.
      Returns:
      all the listeners
    • shouldAutoFocus

      public boolean shouldAutoFocus()
      Description copied from interface: LocationMode
      Tells the LocationModeManager whether the focus should be transferred to a Dockable that has this mode.
      Specified by:
      shouldAutoFocus in interface LocationMode
      Returns:
      whether auto-focus should be enabled or not
    • setShouldAutoFocus

      public void setShouldAutoFocus(boolean autoFocus)
      Sets the result of shouldAutoFocus().
      Parameters:
      autoFocus - whether automatic focus transfer to Dockable in this mode should be allowed
    • add

      public void add(A area)
      Adds an area to this mode.
      Parameters:
      area - the new area, not null
    • remove

      public A remove(String key)
      Removes the area with identifier key from this mode.
      Parameters:
      key - the identifier of the area
      Returns:
      the removed area or null
    • iterator

      public Iterator<A> iterator()
      Specified by:
      iterator in interface Iterable<A extends ModeArea>
    • setDefaultArea

      public void setDefaultArea(A defaultArea)
      Sets the default area of this mode. The default area is used when get(Dockable) returns null for some key.
      Parameters:
      defaultArea - the default area, can be null. Must be registered using add(ModeArea) first.
    • getDefaultArea

      public A getDefaultArea()
      Gets the default area of this mode, can be null. The default area is the oldest area that was added to this mode and whose property ModeArea.autoDefaultArea() is true, or the one area set through setDefaultArea(ModeArea).
      Returns:
      the default area
    • get

      public A get(String key)
      Gets the area with the specified id.
      Parameters:
      key - the name of the area
      Returns:
      the area or null
    • getRepresentation

      public DockStation getRepresentation(String uniqueId)
      Description copied from interface: LocationMode
      Gets the one DockStation that is known with the root-id uniqueId. The uniqueId is the same id as used returned by Location.getRoot() of Locations issued by this mode.
      Specified by:
      getRepresentation in interface LocationMode
      Parameters:
      uniqueId - the id of some station
      Returns:
      the station or null
    • getRepresentationIds

      public Set<String> getRepresentationIds()
      Description copied from interface: LocationMode
      Gets all the unique identifiers that will yield a non-null result when calling LocationMode.getRepresentation(String).
      Specified by:
      getRepresentationIds in interface LocationMode
      Returns:
      the ids of all the available DockStations, the result may not be modifiable
    • get

      public A get(Dockable dockable)
      Recursively searches through all stations of dockable until a station is found that is registered at this mode.
      Parameters:
      dockable - the element whose root is searched
      Returns:
      the root or null, never dockable itself
    • get

      public A get(Dockable dockable, boolean locationRoot)
      Recursively searches through all stations of dockable until a station is found that is registered at this mode.
      Parameters:
      dockable - the element whose root is searched
      locationRoot - if true, then only those ModeAreas are returned which are ModeArea.isLocationRoot()
      Returns:
      the root or null, never dockable itself
    • get

      public A get(DockStation station)
      Recursively searches through all areas known to this mode until the mode is found that represents station. If station is a Dockable that its parent station is searched too.
      Parameters:
      station - the station whose area is to be found
      Returns:
      an area for which ModeArea.getStation() equals station, may be null
    • aside

      public Location aside(AsideRequest request, Location location)
      Description copied from interface: LocationMode
      Calls DockStation.aside(AsideRequest) on a station that matches location.
      Specified by:
      aside in interface LocationMode
      Parameters:
      request - the request to forward to a DockStation or to process
      location - the source of the location whose neighbor is searched
      Returns:
      the neighbor or a value of null if the request could not be processed
    • getActionsFor

      public DockActionSource getActionsFor(Dockable dockable, Mode<Location> mode)
      Description copied from interface: Mode
      Gets a DockActionSource which should be shown on dockable which is currently in mode. This method will be called every time when dockable changes its mode.
      Specified by:
      getActionsFor in interface Mode<A extends ModeArea>
      Parameters:
      dockable - some element, not null
      mode - the mode of dockable, not null
      Returns:
      the actions for dockable, can be null
    • isModeAvailable

      protected boolean isModeAvailable(Dockable dockable)
      Tells whether this mode is available for dockable.
      Parameters:
      dockable - some element to check
      Returns:
      true if this mode is available
    • isModeHidden

      protected boolean isModeHidden(Dockable dockable)
      Tells whether this mode is hidden for dockable. If the mode is hidden then the actions of the action provider do not show up.
      Parameters:
      dockable - some element to check
      Returns:
      true if this mode is available
    • isRepresenting

      public boolean isRepresenting(DockStation station)
      Description copied from interface: LocationMode
      Tells whether this mode knows station and represents the mode children of station are in.
      Specified by:
      isRepresenting in interface LocationMode
      Parameters:
      station - the station which is to be tested
      Returns:
      whether this mode is represented by station
    • apply

      public boolean apply(Dockable dockable, Location history, AffectedSet set)
      Description copied from interface: Mode
      Applies this mode to dockable. This method may fail for example because a DockAcceptance does prevent dockable from being moved.
      Specified by:
      apply in interface Mode<A extends ModeArea>
      Parameters:
      dockable - the element whose mode becomes this
      history - history information that was returned by this mode on its last call to Mode.current(Dockable). May be null if this mode was never applied or returns null on Mode.current(Dockable).
      set - this method has to store all Dockables which might have changed their mode in the set.
      Returns:
      true if dockable was successfully moved on its parent or to a new parent, or false if dockable did not change its location
    • runApply

      protected abstract boolean runApply(Dockable dockable, Location history, AffectedSet set)
      Called by apply(Dockable, Location, AffectedSet) after the LocationModeListeners are informed. Applies this mode to dockable.
      Parameters:
      dockable - the element whose mode becomes this
      history - history information that was returned by this mode when calling Mode.current(Dockable) the last time.
      set - this method has to store all Dockables which might have changed their mode in the set.
      Returns:
      true if dockable was moved, false if the method failed to set the location of dockable for any reason
    • createHandle

      protected AbstractLocationMode<A>.DockableHandle createHandle(Dockable dockable)
      Creates a new handle for dockable.
      Parameters:
      dockable - the newly registered element
      Returns:
      the new handle