Make text labels draggable too
authorRichard Fairhurst <richard@systemeD.net>
Sat, 24 Mar 2012 13:03:36 +0000 (13:03 +0000)
committerRichard Fairhurst <richard@systemeD.net>
Sat, 24 Mar 2012 13:03:36 +0000 (13:03 +0000)
(and move the drag code from the ItemRenderer into the main script body)

net/systemeD/potlatch2/panels/DragAndDropPanel.mxml

index 5b9440a..5b281b8 100644 (file)
                </mx:HBox>
 
                <mx:TileList dataProvider="{dndRep.currentItem.getFeaturesForType('point', true)}" width="100%" height="1"
-                                    rowHeight="32" columnWidth="100" updateComplete="resizePOIGrid(event)" styleName="dndPanelTileList">
+                            id="tl" dragEnabled="true" mouseDown="mouseDownHandler(event)" 
+                            rowHeight="32" columnWidth="100" updateComplete="resizePOIGrid(event)" styleName="dndPanelTileList">
                        <mx:itemRenderer>
                                <fx:Component>
-                                       <mx:HBox toolTip="{data.name}" horizontalScrollPolicy="off">
-                                               <fx:Script><![CDATA[
-                                                       import mx.events.DragEvent;
-                                                       import mx.managers.DragManager;
-                                                       import mx.core.DragSource;
-                                                       import net.systemeD.potlatch2.TagViewer;
-
-                                                       private function dragPOI(event:MouseEvent, tags:Array):void {
-                                                               var sidebar:TagViewer=parentDocument.parentDocument;
-                                                               if (sidebar.controller.map.dragstate==sidebar.controller.map.DRAGGING) return;
-
-                                                               // Get the drag initiator component from the event object.
-                                                               var dragInitiator:Image = event.currentTarget as Image;
-                                                               var dragSource:DragSource = new DragSource();
-                                                               dragSource.addData(tags, 'tags');
-                                                               dragSource.addData(event.target.parent.parent.parent.parent, 'container');
-
-                                                               var dragProxy:Image = new Image();
-                                                               dragProxy.source = dragInitiator.source;
-                                                               dragProxy.width = dragInitiator.width;   // must set width and height explicitly
-                                                               dragProxy.height = dragInitiator.height; // for non-embedded images
-                                                               DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
-                                                       }
-
-                                               ]]></fx:Script>
-                                               <mx:Image id="foo" source="{data.dndimage}" height="24" width="24" mouseMove="dragPOI(event, data.tags)" toolTip="{data.name}" />
+                                       <mx:HBox toolTip="{data.name}" horizontalScrollPolicy="off" >
+                                               <mx:Image id="foo" source="{data.dndimage}" height="24" width="24" toolTip="{data.name}" />
                                                <mx:Label text="{data.name}" />
                                        </mx:HBox>
                                </fx:Component>
        <fx:Script><![CDATA[
 
        import net.systemeD.potlatch2.mapfeatures.*;
+       import mx.core.DragSource;
+       import mx.managers.DragManager;
+       import mx.controls.Image;
 
        [Bindable] public var dndPrompt:String="Add new points by dragging them onto the map";
 
+       private function mouseDownHandler(event:MouseEvent):void {
+               var item:Feature=Feature(TileList(event.currentTarget).selectedItem);
+               var dragInitiator:HBox = event.currentTarget.itemToItemRenderer(item);
+               var dragSource:DragSource = new DragSource();
+               dragSource.addData(item.tags, 'tags');
+               dragSource.addData(event.currentTarget, 'container');
+
+               var dragProxy:Image = new Image();
+               dragProxy.source = item.dndimage;
+               dragProxy.width = 24;   // must set width and height explicitly
+               dragProxy.height = 24;  // for non-embedded images
+
+               DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
+       }
+
        private function resizePOIGrid(event:Event):void {
                var rows:Number=event.target.dataProvider.length/event.target.columnCount;
                if (rows!=Math.floor(rows)) { rows=Math.floor(rows+1); }