e4300f27811003edd7f10990302c7791531640cb
[potlatch2.git] / net / systemeD / potlatch2 / controller / NoSelection.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.display.*;
4         import net.systemeD.potlatch2.EditController;
5         import net.systemeD.halcyon.connection.*;
6         import net.systemeD.halcyon.Map;
7         import net.systemeD.halcyon.MapPaint;
8         import net.systemeD.halcyon.vectorlayers.VectorLayer;
9         import net.systemeD.halcyon.Globals;
10
11         public class NoSelection extends ControllerState {
12
13                 public function NoSelection() {
14                 }
15
16                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
17                         var focus:Entity = getTopLevelFocusEntity(entity);
18
19                         if ( event.type == MouseEvent.MOUSE_DOWN ) {
20                                 var paint:MapPaint = getMapPaint(DisplayObject(event.target));
21                                 if ( entity is Way && event.altKey && paint.isBackground ) {
22                                         return new SelectedWay(paint.findSource().pullThrough(entity,controller.connection));
23                                 } else if ( entity is Way ) {
24                                         return new DragWay(focus as Way,event);
25                 } else if ( focus is Node ) {
26                                         return new DragPOINode(entity as Node,event,false);
27                 } else if ( entity is Node && focus is Way ) {
28                                         return new DragWayNode(focus as Way,entity as Node,event,false);
29                                 }
30                         } else if (event.type==MouseEvent.MOUSE_UP && focus==null && map.dragstate!=map.DRAGGING) {
31                                 map.dragstate=map.NOT_DRAGGING;
32                                 var undo:CompositeUndoableAction = new CompositeUndoableAction("Begin way");
33                                 var startNode:Node = controller.connection.createNode(
34                                         {}, 
35                                         controller.map.coord2lat(event.localY),
36                                         controller.map.coord2lon(event.localX), undo.push);
37                                 var way:Way = controller.connection.createWay({}, [startNode], undo.push);
38                                 MainUndoStack.getGlobalStack().addAction(undo);
39                                 return new DrawWay(way, true, false);
40                         } else if ( event.type == MouseEvent.ROLL_OVER ) {
41                                 controller.map.setHighlight(focus, { hover: true });
42                         } else if ( event.type == MouseEvent.MOUSE_OUT ) {
43                                 controller.map.setHighlight(focus, { hover: false });
44                         } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
45                         }
46                         return this;
47                 }
48                 
49                 public static function getTopLevelFocusEntity(entity:Entity):Entity {
50                         if ( entity is Node ) {
51                                 for each (var parent:Entity in entity.parentWays) {
52                                         return parent;
53                                 }
54                                 return entity;
55                         } else if ( entity is Way ) {
56                                 return entity;
57                         } else {
58                                 return null;
59                         }
60                 }
61
62         override public function enterState():void {
63                         Globals.vars.root.addDebug("**** -> "+this);
64         }
65         override public function exitState():void {
66                         Globals.vars.root.addDebug("**** <- "+this);
67         }
68                 override public function toString():String {
69                         return "NoSelection";
70                 }
71
72         }
73 }