flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject git commit: [flex-asjs] [refs/heads/tlf] - Made the SingleSelectionDragSourceBead and SingleSelectionDropTargetBead a bit more generic to work with DataGrid as well as List. Added dragStartObject to DragMouseController and dropTargetObject to DropMouseCo
Date Thu, 29 Jun 2017 15:20:33 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/tlf c89b3a11e -> 38d7d38a5


Made the SingleSelectionDragSourceBead and SingleSelectionDropTargetBead a bit more generic
to work with DataGrid as well as List. Added dragStartObject to DragMouseController and dropTargetObject
to DropMouseController.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/38d7d38a
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/38d7d38a
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/38d7d38a

Branch: refs/heads/tlf
Commit: 38d7d38a5087b90179d6807ae05ce805820904e1
Parents: c89b3a1
Author: Peter Ent <pent@apache.org>
Authored: Thu Jun 29 11:20:31 2017 -0400
Committer: Peter Ent <pent@apache.org>
Committed: Thu Jun 29 11:20:31 2017 -0400

----------------------------------------------------------------------
 .../html/beads/SingleSelectionDragSourceBead.as |  97 +++++++--------
 .../html/beads/SingleSelectionDropTargetBead.as | 119 +++++++++----------
 .../beads/controllers/DragMouseController.as    |  12 ++
 .../beads/controllers/DropMouseController.as    |  13 ++
 4 files changed, 125 insertions(+), 116 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/38d7d38a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDragSourceBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDragSourceBead.as
b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDragSourceBead.as
index 72b0a00..c911651 100644
--- a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDragSourceBead.as
+++ b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDragSourceBead.as
@@ -101,39 +101,30 @@ package org.apache.flex.html.beads
 		{
 			trace("SingleSelectionDragSourceBead received the DragStart");
 			
-			var downPoint:Point = new Point(event.clientX, event.clientY);//PointUtils.localToGlobal(new
Point(event.clientX, event.clientY), _strand);
-			//trace("Dragging from this point: "+downPoint.x+", "+downPoint.y);
-			//trace("-- find the itemRenderer this object is over");
+			if (DragMouseController.dragStartObject == null) return; // not interested in empty things
 			
-			if (itemRendererParent != null) {
-				var n:Number = itemRendererParent.numElements;
-				for (var i:int=0; i < n; i++) {
-					var child:UIBase = itemRendererParent.getElementAt(i) as UIBase;
-					if (child != null) {
-						var childPoint:Point = PointUtils.localToGlobal(new Point(child.x,child.y), itemRendererParent);
-						//trace("-- child "+i+": "+childPoint.x+" - "+(childPoint.x+child.width)+" x "+childPoint.y+"
- "+(childPoint.y+child.height));
-						var rect:Rectangle = new Rectangle(childPoint.x, childPoint.y, child.width, child.height);
-						if (rect.containsPoint(downPoint)) {							
-							var ir:IItemRenderer = child as IItemRenderer;
-							
-							//trace("-- dragging this child, " + i + ", at "+childPoint.x+", "+childPoint.y);
-							indexOfDragSource = i;
-							
-							var dragImage:UIBase = new Group();
-							dragImage.className = "DragImage";
-							dragImage.width = child.width;
-							dragImage.height = child.height;
-							var label:Label = new Label();
-							label.text = ir.data.toString();
-							dragImage.addElement(label);
-							
-							DragEvent.dragSource = ir.data;
-							DragEvent.dragInitiator = this;
-							DragMouseController.dragImage = dragImage;
-							break;
-						}
-					}
-				}
+			var startHere:Object = DragMouseController.dragStartObject;
+			while( !(startHere is IItemRenderer) && startHere != null) {
+				startHere = startHere.parent;
+			}
+			
+			if (startHere is IItemRenderer) {
+				var ir:IItemRenderer = startHere as IItemRenderer;
+				
+				var p:UIBase = (ir as UIBase).parent as UIBase;
+				indexOfDragSource = p.getElementIndex(ir);
+				
+				var dragImage:UIBase = new Group();
+				dragImage.className = "DragImage";
+				dragImage.width = (ir as UIBase).width;
+				dragImage.height = (ir as UIBase).height;
+				var label:Label = new Label();
+				label.text = ir.data.toString();
+				dragImage.addElement(label);
+				
+				DragEvent.dragSource = ir.data;
+				DragEvent.dragInitiator = this;
+				DragMouseController.dragImage = dragImage;
 			}
 		}
 		
@@ -144,28 +135,26 @@ package org.apache.flex.html.beads
 			trace("Accepting drop of type "+type);
 			if (dragType == "copy") return;
 			
-			if (itemRendererParent != null) {
-				var dataProviderModel:IDataProviderModel = _strand.getBeadByType(IDataProviderModel)
as IDataProviderModel;
-				if (dataProviderModel.dataProvider is Array) {
-					var dataArray:Array = dataProviderModel.dataProvider as Array;
-					
-					// remove the item being selected
-					dataArray.splice(indexOfDragSource,1);
-					
-					// refresh the dataProvider model
-					var newArray:Array = dataArray.slice()
-					dataProviderModel.dataProvider = newArray;
-				}
-				else if (dataProviderModel.dataProvider is ArrayList) {
-					var dataList:ArrayList = dataProviderModel.dataProvider as ArrayList;
-					
-					// remove the item being selected
-					dataList.removeItemAt(indexOfDragSource);
-					
-					// refresh the dataProvider model
-					var newList:ArrayList = new ArrayList(dataList.source);
-					dataProviderModel.dataProvider = newList;
-				}
+			var dataProviderModel:IDataProviderModel = _strand.getBeadByType(IDataProviderModel) as
IDataProviderModel;
+			if (dataProviderModel.dataProvider is Array) {
+				var dataArray:Array = dataProviderModel.dataProvider as Array;
+				
+				// remove the item being selected
+				dataArray.splice(indexOfDragSource,1);
+				
+				// refresh the dataProvider model
+				var newArray:Array = dataArray.slice()
+				dataProviderModel.dataProvider = newArray;
+			}
+			else if (dataProviderModel.dataProvider is ArrayList) {
+				var dataList:ArrayList = dataProviderModel.dataProvider as ArrayList;
+				
+				// remove the item being selected
+				dataList.removeItemAt(indexOfDragSource);
+				
+				// refresh the dataProvider model
+				var newList:ArrayList = new ArrayList(dataList.source);
+				dataProviderModel.dataProvider = newList;
 			}
 		}
 		

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/38d7d38a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDropTargetBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDropTargetBead.as
b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDropTargetBead.as
index 9f85fef..e4ee58a 100644
--- a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDropTargetBead.as
+++ b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/SingleSelectionDropTargetBead.as
@@ -104,80 +104,75 @@ package org.apache.flex.html.beads
 		
 		private function handleDragDrop(event:DragEvent):void
 		{
-			var myX:Number = event.clientX;
 			trace("SingleSelectionDropTargetBead received DragDrop!");
 			
-			var downPoint:Point = new Point(event.clientX, event.clientY); 
-			//trace("Dropping at this point: "+downPoint.x+", "+downPoint.y);
-			//trace("-- find the itemRenderer this object is over");
+			if (DropMouseController.dropTargetObject == null) return; 
 			
 			var targetIndex:int = -1; // indicates drop beyond length of items
 			
-			if (itemRendererParent != null) {
-				var n:Number = itemRendererParent.numElements;
-				for (var i:int=0; i < n; i++) {
-					var child:UIBase = itemRendererParent.getElementAt(i) as UIBase;
-					if (child != null) {
-						var childPoint:Point = new Point(child.x, child.y); 
-						//trace("-- child "+i+": "+childPoint.x+" - "+(childPoint.x+child.width)+" x "+childPoint.y+"
- "+(childPoint.y+child.height));
-						var rect:Rectangle = new Rectangle(childPoint.x, childPoint.y, child.width, child.height);
-						if (rect.containsPoint(downPoint)) {							
-							var ir:IItemRenderer = child as IItemRenderer;
-							targetIndex = i;
-							//trace("-- Found this item: "+i);
-							break;
-						}
-					}
-				}
-				
-				if (targetIndex == (n-1)) { // special case when drop on last item
-					targetIndex--;
-				}
+			var startHere:Object = DropMouseController.dropTargetObject;
+			while( !(startHere is IItemRenderer) && startHere != null) {
+				startHere = startHere.parent;
+			}
+			
+			if (startHere is IItemRenderer) {
+				var ir:IItemRenderer = startHere as IItemRenderer;
+				trace("-- dropping onto an existing object: "+ir.data.toString());
 				
-				// Let the dragInitiator know that the drop was accepted so it can do
-				// whatever it needs to do to prepare the data or structures.
-				if (DragEvent.dragInitiator) {
-					DragEvent.dragInitiator.acceptingDrop(_strand, "object");
-				}
+				var p:UIBase = (ir as UIBase).parent as UIBase;
+				targetIndex = p.getElementIndex(ir);
+			}
+			else  {
+				trace("-- dropping after the last item");
+			}
+			
+			var downPoint:Point = new Point(event.clientX, event.clientY); 
+			//trace("Dropping at this point: "+downPoint.x+", "+downPoint.y);
+			//trace("-- find the itemRenderer this object is over");
+						
+			// Let the dragInitiator know that the drop was accepted so it can do
+			// whatever it needs to do to prepare the data or structures.
+			if (DragEvent.dragInitiator) {
+				DragEvent.dragInitiator.acceptingDrop(_strand, "object");
+			}
 				
-				var dragSource:Object = DragEvent.dragSource;
+			var dragSource:Object = DragEvent.dragSource;
 				
-				var dataProviderModel:IDataProviderModel = _strand.getBeadByType(IDataProviderModel)
as IDataProviderModel;
-				if (dataProviderModel.dataProvider is Array) {
-					var dataArray:Array = dataProviderModel.dataProvider as Array;
+			var dataProviderModel:IDataProviderModel = _strand.getBeadByType(IDataProviderModel) as
IDataProviderModel;
+			if (dataProviderModel.dataProvider is Array) {
+				var dataArray:Array = dataProviderModel.dataProvider as Array;
 
-					// insert the item being dropped
-					if (targetIndex == -1) {
-						// append to the end
-						dataArray.push(dragSource);
-					} else {
-						// insert before targetIndex
-						dataArray.splice(targetIndex, 0, dragSource);
-					}
-					
-					var newArray:Array = dataArray.slice()
-					dataProviderModel.dataProvider = newArray;
-				}
-				else if (dataProviderModel.dataProvider is ArrayList) {
-					var dataList:ArrayList = dataProviderModel.dataProvider as ArrayList;
-					
-					// insert the item being dropped
-					if (targetIndex == -1) {
-						// sppend to the end
-						dataList.addItem(dragSource);
-					} else {
-						// insert before target index
-						dataList.addItemAt(dragSource, targetIndex);
-					}
-					
-					var newList:ArrayList = new ArrayList(dataList.source);
-					dataProviderModel.dataProvider = newList;
+				// insert the item being dropped
+				if (targetIndex == -1) {
+					// append to the end
+					dataArray.push(dragSource);
+				} else {
+					// insert before targetIndex
+					dataArray.splice(targetIndex, 0, dragSource);
 				}
 				
-				// Let the dragInitiator know the drop has been completed.
-				if (DragEvent.dragInitiator) {
-					DragEvent.dragInitiator.acceptedDrop(_strand, "object");
+				var newArray:Array = dataArray.slice()
+				dataProviderModel.dataProvider = newArray;
+			}
+			else if (dataProviderModel.dataProvider is ArrayList) {
+				var dataList:ArrayList = dataProviderModel.dataProvider as ArrayList;
+				
+				// insert the item being dropped
+				if (targetIndex == -1) {
+					// sppend to the end
+					dataList.addItem(dragSource);
+				} else {
+					// insert before target index
+					dataList.addItemAt(dragSource, targetIndex);
 				}
+				
+				var newList:ArrayList = new ArrayList(dataList.source);
+				dataProviderModel.dataProvider = newList;
+			}
+				
+			// Let the dragInitiator know the drop has been completed.
+			if (DragEvent.dragInitiator) {
+				DragEvent.dragInitiator.acceptedDrop(_strand, "object");
 			}
 		}
 	}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/38d7d38a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DragMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DragMouseController.as
b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DragMouseController.as
index e9451fa..6d560a1 100644
--- a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DragMouseController.as
+++ b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DragMouseController.as
@@ -134,6 +134,16 @@ package org.apache.flex.html.beads.controllers
          *  @productversion FlexJS 0.0
          */
         public static var defaultThreshold:int = 4;
+		
+		/**
+		 * The object under the mouse when the dragStart is dispatched.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.8
+		 */
+		public static var dragStartObject:Object;
         
 		/**
 		 *  constructor.
@@ -213,6 +223,8 @@ package org.apache.flex.html.beads.controllers
                 if (Math.abs(event.screenX - mouseDownX) > threshold ||
                     Math.abs(event.screenY - mouseDownY) > threshold)
                 {
+					DragMouseController.dragStartObject = event.target;
+					
                     trace("DRAG-MOUSE: sending dragStart");
                     dragEvent = DragEvent.createDragEvent("dragStart", event);
 					dragEvent.clientX = mouseDownX;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/38d7d38a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DropMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DropMouseController.as
b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DropMouseController.as
index 72e54aa..025a8db 100644
--- a/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DropMouseController.as
+++ b/frameworks/projects/DragDrop/src/main/flex/org/apache/flex/html/beads/controllers/DropMouseController.as
@@ -85,6 +85,17 @@ package org.apache.flex.html.beads.controllers
 	 */
 	public class DropMouseController extends EventDispatcher implements IBead
 	{
+		
+		/**
+		 * The object under the mouse when the drop was executed.
+		 *  
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.8
+		 */
+		public static var dropTargetObject:Object;
+		
 		/**
 		 *  constructor.
 		 *  
@@ -178,6 +189,8 @@ package org.apache.flex.html.beads.controllers
         {
             trace("DROP-MOUSE: dragEnd received for event: "+event.target.toString());
             var dragEvent:DragEvent;
+			
+			DropMouseController.dropTargetObject = event.target;
             
 			var screenPoint:Point = new Point(event.screenX, event.screenY);
 			var newPoint:Point = PointUtils.globalToLocal(screenPoint, _strand);


Mime
View raw message