public class FXBendPolicy extends AbstractPolicy<javafx.scene.Node> implements ITransactional
FXBendPolicy
can be used to manipulate the points constituting an
FXConnection
, i.e. its start point, way points, and end point. When
moving a point the policy takes care of:
IVisualPart
under mouse when
applicable.Modifier and Type | Field and Description |
---|---|
protected static double |
DEFAULT_OVERLAY_THRESHOLD
The overlay threshold, i.e. the distance between two points so that they
are regarded as overlying.
|
protected boolean |
initialized
Stores the initialized flag for this policy, i.e.
|
Constructor and Description |
---|
FXBendPolicy() |
Modifier and Type | Method and Description |
---|---|
protected boolean |
canAttach()
Returns
true if the currently modified point can be attached
to an IVisualPart . |
IUndoableOperation |
commit()
Returns an
IUndoableOperation that performs all manipulations
applied by the policy since the last ITransactional.init() call. |
void |
createAndSelectSegmentPoint(int segmentIndex,
Point mouseInScene)
Creates a new way point at the given segment.
|
protected IFXAnchor |
findAnchor(Point currentReferencePositionInScene,
boolean canAttach)
Determines the
IFXAnchor that replaces the anchor of the
currently modified point. |
protected IFXAnchor |
generateStaticAnchor(Point scene)
Generates an
FXStaticAnchor that yields the given position (in
scene coordinates). |
protected FXConnection |
getConnection()
Returns the
FXConnection that is manipulated by this policy. |
protected Point |
getInitialMousePositionInScene()
Returns the initial mouse position in scene coordinates.
|
protected Point |
getInitialReferencePositionInLocal()
Returns the initial reference position in the local coordinate system of
the
FXConnection that is manipulated by this policy. |
protected double |
getOverlayThreshold()
Removes the overlay threshold, i.e. the distance between two points, so
that they are regarded as overlaying.
|
protected void |
hideShowOverlain(Point currentPositionInScene)
Restores a point that was previously removed because it was overlaid.
|
void |
init()
Initializes the policy, so that the policy's "work" methods can be used.
|
protected boolean |
isOverlain(int candidateIndex,
int currentIndex,
Point currentReferencePositionInScene)
Returns
true if the points given by the specified indices
are overlaying, i.e. their distance is smaller than the
overlay threshold and they are above the
same anchorage. |
protected void |
locallyExecuteOperation()
Locally executes the
FXBendOperation that is updated by this
policy, i.e. not on the operation history. |
void |
moveSelectedSegmentPoint(Point mouseInScene)
Moves the currently selected point to the given mouse position in scene
coordinates.
|
void |
selectSegmentPoint(int segmentIndex,
double segmentParameter,
Point mouseInScene)
Selects the point specified by the given segment index and parameter for
manipulation.
|
java.lang.String |
toString() |
commit, disableRefreshVisuals, enableRefreshVisuals, getAdaptable, getHost, init, setAdaptable
protected static final double DEFAULT_OVERLAY_THRESHOLD
protected boolean initialized
protected boolean canAttach()
true
if the currently modified point can be attached
to an IVisualPart
. Otherwise returns false
. Per
default, only the start and the end point can be attached.true
if the currently modified point can be attached
to an IVisualPart
. Otherwise returns false
.public IUndoableOperation commit()
ITransactional
IUndoableOperation
that performs all manipulations
applied by the policy since the last ITransactional.init()
call. When called
multiple times in sequence, only the first call will yield an operation,
the subsequent calls will yield null
.commit
in interface ITransactional
IUndoableOperation
that performs all manipulations
applied by the policy since the last ITransactional.init()
call.public void createAndSelectSegmentPoint(int segmentIndex, Point mouseInScene)
segmentIndex
- The index of the segment for which a new way point is created.mouseInScene
- The mouse position in scene coordinates.protected IFXAnchor findAnchor(Point currentReferencePositionInScene, boolean canAttach)
IFXAnchor
that replaces the anchor of the
currently modified point. If the point can be attached to an underlying
anchor, then the IVisualPart
at the mouse position is queried for
an IFXAnchor
. Otherwise a static anchor is generated using
generateStaticAnchor(Point)
.currentReferencePositionInScene
- The mouse position in scene coordinates.canAttach
- true
if the point can be attached to an
underlying IVisualPart
, otherwise false
.IFXAnchor
that replaces the anchor of the currently
modified point.protected IFXAnchor generateStaticAnchor(Point scene)
FXStaticAnchor
that yields the given position (in
scene coordinates).scene
- The static position in scene coordinates.FXStaticAnchor
that yields the given position.protected FXConnection getConnection()
FXConnection
that is manipulated by this policy.FXConnection
that is manipulated by this policy.protected Point getInitialMousePositionInScene()
protected Point getInitialReferencePositionInLocal()
FXConnection
that is manipulated by this policy.FXConnection
.protected double getOverlayThreshold()
GridModel.isShowGrid()
, then the grid cell size is used to
determine the overlay threshold. Otherwise, the
DEFAULT_OVERLAY_THRESHOLD
is used.protected void hideShowOverlain(Point currentPositionInScene)
FXConnection
. The overlaid point is removed and saved so that it
can be restored later.
currentPositionInScene
- The current mouse position in scene coordinates.public void init()
ITransactional
IllegalStateException
. It is safe to call ITransactional.init()
multiple times in sequence.init
in interface ITransactional
protected boolean isOverlain(int candidateIndex, int currentIndex, Point currentReferencePositionInScene)
true
if the points given by the specified indices
are overlaying, i.e. their distance is smaller than the
overlay threshold
and they are above the
same anchorage. Otherwise returns false
. If the points are
overlaying, then the anchor at the current index is replaced by the
anchor that can be found at the candidate location. The point at the
candidate index is later on removed within
hideShowOverlain(Point)
.candidateIndex
- The candidate index.currentIndex
- The currently modified index.currentReferencePositionInScene
- The current reference position in scene coordinates.true
if the specified points are overlying,
otherwise false
.protected void locallyExecuteOperation()
FXBendOperation
that is updated by this
policy, i.e. not on the operation history.public void moveSelectedSegmentPoint(Point mouseInScene)
hideShowOverlain(Point)
.mouseInScene
- The current mouse position in scene coordinates.public void selectSegmentPoint(int segmentIndex, double segmentParameter, Point mouseInScene)
segmentIndex
- The index of the segment of which a point is to be
manipulated.segmentParameter
- The parameter on the segment to identify if its the end point.mouseInScene
- The current mouse position in scene coordinates.public java.lang.String toString()
toString
in class java.lang.Object
Copyright (c) 2014 itemis AG and others. All rights reserved.