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 SummaryFieldsModifier 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.PositionConstantsALWAYS_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 SummaryConstructorsConstructorDescriptionSnapToGuides(GraphicalEditPart container) Constructs a new snap-to-guides helper using the given container as the basis.
- 
Method SummaryModifier 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.SnapToHelpermakeAbsolute, makeRelative, snapPoint, snapPoint, snapRectangle
- 
Field Details- 
KEY_VERTICAL_GUIDEThe 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_GUIDEThe 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_ANCHORThe 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_ANCHORThe 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:
 
- 
THRESHOLDprotected 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:
 
- 
containerThe graphical editpart to which guides are relative. This should also the parent of the parts being snapped to guides.
- 
verticalGuidesprotected int[] verticalGuidesThe locations of the vertical guides in the container's coordinates. UsegetVerticalGuides().
- 
horizontalGuidesprotected int[] horizontalGuidesThe locations of the horizontal guides in the container's coordinates. UsegetHorizontalGuides().
 
- 
- 
Constructor Details- 
SnapToGuidesConstructs a new snap-to-guides helper using the given container as the basis.- Parameters:
- container- the container editpart
 
 
- 
- 
Method Details- 
getThresholdprotected double getThreshold()Get the sensitivity of the snapping. Corrections greater than this value will not occur.- Returns:
- the snapping threshold
- Since:
- 3.4
 
- 
setThresholdprotected void setThreshold(double newThreshold) Set the sensitivity of the snapping.- Parameters:
- newThreshold- the new snapping threshold
- Since:
- 3.4
- See Also:
 
- 
getCorrectionForprotected 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 guides
- near- the top or left location
- far- the bottom or right location
- extendedData- the map for storing snap details
- isVertical-- trueif for vertical guides,- falsefor horizontal.
- Returns:
- the correction amount or getThreshold() if no correction was made
 
- 
getCorrectionForprotected 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 guides
- value- the location being tested
- extendedData- the map for storing snap details
- vert-- trueif for vertical guides,- false
- side- the integer indicating which side is being snapped
- Returns:
- a correction amount or getThreshold() if no correction was made
 
- 
getHorizontalGuidesprotected int[] getHorizontalGuides()Returns the horizontal guides in the coordinates of the container's contents pane.- Returns:
- the horizontal guides
 
- 
getVerticalGuidesprotected int[] getVerticalGuides()Returns the vertical guides in the coordinates of the container's contents pane.- Returns:
- the vertical guides
 
- 
snapRectanglepublic 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 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:
 
 
-