slight refactoring of controller states
[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
20         */
21
22         public class Toolbox extends Panel{
23                 
24                 private var entity:Entity;
25                 private var controller:EditController;
26
27                 public function Toolbox(){
28                         super();
29                 }
30                 
31                 public function init(controller:EditController):void {
32                         this.controller=controller;
33                 }
34
35                 override protected function createChildren():void {
36                         super.createChildren();
37                         super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
38                         super.titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);
39                 }
40
41                 public function setEntity(entity:Entity):void {
42                         this.entity=entity;
43                 }
44
45                 private function handleDown(e:Event):void {
46                         this.startDrag();
47                 }
48
49                 private function handleUp(e:Event):void {
50                         this.stopDrag();
51                 }
52
53                 // --------------------------------------------------------------------------------
54                 // Individual toolbox actions
55
56                 public function doDelete():void {
57                         if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
58                         entity.remove(MainUndoStack.getGlobalStack().addAction);
59
60                         if (controller.state is SelectedWayNode) {
61                                 controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
62                         } else {
63                                 controller.setState(new NoSelection());
64                         }
65                 }
66         
67         public function doReverseDirection():void {
68             if (entity is Way) { 
69                 Way(entity).reverseNodes(MainUndoStack.getGlobalStack().addAction);
70             }
71         }
72
73                 public function doQuadrilateralise():void {
74                         if (entity is Way) {
75                                 Quadrilateralise.quadrilateralise(Way(entity));
76                         }
77                 }
78
79                 public function doStraighten():void {
80                         if (entity is Way) {
81                                 Straighten.straighten(Way(entity),controller.map);
82                         }
83                 }
84
85                 public function doCircularise():void {
86                         if (entity is Way) {
87                                 Circularise.circularise(Way(entity),controller.map);
88                         }
89                 }
90                 
91                 public function doSplit():void {
92                         if (entity is Node && controller.state is SelectedWayNode) {
93                                 controller.setState(SelectedWayNode(controller.state).splitWay());
94                         }
95                 }
96
97         }
98 }