parallelise
[potlatch2.git] / net / systemeD / potlatch2 / Toolbox.as
1 package net.systemeD.potlatch2 {
2
3         import flash.events.Event;
4         import flash.events.MouseEvent;
5         import mx.containers.Panel;
6         import net.systemeD.halcyon.connection.*;
7     import net.systemeD.potlatch2.controller.*;
8     import net.systemeD.potlatch2.tools.*;
9
10         /*
11                 Floating toolbox palette
12
13                 Still to do:
14                 ** Should have a close box, and be able to be activated from the top bar
15                 ** Should be automatically positioned at bottom-right of canvas on init
16                 ** Should float above tagViewer, not beneath it
17                 ** Icons should be disabled depending on what's selected (setEntity can do this)
18                 ** Remove annoying Illustrator cruft from SVG icons!
19                 ** Tooltips
20
21         */
22
23         public class Toolbox extends Panel{
24                 
25                 private var entity:Entity;
26                 private var controller:EditController;
27
28                 public function Toolbox(){
29                         super();
30                 }
31                 
32                 public function init(controller:EditController):void {
33                         this.controller=controller;
34                 }
35
36                 override protected function createChildren():void {
37                         super.createChildren();
38                         super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
39                         super.titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);
40                 }
41
42                 public function setEntity(entity:Entity):void {
43                         this.entity=entity;
44                 }
45
46                 private function handleDown(e:Event):void {
47                         this.startDrag();
48                 }
49
50                 private function handleUp(e:Event):void {
51                         this.stopDrag();
52                 }
53
54                 // --------------------------------------------------------------------------------
55                 // Individual toolbox actions
56
57                 public function doDelete():void {
58                         if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
59                         entity.remove(MainUndoStack.getGlobalStack().addAction);
60
61                         if (controller.state is SelectedWayNode) {
62                                 controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
63                         } else {
64                                 controller.setState(new NoSelection());
65                         }
66                 }
67         
68         public function doReverseDirection():void {
69             if (entity is Way) { 
70                 Way(entity).reverseNodes(MainUndoStack.getGlobalStack().addAction);
71             }
72         }
73
74                 public function doQuadrilateralise():void {
75                         if (entity is Way) {
76                                 Quadrilateralise.quadrilateralise(Way(entity));
77                         }
78                 }
79
80                 public function doStraighten():void {
81                         if (entity is Way) {
82                                 Straighten.straighten(Way(entity),controller.map);
83                         }
84                 }
85
86                 public function doCircularise():void {
87                         if (entity is Way) {
88                                 Circularise.circularise(Way(entity),controller.map);
89                         }
90                 }
91                 
92                 public function doSplit():void {
93                         if (entity is Node && controller.state is SelectedWayNode) {
94                                 controller.setState(SelectedWayNode(controller.state).splitWay());
95                         }
96                 }
97                 
98                 public function doParallelise():void {
99                         if (entity is Way) {
100                                 controller.setState(new SelectedParallelWay(Way(entity)));
101                         }
102                 }
103
104         }
105 }