Unify selection ControllerStates so they can work on either background or editable...
[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.MapPaint;
7
8     public class SelectedMarker extends ControllerState {
9         protected var initMarker:Marker;
10
11         public function SelectedMarker(marker:Marker, layer:MapPaint) {
12             initMarker = marker;
13             this.layer = layer;
14         }
15
16         protected function selectMarker(marker:Marker):void {
17             if ( firstSelected is Marker && Marker(firstSelected)==marker )
18                 return;
19
20             clearSelection(this);
21             layer.setHighlight(marker, { selected: true });
22             selection = [marker];
23             controller.updateSelectionUI(layer);
24             initMarker = marker;
25         }
26
27         protected function clearSelection(newState:ControllerState):void {
28             if ( selectCount ) {
29                 layer.setHighlight(firstSelected, { selected: false });
30                 selection = [];
31                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
32             }
33         }
34
35         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
36                         if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
37             if (event.type==MouseEvent.MOUSE_UP) { return this; }
38                         var cs:ControllerState = sharedMouseEvents(event, entity);
39                         return cs ? cs : this;
40         }
41
42                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
43                         switch (event.keyCode) {
44                         }
45                         var cs:ControllerState = sharedKeyboardEvents(event);
46                         return cs ? cs : this;
47                 }
48
49                 public function deletePOI():ControllerState {
50                         return new NoSelection();
51                 }
52
53         override public function enterState():void {
54             selectMarker(initMarker);
55                         layer.setPurgable(selection,false);
56         }
57
58         override public function exitState(newState:ControllerState):void {
59                         layer.setPurgable(selection,true);
60             clearSelection(newState);
61         }
62
63         override public function toString():String {
64             return "SelectedMarker";
65         }
66
67     }
68 }