More refactoring work-in-progress
[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
10         public class NoSelection extends ControllerState {
11
12                 public function NoSelection() {
13                 }
14
15                 override public function isSelectionState():Boolean {
16                         return false;
17                 }
18                 
19                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
20                         var cs:ControllerState = sharedMouseEvents(event, entity);
21                         if (cs) return cs;
22
23                         var paint:MapPaint = getMapPaint(DisplayObject(event.target));
24                         var focus:Entity = getTopLevelFocusEntity(entity);
25
26                         if (event.type==MouseEvent.MOUSE_UP && (focus==null || (paint && paint.isBackground)) && map.dragstate!=map.DRAGGING) {
27                                 map.dragstate=map.NOT_DRAGGING;
28                                 var undo:CompositeUndoableAction = new BeginWayAction();
29                                 var conn:Connection = editableLayer.connection;
30                                 var startNode:Node = conn.createNode(
31                                         {}, 
32                                         controller.map.coord2lat(event.localY),
33                                         controller.map.coord2lon(event.localX), undo.push);
34                                 var way:Way = conn.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         }
49         override public function exitState(newState:ControllerState):void {
50         }
51                 override public function toString():String {
52                         return "NoSelection";
53                 }
54
55         }
56 }