public class SnapToGuides extends SnapToHelper
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.
Modifier and Type | Field and Description |
---|---|
protected GraphicalEditPart |
container
The graphical editpart to which guides are relative.
|
protected int[] |
horizontalGuides
The locations of the horizontal guides in the container's coordinates.
|
static java.lang.String |
KEY_HORIZONTAL_ANCHOR
The key used to identify the horizontal anchor point.
|
static java.lang.String |
KEY_HORIZONTAL_GUIDE
The key used to identify the Horizontal Guide.
|
static java.lang.String |
KEY_VERTICAL_ANCHOR
The key used to identify the vertical anchor point.
|
static java.lang.String |
KEY_VERTICAL_GUIDE
The key used to identify the Vertical Guide.
|
protected static double |
THRESHOLD
The threshold for snapping to guides.
|
protected int[] |
verticalGuides
The locations of the vertical guides in the container's coordinates.
|
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 and Description |
---|
SnapToGuides(GraphicalEditPart container)
Constructs a new snap-to-guides helper using the given container as the
basis.
|
Modifier and Type | Method and Description |
---|---|
protected double |
getCorrectionFor(int[] guides,
double near,
double far,
java.util.Map extendedData,
boolean isVertical)
Returns the correction for the given near and far sides of a rectangle or
getThreshold() if no correction was found. |
protected double |
getCorrectionFor(int[] guides,
double value,
java.util.Map extendedData,
boolean vert,
int side)
Returns the correction for the given location or
getThreshold()
if no correction was found. |
protected int[] |
getHorizontalGuides()
Returns the horizontal guides in the coordinates of the container's
contents pane.
|
protected double |
getThreshold()
Get the sensitivity of the snapping.
|
protected int[] |
getVerticalGuides()
Returns the vertical guides in the coordinates of the container's
contents pane.
|
protected void |
setThreshold(double newThreshold)
Set the sensitivity of the snapping.
|
int |
snapRectangle(Request request,
int snapOrientation,
PrecisionRectangle baseRect,
PrecisionRectangle result)
Applies a snap correction to a Rectangle based on a given Rectangle.
|
makeAbsolute, makeRelative, snapPoint, snapPoint, snapRectangle
public static final java.lang.String KEY_VERTICAL_GUIDE
public static final java.lang.String KEY_HORIZONTAL_GUIDE
public static final java.lang.String KEY_VERTICAL_ANCHOR
-1
indicates the left side should be attached.
0
indicates the center should be attached.
1
indicates the right side should be attached.
public static final java.lang.String KEY_HORIZONTAL_ANCHOR
-1
indicates the top side should be attached.
0
indicates the middle should be attached.
1
indicates the bottom side should be attached.
protected static final double THRESHOLD
protected GraphicalEditPart container
protected int[] verticalGuides
getVerticalGuides()
.protected int[] horizontalGuides
getHorizontalGuides()
.public SnapToGuides(GraphicalEditPart container)
container
- the container editpartprotected double getThreshold()
protected void setThreshold(double newThreshold)
newThreshold
- the new snapping thresholdgetThreshold()
protected double getCorrectionFor(int[] guides, double near, double far, java.util.Map extendedData, boolean isVertical)
getThreshold()
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.guides
- the location of the guidesnear
- the top or left locationfar
- the bottom or right locationextendedData
- the map for storing snap detailsisVertical
- true
if for vertical guides, false
for horizontal.protected double getCorrectionFor(int[] guides, double value, java.util.Map extendedData, boolean vert, int side)
getThreshold()
if no correction was found. If correction occurs, the extendedData will
have the guide and attachment point set. The attachment point is
identified by the side
parameter.
The correction's magnitude will be less than getThreshold().
guides
- the location of the guidesvalue
- the location being testedextendedData
- the map for storing snap detailsvert
- true
if for vertical guides, false
side
- the integer indicating which side is being snappedprotected int[] getHorizontalGuides()
protected int[] getVerticalGuides()
public int snapRectangle(Request request, int snapOrientation, PrecisionRectangle baseRect, PrecisionRectangle result)
SnapToHelper
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.
snapRectangle
in class SnapToHelper
request
- the request or null
snapOrientation
- the input snap locationsbaseRect
- the input rectangleresult
- the correction is applied to this rectangleSnapToHelper.snapRectangle(Request, int, PrecisionRectangle,
PrecisionRectangle)
Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.