Package org.eclipse.gef
Class SnapToGeometry
java.lang.Object
org.eclipse.gef.SnapToHelper
org.eclipse.gef.SnapToGeometry
- All Implemented Interfaces:
PositionConstants
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 ClassesModifier and TypeClassDescriptionprotected static classA vertical or horizontal snapping point. since 3.0 -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SnapToGeometry.Entry[]The vertical columns being snapped to.protected GraphicalEditPartThe container editpart providing the coordinates and the children to which snapping occurs.static final StringThe key used to identify the East anchor point in the extended data of a request.static final StringThe key used to identify the North anchor point in the extended data of a request.static final StringThe key used to identify the South anchor point in the extended data of a request.static final StringThe key used to identify the West anchor point in the extended data of a request.static final StringA property indicating whether this helper should be used.protected SnapToGeometry.Entry[]The horizontal rows being snapped to.protected static final doubleThe 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
ConstructorsConstructorDescriptionSnapToGeometry(GraphicalEditPart container) Constructs a helper that will use the given part as its basis for snapping. -
Method Summary
Modifier and TypeMethodDescriptionprotected List<? extends GraphicalEditPart> generateSnapPartsList(List<? extends EditPart> exclusions) Generates a list of parts which should be snapped to.protected doublegetCorrectionFor(SnapToGeometry.Entry[] entries, Map extendedData, boolean vert, double near, double far) Returns the correction value for the given entries and sides.protected doublegetCorrectionFor(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 RectangleReturns the rectangular contribution for the given editpart.protected doubleGet the sensitivity of the snapping.protected voidpopulateRowsAndCols(List<? extends GraphicalEditPart> parts) Updates the cached row and column Entries using the provided parts.protected voidsetThreshold(double newThreshold) Set the sensitivity of the snapping.intsnapRectangle(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
-
Field Details
-
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 totrue.- See Also:
-
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 anIntegervalue indicating where the snapping is occurring. This is used for feedback purposes.- See Also:
-
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 anIntegervalue indicating where the snapping is occurring. This is used for feedback purposes.- See Also:
-
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 anIntegervalue indicating where the snapping is occurring. This is used for feedback purposes.- See Also:
-
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 anIntegervalue indicating where the snapping is occurring. This is used for feedback purposes.- See Also:
-
THRESHOLD
protected static final double THRESHOLDThe sensitivity of the snapping. Corrections greater than this value will not occur.- See Also:
-
rows
The horizontal rows being snapped to. -
cols
The vertical columns being snapped to. -
container
The container editpart providing the coordinates and the children to which snapping occurs.
-
-
Constructor Details
-
SnapToGeometry
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<? extends GraphicalEditPart> generateSnapPartsList(List<? extends EditPart> 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 entriesextendedData- the requests extended datavert-trueif the correction is verticalnear- the left/top side of the rectanglefar- 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 entriesextendedData- the map for setting valuesvert-trueif verticalvalue- the value being correctedside- which sides should be considered- Returns:
- the correction or #getThreshold () if no correction was made
-
getFigureBounds
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
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:SnapToHelperApplies 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 datamay 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:
snapRectanglein classSnapToHelper- Parameters:
request- the request ornullsnapOrientation- the input snap locationsbaseRect- the input rectangleresult- the correction is applied to this rectangle- Returns:
- the remaining snap locations
- See Also:
-