Packagecom.yworks.canvas.input.snapLines
Classpublic class SnapContext
InheritanceSnapContext Inheritance flash.events.EventDispatcher
Subclasses GraphSnapContext

A class that can be used by 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:

See also

IInputMode
initializeDrag
dragInitialized
handleMove
dragged
disableSnapping
cancelDrag
dragFinished
com.yworks.canvas.input.HandleInputMode.snapContext
com.yworks.canvas.input.MoveInputMode.snapContext
createSnapResultsModelManager


Public Properties
 PropertyDefined 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
Protected Properties
 PropertyDefined By
  _enabled : Boolean = true
SnapContext
Public Methods
 MethodDefined By
  
Initializes a new instance of the SnapContext class.
SnapContext
  
cancelDrag():void
Called when a drag has been canceled.
SnapContext
  
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
  
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
  
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.
SnapContext
  
Collects a list of snap lines.
SnapContext
  
Handles a move.
SnapContext
  
initializeDrag(context:IInputModeContext, originalLocation:IPoint):void
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
Protected Methods
 MethodDefined By
  
cleanUp():void
Performs clean up procedures.
SnapContext
  
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
  
Raises the initialized event.
SnapContext
  
Raises the initializing event.
SnapContext
  
processSnapResults(snapResults:List, originalLocation:IPoint, newLocation:IPoint):SnapState
Chooses the current SnapResults from a temporary list.
SnapContext
Events
 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
Property Detail
_enabledproperty
protected var _enabled:Boolean = true

currentInputModeContextproperty 
currentInputModeContext:IInputModeContext  [read-only]

Gets the current input mode context.


Implementation
    public function get currentInputModeContext():IInputModeContext

See also

enabledproperty 
enabled:Boolean

Gets or sets a value indicating whether this SnapContext is enabled.


Implementation
    public function get enabled():Boolean
    public function set enabled(value:Boolean):void
isInitializedproperty 
isInitialized:Boolean  [read-only]

Whether the context is initialized. The context is initialized between the calls to dragInitialized and dragFinished or cancelDrag.


Implementation
    public function get isInitialized():Boolean

See also

isInitializingproperty 
isInitializing:Boolean  [read-only]

Gets a value indicating whether this instance is currently initializing.


Implementation
    public function get isInitializing():Boolean

See also

originalLocationproperty 
originalLocation:IPoint  [read-only]

Gets the original location of the mouse at the time the gesture was initialized.


Implementation
    public function get originalLocation():IPoint

See also

snapDistanceproperty 
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. The distance is interpreted in view coordinates.

The default value is 5.0.


Implementation
    public function get snapDistance():Number
    public function set snapDistance(value:Number):void

See also

com.yworks.canvas.input.snapLines.CollectSnapResultEvent.snapDistance
snapResultsproperty 
snapResults:ICollectionModel  [read-only]

The collection of SnapResults. This collection is automatically updated during moving the mouse.


Implementation
    public function get snapResults():ICollectionModel

See also

strokeproperty 
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.


Implementation
    public function get stroke():IStroke
    public function set stroke(value:IStroke):void

See also

createDisplayObjectCreator
IDisplayObjectCreator
visualizeSnapResultsproperty 
visualizeSnapResults:Boolean

Gets or sets a value indicating whether to visualize the snap results.

The default value is true.


Implementation
    public function get visualizeSnapResults():Boolean
    public function set visualizeSnapResults(value:Boolean):void

See also

voidInstanceproperty 
voidInstance:SnapContext  [read-only]

The shared void instance. Note that this instance cannot be enabled.


Implementation
    public static function get voidInstance():SnapContext

See also

Constructor Detail
SnapContext()Constructor
public function SnapContext()

Initializes a new instance of the SnapContext class.

Method Detail
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.


Events
#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:

If the implementation is known to have a stroke property, the SnapContext's stroke property is assigned to it.

Parameters

resourceKey:ResourceKey — The resource key describing which paintable implementation to create.

Returns
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.

Returns
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.

Returns
CollectionModelManager — The model manager that manages the visual representation of the SnapResults.

See also

CollectionModelManager
com.yworks.canvas.input.snapLines.SnapResult
CanvasComponent
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.

Returns
SnapState — The adjusted coordinates.

Events
#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

MoveInputMode
HandleInputMode
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.

Returns
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.


Events
#initializing

See also

onCleanedUp()method 
protected function onCleanedUp():void

Raises the cleanedUp event.


Events
#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.


Events
#collectSnapResults
onInitialized()method 
protected function onInitialized():void

Raises the initialized event.


Events
#initialized
onInitializing()method 
protected function onInitializing():void

Raises the initializing event.


Events
#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.

Returns
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.

Returns
IInputModeContext — A modified instance that yields this instance if it is queried for the SnapContext type.

See also

Event Detail
cleanedUp Event
Event Object Type: com.yworks.canvas.input.snapLines.SnapContextEvent
SnapContextEvent.type property = SnapContextEvent.CLEANED_UP

Dispatched when this instance has been cleaned up.

See also

collectSnapResults Event  
Event Object Type: com.yworks.canvas.input.snapLines.CollectSnapResultEvent
CollectSnapResultEvent.type property = com.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  
Event Object Type: com.yworks.canvas.input.snapLines.SnapContextEvent
SnapContextEvent.type property = SnapContextEvent.INITIALIZED

Dispatched when this instance has initialized a drag.

See also

initializing Event  
Event Object Type: com.yworks.canvas.input.snapLines.SnapContextEvent
SnapContextEvent.type property = SnapContextEvent.INITIALIZING

Dispatched when this instance is about to initialize a drag.

See also