Search this API

y.layout
Class PortCalculator

java.lang.Object
  extended by y.layout.AbstractLayoutStage
      extended by y.layout.PortCalculator
All Implemented Interfaces:
Layouter, LayoutStage

public class PortCalculator
extends AbstractLayoutStage
implements LayoutStage

This class implements a LayoutStage that can be used to adjust the final port assignments after a layout has been calculated. This can be useful if the port assignment calculated by the layout algorithm is insufficient. This stage uses DataProvider instances bound to the graph using the keys defined in the IntersectionCalculator interface to calculate the new port offsets. For each edge in the LayoutGraph instance the DataProviders are queried for an implementation of the IntersectionCalculator interface. If the result is non-null, that implementation will be queried and if the result of the query is non-null, the returned point will be applied to the edge layout.

For this layout stage to work use CompositeLayoutStage.prependStage(y.layout.LayoutStage) or CanonicMultiStageLayouter.prependStage(y.layout.LayoutStage) to add this layout stage and register appropriate DataProvider implementations to the graph using the keys defined in IntersectionCalculator.

Note, that this class will not change the coordinates of a port if it is associated with a strong port constraint.

See Also:
IntersectionCalculator, IntersectionCalculator.SOURCE_INTERSECTION_CALCULATOR_DPKEY, IntersectionCalculator.TARGET_INTERSECTION_CALCULATOR_DPKEY, PortConstraint

Field Summary
protected  double EPS
          EPSILON used by equalsEps(double, double, double, double).
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
PortCalculator()
          Creates a new PortCalculator without a core layouter.
PortCalculator(Layouter core)
          Creates a new PortCalculator using the given layouter as the core of this layout stage.
 
Method Summary
protected  void calculatePorts(LayoutGraph graph)
          Performs the actual port calculation on the specified graph instance.
 boolean canLayout(LayoutGraph graph)
          Returns true iff the given graph can be laid out by this algorithm.
 void doLayout(LayoutGraph graph)
          Main layout routine that assigns new layout information to the given graph.
protected  boolean equalsEps(double x1, double y1, double x2, double y2)
          Callback method that determines whether two points are equal.
 
Methods inherited from class y.layout.AbstractLayoutStage
canLayoutCore, doLayoutCore, getCoreLayouter, setCoreLayouter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface y.layout.LayoutStage
getCoreLayouter, setCoreLayouter
 

Field Detail

EPS

protected double EPS
EPSILON used by equalsEps(double, double, double, double). By default this is 0.2d.

Constructor Detail

PortCalculator

public PortCalculator()
Creates a new PortCalculator without a core layouter.


PortCalculator

public PortCalculator(Layouter core)
Creates a new PortCalculator using the given layouter as the core of this layout stage.

Method Detail

canLayout

public boolean canLayout(LayoutGraph graph)
Description copied from interface: Layouter
Returns true iff the given graph can be laid out by this algorithm. Calling doLayout with the given graph as its argument will only success if this method returns true.

Specified by:
canLayout in interface Layouter

doLayout

public void doLayout(LayoutGraph graph)
Description copied from interface: Layouter
Main layout routine that assigns new layout information to the given graph.

Specified by:
doLayout in interface Layouter

calculatePorts

protected void calculatePorts(LayoutGraph graph)
Performs the actual port calculation on the specified graph instance.


equalsEps

protected boolean equalsEps(double x1,
                            double y1,
                            double x2,
                            double y2)
Callback method that determines whether two points are equal.


© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.