45cd47bc1a23c6952a68560addb2f3ce6ec00961
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedMultiple.as
1 package net.systemeD.potlatch2.controller {
2         import flash.events.*;
3         import flash.display.DisplayObject;
4         import flash.ui.Keyboard;
5         import net.systemeD.potlatch2.EditController;
6         import net.systemeD.halcyon.connection.*;
7         import net.systemeD.halcyon.MapPaint;
8         import net.systemeD.halcyon.WayUI;
9         import net.systemeD.halcyon.Globals;
10
11         public class SelectedMultiple extends ControllerState {
12                 protected var initSelection:Array;
13                 
14                 public function SelectedMultiple(sel:Array) {
15                         initSelection=sel.concat();
16                 }
17
18                 override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
19                         if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.ROLL_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
20                         var focus:Entity = getTopLevelFocusEntity(entity);
21
22                         if ( event.type == MouseEvent.MOUSE_DOWN && event.ctrlKey ) {
23                                 // modify selection
24                                 controller.map.setHighlight(entity, { selected: toggleSelection(entity) });
25
26                                 if      (selectCount> 1) { return this; }
27                                 else if (selectCount==1) {
28                                         if (firstSelected is Way) {
29                                                 return new SelectedWay(firstSelected as Way);
30                                         } else if (firstSelected is Node && Node(firstSelected).hasParentWays) {
31                                                 var way:Way=firstSelected.parentWays[0] as Way;
32                                                 return new SelectedWayNode(way, way.indexOfNode(firstSelected as Node));
33                                         } else {
34                                                 return new SelectedPOINode(firstSelected as Node);
35                                         }
36                                 } else {
37                                         return new NoSelection();
38                                 }
39                         }
40                         var cs:ControllerState = sharedMouseEvents(event, entity);
41                         return cs ? cs : this;
42                 }
43
44                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
45                         var cs:ControllerState = sharedKeyboardEvents(event);
46                         return cs ? cs : this;
47                 }
48
49                 override public function enterState():void {
50                         selection=initSelection.concat();
51                         for each (var entity:Entity in selection) {
52                                 controller.map.setHighlight(entity, { selected: true, hover: false });
53                         }
54                         controller.updateSelectionUI();
55                         controller.map.setPurgable(selection,false);
56                         Globals.vars.root.addDebug("**** -> "+this+" "+selection);
57                 }
58
59                 override public function exitState(newState:ControllerState):void {
60                         controller.map.setPurgable(selection,true);
61                         for each (var entity:Entity in selection) {
62                                 controller.map.setHighlight(entity, { selected: false, hover: false });
63                         }
64                         selection = [];
65                         if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
66                         Globals.vars.root.addDebug("**** <- "+this);
67                 }
68
69                 override public function toString():String {
70                         return "SelectedMultiple";
71                 }
72
73         }
74 }