Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Added clickToDrag static property to WireJack to support drags that d…
Browse files Browse the repository at this point in the history
…on't require the user to hold the mouse down.

Tweaked release notes, license, and a few class headers.
Ported previous changes to the standard wire drag image to the arrow drag image as well.
  • Loading branch information
joshtynjala committed Mar 15, 2009
1 parent 22d4e6c commit 773184d
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 23 deletions.
4 changes: 2 additions & 2 deletions license.txt
Expand Up @@ -4,7 +4,7 @@ Wires Library for Adobe Flex

////////////////////////////////////////////////////////////////////////////////

Copyright 2008 Josh Tynjala
Copyright 2009 Josh Tynjala

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -41,6 +41,6 @@ The Original Code is from the Open Source Flex 3 SDK.
The Initial Developer of the Original Code is Adobe Systems, Inc.

Portions created by Josh Tynjala (joshblog.net) are
Copyright (C) 2008 Josh Tynjala. All Rights Reserved.
Copyright (C) 2009 Josh Tynjala. All Rights Reserved.

////////////////////////////////////////////////////////////////////////////////
6 changes: 6 additions & 0 deletions readme.txt
Expand Up @@ -26,5 +26,11 @@ Author's Blog:
Release Notes:
---------------------------------------------------------------------------------

??/??/2008 - 1.1.0
* Added "hasActiveConnectionRequest" to IWireManager and implementations.
* Added "clickToDrag" static property to WireJack class as an alternative
that does not require holding the mouse button down to connect wires.
* Fixed runtime error on drag in AIR. Nothing displays, but it works now.

11/11/2008 - 1.0.0
* Initial Release for Flex 3.2.0
96 changes: 87 additions & 9 deletions source/com/flextoolbox/controls/WireJack.as
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 Josh Tynjala
// Copyright (c) 2009 Josh Tynjala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -46,6 +46,7 @@ package com.flextoolbox.controls
import mx.events.DragEvent;
import mx.events.FlexEvent;
import mx.managers.DragManager;
import mx.managers.dragClasses.DragProxy;
import mx.styles.CSSStyleDeclaration;
import mx.styles.ISimpleStyleClient;
import mx.styles.StyleManager;
Expand Down Expand Up @@ -103,6 +104,24 @@ package com.flextoolbox.controls
// Static Properties
//--------------------------------------

/**
* @private
* The fake proxy for clickToDrag behavior.
*/
protected static var fakeDragProxy:DragProxy;

/**
* If <code>true</code> dragging a wire from one jack to other will be
* initiated by a mouse "click" event on the first jack rather than the
* standard "mouseDown" event.
*
* @example To initialize this alternate behavior, use the following code:
* <listing version="3.0">
* WireJack.clickToDrag = true;
* </listing>
*/
public static var clickToDrag:Boolean = false;

/**
* The dragFormat used by wire jacks for drag and drop operations.
*/
Expand Down Expand Up @@ -166,6 +185,7 @@ package com.flextoolbox.controls
super();

this.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
this.addEventListener(MouseEvent.CLICK, clickHandler);
this.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
this.addEventListener(DragEvent.DRAG_ENTER, dragEnterHandler);

Expand Down Expand Up @@ -739,7 +759,32 @@ package com.flextoolbox.controls
{
//don't try to make more connections than this jack allows
//or do anything if we're disabled
if(this.connectedJacks.length == this.maxConnections || !this.enabled)
if(this.wireManager.hasActiveConnectionRequest || clickToDrag || this.connectedJacks.length == this.maxConnections || !this.enabled)
{
return;
}

this.systemManager.addEventListener(MouseEvent.MOUSE_UP, connectionEndHandler);
this.addEventListener(DragEvent.DRAG_COMPLETE, connectionEndHandler);

this.wireManager.beginConnectionRequest(this);

var source:DragSource = new DragSource();
source.addData(this, WIRE_JACK_DRAG_FORMAT);

var dragImageType:Object = this.getStyle("dragImage");
var dragImage:IFlexDisplayObject = TheInstantiator.newInstance(dragImageType) as IFlexDisplayObject;
if(dragImage is ISimpleStyleClient)
{
ISimpleStyleClient(dragImage).styleName = this.getStyle("dragImageStyleName");
}
DragManager.doDrag(this, source, event, dragImage, -this.mouseX, -this.mouseY, 1);
}

protected function clickHandler(event:MouseEvent):void
{
trace("click!");
if(this.wireManager.hasActiveConnectionRequest || !clickToDrag || this.connectedJacks.length == this.maxConnections || !this.enabled)
{
return;
}
Expand All @@ -749,24 +794,30 @@ package com.flextoolbox.controls

this.wireManager.beginConnectionRequest(this);

//we're going to do a fake drag and drop operation here
var source:DragSource = new DragSource();
source.addData(this, WIRE_JACK_DRAG_FORMAT);

var dragImageType:Object = this.getStyle("dragImage");
var image:IFlexDisplayObject = TheInstantiator.newInstance(dragImageType) as IFlexDisplayObject;
if(image is ISimpleStyleClient)
var dragImage:IFlexDisplayObject = TheInstantiator.newInstance(dragImageType) as IFlexDisplayObject;
if(dragImage is ISimpleStyleClient)
{
ISimpleStyleClient(image).styleName = this.getStyle("dragImageStyleName");
ISimpleStyleClient(dragImage).styleName = this.getStyle("dragImageStyleName");
}
DragManager.doDrag(this, source, event, image, -this.mouseX, -this.mouseY, 1);

fakeDragProxy = new DragProxy(this, source);
this.systemManager.addChildToSandboxRoot("popUpChildren", fakeDragProxy);
fakeDragProxy.addChild(DisplayObject(dragImage));
fakeDragProxy.setActualSize(this.width, this.height);
dragImage.setActualSize(this.width, this.height);
}

/**
* @private
*/
protected function rollOverHandler(event:MouseEvent):void
{
if(DragManager.isDragging)
if(fakeDragProxy || DragManager.isDragging)
{
return;
}
Expand All @@ -789,10 +840,28 @@ package com.flextoolbox.controls
*/
protected function connectionEndHandler(event:Event):void
{
if(fakeDragProxy)
{
this.systemManager.removeChildFromSandboxRoot("popUpChildren", fakeDragProxy);
fakeDragProxy = null;
}

this.removeEventListener(DragEvent.DRAG_COMPLETE, connectionEndHandler);
this.systemManager.removeEventListener(MouseEvent.MOUSE_UP, connectionEndHandler);
this.wireManager.endConnectionRequest(this);

if(clickToDrag)
{
//if we're using clickToDrag, then a click event will follow
//this mouseUpEvent. kill it!
this.systemManager.addEventListener(MouseEvent.CLICK, function(event:MouseEvent):void
{
trace("stopping click!");
event.currentTarget.removeEventListener(event.type, arguments.callee, true);
event.stopImmediatePropagation();
}, true);
}

//note: we don't care if the connection was successful here.
//instead, the wire manager will notify us through an event that the
//connection was made
Expand Down Expand Up @@ -821,8 +890,17 @@ package com.flextoolbox.controls
{
this.addEventListener(DragEvent.DRAG_EXIT, dragExitHandler);
this.addEventListener(DragEvent.DRAG_DROP, dragDropHandler);
DragManager.acceptDragDrop(this);
DragManager.showFeedback(DragManager.LINK);
if(fakeDragProxy)
{
fakeDragProxy.target = this;
fakeDragProxy.action = DragManager.LINK;
fakeDragProxy.showFeedback();
}
else
{
DragManager.acceptDragDrop(this);
DragManager.showFeedback(DragManager.LINK);
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion source/com/flextoolbox/controls/WireSurface.as
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 Josh Tynjala
// Copyright (c) 2009 Josh Tynjala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -166,6 +166,14 @@ package com.flextoolbox.controls
this.manager.wireRenderer = value;
}

/**
* @inheritDoc
*/
public function get hasActiveConnectionRequest():Boolean
{
return this.manager.hasActiveConnectionRequest;
}

//--------------------------------------
// Public Methods
//--------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion source/com/flextoolbox/managers/IWireManager.as
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 Josh Tynjala
// Copyright (c) 2009 Josh Tynjala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -92,6 +92,11 @@ package com.flextoolbox.managers
*/
function set wireRenderer(value:IFactory):void;

/**
* Indicates whether the user is trying to make a wire connection.
*/
function get hasActiveConnectionRequest():Boolean;

//--------------------------------------
// Methods
//--------------------------------------
Expand Down
29 changes: 27 additions & 2 deletions source/com/flextoolbox/managers/WireManager.as
Expand Up @@ -31,6 +31,7 @@ package com.flextoolbox.managers

import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import flash.errors.IllegalOperationError;
import flash.events.EventDispatcher;

import mx.core.Application;
Expand All @@ -39,8 +40,6 @@ package com.flextoolbox.managers
import mx.core.IUIComponent;
import mx.core.UIComponent;
import mx.managers.PopUpManager;
import mx.styles.CSSStyleDeclaration;
import mx.styles.StyleManager;

//--------------------------------------
// Events
Expand Down Expand Up @@ -166,18 +165,38 @@ package com.flextoolbox.managers
*/
protected var connecting:Boolean = false;

/**
* @private
* Storage for the wireRenderer property.
*/
private var _wireRenderer:IFactory = new ClassFactory(DefaultWireRenderer);

/**
* @inheritDoc
*/
public function get wireRenderer():IFactory
{
return this._wireRenderer;
}

/**
* @private
*/
public function set wireRenderer(value:IFactory):void
{
this._wireRenderer = value;
}

private var _hasActiveConnectionRequest:Boolean = false;

/**
* @inheritDoc
*/
public function get hasActiveConnectionRequest():Boolean
{
return this._hasActiveConnectionRequest;
}

//--------------------------------------
// Public Methods
//--------------------------------------
Expand Down Expand Up @@ -209,6 +228,11 @@ package com.flextoolbox.managers
*/
public function beginConnectionRequest(jack:WireJack):void
{
if(this._hasActiveConnectionRequest)
{
throw new IllegalOperationError("Cannot have more than one active connection request at a time.");
}
this._hasActiveConnectionRequest = true;
var begin:WireManagerEvent = new WireManagerEvent(WireManagerEvent.BEGIN_CONNECTION_REQUEST, jack);
this.dispatchEvent(begin);
}
Expand All @@ -218,6 +242,7 @@ package com.flextoolbox.managers
*/
public function endConnectionRequest(jack:WireJack):void
{
this._hasActiveConnectionRequest = false;
var end:WireManagerEvent = new WireManagerEvent(WireManagerEvent.END_CONNNECTION_REQUEST, jack);
this.dispatchEvent(end);
}
Expand Down
34 changes: 27 additions & 7 deletions source/com/flextoolbox/skins/halo/WireJackArrowDragImage.as
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 Josh Tynjala
// Copyright (c) 2009 Josh Tynjala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -205,6 +205,21 @@ package com.flextoolbox.skins.halo
DynamicRegistration.rotate(this.arrowhead, new Point(-distance, headSize / 2), degrees);
}

//--------------------------------------
// Private Methods
//--------------------------------------

private function finish():void
{
this.removeEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, stageMouseMoveHandler);
this.stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUpHandler);

this.done = true;
this.invalidateDisplayList();
this.validateNow();
}

//--------------------------------------
// Private Event Handlers
//--------------------------------------
Expand All @@ -217,22 +232,27 @@ package com.flextoolbox.skins.halo
private function addedToStageHandler(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
this.addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);
this.stage.addEventListener(MouseEvent.MOUSE_MOVE, stageMouseMoveHandler, false, 0, true);
this.stage.addEventListener(MouseEvent.MOUSE_UP, stageMouseUpHandler, false, 0, true);
}

/**
* @private
* If removed from stage, then we need to finish immediately.
*/
private function removedFromStageHandler(event:Event):void
{
this.finish();
}

/**
* @private
* Once the mouse is released, this operation is done.
*/
private function stageMouseUpHandler(event:MouseEvent):void
{
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, stageMouseMoveHandler);
this.stage.removeEventListener(MouseEvent.MOUSE_UP, stageMouseUpHandler);

this.done = true;
this.invalidateDisplayList();
this.validateNow();
this.finish();
}

/**
Expand Down

0 comments on commit 773184d

Please sign in to comment.