couple of todos, and fix the toolbox
[potlatch2.git] / net / systemeD / potlatch2 / Toolbox.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Panel
3         xmlns:mx="http://www.adobe.com/2006/mxml"
4         xmlns:potlatch2="net.systemeD.potlatch2.*"
5         height="46" width="219" 
6         headerHeight="6" headerColors="[black, gray]" 
7         borderThicknessRight="0" borderThicknessLeft="0" borderThicknessBottom="0" 
8         paddingLeft="4" paddingTop="4" layout="absolute" >
9
10                 <mx:Image data="@Embed('../../../embedded/close_small.png')"
11                     includeInLayout="false" id="toolboxClose" click="toggle();" 
12                     y="-6" x="205" />
13
14         <mx:Button icon="@Embed('../../../embedded/delete.svg')"
15                         click='doDelete();' 
16                         enabled="{canDo('delete')}" 
17                         alpha="{getAlpha('delete')}" 
18                         toolTip="Delete item" 
19                         width="28" height="28" textAlign="left" y="4" x="6" paddingLeft="6" paddingRight="0" />
20         <mx:Button icon="@Embed('../../../embedded/direction.svg')" 
21             click='doReverseDirection();'
22                         enabled="{canDo('reverseDirection')}" 
23                         alpha="{getAlpha('reverseDirection')}" 
24                         toolTip="Reverse direction" 
25                         width="28" height="28" textAlign="left" y="4" x="36" paddingLeft="8" paddingRight="0" />
26         <mx:Button icon="@Embed('../../../embedded/cut.svg')" 
27                click='doSplit();'
28                         enabled="{canDo('split')}" 
29                         alpha="{getAlpha('split')}" 
30                         toolTip="Split way" 
31                         width="28" height="28" textAlign="left" y="4" x="66" paddingLeft="8" paddingRight="0" />
32         <mx:Button icon="@Embed('../../../embedded/straighten.svg')" 
33                         click='doStraighten();' 
34                         enabled="{canDo('straighten')}" 
35                         alpha="{getAlpha('straighten')}" 
36                         toolTip="Straighten way" 
37                         width="28" height="28" textAlign="left" y="4" x="96" paddingLeft="5" paddingRight="0" />
38         <mx:Button icon="@Embed('../../../embedded/circle.svg')" 
39                         click='doCircularise();' 
40                         enabled="{canDo('circularise')}" 
41                         alpha="{getAlpha('circularise')}" 
42                         toolTip="Make circular" 
43                         width="28" height="28" textAlign="left" y="4" x="126" paddingLeft="4" paddingRight="0" />
44         <mx:Button icon="@Embed('../../../embedded/quadrilateralise.svg')" 
45                         click='doQuadrilateralise();' 
46                         enabled="{canDo('quadrilateralise')}" 
47                         alpha="{getAlpha('quadrilateralise')}" 
48                         toolTip="Make right-angled" 
49                         width="28" height="28" textAlign="left" y="4" x="156" paddingLeft="6" paddingRight="0" />
50         <mx:Button icon="@Embed('../../../embedded/parallel.svg')" 
51                         click='doParallelise();' 
52                         enabled="{canDo('parallelise')}" 
53                         alpha="{getAlpha('parallelise')}" 
54                         toolTip="Create parallel way" 
55                         width="28" height="28" textAlign="left" y="4" x="186" paddingLeft="8" paddingRight="0" />
56
57         <mx:Script><![CDATA[
58
59                 import flash.events.Event;
60                 import flash.events.MouseEvent;
61                 import net.systemeD.halcyon.connection.*;
62             import net.systemeD.potlatch2.controller.*;
63             import net.systemeD.potlatch2.tools.*;
64
65                 private var entity:Entity;
66                 private var controller:EditController;
67
68                 public function init(controller:EditController):void {
69                         this.controller=controller;
70                 }
71
72                 override protected function createChildren():void {
73                         super.createChildren();
74                         super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
75                         super.titleBar.addEventListener(MouseEvent.MOUSE_UP,handleUp);
76                 }
77
78                 public function setEntity(entity:Entity):void {
79                         this.entity=entity;
80                         dispatchEvent(new Event("updateSkin"));
81                         dispatchEvent(new Event("updateAlpha"));
82                 }
83
84                 private function handleDown(e:Event):void {
85                         this.startDrag();
86                 }
87
88                 private function handleUp(e:Event):void {
89                         this.stopDrag();
90                 }
91                 
92                 public function toggle():void {
93                         this.visible=!this.visible;
94                 }
95                 
96                 // --------------------------------------------------------------------------------
97                 // Enable/disable toolbox buttons
98                 // (ideally we'd use CSS to set alpha in disabled state, but Flex's CSS
99                 //  capabilities aren't up to it)
100                 
101         [Bindable(event="updateSkin")]
102                 public function canDo(op:String):Boolean {
103                         switch (op) {
104                                 case 'delete':                          return (entity is Way || entity is Node);
105                                 case 'reverseDirection':        return (entity is Way);
106                                 case 'quadrilateralise':        return (entity is Way && Way(entity).isArea());
107                                 case 'straighten':                      return (entity is Way && !Way(entity).isArea());
108                                 case 'circularise':                     return (entity is Way && Way(entity).isArea());
109                                 case 'split':                           return (entity is Node && controller.state is SelectedWayNode);
110                                 case 'parallelise':                     return (entity is Way);
111                         }
112                         return false;
113                 }
114
115         [Bindable(event="updateAlpha")]
116                 public function getAlpha(op:String):Number {
117                         if (canDo(op)) { return 1; }
118                         return 0.5;
119                 }
120         
121
122                 // --------------------------------------------------------------------------------
123                 // Individual toolbox actions
124
125                 public function doDelete():void {
126                         if (entity is Node) { controller.connection.unregisterPOI(Node(entity)); }
127                         entity.remove(MainUndoStack.getGlobalStack().addAction);
128
129                         if (controller.state is SelectedWayNode) {
130                                 controller.setState(new SelectedWay(SelectedWayNode(controller.state).selectedWay));
131                         } else {
132                                 controller.setState(new NoSelection());
133                         }
134                 }
135
136         public function doReverseDirection():void {
137             if (entity is Way) { 
138                 Way(entity).reverseNodes(MainUndoStack.getGlobalStack().addAction);
139             }
140         }
141
142                 public function doQuadrilateralise():void {
143                         if (entity is Way) {
144                                 Quadrilateralise.quadrilateralise(Way(entity));
145                         }
146                 }
147
148                 public function doStraighten():void {
149                         if (entity is Way) {
150                                 Straighten.straighten(Way(entity),controller.map);
151                         }
152                 }
153
154                 public function doCircularise():void {
155                         if (entity is Way) {
156                                 Circularise.circularise(Way(entity),controller.map);
157                         }
158                 }
159
160                 public function doSplit():void {
161                         if (entity is Node && controller.state is SelectedWayNode) {
162                                 controller.setState(SelectedWayNode(controller.state).splitWay());
163                         }
164                 }
165                 
166                 public function doParallelise():void {
167                         if (entity is Way) {
168                                 controller.setState(new SelectedParallelWay(Way(entity)));
169                         }
170                 }
171
172
173     ]]>
174 </mx:Script>    
175 </mx:Panel>