Class SnapToHelper
- java.lang.Object
-
- org.eclipse.gef.SnapToHelper
-
- All Implemented Interfaces:
org.eclipse.draw2d.PositionConstants
- Direct Known Subclasses:
CompoundSnapToHelper
,SnapToGeometry
,SnapToGrid
,SnapToGuides
public abstract class SnapToHelper extends java.lang.Object implements org.eclipse.draw2d.PositionConstants
A helper used temporarily by Tools for snapping certain mouse interactions. SnapToHelpers should not be reused by tools or by the editparts which provide them to the tools. For example, for a move operation, the life-cycle of a SnapToHelper begins when a drag is initiated, and ends when the drag is over. If another drag is initiated right after the first one is completed, new SnapToHelpers are employed. This means that helpers can assume that everything else is static, and there is no need to track changes outside of the helper.- Since:
- 3.0
-
-
Field Summary
-
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 SnapToHelper()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
makeAbsolute(org.eclipse.draw2d.IFigure figure, org.eclipse.draw2d.geometry.Translatable t)
Translates from a given figure to absolute coordinates.protected void
makeRelative(org.eclipse.draw2d.IFigure figure, org.eclipse.draw2d.geometry.Translatable t)
Translates from absolute to coordinates relative to the given figure.int
snapPoint(Request request, int snapDirections, org.eclipse.draw2d.geometry.PrecisionPoint where, org.eclipse.draw2d.geometry.PrecisionPoint result)
Applies a snapping correction to the given result.int
snapPoint(Request request, int snapLocations, org.eclipse.draw2d.geometry.PrecisionRectangle[] rects, org.eclipse.draw2d.geometry.PrecisionPoint result)
A convenience method for snapping a Point based on an array of rectangles.int
snapRectangle(Request request, int snapOrientation, org.eclipse.draw2d.geometry.PrecisionRectangle[] baseRects, org.eclipse.draw2d.geometry.PrecisionRectangle result)
A convenience method for snapping a Rectangle based on one or more rectangles.abstract int
snapRectangle(Request request, int snapOrientation, org.eclipse.draw2d.geometry.PrecisionRectangle baseRect, org.eclipse.draw2d.geometry.PrecisionRectangle result)
Applies a snap correction to a Rectangle based on a given Rectangle.
-
-
-
Method Detail
-
makeAbsolute
protected void makeAbsolute(org.eclipse.draw2d.IFigure figure, org.eclipse.draw2d.geometry.Translatable t)
Translates from a given figure to absolute coordinates.- Parameters:
figure
- the reference figuret
- the object to translate
-
makeRelative
protected void makeRelative(org.eclipse.draw2d.IFigure figure, org.eclipse.draw2d.geometry.Translatable t)
Translates from absolute to coordinates relative to the given figure.- Parameters:
figure
- the reference figuret
- the object to translate
-
snapPoint
public int snapPoint(Request request, int snapDirections, org.eclipse.draw2d.geometry.PrecisionPoint where, org.eclipse.draw2d.geometry.PrecisionPoint result)
Applies a snapping correction to the given result. Snapping can occur in the four primary directions: NORTH, SOUTH, EAST, WEST, as defined onPositionConstants
. By default a Point is treated as an empty Rectangle. Only NORTH and WEST should be used in general. But SOUTH and EAST may also be used. Similarly, VERTICAL and HORIZONTAL may be used to allow a point to snap to the "center" or "middle" as defined by the concrete subclass.The returned value should be a subset of the given snapDirections based on what correction was applied to the result. e.g., if the x value was adjusted, the returned value should not contain WEST, EAST, or HORIZONTAL.
All coordinate information received and returned by this method should be in absolute coordinates.
- Parameters:
request
- a request ornull
snapDirections
- the directions in which snapping should occur.where
- the rectangle used to determine snappingresult
- the result- Returns:
- the remaining snap locations
-
snapPoint
public int snapPoint(Request request, int snapLocations, org.eclipse.draw2d.geometry.PrecisionRectangle[] rects, org.eclipse.draw2d.geometry.PrecisionPoint result)
A convenience method for snapping a Point based on an array of rectangles. By default, this method will construct an empty rectangle at the same locations as the provided point, and callsnapRectangle(Request, int, PrecisionRectangle[], PrecisionRectangle)
. The intended usage of this method is when dragging one or more parts in a diagram.The returned value should be a subset of the given snapDirections based on what correction was applied to the result. e.g., if the x value was adjusted, the returned value should not contain WEST, EAST, or HORIZONTAL.
All coordinate information received and returned by this method should be in absolute coordinates.
- Parameters:
request
- the request ornull
snapLocations
- the types of snapping to performrects
- an array of one or more rectangles used to perform the snappingresult
- the correction will be applied to this point- Returns:
- the remaining snap locations
-
snapRectangle
public int snapRectangle(Request request, int snapOrientation, org.eclipse.draw2d.geometry.PrecisionRectangle[] baseRects, org.eclipse.draw2d.geometry.PrecisionRectangle result)
A convenience method for snapping a Rectangle based on one or more rectangles. This method will callsnapRectangle(Request, int, PrecisionRectangle, PrecisionRectangle)
for each rectangle in the array or until no more snap locations remain.All coordinate information received and returned by this method should be in absolute coordinates.
- Parameters:
request
- the request ornull
baseRects
- the prioritized rectangles to snap toresult
- the outputsnapOrientation
- the input snap locations- Returns:
- the remaining snap locations
-
snapRectangle
public abstract int snapRectangle(Request request, int snapOrientation, org.eclipse.draw2d.geometry.PrecisionRectangle baseRect, org.eclipse.draw2d.geometry.PrecisionRectangle result)
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.
- Parameters:
request
- the request ornull
baseRect
- the input rectangleresult
- the correction is applied to this rectanglesnapOrientation
- the input snap locations- Returns:
- the remaining snap locations
- Since:
- 3.0
-
-