de.cau.cs.kieler.kiml.ui.layout
Class DiagramLayoutManager

java.lang.Object
  extended by de.cau.cs.kieler.kiml.ui.layout.DiagramLayoutManager
Direct Known Subclasses:
GmfDiagramLayoutManager

public abstract class DiagramLayoutManager
extends Object

Abstract superclass for managers of diagram layout. Contains static methods to layout a specific diagram, and manages selection of an appropriate subclass to translate the diagram into the internal KGraph structure.

Rating proposed yellow
(2009-12-11) msp

Field Summary
static int MAX_PROGRESS_LEVELS
          maximal number of recursion levels for which progress is displayed.
 
Constructor Summary
DiagramLayoutManager()
           
 
Method Summary
protected abstract  void applyLayout()
          Applies the transferred layout to the original diagram.
protected abstract  KNode buildLayoutGraph(IEditorPart editorPart, EditPart editPart, boolean layoutAncestors)
          Builds a KGraph instance for the given editor or edit part.
static CachedLayout cacheLayout(IEditorPart editorPart, EditPart editPart, boolean animate, boolean progressBar)
          Performs layout on the given editor by choosing an appropriate layout manager instance and caches the layout result.
static int calcAnimationTime(int graphSize)
          Calculates animation time for the given graph size.
 void doLayout(IEditorPart editorPart, EditPart editPart, boolean animate, boolean progressBar, boolean layoutAncestors, boolean cacheLayout)
          Performs layout on the given editor or edit part using this layout manager.
protected abstract  CachedLayout getCachedLayout()
          Returns the cached layout for the last layout run.
protected abstract  KNode getLayoutGraph()
          Returns the last built layout graph.
static void layout(IEditorPart editorPart, EditPart editPart, boolean animate, boolean progressBar)
          Performs layout on the given editor by choosing an appropriate layout manager instance.
static void layout(IEditorPart editorPart, EditPart editPart, boolean animate, boolean progressBar, boolean layoutAncestors)
          Performs layout on the given editor by choosing an appropriate layout manager instance.
static void registerManager(DiagramLayoutManager manager)
          Registers the given diagram layout manager.
protected abstract  boolean supports(EditPart editPart)
          Determines whether this layout manager is able to perform layout for the given edit part.
protected abstract  boolean supports(IEditorPart editorPart)
          Determines whether this layout manager is able to perform layout for the given editor.
protected abstract  void transferLayout(boolean cacheLayout)
          Transfers all layout data from the last created KGraph instance to the original diagram.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PROGRESS_LEVELS

public static final int MAX_PROGRESS_LEVELS
maximal number of recursion levels for which progress is displayed.

See Also:
Constant Field Values
Constructor Detail

DiagramLayoutManager

public DiagramLayoutManager()
Method Detail

registerManager

public static final void registerManager(DiagramLayoutManager manager)
Registers the given diagram layout manager.

Parameters:
manager - an instance of a diagram layout manager

layout

public static final void layout(IEditorPart editorPart,
                                EditPart editPart,
                                boolean animate,
                                boolean progressBar)
Performs layout on the given editor by choosing an appropriate layout manager instance. Animation and a progress bar can be optionally turned on.

Parameters:
editorPart - the editor for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
animate - if true, Draw2D animation is activated
progressBar - if true, a progress bar is displayed

layout

public static final void layout(IEditorPart editorPart,
                                EditPart editPart,
                                boolean animate,
                                boolean progressBar,
                                boolean layoutAncestors)
Performs layout on the given editor by choosing an appropriate layout manager instance. Animation, a progress bar, and layout of ancestors can be optionally turned on.

Parameters:
editorPart - the editor for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
animate - if true, Draw2D animation is activated
progressBar - if true, a progress bar is displayed
layoutAncestors - if true, layout is not only performed for the selected edit part, but also for its ancestors

cacheLayout

public static final CachedLayout cacheLayout(IEditorPart editorPart,
                                             EditPart editPart,
                                             boolean animate,
                                             boolean progressBar)
Performs layout on the given editor by choosing an appropriate layout manager instance and caches the layout result. Animation and a progress bar can be optionally turned on.

Parameters:
editorPart - the editor for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
animate - if true, Draw2D animation is activated
progressBar - if true, a progress bar is displayed
Returns:
the cached layout result

doLayout

public final void doLayout(IEditorPart editorPart,
                           EditPart editPart,
                           boolean animate,
                           boolean progressBar,
                           boolean layoutAncestors,
                           boolean cacheLayout)
Performs layout on the given editor or edit part using this layout manager. A progress bar indicating progress of the layout algorithm is optionally shown to the user.

Parameters:
editorPart - the editor for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
animate - if true, Draw2D animation is activated
progressBar - if true, a progress bar is displayed
layoutAncestors - if true, layout is not only performed for the selected edit part, but also for its ancestors
cacheLayout - if true, the layout result is cached for the underlying model

calcAnimationTime

public static int calcAnimationTime(int graphSize)
Calculates animation time for the given graph size.

Parameters:
graphSize - total number of nodes in the graph
Returns:
number of milliseconds to animate

supports

protected abstract boolean supports(IEditorPart editorPart)
Determines whether this layout manager is able to perform layout for the given editor.

Parameters:
editorPart - an editor part
Returns:
true if this layout manager supports the editor part

supports

protected abstract boolean supports(EditPart editPart)
Determines whether this layout manager is able to perform layout for the given edit part.

Parameters:
editPart - an edit part
Returns:
true if this layout manager supports the edit part

buildLayoutGraph

protected abstract KNode buildLayoutGraph(IEditorPart editorPart,
                                          EditPart editPart,
                                          boolean layoutAncestors)
Builds a KGraph instance for the given editor or edit part. The resulting layout graph should reflect the structure of edit parts in the original diagram.

Parameters:
editorPart - the editor for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
layoutAncestors - if true, layout is not only performed for the selected edit part, but also for its ancestors
Returns:
a layout graph instance

transferLayout

protected abstract void transferLayout(boolean cacheLayout)
Transfers all layout data from the last created KGraph instance to the original diagram. The diagram is not modified yet, but all required preparations are performed.

Parameters:
cacheLayout - if true, the layout result is cached for the underlying model

applyLayout

protected abstract void applyLayout()
Applies the transferred layout to the original diagram. This final step is where the actual change to the diagram is done.


getLayoutGraph

protected abstract KNode getLayoutGraph()
Returns the last built layout graph.

Returns:
the last built layout graph

getCachedLayout

protected abstract CachedLayout getCachedLayout()
Returns the cached layout for the last layout run.

Returns:
the last cached layout