select and move POI nodes, and a handful of smaller fixes too
[potlatch2.git] / net / systemeD / potlatch2 / controller / NoSelection.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.Map;
6         import net.systemeD.halcyon.Globals;
7
8         public class NoSelection extends ControllerState {
9
10                 public function NoSelection() {
11                 }
12  
13                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
14                         var focus:Entity = getTopLevelFocusEntity(entity);
15
16                         if ( event.type == MouseEvent.MOUSE_DOWN ) {
17                                 if ( entity is Way ) {
18                                         return new SelectedWay(focus as Way);
19                 } else if ( focus is Node ) {
20                                         return new DragPOINode(entity as Node,event,false);
21                 } else if ( entity is Node && focus is Way ) {
22                                         return new DragWayNode(focus as Way,entity as Node,event,false);
23                                 }
24                         } else if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
25                                 map.dragstate=map.NOT_DRAGGING;
26                                 var startNode:Node = controller.connection.createNode(
27                                         {}, 
28                                         controller.map.coord2lat(event.localY),
29                                         controller.map.coord2lon(event.localX));
30                                 var way:Way = controller.connection.createWay({}, [startNode]);
31                                 return new DrawWay(way, true, false);
32                         } else if ( event.type == MouseEvent.MOUSE_OVER ) {
33                                 controller.map.setHighlight(focus, { hover: true });
34                         } else if ( event.type == MouseEvent.MOUSE_OUT ) {
35                                 controller.map.setHighlight(focus, { hover: false });
36                         } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
37                         }
38                         return this;
39                 }
40                 
41                 public static function getTopLevelFocusEntity(entity:Entity):Entity {
42                         if ( entity is Node ) {
43                                 for each (var parent:Entity in entity.parentWays) {
44                                         return parent;
45                                 }
46                                 return entity;
47                         } else if ( entity is Way ) {
48                                 return entity;
49                         } else {
50                                 return null;
51                         }
52                 }
53
54         override public function enterState():void {
55                         Globals.vars.root.addDebug("**** -> "+this);
56         }
57         override public function exitState():void {
58                         Globals.vars.root.addDebug("**** <- "+this);
59         }
60                 override public function toString():String {
61                         return "NoSelection";
62                 }
63
64         }
65 }