public class LabelPositionHandler extends Object implements IPositionHandler
IPositionHandler
that shows the various label position candidates and lets the user move a
label to one of those candidate positions.Modifier and Type | Field and Description |
---|---|
static ResourceKey |
CANDIDATE_TEMPLATE_KEY
A
ResourceKey that will be used to find the IVisualTemplate that will be used to represent the
rectangular selection. |
static ResourceKey |
HIGHLIGHT_TEMPLATE_KEY
A
ResourceKey that will be used to find the IVisualTemplate that will be used to represent the
rectangular selection. |
Constructor and Description |
---|
LabelPositionHandler(ILabel label)
Initializes a new instance of the
LabelPositionHandler class. |
Modifier and Type | Method and Description |
---|---|
void |
cancelDrag(IInputModeContext context,
PointD originalLocation)
Called by clients to indicate that the dragging has been canceled by the user.
|
protected ICanvasObjectDescriptor |
createCandidateDescriptor(IInputModeContext context,
boolean highlight)
Creates an
ICanvasObjectDescriptor to display the given candidate position. |
void |
dragFinished(IInputModeContext context,
PointD originalLocation,
PointD newLocation)
Called by clients to indicate that the repositioning has just been finished.
|
IVisualTemplate |
getCandidateTemplate()
Gets the template to use for showing candidates.
|
protected double |
getDistance(IOrientedRectangle rectangle,
PointD location)
Calculates a distance value between a candidate rectangle and the mouse location.
|
protected IGraph |
getGraph()
Gets the graph instance from the
IInputModeContext that has been passed to the initializeDrag(IInputModeContext)
method. |
IVisualTemplate |
getHighlightTemplate()
Gets the template to use for showing highlighted candidates.
|
protected ILabel |
getLabel()
Gets the label instance.
|
IPoint |
getLocation()
Returns a view of the location of the item.
|
protected Iterable<ILabelModelParameter> |
getParameterCandidates(ILabel label)
Callback method that gets the candidates for the given label.
|
void |
handleMove(IInputModeContext context,
PointD originalLocation,
PointD newLocation)
Called by clients to indicate that the element has been dragged and its position should be updated.
|
void |
initializeDrag(IInputModeContext context)
Called by clients to indicate that the element is going to be dragged.
|
boolean |
isUsingFinderEnabled()
Gets a property that determines whether the handler may use a
ILabelModelParameterFinder to assign arbitrary
positions. |
void |
setCandidateTemplate(IVisualTemplate value)
Sets the template to use for showing candidates.
|
void |
setHighlightTemplate(IVisualTemplate value)
Sets the template to use for showing highlighted candidates.
|
protected void |
setLayoutParameter(ILabel label,
ILabelModelParameter layoutParameter)
Actually applies the given parameter at the end of the gesture.
|
void |
setPosition(PointD location) |
void |
setUsingFinderEnabled(boolean value)
Sets a property that determines whether the handler may use a
ILabelModelParameterFinder to assign arbitrary
positions. |
protected boolean |
useParameterFinder(IInputModeContext context)
Determines whether to use a
ILabelModelParameterFinder to find the best candidate. |
public static final ResourceKey CANDIDATE_TEMPLATE_KEY
ResourceKey
that will be used to find the IVisualTemplate
that will be used to represent the
rectangular selection.public static final ResourceKey HIGHLIGHT_TEMPLATE_KEY
ResourceKey
that will be used to find the IVisualTemplate
that will be used to represent the
rectangular selection.public LabelPositionHandler(ILabel label)
LabelPositionHandler
class.label
- The label that shall be moved.public void cancelDrag(IInputModeContext context, PointD originalLocation)
IDragHandler
This method may be called after the initial IDragHandler.initializeDrag(IInputModeContext)
and zero or more invocations of
IDragHandler.handleMove(IInputModeContext, PointD, PointD)
. Implementations should reset the position of the items they
modify to their initial state. Alternatively to this method the IDragHandler.dragFinished(IInputModeContext, PointD, PointD)
method might be called.
cancelDrag
in interface IDragHandler
context
- The context to retrieve information about the drag from.originalLocation
- The value of the coordinate of the Location
property at the time of
IDragHandler.initializeDrag(IInputModeContext)
.protected ICanvasObjectDescriptor createCandidateDescriptor(IInputModeContext context, boolean highlight)
ICanvasObjectDescriptor
to display the given candidate position.context
- The context for which the descriptor is created.highlight
- Whether to highlight the paintable. This will be true
for the current position and false
for the
others.public void dragFinished(IInputModeContext context, PointD originalLocation, PointD newLocation)
IDragHandler
This method may be called after the initial IDragHandler.initializeDrag(IInputModeContext)
and zero or more invocations of
IDragHandler.handleMove(IInputModeContext, PointD, PointD)
. Alternatively to this method the IDragHandler.cancelDrag(IInputModeContext, PointD)
method might be called.
dragFinished
in interface IDragHandler
context
- The context to retrieve information about the drag from.originalLocation
- The value of the Location
property at the time of IDragHandler.initializeDrag(IInputModeContext)
.newLocation
- The coordinates in the world coordinate system that the client wants the handle to be at. Depending on the
implementation the Location
may or may not be modified to reflect the new value. This is the same
value as delivered in the last invocation of IDragHandler.handleMove(IInputModeContext, PointD, PointD)
public final IVisualTemplate getCandidateTemplate()
setCandidateTemplate(IVisualTemplate)
protected double getDistance(IOrientedRectangle rectangle, PointD location)
rectangle
- The rectangle candidate.location
- The mouse location.protected final IGraph getGraph()
IInputModeContext
that has been passed to the initializeDrag(IInputModeContext)
method.public final IVisualTemplate getHighlightTemplate()
setHighlightTemplate(IVisualTemplate)
protected final ILabel getLabel()
public final IPoint getLocation()
IDragHandler
The point describes the current world coordinate of the element that can be modified by this handler.
getLocation
in interface IDragHandler
protected Iterable<ILabelModelParameter> getParameterCandidates(ILabel label)
label
- The label.public void handleMove(IInputModeContext context, PointD originalLocation, PointD newLocation)
IDragHandler
This method may be called more than once after an initial IDragHandler.initializeDrag(IInputModeContext)
and will the final
call will be followed by either one IDragHandler.dragFinished(IInputModeContext, PointD, PointD)
or one IDragHandler.cancelDrag(IInputModeContext, PointD)
call.
handleMove
in interface IDragHandler
context
- The context to retrieve information about the drag from.originalLocation
- The value of the Location
property at the time of IDragHandler.initializeDrag(IInputModeContext)
.newLocation
- The coordinates in the world coordinate system that the client wants the handle to be at. Depending on the
implementation the Location
may or may not be modified to reflect the new value.public void initializeDrag(IInputModeContext context)
IDragHandler
This call will be followed by one or more calls to IDragHandler.handleMove(IInputModeContext, PointD, PointD)
, and a final IDragHandler.dragFinished(IInputModeContext, PointD, PointD)
or IDragHandler.cancelDrag(IInputModeContext, PointD)
.
initializeDrag
in interface IDragHandler
context
- The context to retrieve information about the drag from.public final boolean isUsingFinderEnabled()
ILabelModelParameterFinder
to assign arbitrary
positions.
The default value is true
useParameterFinder(IInputModeContext)
,
setUsingFinderEnabled(boolean)
public final void setCandidateTemplate(IVisualTemplate value)
value
- The CandidateTemplate to set.getCandidateTemplate()
public final void setHighlightTemplate(IVisualTemplate value)
value
- The HighlightTemplate to set.getHighlightTemplate()
protected void setLayoutParameter(ILabel label, ILabelModelParameter layoutParameter)
label
- The label to set the parameter for.layoutParameter
- The new parameter.public void setPosition(PointD location)
public final void setUsingFinderEnabled(boolean value)
ILabelModelParameterFinder
to assign arbitrary
positions.
The default value is true
value
- The UsingFinderEnabled to set.useParameterFinder(IInputModeContext)
,
isUsingFinderEnabled()
protected boolean useParameterFinder(IInputModeContext context)
ILabelModelParameterFinder
to find the best candidate.
This implementation returns true
if the UsingFinderEnabled
property is true
and the control key is pressed.
context
- The context that is currently being used - may be null
if the method is called without context.