bibliothek.gui.dock.action.view
Class ActionViewConverter

java.lang.Object
  extended by bibliothek.gui.dock.action.view.ActionViewConverter

public class ActionViewConverter
extends java.lang.Object

The ActionViewConverter transforms DockActions into views like buttons or menu-items.
Every application has a set DockActions. In order to create a view for an action, the ActionType of the DockAction must be known. The ActionType tells how the action normally behaves. Some types are already defined, for example the ActionType.BUTTON behaves like a button: once the action is triggered, it does something, and later the action can be triggered again. There are several DockActions which act like a button, but their internal organization differs a lot.
On the other hand, every application has a set of platforms which want to display a DockAction. A platform might be a popup-menu, or one of the many DockTitles. Since some platforms need the same visualization of DockActions (i.e. a popup-menu and a normal menu both need menu-items), the platforms are grouped. Every group is identified by a ViewTarget. There are already some ViewTargets defined, i.e. the ViewTarget.TITLE is used for the group of DockTitles.
The ActionViewConverter must known how to create a view for all possible pairs of ActionTypes and ViewTargets. In order to do so, he has a set of ViewGenerators. Each ViewGenerator is used to handle one pair of ActionType and ViewTarget.
The ActionViewConverter has three slots for each pair. There can be a ViewGenerator in every slot. The slots have different priority and meaning. Whenever a ViewGenerator for a pair is needed, the slots are searched for the first non-null value with the highest priority. The meaning of the three slots are:


Note: if a client creates new ActionTypes or new ViewTargets, he has to provide the ViewGenerators for all new possible pairs. That includes pairs where one partner is a predefined ActionType or ViewTarget.

Author:
Benjamin Sigg

Constructor Summary
ActionViewConverter()
          Creates a new ActionViewConverter
 
Method Summary
<A,D extends DockAction>
A
createView(ActionType<D> type, D action, ViewTarget<A> target, Dockable dockable)
          Creates and sets up a new view.
<A> A
createView(DockAction action, ViewTarget<A> target, Dockable dockable)
          Creates and sets up a new view.
protected
<A,D extends DockAction>
ViewGenerator<D,A>
getConverter(ActionType<D> action, ViewTarget<? super A> target)
          Searches a converter for the given action and target.
<A,D extends DockAction>
void
putClient(ActionType<D> action, ViewTarget<A> target, ViewGenerator<D,A> generator)
          Registers a new ViewGenerator to this ActionViewConverter.
<A,D extends DockAction>
void
putDefault(ActionType<D> action, ViewTarget<A> target, ViewGenerator<D,A> generator)
          Registers a new ViewGenerator to this ActionViewConverter.
<A,D extends DockAction>
void
putTheme(ActionType<D> action, ViewTarget<A> target, ViewGenerator<D,A> generator)
          Registers a new ViewGenerator to this ActionViewConverter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionViewConverter

public ActionViewConverter()
Creates a new ActionViewConverter

Method Detail

putClient

public <A,D extends DockAction> void putClient(ActionType<D> action,
                                               ViewTarget<A> target,
                                               ViewGenerator<D,A> generator)
Registers a new ViewGenerator to this ActionViewConverter. The generator will have the high priority.

Type Parameters:
A - the type of view created by the converter
D - the type of action needed as input for the converter
Parameters:
action - the type of actions needed as input
target - the platform for which converter creates output
generator - the generator to store, may be null

putTheme

public <A,D extends DockAction> void putTheme(ActionType<D> action,
                                              ViewTarget<A> target,
                                              ViewGenerator<D,A> generator)
Registers a new ViewGenerator to this ActionViewConverter. The generator will have the normal priority.

Type Parameters:
A - the type of view created by the converter
D - the type of action needed as input for the converter
Parameters:
action - the type of actions needed as input
target - the platform for which converter creates output
generator - the generator to store, may be null

putDefault

public <A,D extends DockAction> void putDefault(ActionType<D> action,
                                                ViewTarget<A> target,
                                                ViewGenerator<D,A> generator)
Registers a new ViewGenerator to this ActionViewConverter. The generator will have the low priority.

Type Parameters:
A - the type of view created by the converter
D - the type of action needed as input for the converter
Parameters:
action - the type of actions needed as input
target - the platform for which converter creates output
generator - the generator to store, may be null

createView

public <A> A createView(DockAction action,
                        ViewTarget<A> target,
                        Dockable dockable)
Creates and sets up a new view. This method does nothing more than calling the method createView of DockAction.

Type Parameters:
A - the type of the view
Parameters:
action - the action for which a view is created
target - the target platform, where the view will be shown
dockable - the Dockable for which the action is used
Returns:
the new view or null if nothing should be shown
Throws:
java.lang.IllegalArgumentException - if an unknown argument is used

createView

public <A,D extends DockAction> A createView(ActionType<D> type,
                                             D action,
                                             ViewTarget<A> target,
                                             Dockable dockable)
Creates and sets up a new view.

Type Parameters:
A - the type of the view
D - the type of action to convert
Parameters:
type - the type of action
action - the action for which a view is created
target - the target platform, where the view will be shown
dockable - the Dockable for which the action is used
Returns:
the new view or null if nothing should be shown
Throws:
java.lang.IllegalArgumentException - if an unknown argument is used

getConverter

protected <A,D extends DockAction> ViewGenerator<D,A> getConverter(ActionType<D> action,
                                                                   ViewTarget<? super A> target)
Searches a converter for the given action and target.

Type Parameters:
A - the type that the converter will produce
D - the type of action needed as input
Parameters:
action - the action that will be transformed
target - the target platform
Returns:
the converter or null if no converter is found