org.eclipse.zest.layouts.algorithms

## Class AbstractLayoutAlgorithm

- java.lang.Object
- - org.eclipse.zest.layouts.algorithms.AbstractLayoutAlgorithm

All Implemented Interfaces:
  LayoutAlgorithm, Stoppable

Direct Known Subclasses:
  CompositeLayoutAlgorithm, ContinuousLayoutAlgorithm, DirectedGraphLayoutAlgorithm, GridLayoutAlgorithm, HorizontalShift, TreeLayoutAlgorithm

    public abstract class AbstractLayoutAlgorithm
    extends java.lang.Object
    implements LayoutAlgorithm, Stoppable

Handles common elements in all layout algorithms [irbull] Refactored into a template pattern. ApplyLayout now delegates the task to ApplyLayoutInternal [irbull] Included asynchronous layouts

### Field Summary

Fields
`protected java.util.Comparator` `comparator`
`protected Filter` `filter`
`protected boolean` `internalAsynchronous`
`protected boolean` `internalContinuous`
`protected int` `layout_styles`
`protected boolean` `layoutStopped`
`static int` `MIN_ENTITY_SIZE`
`protected boolean` `resizeEntitiesAfterLayout`

### Constructor Summary

Constructors
Constructor and Description
`AbstractLayoutAlgorithm(int styles)` Initializes the abstract layout algorithm.

### Method Summary

Methods
`void` `addEntity(LayoutEntity entity)` Queues up the given entity (if it isn't in the list) to be added to the algorithm.
`void` `addProgressListener(ProgressListener listener)` A layout algorithm could take an uncomfortable amout of time to complete.
`void` `addRelationship(LayoutRelationship relationship)` Queues up the given relationshp (if it isn't in the list) to be added to the algorithm.
`void` `applyLayout(LayoutEntity[] entitiesToLayout, LayoutRelationship[] relationshipsToConsider, double x, double y, double width, double height, boolean asynchronous, boolean continuous)` This actually applies the layout
`protected abstract void` `applyLayoutInternal(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider, double boundsX, double boundsY, double boundsWidth, double boundsHeight)` Apply the layout to the given entities.
`protected void` `defaultFitWithinBounds(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle realBounds)` Find an appropriate size for the given nodes, then fit them into the given bounds.
`protected void` `defaultFitWithinBounds(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationships, org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle realBounds)` Find an appropriate size for the given nodes, then fit them into the given bounds.
`protected void` `fireProgressEnded(int totalNumberOfSteps)`
`protected void` `fireProgressEvent(int currentStep, int totalNumberOfSteps)` Fires an event to notify all of the registered ProgressListeners that another step has been completed in the algorithm.
`protected void` `fireProgressStarted(int totalNumberOfSteps)`
`protected abstract int` `getCurrentLayoutStep()` Gets the current layout step
`double` `getEntityAspectRatio()` Returns the width to height ratio this layout will use to set the size of the entities.
`protected org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle` `getLayoutBounds(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, boolean includeNodeSize)` Find the bounds in which the nodes are located.
`protected org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint` `getLocalLocation(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, double x, double y, org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle realBounds)` Gets the location in the layout bounds for this node
`protected int` `getNumberOfProgressListeners()`
`int` `getStyle()` Gets the current layout style
`protected abstract int` `getTotalNumberOfLayoutSteps()` Gets the total number of steps in this layout
`boolean` `isRunning()` Returns true if the layout algorithm is running
`protected abstract boolean` `isValidConfiguration(boolean asynchronous, boolean continuous)` Determines if the configuration is valid for this layout
`protected abstract void` `postLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)` Code called after the layout algorithm ends
`protected abstract void` `preLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout, org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider, double x, double y, double width, double height)` Code called before the layout algorithm starts
`void` `removeEntity(LayoutEntity entity)` Queues up the given entity to be removed from the algorithm next time it runs.
`void` `removeProgressListener(ProgressListener listener)` Removes the given progress listener, preventing it from receiving any more updates.
`void` `removeRelationship(LayoutRelationship relationship)` Queues up the given relationship to be removed from the algorithm next time it runs.
`void` `removeRelationships(java.util.Collection collection)`
`void` `removeRelationships(java.util.List relationships)` Queues up all the relationships in the list to be removed.
`void` `setComparator(java.util.Comparator comparator)` Determines the order in which the objects should be displayed.
`void` `setEntityAspectRatio(double ratio)` Set the width to height ratio you want the entities to use
`void` `setFilter(Filter filter)` Filters the entities and relationships to apply the layout on
`abstract void` `setLayoutArea(double x, double y, double width, double height)`
`void` `setStyle(int style)` Sets the current layout style.
`void` `stop()` Stops the current layout from running.
`protected void` `updateBendPoints(org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)` Update external bend points from the internal bendpoints list.
`protected org.eclipse.zest.layouts.dataStructures.InternalNode[]` `updateEntities(org.eclipse.zest.layouts.dataStructures.InternalNode[] entities)` Updates the given array of entities checking if any need to be removed or added.
`protected void` `updateLayoutLocations(org.eclipse.zest.layouts.dataStructures.InternalNode[] nodes)` Updates the layout locations so the external nodes know about the new locations
`protected org.eclipse.zest.layouts.dataStructures.InternalRelationship[]` `updateRelationships(org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationships)` Updates the given array of relationships checking if any need to be removed or added.
`static boolean` `verifyInput(LayoutEntity[] entitiesToLayout, LayoutRelationship[] relationshipsToConsider)` Verifies the endpoints of the relationships are entities in the entitiesToLayout list.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### MIN_ENTITY_SIZE

    public static final int MIN_ENTITY_SIZE

See Also:
  Constant Field Values

#### comparator

    protected java.util.Comparator comparator

#### filter

    protected Filter filter

#### internalContinuous

    protected boolean internalContinuous

#### internalAsynchronous

    protected boolean internalAsynchronous

#### layoutStopped

    protected boolean layoutStopped

#### layout_styles

    protected int layout_styles

#### resizeEntitiesAfterLayout

    protected boolean resizeEntitiesAfterLayout

### Constructor Detail

#### AbstractLayoutAlgorithm

    public AbstractLayoutAlgorithm(int styles)

Initializes the abstract layout algorithm.

See Also:
  `LayoutStyles`

### Method Detail

#### removeRelationships

    public void removeRelationships(java.util.Collection collection)

#### addEntity

    public void addEntity(LayoutEntity entity)

Queues up the given entity (if it isn't in the list) to be added to the algorithm.

Specified by:
  `addEntity` in interface `LayoutAlgorithm`
Parameters:
  `entity` -

#### addRelationship

    public void addRelationship(LayoutRelationship relationship)

Queues up the given relationshp (if it isn't in the list) to be added to the algorithm.

Specified by:
  `addRelationship` in interface `LayoutAlgorithm`
Parameters:
  `relationship` -

#### removeEntity

    public void removeEntity(LayoutEntity entity)

Queues up the given entity to be removed from the algorithm next time it runs.

Specified by:
  `removeEntity` in interface `LayoutAlgorithm`
Parameters:
  `entity` - The entity to remove

#### removeRelationship

    public void removeRelationship(LayoutRelationship relationship)

Queues up the given relationship to be removed from the algorithm next time it runs.

Specified by:
  `removeRelationship` in interface `LayoutAlgorithm`
Parameters:
  `relationship` - The relationship to remove.

#### removeRelationships

    public void removeRelationships(java.util.List relationships)

Queues up all the relationships in the list to be removed.

Specified by:
  `removeRelationships` in interface `LayoutAlgorithm`
Parameters:
  `relationships` -

#### setStyle

    public void setStyle(int style)

Sets the current layout style. This overwrites all other layout styles. Use getStyle to get the current style.

Specified by:
  `setStyle` in interface `LayoutAlgorithm`
Parameters:
  `style` -

#### getStyle

    public int getStyle()

Gets the current layout style

Specified by:
  `getStyle` in interface `LayoutAlgorithm`
Returns:

#### setLayoutArea

    public abstract void setLayoutArea(double x,
                     double y,
                     double width,
                     double height)

#### isValidConfiguration

    protected abstract boolean isValidConfiguration(boolean asynchronous,
                               boolean continuous)

Determines if the configuration is valid for this layout

Parameters:
  `asynchronous` -
  `continuous` -

#### applyLayoutInternal

    protected abstract void applyLayoutInternal(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                           org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider,
                           double boundsX,
                           double boundsY,
                           double boundsWidth,
                           double boundsHeight)

Apply the layout to the given entities. The entities will be moved and resized based on the algorithm.

Parameters:
  `entitiesToLayout` - Apply the algorithm to these entities
  `relationshipsToConsider` - Only consider these relationships when applying the algorithm.
  `x` - The left side of the bounds in which the layout can place the entities.
  `y` - The top side of the bounds in which the layout can place the entities.
  `width` - The width of the bounds in which the layout can place the entities.
  `height` - The height of the bounds in which the layout can place the entities.

#### updateEntities

    protected org.eclipse.zest.layouts.dataStructures.InternalNode[] updateEntities(org.eclipse.zest.layouts.dataStructures.InternalNode[] entities)

Updates the given array of entities checking if any need to be removed or added.

Parameters:
  `entities` - the current entities
Returns:
  the updated entities array

#### updateRelationships

    protected org.eclipse.zest.layouts.dataStructures.InternalRelationship[] updateRelationships(org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationships)

Updates the given array of relationships checking if any need to be removed or added. Also updates the original array of relationships.

Parameters:
  `relationships` - the current relationships
Returns:
  the update relationships array

#### isRunning

    public boolean isRunning()

Returns true if the layout algorithm is running

Specified by:
  `isRunning` in interface `LayoutAlgorithm`
Returns:
  boolean if the layout algorithm is running

#### stop

    public void stop()

Stops the current layout from running. All layout algorithms should constantly check isLayoutRunning

Specified by:
  `stop` in interface `LayoutAlgorithm`
Specified by:
  `stop` in interface `Stoppable`

#### preLayoutAlgorithm

    protected abstract void preLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                          org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider,
                          double x,
                          double y,
                          double width,
                          double height)

Code called before the layout algorithm starts

#### postLayoutAlgorithm

    protected abstract void postLayoutAlgorithm(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                           org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)

Code called after the layout algorithm ends

#### getTotalNumberOfLayoutSteps

    protected abstract int getTotalNumberOfLayoutSteps()

Gets the total number of steps in this layout

#### getCurrentLayoutStep

    protected abstract int getCurrentLayoutStep()

Gets the current layout step

Returns:

#### applyLayout

    public void applyLayout(LayoutEntity[] entitiesToLayout,
                   LayoutRelationship[] relationshipsToConsider,
                   double x,
                   double y,
                   double width,
                   double height,
                   boolean asynchronous,
                   boolean continuous)
                     throws InvalidLayoutConfiguration

This actually applies the layout

Specified by:
  `applyLayout` in interface `LayoutAlgorithm`
Parameters:
  `entitiesToLayout` - Apply the algorithm to these entities
  `relationshipsToConsider` - Only consider these relationships when applying the algorithm.
  `x` - The left side of the bounds in which the layout can place the entities.
  `y` - The top side of the bounds in which the layout can place the entities.
  `width` - The width of the bounds in which the layout can place the entities.
  `height` - The height of the bounds in which the layout can place the entities.
  `asynchronous` - Should the algorithm run Asynchronously
Throws:
  `InvalidLayoutConfiguration`

#### updateBendPoints

    protected void updateBendPoints(org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationshipsToConsider)

Update external bend points from the internal bendpoints list. Save the source and destination points for later use in scaling and translating

Parameters:
  `relationshipsToConsider` -

#### setFilter

    public void setFilter(Filter filter)

Filters the entities and relationships to apply the layout on

Specified by:
  `setFilter` in interface `LayoutAlgorithm`

#### setComparator

    public void setComparator(java.util.Comparator comparator)

Determines the order in which the objects should be displayed. Note: Some algorithms force a specific order.

Specified by:
  `setComparator` in interface `LayoutAlgorithm`

#### verifyInput

    public static boolean verifyInput(LayoutEntity[] entitiesToLayout,
                      LayoutRelationship[] relationshipsToConsider)

Verifies the endpoints of the relationships are entities in the entitiesToLayout list. Allows other classes in this package to use this method to verify the input

#### getLocalLocation

    protected org.eclipse.zest.layouts.dataStructures.DisplayIndependentPoint getLocalLocation(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                                                                   double x,
                                                                                   double y,
                                                                                   org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle realBounds)

Gets the location in the layout bounds for this node

Parameters:
  `x` -
  `y` -
Returns:

#### defaultFitWithinBounds

    protected void defaultFitWithinBounds(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                              org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle realBounds)

Find an appropriate size for the given nodes, then fit them into the given bounds. The relative locations of the nodes to each other must be preserved. Child classes should set flag reresizeEntitiesAfterLayout to false if they want to preserve node sizes.

#### defaultFitWithinBounds

    protected void defaultFitWithinBounds(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                              org.eclipse.zest.layouts.dataStructures.InternalRelationship[] relationships,
                              org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle realBounds)

Find an appropriate size for the given nodes, then fit them into the given bounds. The relative locations of the nodes to each other must be preserved. Child classes should set flag reresizeEntitiesAfterLayout to false if they want to preserve node sizes.

#### getLayoutBounds

    protected org.eclipse.zest.layouts.dataStructures.DisplayIndependentRectangle getLayoutBounds(org.eclipse.zest.layouts.dataStructures.InternalNode[] entitiesToLayout,
                                                                                      boolean includeNodeSize)

Find the bounds in which the nodes are located. Using the bounds against the real bounds of the screen, the nodes can proportionally be placed within the real bounds. The bounds can be determined either including the size of the nodes or not. If the size is not included, the bounds will only be guaranteed to include the center of each node.

#### setEntityAspectRatio

    public void setEntityAspectRatio(double ratio)

Set the width to height ratio you want the entities to use

Specified by:
  `setEntityAspectRatio` in interface `LayoutAlgorithm`

#### getEntityAspectRatio

    public double getEntityAspectRatio()

Returns the width to height ratio this layout will use to set the size of the entities.

Specified by:
  `getEntityAspectRatio` in interface `LayoutAlgorithm`

#### addProgressListener

    public void addProgressListener(ProgressListener listener)

A layout algorithm could take an uncomfortable amout of time to complete. To relieve some of the mystery, the layout algorithm will notify each ProgressListener of its progress.

Specified by:
  `addProgressListener` in interface `LayoutAlgorithm`
Specified by:
  `addProgressListener` in interface `Stoppable`

#### removeProgressListener

    public void removeProgressListener(ProgressListener listener)

Removes the given progress listener, preventing it from receiving any more updates.

Specified by:
  `removeProgressListener` in interface `LayoutAlgorithm`

#### updateLayoutLocations

    protected void updateLayoutLocations(org.eclipse.zest.layouts.dataStructures.InternalNode[] nodes)

Updates the layout locations so the external nodes know about the new locations

#### fireProgressStarted

    protected void fireProgressStarted(int totalNumberOfSteps)

#### fireProgressEnded

    protected void fireProgressEnded(int totalNumberOfSteps)

#### fireProgressEvent

    protected void fireProgressEvent(int currentStep,
                         int totalNumberOfSteps)

Fires an event to notify all of the registered ProgressListeners that another step has been completed in the algorithm.

Parameters:
  `currentStep` - The current step completed.
  `totalNumberOfSteps` - The total number of steps in the algorithm.

#### getNumberOfProgressListeners

    protected int getNumberOfProgressListeners()