POI-to-quadrilateral drawing mode
[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
7     public class SelectedPOINode extends ControllerState {
8         protected var initNode:Node;
9
10         public function SelectedPOINode(node:Node) {
11             initNode = node;
12         }
13  
14         protected function selectNode(node:Node):void {
15             if ( firstSelected is Node && Node(firstSelected)==node )
16                 return;
17
18             clearSelection(this);
19             controller.map.setHighlight(node, { selected: true });
20             selection = [node];
21             controller.updateSelectionUI();
22             initNode = node;
23         }
24                 
25         protected function clearSelection(newState:ControllerState):void {
26             if ( selectCount ) {
27                 controller.map.setHighlight(firstSelected, { selected: false });
28                 selection = [];
29                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
30             }
31         }
32         
33         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
34                         if (event.type==MouseEvent.MOUSE_MOVE) { return this; }
35                         if (event.type==MouseEvent.MOUSE_DOWN && event.ctrlKey && entity && entity!=firstSelected) {
36                                 return new SelectedMultiple([firstSelected,entity]);
37                         }
38                         if (event.type==MouseEvent.MOUSE_DOWN && event.shiftKey && !entity) {
39                                 return new DrawQuadrilateral(firstSelected as Node);
40                         }
41                         var cs:ControllerState = sharedMouseEvents(event, entity);
42                         return cs ? cs : this;
43         }
44
45                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
46                         switch (event.keyCode) {
47                                 case Keyboard.BACKSPACE:        return deletePOI();
48                                 case Keyboard.DELETE:           return deletePOI();
49                                 case 82:                                        repeatTags(firstSelected); return this; // 'R'
50                         }
51                         var cs:ControllerState = sharedKeyboardEvents(event);
52                         return cs ? cs : this;
53                 }
54
55                 public function deletePOI():ControllerState {
56                         controller.connection.unregisterPOI(firstSelected as Node);
57                         firstSelected.remove(MainUndoStack.getGlobalStack().addAction);
58                         return new NoSelection();
59                 }
60
61         override public function enterState():void {
62             selectNode(initNode);
63                         controller.map.setPurgable(selection,false);
64         }
65         override public function exitState(newState:ControllerState):void {
66             if(firstSelected.hasTags()) {
67               controller.clipboards['node']=firstSelected.getTagsCopy();
68             }
69                         controller.map.setPurgable(selection,true);
70             clearSelection(newState);
71         }
72
73         override public function toString():String {
74             return "SelectedPOINode";
75         }
76
77     }
78 }