Class SnapToGeometry

java.lang.Object
org.eclipse.gef.SnapToHelper
org.eclipse.gef.SnapToGeometry
All Implemented Interfaces:
org.eclipse.draw2d.PositionConstants

public class SnapToGeometry extends SnapToHelper
A temporary helper used to perform snapping to existing elements. This helper can be used in conjunction with the DragEditPartsTracker when dragging editparts within a graphical viewer. Snapping is based on the existing children of a container. When snapping a rectangle, the edges of the rectangle will snap to edges of other rectangles generated from the children of the given container. Similarly, the centers and middles of rectangles will snap to each other.

If the snap request is being made during a Move, Reparent or Resize, then the figures of the participants of that request will not be used for snapping. If the request is a Clone, then the figures for the parts being cloned will be used as possible snap locations.

This helper does not keep up with changes made to the container editpart. Clients should instantiate a new helper each time one is requested and not hold on to instances of the helper.

Since:
3.0
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    A vertical or horizontal snapping point. since 3.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The vertical columnd being snapped to.
    The container editpart providing the coordinates and the children to which snapping occurs.
    static final String
    The key used to identify the East anchor point in the extended data of a request.
    static final String
    The key used to identify the North anchor point in the extended data of a request.
    static final String
    The key used to identify the South anchor point in the extended data of a request.
    static final String
    The key used to identify the West anchor point in the extended data of a request.
    static final String
    A property indicating whether this helper should be used.
    The horizontal rows being snapped to.
    protected static final double
    The sensitivity of the snapping.

    Fields inherited from interface org.eclipse.draw2d.PositionConstants

    ALWAYS_LEFT, ALWAYS_RIGHT, BOTTOM, CENTER, EAST, EAST_WEST, HORIZONTAL, LEFT, LEFT_CENTER_RIGHT, MIDDLE, NONE, NORTH, NORTH_EAST, NORTH_SOUTH, NORTH_WEST, NSEW, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TOP_MIDDLE_BOTTOM, VERTICAL, WEST
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a helper that will use the given part as its basis for snapping.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected List
    Generates a list of parts which should be snapped to.
    protected double
    getCorrectionFor(SnapToGeometry.Entry[] entries, Map extendedData, boolean vert, double near, double far)
    Returns the correction value for the given entries and sides.
    protected double
    getCorrectionFor(SnapToGeometry.Entry[] entries, Map extendedData, boolean vert, double value, int side)
    Returns the correction value between +/- getThreshold(), or the #getThreshold () if no corrections were found.
    protected org.eclipse.draw2d.geometry.Rectangle
    Returns the rectangular contribution for the given editpart.
    protected double
    Get the sensitivity of the snapping.
    protected void
    Updates the cached row and column Entries using the provided parts.
    protected void
    setThreshold(double newThreshold)
    Set the sensitivity of the snapping.
    int
    snapRectangle(Request request, int snapOrientation, org.eclipse.draw2d.geometry.PrecisionRectangle baseRect, org.eclipse.draw2d.geometry.PrecisionRectangle result)
    Applies a snap correction to a Rectangle based on a given Rectangle.

    Methods inherited from class org.eclipse.gef.SnapToHelper

    makeAbsolute, makeRelative, snapPoint, snapPoint, snapRectangle

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PROPERTY_SNAP_ENABLED

      public static final String PROPERTY_SNAP_ENABLED
      A property indicating whether this helper should be used. The value should be an instance of Boolean. Currently, this class does not check to see if the viewer property is set to true.
      See Also:
    • KEY_NORTH_ANCHOR

      public static final String KEY_NORTH_ANCHOR
      The key used to identify the North anchor point in the extended data of a request. The north anchor may be set to an Integer value indicating where the snapping is occurring. This is used for feedback purposes.
      See Also:
    • KEY_SOUTH_ANCHOR

      public static final String KEY_SOUTH_ANCHOR
      The key used to identify the South anchor point in the extended data of a request. The south anchor may be set to an Integer value indicating where the snapping is occurring. This is used for feedback purposes.
      See Also:
    • KEY_WEST_ANCHOR

      public static final String KEY_WEST_ANCHOR
      The key used to identify the West anchor point in the extended data of a request. The west anchor may be set to an Integer value indicating where the snapping is occurring. This is used for feedback purposes.
      See Also:
    • KEY_EAST_ANCHOR

      public static final String KEY_EAST_ANCHOR
      The key used to identify the East anchor point in the extended data of a request. The east anchor may be set to an Integer value indicating where the snapping is occurring. This is used for feedback purposes.
      See Also:
    • THRESHOLD

      protected static final double THRESHOLD
      The sensitivity of the snapping. Corrections greater than this value will not occur.
      See Also:
    • rows

      protected SnapToGeometry.Entry[] rows
      The horizontal rows being snapped to.
    • cols

      protected SnapToGeometry.Entry[] cols
      The vertical columnd being snapped to.
    • container

      protected GraphicalEditPart container
      The container editpart providing the coordinates and the children to which snapping occurs.
  • Constructor Details

    • SnapToGeometry

      public SnapToGeometry(GraphicalEditPart container)
      Constructs a helper that will use the given part as its basis for snapping. The part's contents pane will provide the coordinate system and its children determine the existing elements.
      Parameters:
      container - the container editpart
      Since:
      3.0
  • Method Details

    • getThreshold

      protected double getThreshold()
      Get the sensitivity of the snapping. Corrections greater than this value will not occur.
      Returns:
      the snapping threshold
      Since:
      3.4
    • setThreshold

      protected void setThreshold(double newThreshold)
      Set the sensitivity of the snapping.
      Parameters:
      newThreshold - the new snapping threshold
      Since:
      3.4
      See Also:
    • generateSnapPartsList

      protected List generateSnapPartsList(List exclusions)
      Generates a list of parts which should be snapped to. The list is the original children, minus the given exclusions, minus and children whose figures are not visible.
      Parameters:
      exclusions - the children to exclude
      Returns:
      a list of parts which should be snapped to
      Since:
      3.0
    • getCorrectionFor

      protected double getCorrectionFor(SnapToGeometry.Entry[] entries, Map extendedData, boolean vert, double near, double far)
      Returns the correction value for the given entries and sides. During a move, the left, right, or center is free to snap to a location.
      Parameters:
      entries - the entries
      extendedData - the requests extended data
      vert - true if the correction is vertical
      near - the left/top side of the rectangle
      far - the right/bottom side of the rectangle
      Returns:
      the correction amount or #getThreshold () if no correction was made
    • getCorrectionFor

      protected double getCorrectionFor(SnapToGeometry.Entry[] entries, Map extendedData, boolean vert, double value, int side)
      Returns the correction value between +/- getThreshold(), or the #getThreshold () if no corrections were found.
      Parameters:
      entries - the entries
      extendedData - the map for setting values
      vert - true if vertical
      value - the value being corrected
      side - which sides should be considered
      Returns:
      the correction or #getThreshold () if no correction was made
    • getFigureBounds

      protected org.eclipse.draw2d.geometry.Rectangle getFigureBounds(GraphicalEditPart part)
      Returns the rectangular contribution for the given editpart. This is the rectangle with which snapping is performed.
      Parameters:
      part - the child
      Returns:
      the rectangular guide for that part
      Since:
      3.0
    • populateRowsAndCols

      protected void populateRowsAndCols(List parts)
      Updates the cached row and column Entries using the provided parts.
      Parameters:
      parts - a List of EditParts
      Since:
      3.0
    • snapRectangle

      public int snapRectangle(Request request, int snapOrientation, org.eclipse.draw2d.geometry.PrecisionRectangle baseRect, org.eclipse.draw2d.geometry.PrecisionRectangle result)
      Description copied from class: SnapToHelper
      Applies a snap correction to a Rectangle based on a given Rectangle. The provided baseRect will be used as a reference for snapping. The types of snapping to be performed are indicated by the snapOrientation parameter. The correction is applied to the result field.

      The baseRect is not modified. The correction is applied to the result. The request's extended data may contain additional information about the snapping which was performed.

      All coordinate information received and returned by this method should be in absolute coordinates.

      Specified by:
      snapRectangle in class SnapToHelper
      Parameters:
      request - the request or null
      snapOrientation - the input snap locations
      baseRect - the input rectangle
      result - the correction is applied to this rectangle
      Returns:
      the remaining snap locations
      See Also: