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