Allow markers to be selected, and show a custom marker panel
authorAndy Allan <gravitystorm@gmail.com>
Tue, 16 Nov 2010 15:01:13 +0000 (15:01 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Tue, 16 Nov 2010 15:01:13 +0000 (15:01 +0000)
net/systemeD/potlatch2/MarkerPanel.mxml [new file with mode: 0644]
net/systemeD/potlatch2/TagViewer.mxml
net/systemeD/potlatch2/controller/ControllerState.as
net/systemeD/potlatch2/controller/SelectedMarker.as [new file with mode: 0644]

diff --git a/net/systemeD/potlatch2/MarkerPanel.mxml b/net/systemeD/potlatch2/MarkerPanel.mxml
new file mode 100644 (file)
index 0000000..21324be
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+    Marker Panel
+-->
+
+<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" >
+  <mx:Text id="markerPanelText" text="You have selected a marker." width="100%" styleName="helpInfo" />
+  <mx:DataGrid editable="false" dataProvider="tagDataProvider" id="markerPanelDG" width="100%">
+    <mx:columns>
+      <mx:DataGridColumn editable="false" dataField="key" headerText="key" />
+      <mx:DataGridColumn editable="false" dataField="value" headerText="value" />
+    </mx:columns>
+  </mx:DataGrid>
+  <mx:Script><![CDATA[
+
+      import net.systemeD.halcyon.connection.*;
+      import mx.collections.*;
+
+      private var selectedEntity:Entity;
+      private var tagDataProvider:ArrayCollection;
+
+      public function init(entity:Entity):void {
+            if ( tagDataProvider == null ) {
+                tagDataProvider = new ArrayCollection();
+                markerPanelDG.dataProvider = tagDataProvider;
+            }
+
+            selectedEntity=entity;
+            updateTagDataProvider();
+      }
+
+      private function updateTagDataProvider():void {
+            tagDataProvider.removeAll();
+            if (selectedEntity==null) { return; }
+            var tags:Array = selectedEntity.getTagArray();
+            tags.sortOn("key");
+            for each(var tag:Tag in tags) { tagDataProvider.addItem(tag); }
+        }
+      ]]>
+  </mx:Script>
+</mx:VBox>
\ No newline at end of file
index deabda7..d10712a 100644 (file)
   <mx:VBox id="multiplePanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
     <mx:Text id="multiplePanelText" text="You have selected multiple items." width="100%" styleName="helpInfo" />
   </mx:VBox>
+
+  <mx:VBox id="markerPanel" width="100%" height="100%" horizontalScrollPolicy="off" styleName="dndPanelVbox">
+    <potlatch2:MarkerPanel id="markerPanelContents" width="100%"/>
+  </mx:VBox>
+
 </mx:ViewStack>
 
   <mx:Script><![CDATA[
                        if (selectedEntity!=null) { selectedEntity.addEventListener(Connection.TAG_CHANGED, tagChanged); }
                        if (advancedID!=null) { setupAdvanced(firstSelected); }
                        if (firstSelected is Relation) { stack.addChild(membersVBox); }
-                       refreshFeatureIcon(); 
-                       initialiseEditors();
-                       sidebar.selectedChild = tagsPanel;
+            if (selectedEntity is Marker) {
+              markerPanelContents.init(selectedEntity);
+              sidebar.selectedChild = markerPanel;
+            } else {
+              refreshFeatureIcon();
+              initialiseEditors();
+              sidebar.selectedChild = tagsPanel;
+            }
                
                } else {
                        // Multiple selection, so for now show a largely blank panel/
index d188544..3237322 100644 (file)
@@ -72,6 +72,8 @@ package net.systemeD.potlatch2.controller {
                                        var newEntity:Entity=paint.findSource().pullThrough(entity,controller.connection);
                                        if (entity is Way) { return new SelectedWay(newEntity as Way); }
                                        else if (entity is Node) { return new SelectedPOINode(newEntity as Node); }
+                } else if (event.type == MouseEvent.MOUSE_DOWN && entity is Marker) {
+                    return new SelectedMarker(entity as Marker);
                                } else if ( event.type == MouseEvent.MOUSE_UP ) { 
                                        return (this is NoSelection) ? null : new NoSelection();
                                } else { return null; }
diff --git a/net/systemeD/potlatch2/controller/SelectedMarker.as b/net/systemeD/potlatch2/controller/SelectedMarker.as
new file mode 100644 (file)
index 0000000..3e6207b
--- /dev/null
@@ -0,0 +1,70 @@
+package net.systemeD.potlatch2.controller {
+       import flash.events.*;
+       import flash.ui.Keyboard;
+    import net.systemeD.potlatch2.EditController;
+    import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
+
+    public class SelectedMarker extends ControllerState {
+        protected var initMarker:Marker;
+
+        public function SelectedMarker(marker:Marker) {
+            initMarker = marker;
+        }
+
+        protected function selectMarker(marker:Marker):void {
+            if ( firstSelected is Marker && Marker(firstSelected)==marker )
+                return;
+
+            clearSelection(this);
+            controller.map.setHighlight(marker, { selected: true });
+            selection = [marker];
+            controller.updateSelectionUI();
+            initMarker = marker;
+        }
+
+        protected function clearSelection(newState:ControllerState):void {
+            if ( selectCount ) {
+                controller.map.setHighlight(firstSelected, { selected: false });
+                selection = [];
+                if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
+            }
+        }
+
+        override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
+                       if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
+            if (event.type==MouseEvent.MOUSE_UP) { return this; }
+                       var cs:ControllerState = sharedMouseEvents(event, entity);
+                       return cs ? cs : this;
+        }
+
+               override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
+                       switch (event.keyCode) {
+                       }
+                       var cs:ControllerState = sharedKeyboardEvents(event);
+                       return cs ? cs : this;
+               }
+
+               public function deletePOI():ControllerState {
+                       return new NoSelection();
+               }
+
+        override public function enterState():void {
+            selectMarker(initMarker);
+                       controller.map.setPurgable(selection,false);
+                       Globals.vars.root.addDebug("**** -> "+this);
+        }
+
+        override public function exitState(newState:ControllerState):void {
+                       controller.clipboards['marker']=firstSelected.getTagsCopy();
+                       controller.map.setPurgable(selection,true);
+            clearSelection(newState);
+                       Globals.vars.root.addDebug("**** <- "+this);
+        }
+
+        override public function toString():String {
+            return "SelectedMarker";
+        }
+
+    }
+}