Eclipse GEF
3.0.1

org.eclipse.gef
Class SnapToGeometry

java.lang.Object
  extended byorg.eclipse.gef.SnapToHelper
      extended byorg.eclipse.gef.SnapToGeometry
All Implemented Interfaces:
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 onto instances of the helper.

Since:
3.0

Nested Class Summary
protected static class SnapToGeometry.Entry
          A vertical or horizontal snapping point.
 
Field Summary
protected  SnapToGeometry.Entry[] cols
          The vertical columnd being snapped to.
protected  GraphicalEditPart container
          The container editpart providing the coordinates and the children to which snapping occurs.
static String KEY_EAST_ANCHOR
          The key used to identify the East anchor point in the extended data of a request.
static String KEY_NORTH_ANCHOR
          The key used to identify the North anchor point in the extended data of a request.
static String KEY_SOUTH_ANCHOR
          The key used to identify the South anchor point in the extended data of a request.
static String KEY_WEST_ANCHOR
          The key used to identify the West anchor point in the extended data of a request.
static String PROPERTY_SNAP_ENABLED
          A property indicating whether this helper should be used.
protected  SnapToGeometry.Entry[] rows
          The horizontal rows being snapped to.
protected static double THRESHOLD
          The sensitivity of the snapping.
 
Fields inherited from interface org.eclipse.draw2d.PositionConstants
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
SnapToGeometry(GraphicalEditPart container)
          Constructs a helper that will use the given part as its basis for snapping.
 
Method Summary
protected  List generateSnapPartsList(List exclusions)
          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 ± THRESHOLD, or the THRESHOLD if no corrections were found.
protected  Rectangle getFigureBounds(GraphicalEditPart part)
          Returns the rectangular contribution for the given editpart.
protected  void populateRowsAndCols(List parts)
          Updates the cached row and column Entries using the provided parts.
 int snapRectangle(Request request, int snapOrientation, PrecisionRectangle baseRect, 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 Detail

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:
EditPartViewer.setProperty(String, Object), Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

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:
Constant Field Values

THRESHOLD

protected static final double THRESHOLD
The sensitivity of the snapping. Corrections greater than this value will not occur.

See Also:
Constant Field Values

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 Detail

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 Detail

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 THRESHOLD 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 ± THRESHOLD, or the THRESHOLD 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 THRESHOLD if no correction was made

getFigureBounds

protected 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,
                         PrecisionRectangle baseRect,
                         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
baseRect - the input rectangle
result - the correction is applied to this rectangle
snapOrientation - the input snap locations
Returns:
the remaining snap locations
See Also:
SnapToHelper.snapRectangle(Request, int, PrecisionRectangle, PrecisionRectangle)

Eclipse GEF
3.0.1

Copyright (c) IBM Corp. and others 2000, 2004. All Rights Reserved.