more selection fixes
[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.CLICK ) {
17                                 if ( focus is Way ) {
18                                         return new SelectedWay(focus as Way);
19                                 } else if ( focus is Node ) {
20                                         // *** select node
21                                         Globals.vars.root.addDebug("- selected POI");
22                                 }
23                         } else if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
24                                 map.dragstate=map.NOT_DRAGGING;
25                                 return new CreateWay(event);
26                         } else if ( event.type == MouseEvent.MOUSE_OVER ) {
27                                 controller.map.setHighlight(focus, { hover: true });
28                         } else if ( event.type == MouseEvent.MOUSE_OUT ) {
29                                 controller.map.setHighlight(focus, { hover: false });
30                         } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
31                         }
32                         return this;
33                 }
34                 
35                 public static function getTopLevelFocusEntity(entity:Entity):Entity {
36                         if ( entity is Node ) {
37                                 for each (var parent:Entity in entity.parentWays) {
38                                         return parent;
39                                 }
40                                 return entity;
41                         } else if ( entity is Way ) {
42                                 return entity;
43                         } else {
44                                 return null;
45                         }
46                 }
47
48         override public function enterState():void {
49                         Globals.vars.root.addDebug("**** -> "+this);
50         }
51         override public function exitState():void {
52                         Globals.vars.root.addDebug("**** <- "+this);
53         }
54                 override public function toString():String {
55                         return "NoSelection";
56                 }
57
58         }
59 }