Allow markers to be selected, and show a custom marker panel
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedMarker.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.ui.Keyboard;
4     import net.systemeD.potlatch2.EditController;
5     import net.systemeD.halcyon.connection.*;
6         import net.systemeD.halcyon.Globals;
7
8     public class SelectedMarker extends ControllerState {
9         protected var initMarker:Marker;
10
11         public function SelectedMarker(marker:Marker) {
12             initMarker = marker;
13         }
14
15         protected function selectMarker(marker:Marker):void {
16             if ( firstSelected is Marker && Marker(firstSelected)==marker )
17                 return;
18
19             clearSelection(this);
20             controller.map.setHighlight(marker, { selected: true });
21             selection = [marker];
22             controller.updateSelectionUI();
23             initMarker = marker;
24         }
25
26         protected function clearSelection(newState:ControllerState):void {
27             if ( selectCount ) {
28                 controller.map.setHighlight(firstSelected, { selected: false });
29                 selection = [];
30                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
31             }
32         }
33
34         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
35                         if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
36             if (event.type==MouseEvent.MOUSE_UP) { return this; }
37                         var cs:ControllerState = sharedMouseEvents(event, entity);
38                         return cs ? cs : this;
39         }
40
41                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
42                         switch (event.keyCode) {
43                         }
44                         var cs:ControllerState = sharedKeyboardEvents(event);
45                         return cs ? cs : this;
46                 }
47
48                 public function deletePOI():ControllerState {
49                         return new NoSelection();
50                 }
51
52         override public function enterState():void {
53             selectMarker(initMarker);
54                         controller.map.setPurgable(selection,false);
55                         Globals.vars.root.addDebug("**** -> "+this);
56         }
57
58         override public function exitState(newState:ControllerState):void {
59                         controller.clipboards['marker']=firstSelected.getTagsCopy();
60                         controller.map.setPurgable(selection,true);
61             clearSelection(newState);
62                         Globals.vars.root.addDebug("**** <- "+this);
63         }
64
65         override public function toString():String {
66             return "SelectedMarker";
67         }
68
69     }
70 }