press '/' to cycle through overlapping ways
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.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 SelectedPOINode extends ControllerState {
9         protected var initNode:Node;
10
11         public function SelectedPOINode(node:Node) {
12             initNode = node;
13         }
14  
15         protected function selectNode(node:Node):void {
16             if ( firstSelected is Node && Node(firstSelected)==node )
17                 return;
18
19             clearSelection(this);
20             controller.map.setHighlight(node, { selected: true });
21             selection = [node];
22             controller.updateSelectionUI();
23             initNode = node;
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                         var cs:ControllerState = sharedMouseEvents(event, entity);
37                         return cs ? cs : this;
38         }
39
40                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
41                         switch (event.keyCode) {
42                                 case Keyboard.BACKSPACE:        return deletePOI();
43                                 case Keyboard.DELETE:           return deletePOI();
44                                 case 82:                                        repeatTags(firstSelected); return this; // 'R'
45                         }
46                         var cs:ControllerState = sharedKeyboardEvents(event);
47                         return cs ? cs : this;
48                 }
49
50                 public function deletePOI():ControllerState {
51                         controller.connection.unregisterPOI(firstSelected as Node);
52                         firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
53                         return new NoSelection();
54                 }
55
56         override public function enterState():void {
57             selectNode(initNode);
58                         controller.map.setPurgable(selection,false);
59                         Globals.vars.root.addDebug("**** -> "+this);
60         }
61         override public function exitState(newState:ControllerState):void {
62                         controller.clipboards['node']=firstSelected.getTagsCopy();
63                         controller.map.setPurgable(selection,true);
64             clearSelection(newState);
65                         Globals.vars.root.addDebug("**** <- "+this);
66         }
67
68         override public function toString():String {
69             return "SelectedPOINode";
70         }
71
72     }
73 }