select and move POI nodes, and a handful of smaller fixes too
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedPOINode.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3     import net.systemeD.potlatch2.EditController;
4     import net.systemeD.halcyon.connection.*;
5         import net.systemeD.halcyon.Globals;
6
7     public class SelectedPOINode extends ControllerState {
8         protected var selectedNode:Node;
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.setTagViewer(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.setTagViewer(null);
30                 selectedNode = null;
31             }
32         }
33         
34         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
35                         if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.MOUSE_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
36             var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
37
38             if ( event.type == MouseEvent.MOUSE_UP ) {
39                                 if ( entity is Way ) {
40                     return new SelectedWay(entity as Way);
41                                 // ** do we need 'entity is Node && focus is Way' for POIs in ways?
42                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
43                     return new NoSelection();
44                                 }
45             } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
46 //                              if ( entity is Way && focus==selectedWay && event.shiftKey) {
47 //                                      // insert node within way (shift-click)
48 //                  var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event);
49 //                                      d.forceDragStart();
50 //                                      return d;
51 //                              } else
52                 if ( focus is Node ) {
53                                         return new DragPOINode(entity as Node,event,false);
54                 } else if ( entity is Node && focus is Way ) {
55                                         return new DragWayNode(focus as Way,entity as Node,event,false);
56                                 }
57             }
58
59             return this;
60         }
61
62         override public function enterState():void {
63             selectNode(initNode);
64                         Globals.vars.root.addDebug("**** -> "+this);
65         }
66         override public function exitState():void {
67             clearSelection();
68                         Globals.vars.root.addDebug("**** <- "+this);
69         }
70
71         override public function toString():String {
72             return "SelectedPOINode";
73         }
74
75     }
76 }