| Package | com.yworks.canvas.input.snapLines |
| Class | public class SnapContext |
| Inheritance | SnapContext flash.events.EventDispatcher |
| Subclasses | GraphSnapContext |
IInputMode implementations and similar code to manage interactive snapping
of elements to other elements during a drag-like operation.
This class should be used by the drag implementation as follows:
initializeDrag needs to be called.dragInitialized needs to be called after the mode has performed all of its own
initialization.handleMove or disableSnapping
needs to be called for each incremental movement of the user's input device.handleMove had been called, the mode should perform the move and report back to the instance
by calling the dragged method.cancelDrag should be called.dragFinished method should be called.See also
| Property | Defined By | ||
|---|---|---|---|
| currentInputModeContext : IInputModeContext [read-only]
Gets the current input mode context. | SnapContext | ||
| enabled : Boolean
Gets or sets a value indicating whether this SnapContext is enabled. | SnapContext | ||
| isInitialized : Boolean [read-only]
Whether the context is initialized. | SnapContext | ||
| isInitializing : Boolean [read-only]
Gets a value indicating whether this instance is currently initializing. | SnapContext | ||
| originalLocation : IPoint [read-only]
Gets the original location of the mouse at the time the gesture was initialized. | SnapContext | ||
| snapDistance : Number
Gets or sets the global snap distance, which is the maximum distance between the current mouse coordinates
and the coordinates to which the mouse will snap. | SnapContext | ||
| snapResults : ICollectionModel [read-only]
The collection of SnapResults. | SnapContext | ||
| stroke : IStroke
The stroke that shall be used by the created DisplayObjects to visualize the snap results. | SnapContext | ||
| visualizeSnapResults : Boolean
Gets or sets a value indicating whether to visualize the snap results. | SnapContext | ||
| voidInstance : SnapContext [static] [read-only]
The shared void instance. | SnapContext | ||
| Property | Defined By | ||
|---|---|---|---|
| _enabled : Boolean = true | SnapContext | ||
| Method | Defined By | ||
|---|---|---|---|
Initializes a new instance of the SnapContext class. | SnapContext | ||
cancelDrag():void
Called when a drag has been canceled. | SnapContext | ||
checkEnabledAccess():void | SnapContext | ||
Creates and returns a new instance of an IDisplayObjectCreator implementation that can be used to
visualize a SnapResult with the given resourceKey. | SnapContext | ||
Helper method used by createSnapResultsModelManager to create the
IModelItemInstaller for the SnapResult type. | SnapContext | ||
Helper method that creates a CollectionModelManager that can be used
to present the current SnapResults in the provided CanvasComponent. | SnapContext | ||
disableSnapping():void
This method can be called by the IInputMode while this instance is initialized
alternatively to handleMove. | SnapContext | ||
Called when a drag has been successfully finished. | SnapContext | ||
This method needs to be called by the client IInputMode that initialized this instance after
it has performed the actual move operation with the adjusted coordinates after a call to
handleMove. | SnapContext | ||
dragInitialized():void
Collects a list of snap lines. | SnapContext | ||
Handles a move. | SnapContext | ||
Called by IInputMode implementations when an interactive drag is started. | SnapContext | ||
Helper method that wraps the given context so that a ILookup.lookup
query on the wrapped context for the SnapContext type yields this instance. | SnapContext | ||
| Method | Defined By | ||
|---|---|---|---|
cleanUp():void
Performs clean up procedures. | SnapContext | ||
onCleanedUp():void
Raises the cleanedUp event. | SnapContext | ||
onCollectSnapResults(inputContext:IInputModeContext, originalLocation:IPoint, newLocation:IPoint, snapDistance:Number, snapResults:Collection):void
Raises the collectSnapResults event using the provided data. | SnapContext | ||
onInitialized():void
Raises the initialized event. | SnapContext | ||
onInitializing():void
Raises the initializing event. | SnapContext | ||
Chooses the current SnapResults from a temporary list. | SnapContext | ||
| Event | Summary | Defined By | ||
|---|---|---|---|---|
| Dispatched when this instance has been cleaned up. | SnapContext | |||
| Dispatched during moving gestures to collect SnapResults for the moved objects. | SnapContext | |||
| Dispatched when this instance has initialized a drag. | SnapContext | |||
| Dispatched when this instance is about to initialize a drag. | SnapContext | |||
| _enabled | property |
protected var _enabled:Boolean = true| currentInputModeContext | property |
currentInputModeContext:IInputModeContext [read-only] Gets the current input mode context.
public function get currentInputModeContext():IInputModeContextSee also
| enabled | property |
enabled:Boolean
Gets or sets a value indicating whether this SnapContext is enabled.
public function get enabled():Boolean public function set enabled(value:Boolean):void| isInitialized | property |
isInitialized:Boolean [read-only]
Whether the context is initialized.
The context is initialized between the calls to dragInitialized and dragFinished
or cancelDrag.
public function get isInitialized():BooleanSee also
| isInitializing | property |
isInitializing:Boolean [read-only] Gets a value indicating whether this instance is currently initializing.
public function get isInitializing():BooleanSee also
| originalLocation | property |
originalLocation:IPoint [read-only] Gets the original location of the mouse at the time the gesture was initialized.
public function get originalLocation():IPointSee also
| snapDistance | property |
snapDistance:NumberGets or sets the global snap distance, which is the maximum distance between the current mouse coordinates and the coordinates to which the mouse will snap. The distance is interpreted in view coordinates.
The default value is 5.0.
public function get snapDistance():Number public function set snapDistance(value:Number):voidSee also
| snapResults | property |
snapResults:ICollectionModel [read-only]
The collection of SnapResults.
This collection is automatically updated during moving the mouse.
public function get snapResults():ICollectionModelSee also
| stroke | property |
stroke:IStroke
The stroke that shall be used by the created DisplayObjects to visualize the snap results.
In the createDisplayObjectCreator method the value of this property is assigned to the stroke property
of the created IDisplayObjectCreator implementation if the implementation is known to have such a property.
public function get stroke():IStroke public function set stroke(value:IStroke):voidSee also
| visualizeSnapResults | property |
visualizeSnapResults:BooleanGets or sets a value indicating whether to visualize the snap results.
The default value is true.
public function get visualizeSnapResults():Boolean public function set visualizeSnapResults(value:Boolean):voidSee also
| voidInstance | property |
voidInstance:SnapContext [read-only] The shared void instance. Note that this instance cannot be enabled.
public static function get voidInstance():SnapContextSee also
| SnapContext | () | Constructor |
public function SnapContext()Initializes a new instance of the SnapContext class.
| cancelDrag | () | method |
public function cancelDrag():void
Called when a drag has been canceled.
Clears all temporary lists and sets isInitialized back to false, as well as
performs cleanUp and finally triggers the cleanedUp event.
#cleanedUp
— |
See also
| checkEnabledAccess | () | method |
public function checkEnabledAccess():void| cleanUp | () | method |
protected function cleanUp():void
Performs clean up procedures.
This is called in response to cancelDrag and dragFinished as well as initially
during initializeDrag.
See also
| createDisplayObjectCreator | () | method |
public function createDisplayObjectCreator(resourceKey:ResourceKey):IDisplayObjectCreator
Creates and returns a new instance of an IDisplayObjectCreator implementation that can be used to
visualize a SnapResult with the given resourceKey.
Subclasses of SnapResult use this factory method and can expect to receive a new instance
of a default implementation of IDisplayObjectCreator that matches their resourceKey,
so they can set it's properties after casting it down to the default implementation class type.
The following default implementations are returned for the following keys:
EqualWidthPaintable for SnapLine.SNAP_LINE_EQUAL_WIDTH_KEYEqualHeightPaintable for SnapLine.SNAP_LINE_EQUAL_HEIGHT_KEYFixedLinePaintable for SnapLine.SNAP_LINE_FIXED_LINE_KEYVariableLinePaintable for SnapLine.SNAP_LINE_VARIABLE_LINE_KEYVariableLinePaintable for SnapLine.SNAP_LINE_EXTENDED_VARIABLE_LINE_KEYBlankVariableLinePaintable for SnapLine.SNAP_LINE_BLANK_VARIABLE_LINE_KEYFixedDistanceSnapResultPaintable for SnapLine.SNAP_LINE_FIXED_DISTANCE_KEYCenterBetweenBoundsPaintable for SnapLine.SNAP_LINE_CENTER_BETWEEN_BOUNDS_KEYCenterBetweenCenterPaintable for SnapLine.SNAP_LINE_CENTER_BETWEEN_CENTERS_KEYEqualDistanceBetweenBoundsPaintable for SnapLine.SNAP_LINE_EQUAL_DISTANCE_BETWEEN_BOUNDS_KEYEqualDistanceBetweenCentersPaintable for SnapLine.SNAP_LINE_EQUAL_DISTANCE_BETWEEN_CENTERS_KEYGridSnapResultPaintable for SnapLine.SNAP_TO_GRID_KEYstroke property, the SnapContext's
stroke property is assigned to it.
Parameters
resourceKey:ResourceKey — The resource key describing which paintable implementation to create.
|
IDisplayObjectCreator — A new instance of an IDisplayObjectCreator implementation that can be used to
visualize a SnapResult with the given resourceKey or null if
the given key can't be matched to an implementation.
|
See also
| createSnapResultModelItemInstaller | () | method |
public function createSnapResultModelItemInstaller():IModelItemInstaller
Helper method used by createSnapResultsModelManager to create the
IModelItemInstaller for the SnapResult type.
IModelItemInstaller — An instance that can install SnapResults in a CanvasControl.
|
See also
| createSnapResultsModelManager | () | method |
public function createSnapResultsModelManager(component:CanvasComponent):CollectionModelManager
Helper method that creates a CollectionModelManager that can be used
to present the current SnapResults in the provided CanvasComponent.
Parameters
component:CanvasComponent — The component to initialize the CollectionModelManager with.
|
CollectionModelManager — The model manager that manages the visual representation of the SnapResults.
|
See also
| disableSnapping | () | method |
public function disableSnapping():void
This method can be called by the IInputMode while this instance is initialized
alternatively to handleMove.
Calling this method will temporarily disable any snapping operations and clears all SnapResults.
See also
| dragFinished | () | method |
public function dragFinished(newLocation:IPoint):SnapState
Called when a drag has been successfully finished.
Clears all temporary lists and sets isInitialized back to false.
Also the cleanUp method is invoked and the cleanedUp event is triggered.
Parameters
newLocation:IPoint — The current mouse location.
|
SnapState — The adjusted coordinates.
|
#cleanedUp
— |
See also
| dragged | () | method |
public function dragged(mouseLocation:IPoint, finalSnapState:SnapState):void
This method needs to be called by the client IInputMode that initialized this instance after
it has performed the actual move operation with the adjusted coordinates after a call to
handleMove.
Most of the client code implementations will just call this method with the exact values returned by
handleMove.
This method does not need to be called in the case where disableSnapping was called for the
current move.
Parameters
mouseLocation:IPoint — The actual mouse location.
| |
finalSnapState:SnapState — The final snap state that contains the location that has been used by the client code
for the move and how it has been snapped.
|
See also
| dragInitialized | () | method |
public function dragInitialized():void
Collects a list of snap lines.
Snap lines represent possible horizontal or vertical lines to which a moved item can "snap".
This method is called in the MoveInputMode's or HandleInputMode's
beginDrag method after all items to be moved or reshaped have been added.
See also
| handleMove | () | method |
public function handleMove(newLocation:IPoint):SnapState
Handles a move.
This method returns a composite of the adjusted (mouse) coordinates and an indication to the caller what
kind of snapping was applied. It also manages the collection of SnapResults.
If snapping should be temporarily (for a mouse move) disabled, disableSnapping
should be called instead.
Parameters
newLocation:IPoint — The current mouse location.
|
SnapState — The adjusted coordinates and how they have been adjusted.
|
See also
| initializeDrag | () | method |
public function initializeDrag(context:IInputModeContext, originalLocation:IPoint):void
Called by IInputMode implementations when an interactive drag is started.
Updates isInitializing, originalLocation and currentInputModeContext
and then triggers the initializing event.
An IllegalOperationException is thrown if this context is already initialized.
Parameters
context:IInputModeContext — The context in which the interactive drag is started.
| |
originalLocation:IPoint — The original location of the mouse.
|
#initializing
— |
See also
| onCleanedUp | () | method |
protected function onCleanedUp():void
Raises the cleanedUp event.
#cleanedUp
— |
| onCollectSnapResults | () | method |
protected function onCollectSnapResults(inputContext:IInputModeContext, originalLocation:IPoint, newLocation:IPoint, snapDistance:Number, snapResults:Collection):void
Raises the collectSnapResults event using the provided data.
Parameters
inputContext:IInputModeContext — The context for which the event is queried.
| |
originalLocation:IPoint — The original location of the mouse at the beginning of the gesture.
| |
newLocation:IPoint — The new (current) location of the mouse.
| |
snapDistance:Number — The zoom invariant snap distance.
| |
snapResults:Collection — The collection to store the snap results in.
|
#collectSnapResults
— |
| onInitialized | () | method |
protected function onInitialized():void
Raises the initialized event.
#initialized
— |
| onInitializing | () | method |
protected function onInitializing():void
Raises the initializing event.
#initializing
— |
| processSnapResults | () | method |
protected function processSnapResults(snapResults:List, originalLocation:IPoint, newLocation:IPoint):SnapState
Chooses the current SnapResults from a temporary list.
Chooses from a list of possible results the most important ones. Also maintains the collection of snap results.
Parameters
snapResults:List — A temporary list of suggested SnapResults.
| |
originalLocation:IPoint — The point in world coordinates where the mouse move started.
| |
newLocation:IPoint — The current mouse location.
|
SnapState — The adjusted coordinates and how they have been adjusted.
|
See also
| wrapContext | () | method |
public function wrapContext(context:IInputModeContext):IInputModeContext
Helper method that wraps the given context so that a ILookup.lookup
query on the wrapped context for the SnapContext type yields this instance.
Parameters
context:IInputModeContext — The context to wrap and delegate all calls to.
|
IInputModeContext — A modified instance that yields this instance if it is queried for the SnapContext type.
|
See also
| cleanedUp | Event |
com.yworks.canvas.input.snapLines.SnapContextEventSnapContextEvent.CLEANED_UPDispatched when this instance has been cleaned up.
See also
| collectSnapResults | Event |
com.yworks.canvas.input.snapLines.CollectSnapResultEventcom.yworks.canvas.input.snapLines.CollectSnapResultEvent#COLLECT_SNAP_RESULTS
Dispatched during moving gestures to collect SnapResults for the moved objects.
The moving model items must register for this event, preferably in the initializeDrag method of the
IDragHandler.
The event handler has to add SnapResults for the moving object to the list.
The IDragHandlers of the moved items have to take care themselves whether to add a handler to the list
depending on the their settings.
See also
| initialized | Event |
com.yworks.canvas.input.snapLines.SnapContextEventSnapContextEvent.INITIALIZEDDispatched when this instance has initialized a drag.
See also
| initializing | Event |
com.yworks.canvas.input.snapLines.SnapContextEventSnapContextEvent.INITIALIZINGDispatched when this instance is about to initialize a drag.
See also