support GPX 1.1 too
[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.connection.actions.*;
7         import net.systemeD.halcyon.Map;
8         import net.systemeD.halcyon.MapPaint;
9         import net.systemeD.halcyon.Globals;
10
11         public class NoSelection extends ControllerState {
12
13                 public function NoSelection() {
14                 }
15
16                 override public function isSelectionState():Boolean {
17                         return false;
18                 }
19                 
20                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
21                         var cs:ControllerState = sharedMouseEvents(event, entity);
22                         if (cs) return cs;
23
24                         var paint:MapPaint = getMapPaint(DisplayObject(event.target));
25                         var focus:Entity = getTopLevelFocusEntity(entity);
26
27                         if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING) {
28                                 map.dragstate=map.NOT_DRAGGING;
29                                 var undo:CompositeUndoableAction = new BeginWayAction();
30                                 var startNode:Node = controller.connection.createNode(
31                                         {}, 
32                                         controller.map.coord2lat(event.localY),
33                                         controller.map.coord2lon(event.localX), undo.push);
34                                 var way:Way = controller.connection.createWay({}, [startNode], undo.push);
35                                 MainUndoStack.getGlobalStack().addAction(undo);
36                                 return new DrawWay(way, true, false);
37                         }
38                         return this;
39                 }
40                 
41                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
42                         var cs:ControllerState = sharedKeyboardEvents(event);
43                         return cs ? cs : this;
44                 }
45                 
46         override public function enterState():void {
47                         controller.map.mouseUpHandler();
48                         Globals.vars.root.addDebug("**** -> "+this);
49         }
50         override public function exitState(newState:ControllerState):void {
51                         Globals.vars.root.addDebug("**** <- "+this);
52         }
53                 override public function toString():String {
54                         return "NoSelection";
55                 }
56
57         }
58 }