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