refactor EditController to make it stateful, and add addWayNodes functionality with...
[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
6     public class NoSelection extends ControllerState {
7         public function NoSelection() {
8         }
9  
10         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
11             var focus:Entity = getTopLevelFocusEntity(entity);
12             if ( event.type == MouseEvent.CLICK )
13                 if ( focus is Way )
14                     return new SelectedWay(focus as Way);
15                 else if ( focus is Node )
16                     trace("select poi");
17             else if ( event.type == MouseEvent.MOUSE_OVER )
18                 controller.map.setHighlight(focus, "hover", true);
19             else if ( event.type == MouseEvent.MOUSE_OUT )
20                 controller.map.setHighlight(focus, "hover", false);
21                 
22             return this;
23         }
24         
25         public static function getTopLevelFocusEntity(entity:Entity):Entity {
26             if ( entity is Node ) {
27                 for each (var parent:Entity in entity.parentWays) {
28                     return parent;
29                 }
30                 return entity;
31             } else if ( entity is Way ) {
32                 return entity;
33             } else {
34                 return null;
35             }
36         }
37     }
38 }