Package org.eclipse.gef
Class SnapToGrid
- java.lang.Object
-
- org.eclipse.gef.SnapToHelper
-
- org.eclipse.gef.SnapToGrid
-
- All Implemented Interfaces:
org.eclipse.draw2d.PositionConstants
public class SnapToGrid extends SnapToHelper
A helper used to perform snapping to a grid, which is specified on the graphical viewer via the various properties defined in this class. This helper can be used in conjunction with theDragEditPartsTracker
when dragging editparts within a graphical viewer. When snapping a rectangle, the edges of the rectangle will snap along gridlines.This helper does not keep up with changes made to the graphical viewer's properties. Clients should instantiate a new helper each time one is requested and not hold on to instances of the helper, if the grid properties specified on the viewer are subject to change.
- Since:
- 3.0
- See Also:
GridLayer
-
-
Field Summary
Fields Modifier and Type Field Description protected GraphicalEditPart
container
The graphical part whose content's figure defines the grid.static int
DEFAULT_GAP
Deprecated.use DEFAULT_GRID_SIZEstatic int
DEFAULT_GRID_SIZE
The default grid size if the viewer does not specify a size.protected int
gridX
The horizontal interval for the gridprotected int
gridY
The vertical interval for the gridprotected org.eclipse.draw2d.geometry.Point
origin
The origin of the grid.static java.lang.String
PROPERTY_GRID_ENABLED
A viewer property indicating whether the snap function is enabled.static java.lang.String
PROPERTY_GRID_ORIGIN
A viewer property indicating the grid's origin.static java.lang.String
PROPERTY_GRID_SPACING
A viewer property indicating the grid spacing.static java.lang.String
PROPERTY_GRID_VISIBLE
A viewer property indicating whether the grid should be displayed.-
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
Constructors Constructor Description SnapToGrid(GraphicalEditPart container)
Constructs a gridded snap helper on the given editpart.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
snapRectangle(Request request, int snapLocations, org.eclipse.draw2d.geometry.PrecisionRectangle rect, org.eclipse.draw2d.geometry.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 Detail
-
PROPERTY_GRID_ENABLED
public static final java.lang.String PROPERTY_GRID_ENABLED
A viewer property indicating whether the snap function is enabled. The value must be a Boolean.- See Also:
- Constant Field Values
-
PROPERTY_GRID_VISIBLE
public static final java.lang.String PROPERTY_GRID_VISIBLE
A viewer property indicating whether the grid should be displayed. The value must be a Boolean.- See Also:
- Constant Field Values
-
PROPERTY_GRID_SPACING
public static final java.lang.String PROPERTY_GRID_SPACING
A viewer property indicating the grid spacing. The value must be aDimension
.- See Also:
- Constant Field Values
-
PROPERTY_GRID_ORIGIN
public static final java.lang.String PROPERTY_GRID_ORIGIN
A viewer property indicating the grid's origin. The value must be aPoint
.- See Also:
- Constant Field Values
-
DEFAULT_GRID_SIZE
public static final int DEFAULT_GRID_SIZE
The default grid size if the viewer does not specify a size.- See Also:
PROPERTY_GRID_SPACING
, Constant Field Values
-
DEFAULT_GAP
public static final int DEFAULT_GAP
Deprecated.use DEFAULT_GRID_SIZE- See Also:
- Constant Field Values
-
container
protected GraphicalEditPart container
The graphical part whose content's figure defines the grid.
-
gridX
protected int gridX
The horizontal interval for the grid
-
gridY
protected int gridY
The vertical interval for the grid
-
origin
protected org.eclipse.draw2d.geometry.Point origin
The origin of the grid.
-
-
Constructor Detail
-
SnapToGrid
public SnapToGrid(GraphicalEditPart container)
Constructs a gridded snap helper on the given editpart. The editpart should be the graphical editpart whose contentspane figure is used as the reference for the grid.- Parameters:
container
- the editpart which the grid is on
-
-
Method Detail
-
snapRectangle
public int snapRectangle(Request request, int snapLocations, org.eclipse.draw2d.geometry.PrecisionRectangle rect, org.eclipse.draw2d.geometry.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 classSnapToHelper
- Parameters:
request
- the request ornull
snapLocations
- the input snap locationsrect
- the input rectangleresult
- the correction is applied to this rectangle- Returns:
- the remaining snap locations
- See Also:
SnapToHelper.snapRectangle(Request, int, PrecisionRectangle, PrecisionRectangle)
-
-