org.eclipse.gef
Class SnapToGuides
java.lang.Object
org.eclipse.gef.SnapToHelper
org.eclipse.gef.SnapToGuides
-
All Implemented Interfaces:
-
PositionConstants
- public class SnapToGuides
- extends
SnapToHelper
A helper used to perform snapping to guides. The guides are obtained from the viewer's
horizontal and vertical
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
|
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. |
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
|
Method Summary
|
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. |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
|
KEY_VERTICAL_GUIDE
public static final java.lang.String 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:
-
Constant Field Values
KEY_HORIZONTAL_GUIDE
public static final java.lang.String 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:
-
Constant Field Values
KEY_VERTICAL_ANCHOR
public static final java.lang.String 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.
-
-1
indicates the left side should be attached.
-
0
indicates the center should be attached.
-
1
indicates the right side should be attached.
-
See Also:
-
Constant Field Values
KEY_HORIZONTAL_ANCHOR
public static final java.lang.String 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.
-
-1
indicates the top side should be attached.
-
0
indicates the middle should be attached.
-
1
indicates the bottom side should be attached.
-
See Also:
-
Constant Field Values
THRESHOLD
protected static final double THRESHOLD
- The threshold for snapping to guides. The rectangle being snapped must be within +/-
the THRESHOLD. The default value is 5.001;
-
See Also:
-
Constant Field Values
container
protected
GraphicalEditPart container
- The graphical editpart to which guides are relative. This should also the parent of
the parts being snapped to guides.
verticalGuides
protected int[] verticalGuides
- The locations of the vertical guides in the container's coordinates. Use
getVerticalGuides()
.
horizontalGuides
protected int[] horizontalGuides
- The locations of the horizontal guides in the container's coordinates. Use
getHorizontalGuides()
.
SnapToGuides
public SnapToGuides(
GraphicalEditPart container)
- Constructs a new snap-to-guides helper using the given container as the basis.
-
Parameters:
-
container
- the container editpart
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:
-
getThreshold()
getCorrectionFor
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. 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
- true
if for vertical guides, false
for horizontal.
-
Returns:
- the correction amount or getThreshold() if no correction was made
getCorrectionFor
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. 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().
-
-
Parameters:
-
guides
- the location of the guides -
value
- the location being tested -
extendedData
- the map for storing snap details -
vert
- true
if for vertical guides, false
-
side
- 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:
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)
Copyright (c) IBM Corp. and others 2000, 2007. All Rights Reserved.