bibliothek.gui.dock.facile.mode
Class LocationModeManager<M extends LocationMode>

java.lang.Object
  extended by bibliothek.gui.dock.support.mode.ModeManager<Location,M>
      extended by bibliothek.gui.dock.facile.mode.LocationModeManager<M>
Type Parameters:
M - the kind of mode this manager handles
Direct Known Subclasses:
CLocationModeManager

public class LocationModeManager<M extends LocationMode>
extends ModeManager<Location,M>

ModeManager for the location of a Dockable. This manager is able to work together with CControl or together with DockController. Clients using it together with a DockController need to set icons for the modes manually, they can use the IconManager and the keys provided in each mode (e.g. NormalMode.ICON_IDENTIFIER).

Author:
Benjamin Sigg

Field Summary
static PropertyKey<DoubleClickLocationStrategy> DOUBLE_CLICK_STRATEGY
          PropertyKey for the DoubleClickLocationStrategy that should be used to change the ExtendedMode of an element which has been double-clicked.
static PropertyKey<ExtendedModeEnablementFactory> MODE_ENABLEMENT
          PropertyKey for the ExtendedModeEnablement that should be used by a LocationModeManager to activate and deactivate the modes.
 
Constructor Summary
LocationModeManager(DockController controller)
          Creates a new manager.
 
Method Summary
 void addListener(Path identifier, LocationModeListener listener)
          Adds a listener to the mode with unique identifier identifier.
 void apply(Dockable dockable, ExtendedMode extendedMode, CGroupMovement action)
          Executes action in a transaction assuming that the result of this action will lead to dockable having the new mode extendedMode.
protected  void applyDuringRead(java.lang.String key, Path old, Path current, Dockable dockable)
          Ignores the call, the position of Dockables is set elsewhere.
 void destroy()
          Unregisters listeners which this manager added to the DockController and other components.
 void ensureNotHidden(Dockable dockable)
          Ensures that dockable is not hidden behind another Dockable.
 void ensureValidLocation(Dockable dockable)
          Empty method evaluating the correct location of a Dockable.
 CGroupMovement getCurrentAction()
          Gets the action that is currently carried out.
 M getCurrentMode(Dockable dockable)
          Tries to find the mode dockable is currently in.
 DoubleClickLocationStrategy getDoubleClickStrategy()
          Gets the current strategy for handing double-clicks.
 CGroupBehavior getGroupBehavior()
          Gets the current group behavior.
 ExtendedMode getMode(Dockable dockable)
          Gets the current mode of dockable.
 java.util.Map<ExtendedMode,DockStation> getRepresentations(java.lang.String id)
          Checks all LocationModes of this manager and returns all DockStations that were registered with the given id.
 DockActionSource getSharedActions(DockStation station)
          Gets a list of actions that should be shown on station depending on the current children of station.
 boolean isLayouting()
          Tells whether this mode is currently in layouting mode.
 boolean isModeAvailable(Dockable dockable, ExtendedMode mode)
          Using the current ExtendedModeEnablement this method tells whether mode mode can be applied to dockable.
 void removeListener(Path identifier, LocationModeListener listener)
          Removes a listener from the mode identifier.
 void runLayoutTransaction(java.lang.Runnable run)
          Activates the layout mode while run is running.
 void setDoubleClickStrategy(DoubleClickLocationStrategy strategy)
          Sets the current strategy for handling double-clicks on Dockables.
 void setGroupBehavior(CGroupBehavior behavior)
          Sets the group behavior.
 void setMode(Dockable dockable, ExtendedMode extendedMode)
          Sets the current mode of dockable.
protected  void updateEnablement()
          Updates the current ExtendedModeEnablement using the factory provided by MODE_ENABLEMENT.
 
Methods inherited from class bibliothek.gui.dock.support.mode.ModeManager
add, addAffected, addEmpty, addModeManagerListener, apply, apply, apply, apply, apply, apply, createEntryDuringRead, createModeSettings, createSettings, fireAdded, fireAdded, fireModeChanged, fireRemoved, fireRemoved, getController, getDefaultMode, getDoubleClickTarget, getFactories, getHistory, getKey, getMode, getModeHistory, getPreviousMode, getProperties, getPropertyHistory, isEmpty, isOnContinuous, isOnTransaction, isRegistered, listDockables, listeners, modes, put, putFactory, putMode, readSettings, readSettings, rebuild, rebuildAll, reduceToEmpty, refresh, refresh, remove, removeEmpty, removeMode, removeModeManagerListener, runTransaction, runTransaction, runTransaction, runTransaction, setProperties, store, store, toString, writeSettings
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODE_ENABLEMENT

public static final PropertyKey<ExtendedModeEnablementFactory> MODE_ENABLEMENT
PropertyKey for the ExtendedModeEnablement that should be used by a LocationModeManager to activate and deactivate the modes.


DOUBLE_CLICK_STRATEGY

public static final PropertyKey<DoubleClickLocationStrategy> DOUBLE_CLICK_STRATEGY
PropertyKey for the DoubleClickLocationStrategy that should be used to change the ExtendedMode of an element which has been double-clicked.

Constructor Detail

LocationModeManager

public LocationModeManager(DockController controller)
Creates a new manager.

Parameters:
controller - the controller in whose realm this manager will work
Method Detail

destroy

public void destroy()
Description copied from class: ModeManager
Unregisters listeners which this manager added to the DockController and other components.

Overrides:
destroy in class ModeManager<Location,M extends LocationMode>

updateEnablement

protected void updateEnablement()
Updates the current ExtendedModeEnablement using the factory provided by MODE_ENABLEMENT.


setGroupBehavior

public void setGroupBehavior(CGroupBehavior behavior)
Sets the group behavior. The group behavior is applied if setMode(Dockable, ExtendedMode) is called and modifies the call such that another Dockable receives the event. Any call directly to any of the apply methods will not be modified by the group behavior.

Parameters:
behavior - the new behavior, not null

getGroupBehavior

public CGroupBehavior getGroupBehavior()
Gets the current group behavior.

Returns:
the current behavior, not null
See Also:
setGroupBehavior(CGroupBehavior)

setMode

public void setMode(Dockable dockable,
                    ExtendedMode extendedMode)
Sets the current mode of dockable.

Parameters:
dockable - the dockable whose mode is to be set
extendedMode - the mode
Throws:
java.lang.IllegalArgumentException - if extendedMode is unknown

getCurrentAction

public CGroupMovement getCurrentAction()
Gets the action that is currently carried out.

Returns:
the current action, can be null

apply

public void apply(Dockable dockable,
                  ExtendedMode extendedMode,
                  CGroupMovement action)
Executes action in a transaction assuming that the result of this action will lead to dockable having the new mode extendedMode.

Parameters:
dockable - the primary Dockable, this item may very well be the new focus owner
extendedMode - the expected mode dockable will have after action completed
action - the action to execute

getMode

public ExtendedMode getMode(Dockable dockable)
Gets the current mode of dockable.

Parameters:
dockable - the element whose mode is searched
Returns:
the mode or null if not found

getRepresentations

public java.util.Map<ExtendedMode,DockStation> getRepresentations(java.lang.String id)
Checks all LocationModes of this manager and returns all DockStations that were registered with the given id. The same station or the same id might be used for different modes.

Parameters:
id - the id of some station
Returns:
each mode-area pair where the area is not null, can be empty

applyDuringRead

protected void applyDuringRead(java.lang.String key,
                               Path old,
                               Path current,
                               Dockable dockable)
Ignores the call, the position of Dockables is set elsewhere.

Specified by:
applyDuringRead in class ModeManager<Location,M extends LocationMode>
Parameters:
key - the identifier of dockable
old - the mode dockable is currently in
current - the mode dockable is going to be
dockable - the element that changes its mode, might be null

isModeAvailable

public boolean isModeAvailable(Dockable dockable,
                               ExtendedMode mode)
Using the current ExtendedModeEnablement this method tells whether mode mode can be applied to dockable.

Parameters:
dockable - some element, not null
mode - some mode, not null
Returns:
the result of ExtendedModeEnablement.isAvailable(Dockable, ExtendedMode)

addListener

public void addListener(Path identifier,
                        LocationModeListener listener)
Adds a listener to the mode with unique identifier identifier. If the mode is exchanged then this listener is automatically removed and may be re-added to the new mode.

Parameters:
identifier - the identifier of some mode (not necessarily registered yet).
listener - the new listener, not null

removeListener

public void removeListener(Path identifier,
                           LocationModeListener listener)
Removes a listener from the mode identifier.

Parameters:
identifier - the name of a mode
listener - the listener to remove

getCurrentMode

public M getCurrentMode(Dockable dockable)
Description copied from class: ModeManager
Tries to find the mode dockable is currently in. This method calls Mode.isCurrentMode(Dockable) and returns the first Mode where the answer was true.

Overrides:
getCurrentMode in class ModeManager<Location,M extends LocationMode>
Parameters:
dockable - some dockable, not null
Returns:
the current mode or null if not found

getDoubleClickStrategy

public DoubleClickLocationStrategy getDoubleClickStrategy()
Gets the current strategy for handing double-clicks.

Returns:
the strategy, never null
See Also:
setDoubleClickStrategy(DoubleClickLocationStrategy)

setDoubleClickStrategy

public void setDoubleClickStrategy(DoubleClickLocationStrategy strategy)
Sets the current strategy for handling double-clicks on Dockables. This strategy will be asked what mode to assign to an element that has been double-clicked. Results that are not allowed by the current ExtendedModeEnablement are ignored.

Parameters:
strategy - the new strategy, can be null to set the default strategy

isLayouting

public boolean isLayouting()
Tells whether this mode is currently in layouting mode. Some methods of this manager do not react while in layouting mode.

Returns:
true if layouting mode is active

runLayoutTransaction

public void runLayoutTransaction(java.lang.Runnable run)
Activates the layout mode while run is running.

Parameters:
run - some code to execute

ensureNotHidden

public void ensureNotHidden(Dockable dockable)
Ensures that dockable is not hidden behind another Dockable. That does not mean that dockable becomes visible, just that it is easier reachable without the need to change modes of any Dockables.
This method returns immediatelly if in layouting mode

Parameters:
dockable - the element which should not be hidden

ensureValidLocation

public void ensureValidLocation(Dockable dockable)
Empty method evaluating the correct location of a Dockable. To be overridden by subclasses to handle elements which have additional restrictions.

Parameters:
dockable - the element to check

getSharedActions

public DockActionSource getSharedActions(DockStation station)
Description copied from class: ModeManager
Gets a list of actions that should be shown on station depending on the current children of station. This method is called everytime when either a child is added, removed or selected on station.

Specified by:
getSharedActions in class ModeManager<Location,M extends LocationMode>
Parameters:
station - the station whose actions are asked
Returns:
the actions, can be null