Reformat dates. Surprisingly limited options for parsing and displaying dates.
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedWay.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.potlatch2.tools.Parallelise;
7     import net.systemeD.potlatch2.tools.Simplify;
8     import net.systemeD.halcyon.connection.*;
9         import net.systemeD.halcyon.MapPaint;
10         import net.systemeD.halcyon.WayUI;
11         import net.systemeD.halcyon.Globals;
12
13     public class SelectedWay extends ControllerState {
14         protected var initWay:Way;
15         
16         public function SelectedWay(way:Way) {
17             initWay = way;
18         }
19  
20         protected function selectWay(way:Way):void {
21             if ( firstSelected is Way && Way(firstSelected)==way )
22                 return;
23
24             clearSelection(this);
25             controller.map.setHighlight(way, { selected: true, hover: false });
26             controller.map.setHighlightOnNodes(way, { selectedway: true });
27             selection = [way];
28             controller.updateSelectionUI();
29             initWay = way;
30         }
31
32         protected function clearSelection(newState:ControllerState):void {
33             if ( selectCount ) {
34                 controller.map.setHighlight(firstSelected, { selected: false, hover: false });
35                 controller.map.setHighlightOnNodes(firstSelected as Way, { selectedway: false });
36                 selection = [];
37                 if (!newState.isSelectionState()) { controller.updateSelectionUI(); }
38             }
39         }
40         
41         override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
42                         if (event.type==MouseEvent.MOUSE_MOVE || event.type==MouseEvent.ROLL_OVER || event.type==MouseEvent.MOUSE_OUT) { return this; }
43             var focus:Entity = getTopLevelFocusEntity(entity);
44
45             if ( event.type == MouseEvent.MOUSE_UP && entity is Node && event.shiftKey ) {
46                                 // start new way
47                                 var way:Way = controller.connection.createWay({}, [entity], MainUndoStack.getGlobalStack().addAction);
48                                 return new DrawWay(way, true, false);
49                         } else if ( event.type == MouseEvent.MOUSE_DOWN && entity is Way && focus==firstSelected && event.shiftKey) {
50                                 // insert node within way (shift-click)
51                 var d:DragWayNode=new DragWayNode(firstSelected as Way, -1, event, true);
52                                 d.forceDragStart();
53                                 return d;
54                         } else if ( event.type == MouseEvent.MOUSE_DOWN && event.ctrlKey && entity!=firstSelected) {
55                                 // multiple selection
56                                 return new SelectedMultiple([firstSelected,entity]);
57                         }
58                         var cs:ControllerState = sharedMouseEvents(event, entity);
59                         return cs ? cs : this;
60         }
61         
62                 override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
63                         switch (event.keyCode) {
64                                 case 80:                                        return new SelectedParallelWay(firstSelected as Way);
65                                 case 82:                                        repeatTags(firstSelected); return this;
66                 case 86:                    Way(firstSelected).reverseNodes(MainUndoStack.getGlobalStack().addAction); return this;
67                 case 89:                    Simplify.simplify(firstSelected as Way, controller.map, true); return this;         
68                                 case Keyboard.BACKSPACE:        if (event.shiftKey) { return deleteWay(); } break;
69                                 case Keyboard.DELETE:           if (event.shiftKey) { return deleteWay(); } break;
70                         }
71                         var cs:ControllerState = sharedKeyboardEvents(event);
72                         return cs ? cs : this;
73                 }
74         
75                 public function deleteWay():ControllerState {
76                         controller.map.setHighlightOnNodes(firstSelected as Way, {selectedway: false});
77                         selectedWay.remove(MainUndoStack.getGlobalStack().addAction);
78                         return new NoSelection();
79                 }
80
81         override public function enterState():void {
82             selectWay(initWay);
83                         controller.map.setPurgable(selection,false);
84                         Globals.vars.root.addDebug("**** -> "+this+" "+firstSelected.id);
85         }
86         override public function exitState(newState:ControllerState):void {
87                         controller.clipboards['way']=firstSelected.getTagsCopy();
88                         controller.map.setPurgable(selection,true);
89             clearSelection(newState);
90                         Globals.vars.root.addDebug("**** <- "+this);
91         }
92
93         override public function toString():String {
94             return "SelectedWay";
95         }
96
97     }
98 }