bibliothek.gui.dock.support.action
Class ModeTransitionManager<A>

java.lang.Object
  extended by bibliothek.gui.dock.support.action.ModeTransitionManager<A>
Type Parameters:
A - the type of properties that has to be stored for every dockable-mode relation
All Implemented Interfaces:
ActionGuard
Direct Known Subclasses:
StateManager

public abstract class ModeTransitionManager<A>
extends Object
implements ActionGuard

A set of modes. Adds some ButtonDockActions to Dockables, and when the user clicks on one of these actions, then the Dockable goes into another mode.
Subclasses can assign some properties that connect mode and Dockable.
This class is an ActionGuard and will only have an influence if it is added to the DockController through DockController.addActionGuard(ActionGuard)

Author:
Benjamin Sigg

Constructor Summary
ModeTransitionManager(String... modes)
          Creates a new manager
 
Method Summary
 void add(String name, Dockable dockable)
          Makes an entry for dockable and adds actions to its global DockActionSource.
protected abstract  String[] availableModes(String current, Dockable dockable)
          Makes a list of all modes dockable can be going into.
protected
<B> ModeTransitionSetting<A,B>
createSetting(ModeTransitionConverter<A,B> converter)
          Creates a new, empty setting.
protected abstract  String currentMode(Dockable dockable)
          Gets the mode dockable is currently into.
protected abstract  String getDefaultMode(Dockable dockable)
          Gets the mode dockable should be go to if no other mode is preferred.
 List<Dockable> getDockables()
          Gets a list that contains all Dockables that are currently known to this manager.
 SimpleButtonAction getIngoingAction(String mode)
          Gets the action that is displayed on Dockables which might go into the mode mode.
 String getName(Dockable dockable)
          Searches the name of dockable.
 SimpleButtonAction getOutgoingAction(String mode)
          Gets the action that is displayed on Dockables which are currently in the mode mode.
protected  A getProperties(String mode, Dockable dockable)
          Gets the properties which correspond to dockable and mode.
<B> ModeTransitionSetting<A,B>
getSetting(ModeTransitionConverter<A,B> converter)
          Gets the current set or properties.
 DockActionSource getSource(Dockable dockable)
          Gets a list of actions for the Dockable
protected  void goIn(String mode, Dockable dockable)
          Called when the button to go into mode is pressed.
protected  void goOut(String mode, Dockable dockable)
          Called when the button to go out of mode is pressed.
protected  String[] history(Dockable dockable)
          Gets the history of modes dockable was into.
protected  String previousMode(Dockable dockable)
          Gets the mode in which Dockable was previously
 void put(String name, Dockable dockable)
          Ensures that dockable is registered under name and that dockable has an entry.
protected  void putIngoingAction(String mode, SimpleButtonAction action)
          Sets the action that is displayed on Dockables which might go into the mode mode.
protected  void putMode(Dockable dockable, String mode)
          Stores mode as new mode of dockable, put does not call transition(String, String, Dockable).
protected  void putOutgoingAction(String mode, SimpleButtonAction action)
          Sets the action that is displayed on Dockables which might go out of the mode mode.
 boolean react(Dockable dockable)
          Tests the given Dockable and tells whether this ActionGuard is interested in it and wants to add some additional actions to it, or if this guard is not made for the dockable.
<B> void
read(ModeTransitionConverter<A,B> converter, DataInputStream in)
          Reads the properties of this manager.
protected  void rebuild(Dockable dockable)
          Called when the list of actions for dockable has to be rebuild.
protected  void rebuildAll()
          Called when the list of actions has to be rebuilt for each Dockable.
 void remove(Dockable dockable)
          Removes the properties that belong to dockable.
 void setMode(Dockable dockable, String mode)
          Sets the mode of dockable to mode.
protected  void setProperties(String mode, Dockable dockable, A properties)
          Sets the properties which correspond to dockable and mode.
 void setSetting(ModeTransitionSetting<A,?> setting)
          Sets all properties of this manager.
protected abstract  void transition(String oldMode, String newMode, Dockable dockable)
          Called when a Dockable has to change from one mode to another mode.
Subclasses might use getProperties(String, Dockable) and setProperties(String, Dockable, Object) to get or store properties associated with the mode.
protected abstract  void transitionDuringRead(String oldMode, String newMode, Dockable dockable)
          Called while reading modes in setSetting(ModeTransitionSetting).
<B> void
write(ModeTransitionConverter<A,B> converter, DataOutputStream out)
          Writes the properties of this manager into out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModeTransitionManager

public ModeTransitionManager(String... modes)
Creates a new manager

Parameters:
modes - the list of modes in which a Dockable might go into
Method Detail

react

public boolean react(Dockable dockable)
Description copied from interface: ActionGuard
Tests the given Dockable and tells whether this ActionGuard is interested in it and wants to add some additional actions to it, or if this guard is not made for the dockable.

Specified by:
react in interface ActionGuard
Parameters:
dockable - The Dockable to test
Returns:
true if the ActionGuard.getSource(Dockable)-method should be invoked, false otherwise

getSource

public DockActionSource getSource(Dockable dockable)
Description copied from interface: ActionGuard
Gets a list of actions for the Dockable

Specified by:
getSource in interface ActionGuard
Parameters:
dockable - The Dockable for which ActionGuard.react(Dockable) is true
Returns:
The actions which shall be used together with the dockable.

add

public void add(String name,
                Dockable dockable)
Makes an entry for dockable and adds actions to its global DockActionSource.

Parameters:
name - a unique name for dockable
dockable - the element to add

put

public void put(String name,
                Dockable dockable)
Ensures that dockable is registered under name and that dockable has an entry. If there is already a Dockable known under name, then this other Dockable is replaced by dockable.

Parameters:
name - the name of dockable
dockable - the new Dockable

remove

public void remove(Dockable dockable)
Removes the properties that belong to dockable.

Parameters:
dockable - the element to remove

getDockables

public List<Dockable> getDockables()
Gets a list that contains all Dockables that are currently known to this manager.

Returns:
the list of known Dockables, the list can be modified without disturbing this manager.

getName

public String getName(Dockable dockable)
Searches the name of dockable.

Parameters:
dockable - an element whose name is searched
Returns:
the name or null

getOutgoingAction

public SimpleButtonAction getOutgoingAction(String mode)
Gets the action that is displayed on Dockables which are currently in the mode mode.

Parameters:
mode - the mode whose outgoing action is searched
Returns:
the action or null if mode is unknown

putOutgoingAction

protected void putOutgoingAction(String mode,
                                 SimpleButtonAction action)
Sets the action that is displayed on Dockables which might go out of the mode mode.

Parameters:
mode - some mode whose action should be exchanged
action - the new action, can be null
Throws:
IllegalArgumentException - if mode is unknown

getIngoingAction

public SimpleButtonAction getIngoingAction(String mode)
Gets the action that is displayed on Dockables which might go into the mode mode.

Parameters:
mode - the mode whose ingoing action is searched
Returns:
the action or null if mode is unknown

putIngoingAction

protected void putIngoingAction(String mode,
                                SimpleButtonAction action)
Sets the action that is displayed on Dockables which might go into the mode mode.

Parameters:
mode - some mode whose action should be exchanged
action - the new action, can be null
Throws:
IllegalArgumentException - if mode is unknown

currentMode

protected abstract String currentMode(Dockable dockable)
Gets the mode dockable is currently into. This method must also work if dockable is not registered at this ModeTransitionManager.

Parameters:
dockable - the element whose mode is searched
Returns:
the current mode in dockable is, null is not valid.

availableModes

protected abstract String[] availableModes(String current,
                                           Dockable dockable)
Makes a list of all modes dockable can be going into.

Parameters:
current - the mode dockable is currently in
dockable - the element whose available modes are searched
Returns:
an ordered list of available modes. If there is a logic for "going of of a mode", then the current mode should be included

getDefaultMode

protected abstract String getDefaultMode(Dockable dockable)
Gets the mode dockable should be go to if no other mode is preferred.

Parameters:
dockable - the element whose default mode is asked
Returns:
the mode

transition

protected abstract void transition(String oldMode,
                                   String newMode,
                                   Dockable dockable)
Called when a Dockable has to change from one mode to another mode.
Subclasses might use getProperties(String, Dockable) and setProperties(String, Dockable, Object) to get or store properties associated with the mode.

Parameters:
oldMode - the mode dockable is currently in
newMode - the mode dockable is going to be
dockable - the element that changes its mode

transitionDuringRead

protected abstract void transitionDuringRead(String oldMode,
                                             String newMode,
                                             Dockable dockable)
Called while reading modes in setSetting(ModeTransitionSetting). Subclasses might change the mode according to newMode.

Parameters:
oldMode - the mode dockable is currently in
newMode - the mode dockable is going to be
dockable - the element that changes its mode

history

protected String[] history(Dockable dockable)
Gets the history of modes dockable was into. The history contains every mode at most once, beginning with oldest mode.

Parameters:
dockable - the element whose history is searched
Returns:
the history or null if dockable is not known. Modifications of the array will not have any sideeffects.

goOut

protected void goOut(String mode,
                     Dockable dockable)
Called when the button to go out of mode is pressed.

Parameters:
mode - the mode to leave
dockable - the affected element

goIn

protected void goIn(String mode,
                    Dockable dockable)
Called when the button to go into mode is pressed.

Parameters:
mode - the mode to go into
dockable - the affected element

setMode

public void setMode(Dockable dockable,
                    String mode)
Sets the mode of dockable to mode.

Parameters:
dockable - the element to set the mode
mode - the new mode of dockable

rebuildAll

protected void rebuildAll()
Called when the list of actions has to be rebuilt for each Dockable.


rebuild

protected void rebuild(Dockable dockable)
Called when the list of actions for dockable has to be rebuild.

Parameters:
dockable - the element whose actions are searched

getProperties

protected A getProperties(String mode,
                          Dockable dockable)
Gets the properties which correspond to dockable and mode.

Parameters:
mode - the first part of the key
dockable - the second part of the key
Returns:
the properties or null

setProperties

protected void setProperties(String mode,
                             Dockable dockable,
                             A properties)
Sets the properties which correspond to dockable and mode. Does nothing if dockable is unknown.

Parameters:
mode - the first part of the key
dockable - the second part of the key
properties - the things to store or null to delete the entry

putMode

protected void putMode(Dockable dockable,
                       String mode)
Stores mode as new mode of dockable, put does not call transition(String, String, Dockable).

Parameters:
dockable - the element whose mode changes
mode - the new mode

previousMode

protected String previousMode(Dockable dockable)
Gets the mode in which Dockable was previously

Parameters:
dockable - the element whose mode is searched
Returns:
the previous more or null

getSetting

public <B> ModeTransitionSetting<A,B> getSetting(ModeTransitionConverter<A,B> converter)
Gets the current set or properties.

Type Parameters:
B - the type of the internal representation of the properties
Parameters:
converter - converts the properties into the internal representation
Returns:
the set of properties

setSetting

public void setSetting(ModeTransitionSetting<A,?> setting)
Sets all properties of this manager. Registered elements which are not present in setting will not be affected by this method.

Parameters:
setting - the set of properties

createSetting

protected <B> ModeTransitionSetting<A,B> createSetting(ModeTransitionConverter<A,B> converter)
Creates a new, empty setting.

Type Parameters:
B - the type of properties stored in the setting
Parameters:
converter - used to convert properties of this manager to the properties of the setting
Returns:
the new setting

write

public <B> void write(ModeTransitionConverter<A,B> converter,
                      DataOutputStream out)
           throws IOException
Writes the properties of this manager into out.

Parameters:
converter - a converter that can write the properties of this manager.
out - the stream to write into
Throws:
IOException - if an I/O-error occurs

read

public <B> void read(ModeTransitionConverter<A,B> converter,
                     DataInputStream in)
          throws IOException
Reads the properties of this manager. This is equivalent then calling:
ModeTransitionSetting setting = createSetting( converter );
 setting.read( in );
 setSetting( setting );

Parameters:
converter - a converter that can read the properties
in - the stream to read from
Throws:
IOException - if the stream can't be read