start of floating geometry palette
[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 selectedNode:Node;
10         protected var initNode:Node;
11         
12         public function SelectedPOINode(node:Node) {
13             initNode = node;
14         }
15  
16         protected function selectNode(node:Node):void {
17             if ( node == selectedNode )
18                 return;
19
20             clearSelection();
21             controller.setSelectedEntity(node);
22             controller.map.setHighlight(node, { selected: true });
23             selectedNode = node;
24             initNode = node;
25         }
26                 
27         protected function clearSelection():void {
28             if ( selectedNode != null ) {
29                 controller.map.setHighlight(selectedNode, { selected: false });
30                 controller.setSelectedEntity(null);
31                 selectedNode = null;
32             }
33         }
34         
35         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
36                         if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.ROLL_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
37             var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
38
39             if ( event.type == MouseEvent.MOUSE_UP ) {
40                                 if ( entity is Way ) {
41                     return new SelectedWay(entity as Way);
42                                 // ** do we need 'entity is Node && focus is Way' for POIs in ways?
43                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
44                     return new NoSelection();
45                                 }
46             } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
47                 if ( focus is Node ) {
48                                         return new DragPOINode(entity as Node,event,false);
49                 } else if ( entity is Node && focus is Way ) {
50                                         return new DragWayNode(focus as Way,entity as Node,event,false);
51                                 }
52             }
53
54             return this;
55         }
56
57                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
58                         switch (event.keyCode) {
59                                 case Keyboard.BACKSPACE:        return deletePOI();
60                                 case Keyboard.DELETE:           return deletePOI();
61                         }
62                         return this;
63                 }
64                 
65                 public function deletePOI():ControllerState {
66                         controller.connection.unregisterPOI(selectedNode);
67                         selectedNode.remove();
68                         return new NoSelection();
69                 }
70                 
71         override public function enterState():void {
72             selectNode(initNode);
73                         Globals.vars.root.addDebug("**** -> "+this);
74         }
75         override public function exitState():void {
76             clearSelection();
77                         Globals.vars.root.addDebug("**** <- "+this);
78         }
79
80         override public function toString():String {
81             return "SelectedPOINode";
82         }
83
84     }
85 }