Class SnapToGuides
- All Implemented Interfaces:
PositionConstants
RulerProviders. If
snapping is performed, the request's extended data will contain keyed values
indicating which guides were snapped to, and which side of the part should be
attached. Generally snapping to a guide should attach the part to that guide,
but application behavior may differ.
Snapping (and attaching) to a guide is only possible if a single part is being dragged. The current implementation will not snap if a request contains multiple parts. This may be relaxed in the future to allow snapping, but without setting the attachment extended data.
This helper does not keep up with changes in guides. Clients should instantiate a new helper each time one is requested and not hold on to instances of the helper.
- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GraphicalEditPartThe graphical editpart to which guides are relative.protected int[]The locations of the horizontal guides in the container's coordinates.static final StringThe key used to identify the horizontal anchor point.static final StringThe key used to identify the Horizontal Guide.static final StringThe key used to identify the vertical anchor point.static final StringThe key used to identify the Vertical Guide.protected static final doubleThe threshold for snapping to guides.protected int[]The locations of the vertical guides in the container's coordinates.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
ConstructorsConstructorDescriptionSnapToGuides(GraphicalEditPart container) Constructs a new snap-to-guides helper using the given container as the basis. -
Method Summary
Modifier and TypeMethodDescriptionprotected doublegetCorrectionFor(int[] guides, double near, double far, Map extendedData, boolean isVertical) Returns the correction for the given near and far sides of a rectangle orgetThreshold()if no correction was found.protected doublegetCorrectionFor(int[] guides, double value, Map extendedData, boolean vert, int side) Returns the correction for the given location orgetThreshold()if no correction was found.protected int[]Returns the horizontal guides in the coordinates of the container's contents pane.protected doubleGet the sensitivity of the snapping.protected int[]Returns the vertical guides in the coordinates of the container's contents pane.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
-
KEY_VERTICAL_GUIDE
The key used to identify the Vertical Guide. This key is used with the request's extended data map to store an Integer. The integer value is the location of the guide that is being snapped to.- See Also:
-
KEY_HORIZONTAL_GUIDE
The key used to identify the Horizontal Guide. This key is used with the request's extended data map to store an Integer. The integer value is the location of the guide that is being snapped to.- See Also:
-
KEY_VERTICAL_ANCHOR
The key used to identify the vertical anchor point. This key is used with the request's extended data map to store an Integer. If the VERTICAL_GUIDE has been set, then this integer is a number identifying which side of the dragged object is being snapped to that guide.-1indicates the left side should be attached.0indicates the center should be attached.1indicates the right side should be attached.
- See Also:
-
KEY_HORIZONTAL_ANCHOR
The key used to identify the horizontal anchor point. This key is used with the request's extended data map to store an Integer. If the HORIZONTAL_GUIDE has been set, then this integer is a number identifying which side of the dragged object is being snapped to that guide.-1indicates the top side should be attached.0indicates the middle should be attached.1indicates the bottom side should be attached.
- See Also:
-
THRESHOLD
protected static final double THRESHOLDThe threshold for snapping to guides. The rectangle being snapped must be within +/- the THRESHOLD. The default value is 5.001;- See Also:
-
container
The graphical editpart to which guides are relative. This should also the parent of the parts being snapped to guides. -
verticalGuides
protected int[] verticalGuidesThe locations of the vertical guides in the container's coordinates. UsegetVerticalGuides(). -
horizontalGuides
protected int[] horizontalGuidesThe locations of the horizontal guides in the container's coordinates. UsegetHorizontalGuides().
-
-
Constructor Details
-
SnapToGuides
Constructs a new snap-to-guides helper using the given container as the basis.- Parameters:
container- the container editpart
-
-
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:
-
getCorrectionFor
protected double getCorrectionFor(int[] guides, double near, double far, Map extendedData, boolean isVertical) Returns the correction for the given near and far sides of a rectangle orgetThreshold()if no correction was found. The near side represents the top or left side of a rectangle being snapped. Similar for far. If snapping occurs, the extendedData will have the guide and attachment point set.- Parameters:
guides- the location of the guidesnear- the top or left locationfar- the bottom or right locationextendedData- the map for storing snap detailsisVertical-trueif for vertical guides,falsefor horizontal.- Returns:
- the correction amount or getThreshold() if no correction was made
-
getCorrectionFor
protected double getCorrectionFor(int[] guides, double value, Map extendedData, boolean vert, int side) Returns the correction for the given location orgetThreshold()if no correction was found. If correction occurs, the extendedData will have the guide and attachment point set. The attachment point is identified by thesideparameter.The correction's magnitude will be less than getThreshold().
- Parameters:
guides- the location of the guidesvalue- the location being testedextendedData- the map for storing snap detailsvert-trueif for vertical guides,falseside- the integer indicating which side is being snapped- Returns:
- a correction amount or getThreshold() if no correction was made
-
getHorizontalGuides
protected int[] getHorizontalGuides()Returns the horizontal guides in the coordinates of the container's contents pane.- Returns:
- the horizontal guides
-
getVerticalGuides
protected int[] getVerticalGuides()Returns the vertical guides in the coordinates of the container's contents pane.- Returns:
- the vertical guides
-
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:
-