highlight nodes in mouseover
[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 from NoSelection");
22                                 }
23                         } else if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
24                                 map.dragstate=map.NOT_DRAGGING;
25                                 var startNode:Node = controller.connection.createNode(
26                                         {}, 
27                                         controller.map.coord2lat(event.localY),
28                                         controller.map.coord2lon(event.localX));
29                                 var way:Way = controller.connection.createWay({}, [startNode]);
30                                 return new DrawWay(way, true);
31                         } else if ( event.type == MouseEvent.MOUSE_OVER ) {
32                                 controller.map.setHighlight(focus, { hover: true });
33                         } else if ( event.type == MouseEvent.MOUSE_OUT ) {
34                                 controller.map.setHighlight(focus, { hover: false });
35                         } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
36                         }
37                         return this;
38                 }
39                 
40                 public static function getTopLevelFocusEntity(entity:Entity):Entity {
41                         if ( entity is Node ) {
42                                 for each (var parent:Entity in entity.parentWays) {
43                                         return parent;
44                                 }
45                                 return entity;
46                         } else if ( entity is Way ) {
47                                 return entity;
48                         } else {
49                                 return null;
50                         }
51                 }
52
53         override public function enterState():void {
54                         Globals.vars.root.addDebug("**** -> "+this);
55         }
56         override public function exitState():void {
57                         Globals.vars.root.addDebug("**** <- "+this);
58         }
59                 override public function toString():String {
60                         return "NoSelection";
61                 }
62
63         }
64 }