slight refactoring of controller states
[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 ( node == selectedNode )
17                 return;
18
19             clearSelection();
20             controller.setSelectedEntity(node);
21             controller.map.setHighlight(node, { selected: true });
22             selectedNode = node;
23             initNode = node;
24         }
25                 
26         protected function clearSelection():void {
27             if ( selectedNode != null ) {
28                 controller.map.setHighlight(selectedNode, { selected: false });
29                 controller.setSelectedEntity(null);
30                 selectedNode = null;
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                         if (cs) return cs;
38             return this;
39         }
40
41                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
42                         switch (event.keyCode) {
43                                 case Keyboard.BACKSPACE:        return deletePOI();
44                                 case Keyboard.DELETE:           return deletePOI();
45                         }
46                         return this;
47                 }
48                 
49                 public function deletePOI():ControllerState {
50                         controller.connection.unregisterPOI(selectedNode);
51                         selectedNode.remove(MainUndoStack.getGlobalStack().addAction);
52                         return new NoSelection();
53                 }
54                 
55         override public function enterState():void {
56             selectNode(initNode);
57                         Globals.vars.root.addDebug("**** -> "+this);
58         }
59         override public function exitState():void {
60             clearSelection();
61                         Globals.vars.root.addDebug("**** <- "+this);
62         }
63
64         override public function toString():String {
65             return "SelectedPOINode";
66         }
67
68     }
69 }