continuing to expand and rework selection stuff. Not finished yet but getting there
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedWayNode.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.Globals;
6
7     public class SelectedWayNode extends SelectedWay {
8         protected var selectedNode:Node;
9         protected var initNode:Node;
10         
11         public function SelectedWayNode(way:Way,node:Node) {
12                         Globals.vars.root.addDebug("- SelectedWayNode: constructor");
13                         super (way);
14             initNode = node;
15         }
16  
17         protected function selectNode(way:Way,node:Node):void {
18                         Globals.vars.root.addDebug("- SelectedWayNode: selectNode");
19             if ( way == selectedWay && node == selectedNode )
20                 return;
21
22             clearSelection();
23             controller.setTagViewer(node);
24             controller.map.setHighlight(node, { selected: true });
25             controller.map.setHighlight(way, { showNodes: true });
26             selectedWay = way;   initWay  = way;
27             selectedNode = node; initNode = node;
28         }
29                 
30         override protected function clearSelection():void {
31             if ( selectedNode != null ) {
32                 controller.map.setHighlight(selectedNode, { selected: false });
33                 controller.map.setHighlight(selectedWay, { selected: false, showNodes: false });
34                 controller.setTagViewer(null);
35                 selectedNode = null;
36                                 selectedWay = null;
37             }
38         }
39         
40         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
41                         if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.MOUSE_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
42             var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
43
44             if ( event.type == MouseEvent.MOUSE_UP ) {
45                                 if ( entity is Node && event.shiftKey ) {
46                                         // start new way
47                                         Globals.vars.root.addDebug("- SelectedWayNode: start new way");
48                     var way:Way = controller.connection.createWay({}, [entity, entity]);
49                     return new DrawWay(way, true);
50                                 } else if ( entity is Node ) {
51                                         // select node within way
52                                         Globals.vars.root.addDebug("- SelectedWayNode: select other node");
53                                         return new SelectedWayNode(selectedWay,Node(entity));
54                 } else if ( entity is Way ) {
55                                         // select way
56                                         Globals.vars.root.addDebug("- SelectedWayNode: select way");
57                                         return new SelectedWay(selectedWay);
58                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
59                                         Globals.vars.root.addDebug("- SelectedWayNode: deselect");
60                     return new NoSelection();
61                                 }
62             } else if ( event.type == MouseEvent.MOUSE_DOWN ) {
63                                 if ( entity is Way && focus==selectedWay && event.shiftKey) {
64                                         // insert node within way (shift-click)
65                         var d:DragWayNode=new DragWayNode(selectedWay, addNode(event), event);
66                                         d.forceDragStart();
67                                         return d;
68                                 } else if ( entity is Node && entity.hasParent(selectedWay) ) {
69                                         Globals.vars.root.addDebug("- SelectedWayNode: dragwaynode");
70                     return new DragWayNode(selectedWay, Node(entity), event);
71                                 }
72             }
73
74             return this;
75         }
76
77                 override public function enterState():void {
78             selectNode(initWay,initNode);
79         }
80
81         override public function toString():String {
82             return "SelectedWayNode";
83         }
84
85     }
86 }