Class AbstractDiagramLayouter
- java.lang.Object
-
- com.nomagic.magicdraw.uml.symbols.layout.AbstractDiagramLayouter
-
- All Implemented Interfaces:
DiagramLayouter
,java.lang.Cloneable
- Direct Known Subclasses:
AbstractLinkDiagramLayouter
,CircularDiagramLayouter
,HierarchicDiagramLayouter
,OrganicDiagramLayouter
,OrthogonalDiagramLayouter
,TreeDiagramLayouter
@OpenApi public abstract class AbstractDiagramLayouter extends java.lang.Object implements DiagramLayouter, java.lang.Cloneable
Abstract diagram layouter contains post processing, preprocessing and other important methods for layouting diagrams.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
anchoredDefaultPreferred
private PresentationElement
anchoredShape
The shape element that should be anchored while layouting.private com.nomagic.magicdraw.uml.symbols.layout.DiagramLayouterAbortHandler
diagramLayouterAbortHandler
private java.util.Map<java.lang.String,java.lang.Object>
layoutParameters
private java.lang.String
optionId
private java.util.Set<PresentationElement>
selectedElementCache
private static int
SPACE
private static int
SPACEX
private static int
SPACEY
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDiagramLayouter(java.lang.String optionId)
Constructorprotected
AbstractDiagramLayouter(java.lang.String optionId, boolean supportsSubgraph)
Deprecated.supportsSubgraph has no effectprotected
AbstractDiagramLayouter(java.lang.String optionId, boolean nodes, boolean paths)
Constructorprotected
AbstractDiagramLayouter(java.lang.String optionId, boolean nodes, boolean paths, boolean supportsSubgraph)
Deprecated.supportsSubgraph has no effect
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
afterLayout(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, UMLGraph graph, com.nomagic.magicdraw.commands.MacroCommand mc)
private static java.awt.Dimension
calculateFrameLayers(DiagramPresentationElement dpe)
Calculates the amount of pixels diagram frame should be extended regarding elements that are on bottom and right edge.boolean
canLayout(DiagramPresentationElement dpe)
Checks is diagram can be layouterprivate boolean
checkHasSameParent(DiagramPresentationElement dpe)
Checks if selected elements have same parent.protected void
clearOldRectangles(UMLGraph graph)
Clears old rectangles for shapes.AbstractDiagramLayouter
clone()
private static y.base.EdgeList
collectEdgesBySelectedPaths(UMLGraph graph, y.base.EdgeCursor allEdges)
Collects all edges to a edge list whose corresponding path elements are selected in diagram.private static y.base.NodeList
collectNodesBySelectedShapes(UMLGraph graph, y.base.NodeCursor allNodes)
Collects all nodes to a node list whose corresponding shape elements are selected in diagram.protected boolean
containsSelectedFromTheSameParent(DiagramPresentationElement dpe)
Checks if selected elements have the same parent.protected void
createCommands(com.nomagic.magicdraw.commands.MacroCommand mc, UMLGraph graph)
Draws the graph shapes on diagram frameprotected UMLGraph
createGraph(DiagramPresentationElement dpe, boolean useIntegratedLabels)
protected UMLGraph
createGraph(DiagramPresentationElement dpe, AbstractDiagramLayouterOptionsGroup optionsGroup)
Constructs a graph for layoutprotected void
createLayoutParameters()
void
drawLayoutResults(UMLGraph graph)
Draws layout resultsprivate static PresentationElement
getAdjustedParentWhenFindingSameParent(PresentationElement element)
PresentationElement
getAnchoredPresentationElement()
com.nomagic.magicdraw.uml.symbols.layout.DiagramLayouterAbortHandler
getDiagramLayouterAbortHandler()
private static int
getFrameLayerAtEdge(DiagramPresentationElement dpe, int side)
java.lang.Object
getLayoutParameter(java.lang.String key)
protected java.util.List<MessageView>
getMessagesFromPath(PathElement path)
java.lang.String
getOptionsID()
protected java.util.Set<PresentationElement>
getSelected(DiagramPresentationElement diagramView)
Collects a set of selected layoutable presentation elements in a diagramprivate boolean
hasOnlyNonLayoutableSelectedSymbols(DiagramPresentationElement dpe)
Checks if no possible layoutable symbols are among selected symbols(that could be a label, or a swimlane cell etc.)private boolean
internalLayout(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, com.nomagic.magicdraw.commands.MacroCommand mc)
boolean
isTypeSupported(DiagramType type)
Test the given type is supported.boolean
layout(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, com.nomagic.magicdraw.commands.MacroCommand mc)
Layouts diagram.protected abstract boolean
layout(AbstractDiagramLayouterOptionsGroup opt, DiagramPresentationElement dpe, UMLGraph graph)
Layouts a diagramprivate static void
minimiseSwimlaneHeaders(UMLGraph graph, com.nomagic.magicdraw.commands.MacroCommand mc)
Updates swimlane header views.private static void
moveAllToFrame(UMLGraph graph, DiagramPresentationElement diagram, DiagramFrameView diagramFrame)
private static void
moveBBToBB(UMLGraph graph, DiagramPresentationElement diagram)
Calculates the bounding of selected elements, the bounding box of those elements after layout and places the new bounding box at the position (x,y) of the old bounding box.private void
moveToAnchored(UMLGraph graph, com.nomagic.magicdraw.commands.MacroCommand mc, DiagramPresentationElement diagram)
private void
moveToFreeSpace(UMLGraph graph, DiagramPresentationElement diagram)
protected boolean
needPartitionData(DiagramPresentationElement dpe)
protected void
placeLegendAndInfo(DiagramPresentationElement diagram, UMLGraph graph)
Places diagram legends and infos.protected void
postprocessing(UMLGraph graph, com.nomagic.magicdraw.commands.MacroCommand mc)
Does some post processing after layout.protected void
preProcessing(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, com.nomagic.magicdraw.commands.MacroCommand mc)
private void
resetAnchoredShape()
Sets anchored shape element to null.protected void
resizeFrameIfNecessary(DiagramPresentationElement dpe, UMLGraph graph, com.nomagic.magicdraw.commands.MacroCommand mc)
Resizes diagram frame if there are no elements selected.void
setAnchoredPresentationElement(PresentationElement shape, boolean makePreferred)
Sets a shape element that should be anchored to, and saves the set preferred option, so that is can be restored after layout.protected void
setLabelConsiderationMode(AbstractDiagramLayouterOptionsGroup optionsGroup, UMLGraph umlGraph)
void
setLayoutParameter(java.lang.String key, java.lang.Object value)
The need to reset the values back must be taken into consideration if a layouter is reused in few placesprivate void
setupDrawResultAction(UMLGraph graph)
-
-
-
Field Detail
-
SPACE
private static final int SPACE
- See Also:
- Constant Field Values
-
SPACEX
private static final int SPACEX
- See Also:
- Constant Field Values
-
SPACEY
private static final int SPACEY
- See Also:
- Constant Field Values
-
optionId
private final java.lang.String optionId
-
selectedElementCache
@CheckForNull private java.util.Set<PresentationElement> selectedElementCache
-
anchoredShape
@CheckForNull private PresentationElement anchoredShape
The shape element that should be anchored while layouting. This is related to Display Related Elements action.
-
anchoredDefaultPreferred
private boolean anchoredDefaultPreferred
-
diagramLayouterAbortHandler
private com.nomagic.magicdraw.uml.symbols.layout.DiagramLayouterAbortHandler diagramLayouterAbortHandler
-
layoutParameters
private java.util.Map<java.lang.String,java.lang.Object> layoutParameters
-
-
Constructor Detail
-
AbstractDiagramLayouter
@OpenApi protected AbstractDiagramLayouter(java.lang.String optionId, boolean nodes, boolean paths)
Constructor- Parameters:
optionId
- layouter options idnodes
- true if should layout nodespaths
- true if should layout edges
-
AbstractDiagramLayouter
@OpenApi @Deprecated protected AbstractDiagramLayouter(java.lang.String optionId, boolean nodes, boolean paths, boolean supportsSubgraph)
Deprecated.supportsSubgraph has no effect
-
AbstractDiagramLayouter
@OpenApi protected AbstractDiagramLayouter(java.lang.String optionId)
Constructor- Parameters:
optionId
- layouter options id
-
AbstractDiagramLayouter
@OpenApi @Deprecated protected AbstractDiagramLayouter(java.lang.String optionId, boolean supportsSubgraph)
Deprecated.supportsSubgraph has no effect- Parameters:
optionId
- layouter options id
-
-
Method Detail
-
layout
public final boolean layout(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
Description copied from interface:DiagramLayouter
Layouts diagram.- Specified by:
layout
in interfaceDiagramLayouter
- Parameters:
options
- defined layouter optionsdpe
- diagrammc
- macro command to add layouting to- Returns:
- true if layout was a success, false otherwise
-
internalLayout
private boolean internalLayout(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
-
createLayoutParameters
protected void createLayoutParameters()
-
hasOnlyNonLayoutableSelectedSymbols
private boolean hasOnlyNonLayoutableSelectedSymbols(DiagramPresentationElement dpe)
Checks if no possible layoutable symbols are among selected symbols(that could be a label, or a swimlane cell etc.)- Parameters:
dpe
- diagram- Returns:
- true if has layoutable symbols
-
checkHasSameParent
private boolean checkHasSameParent(DiagramPresentationElement dpe)
Checks if selected elements have same parent. Only then they can be layouted.- Parameters:
dpe
- layouted diagram- Returns:
- true if has same parent, false otherwise.
-
setupDrawResultAction
private void setupDrawResultAction(UMLGraph graph)
-
clearOldRectangles
protected void clearOldRectangles(UMLGraph graph)
Clears old rectangles for shapes. The old rectangle is used for link placement in movePath, MoveManager.- Parameters:
graph
- layouted graph
-
minimiseSwimlaneHeaders
private static void minimiseSwimlaneHeaders(UMLGraph graph, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
Updates swimlane header views.
-
createGraph
@OpenApi @Deprecated protected UMLGraph createGraph(DiagramPresentationElement dpe, boolean useIntegratedLabels)
Constructs a graph for layout- Parameters:
dpe
- shapes and edges are taken from this diagram- Returns:
- a created UMLGraph
-
createGraph
@OpenApi protected UMLGraph createGraph(DiagramPresentationElement dpe, AbstractDiagramLayouterOptionsGroup optionsGroup)
Constructs a graph for layout- Parameters:
dpe
- shapes and edges are taken from this diagramoptionsGroup
- layouter options- Returns:
- a created UMLGraph
-
setLabelConsiderationMode
protected void setLabelConsiderationMode(AbstractDiagramLayouterOptionsGroup optionsGroup, UMLGraph umlGraph)
-
containsSelectedFromTheSameParent
protected boolean containsSelectedFromTheSameParent(DiagramPresentationElement dpe)
Checks if selected elements have the same parent. if nothing is selected return true
-
getAdjustedParentWhenFindingSameParent
private static PresentationElement getAdjustedParentWhenFindingSameParent(PresentationElement element)
-
createCommands
protected void createCommands(@CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc, UMLGraph graph)
Draws the graph shapes on diagram frame- Parameters:
mc
- macro command to store commands ingraph
- this graph will be taken as data for elements
-
placeLegendAndInfo
protected void placeLegendAndInfo(DiagramPresentationElement diagram, UMLGraph graph)
Places diagram legends and infos.- Parameters:
diagram
- diagram
-
getMessagesFromPath
protected java.util.List<MessageView> getMessagesFromPath(PathElement path)
-
needPartitionData
protected boolean needPartitionData(DiagramPresentationElement dpe)
- Parameters:
dpe
- diagram
-
postprocessing
protected void postprocessing(UMLGraph graph, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
Does some post processing after layout. Moves the graph, layouts swimlanes.- Parameters:
graph
- the graph data for post processing
-
collectEdgesBySelectedPaths
private static y.base.EdgeList collectEdgesBySelectedPaths(UMLGraph graph, y.base.EdgeCursor allEdges)
Collects all edges to a edge list whose corresponding path elements are selected in diagram.- Parameters:
graph
- current graphallEdges
- edge cursor from graph- Returns:
- a new list of edges
-
collectNodesBySelectedShapes
private static y.base.NodeList collectNodesBySelectedShapes(UMLGraph graph, y.base.NodeCursor allNodes)
Collects all nodes to a node list whose corresponding shape elements are selected in diagram.- Parameters:
graph
- current graphallNodes
- node cursor from graph- Returns:
- a new list of nodes
-
moveAllToFrame
private static void moveAllToFrame(UMLGraph graph, DiagramPresentationElement diagram, @CheckForNull DiagramFrameView diagramFrame)
-
moveToAnchored
private void moveToAnchored(UMLGraph graph, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc, DiagramPresentationElement diagram)
-
moveToFreeSpace
private void moveToFreeSpace(UMLGraph graph, DiagramPresentationElement diagram)
-
moveBBToBB
private static void moveBBToBB(UMLGraph graph, DiagramPresentationElement diagram)
Calculates the bounding of selected elements, the bounding box of those elements after layout and places the new bounding box at the position (x,y) of the old bounding box. This action might(mostly will) move elements , but will be close to the original point.- Parameters:
graph
- the graph where all elements residediagram
- the layouted diagram
-
getSelected
@OpenApi protected java.util.Set<PresentationElement> getSelected(DiagramPresentationElement diagramView)
Collects a set of selected layoutable presentation elements in a diagram- Parameters:
diagramView
- the diagram that elements were selected in- Returns:
- a set of selected layoutable presentation elements in a diagram. Empty if whole diagram is layouted.
-
afterLayout
protected void afterLayout(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, UMLGraph graph, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
-
preProcessing
protected void preProcessing(AbstractDiagramLayouterOptionsGroup options, DiagramPresentationElement dpe, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
-
layout
@OpenApi protected abstract boolean layout(AbstractDiagramLayouterOptionsGroup opt, DiagramPresentationElement dpe, UMLGraph graph)
Layouts a diagram- Parameters:
opt
- layouter optionsdpe
- diagram to layoutgraph
- a constructed graph from the diagram- Returns:
- true if it was layouted successfully , false otherwise.
-
canLayout
public boolean canLayout(DiagramPresentationElement dpe)
Description copied from interface:DiagramLayouter
Checks is diagram can be layouter- Specified by:
canLayout
in interfaceDiagramLayouter
- Parameters:
dpe
- diagram to layout- Returns:
- true if it can be layouted, false otherwise
-
resizeFrameIfNecessary
protected void resizeFrameIfNecessary(DiagramPresentationElement dpe, UMLGraph graph, @CheckForNull com.nomagic.magicdraw.commands.MacroCommand mc)
Resizes diagram frame if there are no elements selected.- Parameters:
dpe
- diagrammc
- macro command
-
calculateFrameLayers
private static java.awt.Dimension calculateFrameLayers(DiagramPresentationElement dpe)
Calculates the amount of pixels diagram frame should be extended regarding elements that are on bottom and right edge.- Returns:
- dimension of maximum width and height for bottom and right side
-
getFrameLayerAtEdge
private static int getFrameLayerAtEdge(DiagramPresentationElement dpe, int side)
-
isTypeSupported
@OpenApi public boolean isTypeSupported(DiagramType type)
Test the given type is supported.- Parameters:
type
- The given type.- Returns:
- true, if diagram type is supported
-
drawLayoutResults
public void drawLayoutResults(UMLGraph graph)
Description copied from interface:DiagramLayouter
Draws layout results- Specified by:
drawLayoutResults
in interfaceDiagramLayouter
- Parameters:
graph
- current graph that is layouted
-
getOptionsID
public java.lang.String getOptionsID()
- Specified by:
getOptionsID
in interfaceDiagramLayouter
- Returns:
- options ID
-
setAnchoredPresentationElement
public void setAnchoredPresentationElement(PresentationElement shape, boolean makePreferred)
Sets a shape element that should be anchored to, and saves the set preferred option, so that is can be restored after layout.- Parameters:
shape
- the shape that should be anchored while layouting.makePreferred
- sets make preferred size option. For related elements should be set to false.
-
resetAnchoredShape
private void resetAnchoredShape()
Sets anchored shape element to null. Sets back the makePreferredSize option to what it was before.
-
getAnchoredPresentationElement
@CheckForNull public PresentationElement getAnchoredPresentationElement()
- Returns:
- the shape that should be anchored and not moved anywhere after layout. Returns null if shape was not set.
-
getDiagramLayouterAbortHandler
public com.nomagic.magicdraw.uml.symbols.layout.DiagramLayouterAbortHandler getDiagramLayouterAbortHandler()
-
setLayoutParameter
public void setLayoutParameter(java.lang.String key, java.lang.Object value)
The need to reset the values back must be taken into consideration if a layouter is reused in few places
-
getLayoutParameter
@CheckForNull public java.lang.Object getLayoutParameter(java.lang.String key)
-
clone
public AbstractDiagramLayouter clone()
- Overrides:
clone
in classjava.lang.Object
-
-