|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.layout.organic.InteractiveOrganicLayouter
public class InteractiveOrganicLayouter
The InteractiveOrganicLayouter is a special organic layouter that offers functionality to change the
laid out graph while the layouter is running.
This layouter may be used in a threaded environment. The read-access getCenter(y.base.Node)
does not have to be synchronized.
The setters (e.g. setCenter(y.base.Node, double, double)
) are scheduled and executed at
a specific point within the life-cycle of the layouter.
If a CopiedLayoutGraph
is being laid out, structural changes (node and edge additions/removals)
in the original graph are automatically scheduled and executed on the copy.
The method addStructureUpdate(Runnable)
may be used to schedule a Runnable that is executed in a
synchronized context and may safely update the structure of the graph.
The layouter can also run in a single-threaded mode that is provided by a
startLayoutSingleThreaded(y.layout.LayoutGraph)
single threaded context}. The InteractiveOrganicLayouter.SingleThreadContext
provides methods to
control layout calculation.
startLayout(y.layout.LayoutGraph)
,
stop()
,
stopAndWait()
,
startLayoutSingleThreaded(y.layout.LayoutGraph)
,
InteractiveOrganicLayouter.SingleThreadContext
Nested Class Summary | |
---|---|
static interface |
InteractiveOrganicLayouter.SingleThreadContext
Context object that provides controls of layout calculation in case the layouter runs single-threaded. |
Field Summary |
---|
Fields inherited from interface y.layout.Layouter |
---|
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES |
Constructor Summary | |
---|---|
InteractiveOrganicLayouter()
Create a new instance of the InteractiveOrganicLayouter. |
Method Summary | |
---|---|
void |
addStructureUpdate(Runnable runnable)
Adds a structural update to the queue. |
boolean |
canLayout(LayoutGraph graph)
Returns whether this layouter can layout the given graph. |
void |
commitPositions()
This method writes the calculated positions (represented by the internal data structure of this layouter) to the LayoutGraph. |
double |
commitPositionsSmoothly(double maxMovement,
double factor)
This method transfers the calculated positions (represented by the internal data structure of this layouter) to the LayoutGraph. |
void |
doLayout(LayoutGraph graph)
Calculates the layout for the graph. |
void |
enableOnlyCore()
Makes sure that the core of this layouter will not use the usual LayoutStage s,
like ComponentLayouter , ParallelEdgeLayouter , etc. |
YPoint |
getCenter(Node node)
Return the actual center of the node |
double |
getCenterX(Node node)
Return the actual center of the node. |
double |
getCenterY(Node node)
Return the actual center of the node. |
long |
getLastWakeupTime()
Returns the time when the last wake-up has occurred |
long |
getMaxTime()
Return the maximal time the layouter will run (in milliseconds). |
OutputRestriction |
getOutputRestriction()
Returns the current OutputRestriction instance set for this instance. |
double |
getQuality()
The quality time ratio set. |
double |
getStress(Node node)
Gets the stress for the given node. |
double |
getWorkingRatio()
Returns the actual working ratio. |
boolean |
isAutomaticStructureUpdateEnabled()
Determines whether this algorithm performs automatic structure updates. |
boolean |
isRunning()
Returns whether the layouter is running at the moment. |
boolean |
isSleeping()
Returns whether the layouter is sleeping. |
boolean |
isStopped()
Returns whether the layouter has been stopped. |
void |
setAutomaticStructureUpdateEnabled(boolean automaticStructureUpdateEnabled)
Determines whether this algorithm performs automatic structure updates. |
void |
setCenter(Node node,
double x,
double y)
Sets the center for the node. |
void |
setCenterX(Node node,
double x)
Sets the center of the node. |
void |
setCenterY(Node node,
double y)
Sets the center of the node. |
void |
setInertia(Node node,
double inertia)
Set the inertia for the node. |
void |
setMaxTime(long maxTime)
Sets the maximal time the layouter will run. |
void |
setOutputRestriction(OutputRestriction restriction)
Sets a restriction on the output generated by this layouter |
void |
setPreferredEdgeLength(double preferredEdgeLength)
Sets the preferred edge length. |
void |
setPreferredEdgeLength(Edge edge,
double newEdgeLength)
Sets the preferred edge length for the given edge. |
void |
setPreferredNodeDistance(double preferredNodeDistance)
Sets the preferred node distance. |
void |
setQuality(double quality)
Sets the quality ratio (value between 0.0 and 1.0) The higher this value is, the better will be the quality for the resulting layout but also the needed time. |
void |
setRadius(Node node,
double radius)
Sets the radius for the given node |
void |
setStress(Node node,
double stress)
Sets the stress for the given node. |
void |
setWorkingRatio(double workingRatio)
Sets the working ratio. |
Thread |
startLayout(LayoutGraph graph)
Calls doLayout(y.layout.LayoutGraph) in a separate, newly started Thread. |
InteractiveOrganicLayouter.SingleThreadContext |
startLayoutSingleThreaded(LayoutGraph graph)
Creates a context object that provides methods to continue and stop
the layout calculation. |
void |
stop()
Stops the layouter. |
void |
stopAndWait()
Stops a previously started layout
Thread and blocks until the layout is completed. |
void |
syncStructure()
This method synchronizes the CopiedLayoutGraph given as parameter to doLayout(y.layout.LayoutGraph) with
the original graph. |
void |
wakeUp()
This method may be called if something has "changed" and the layouter shall restart/continue layout calculation. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public InteractiveOrganicLayouter()
Method Detail |
---|
public void enableOnlyCore()
LayoutStage
s,
like ComponentLayouter
, ParallelEdgeLayouter
, etc.
If you really need this feature, override this method and return silently.
public boolean isAutomaticStructureUpdateEnabled()
true
this algorithm will register a listener
on the graph to be laid out to automatically update internal data structures
as soon as the structure of the original graph changes.
The default is false
.
public void setAutomaticStructureUpdateEnabled(boolean automaticStructureUpdateEnabled)
true
this algorithm will register a listener
on the graph to be laid out to automatically update internal data structures
as soon as the structure of the original graph changes.
The default is false
.
automaticStructureUpdateEnabled
- whether to enable automatic updates.public boolean canLayout(LayoutGraph graph)
canLayout
in interface Layouter
true
if the graph may be laid out, false
otherwise.public void doLayout(LayoutGraph graph)
setAutomaticStructureUpdateEnabled(boolean)
is set to true, structural changes
to the original graph are automatically transferred to the copy.
InteractiveOrganicLayouter layouter = new InteractiveOrganicLayouter(); Graph2D originalGraph = new Graph2D(); CopiedLayoutGraph copy = new CopiedLayoutGraph( originalGraph ); layouter.setAutomaticStructureUpdateEnabled( true ); layouter.doLayout( copy );If an instance of CopiedLayoutGraph is laid out, the setters and getters having a node or edge as parameter may be used with instances from the original graph *or* the copied graph.
stop()
is called.
doLayout
in interface Layouter
graph
- the graph that is laid outstartLayout(y.layout.LayoutGraph)
public Thread startLayout(LayoutGraph graph)
doLayout(y.layout.LayoutGraph)
in a separate, newly started Thread.
graph
- the graph to pass on to doLayout(y.layout.LayoutGraph)
public InteractiveOrganicLayouter.SingleThreadContext startLayoutSingleThreaded(LayoutGraph graph)
continue
and stop
the layout calculation.
Note that simply calling this method will not perform any layout. Repeated calls to InteractiveOrganicLayouter.SingleThreadContext.doLayout(long)
need to be made in order for the layout calculation to be performed.
graph
- the graph that gets layouted.
public void commitPositions()
isRunning()
.
final InteractiveOrganicLayouter layouter = new InteractiveOrganicLayouter(); new Thread( new Runnable() { public void run() { layouter.doLayout( copiedGraph ); } } ).start(); new javax.swing.Timer( 24, new ActionListener() { public void actionPerformed( ActionEvent e ) { layouter.commitPositions(); } } ).start();There may occur synchronization issues, if
doLayout(y.layout.LayoutGraph)
is not called
using a CopiedLayoutGraph.
public double commitPositionsSmoothly(double maxMovement, double factor)
isRunning()
.
The positions are not transferred directly. Instead the nodes are moved towards the calculated position in each step.
"Good" values for this method may be about 50 for the maxMovement and about 0.15 as factor (when the
positions are updates about 25 times a second).
maxMovement
- the maximal distance a node is movedfactor
- determines the node movement (movement = factor * distance between calculated and actual location)
public void wakeUp()
public long getLastWakeupTime()
public void addStructureUpdate(Runnable runnable)
setCenter(y.base.Node, double, double)
.
runnable
- public void stop()
public boolean isStopped()
public boolean isSleeping()
wakeUp()
and will continue its work.
public boolean isRunning()
public double getWorkingRatio()
public void setWorkingRatio(double workingRatio)
workingRatio
- between Double.MIN_VALUE
and 1public void setPreferredEdgeLength(double preferredEdgeLength)
preferredEdgeLength
- public void setPreferredNodeDistance(double preferredNodeDistance)
preferredNodeDistance
- public void setPreferredEdgeLength(Edge edge, double newEdgeLength)
edge
- newEdgeLength
- public void setInertia(Node node, double inertia)
node
- inertia
- public void setCenter(Node node, double x, double y)
node
- x
- y
- public void setRadius(Node node, double radius)
node
- radius
- public void setStress(Node node, double stress)
node
- stress
- a value between 0 and 1public double getStress(Node node)
node
- public void setCenterX(Node node, double x)
node
- x
- public void setCenterY(Node node, double y)
node
- y
- public YPoint getCenter(Node node)
node
-
public double getCenterX(Node node)
node
-
public double getCenterY(Node node)
node
-
public void setMaxTime(long maxTime)
maxTime
- public void setQuality(double quality)
quality
- a value between 0 and 1. "1": maximal quality (long running), "0" minimum quality (short running)public long getMaxTime()
public double getQuality()
public void syncStructure()
doLayout(y.layout.LayoutGraph)
with
the original graph.
This method
public void setOutputRestriction(OutputRestriction restriction)
restriction
- the restriction to useOutputRestriction.NONE
,
OutputRestriction
public OutputRestriction getOutputRestriction()
OutputRestriction.NONE
.
public void stopAndWait()
started
layout
Thread and blocks until the layout is completed.
|
© Copyright 2000-2013, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |