fun with tooltips
[potlatch2.git] / potlatch2.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application 
3         xmlns:mx="http://www.adobe.com/2006/mxml" 
4         xmlns:halcyon="net.systemeD.halcyon.*"
5         xmlns:potlatch2="net.systemeD.potlatch2.*"
6         layout="vertical"
7         horizontalAlign="center" 
8         addedToStage="initApp()">
9         
10         <mx:Style source="styles/Application.css"/>
11
12     <mx:Glow id="glowImage" duration="100" 
13         alphaFrom="0.3" alphaTo="1.0" 
14         blurXFrom="0.0" blurXTo="5.0" 
15         blurYFrom="0.0" blurYTo="5.0" 
16         color="0xFF8000"/>
17     <mx:Glow id="unglowImage" duration="100" 
18         alphaFrom="1.0" alphaTo="0.3" 
19         blurXFrom="5.0" blurXTo="0.0" 
20         blurYFrom="5.0" blurYTo="0.0" 
21         color="0xFF8000"/>
22     <mx:WipeLeft id="wipeOut" duration="250"/>
23     <mx:WipeRight id="wipeIn" duration="250"/>
24
25     <mx:ApplicationControlBar dock="true">
26         <mx:PopUpButton id="bgButton" label="Background" openAlways="true"
27             creationComplete="bgButton.popUp = new BackgroundSelector();"/>
28         <mx:PopUpButton id="styleButton" label="Map Style" openAlways="true"
29             creationComplete="styleButton.popUp = new StyleSelector();"/>
30         <mx:Spacer width="100%"/>
31         <mx:Button label="Undo" click="MainUndoStack.getGlobalStack().undo();"
32             enabled="{MainUndoStack.getGlobalStack().canUndo()}"/>
33         <mx:Button label="Redo" click="MainUndoStack.getGlobalStack().redo();"
34             enabled="{MainUndoStack.getGlobalStack().canRedo()}"/>
35         <mx:Spacer width="100%"/>
36         <mx:Button label="Help" click="new HelpDialog().init();" />
37         <mx:Button label="Options" click="new OptionsDialog().init();" />
38         <mx:Button label="Save" icon="@Embed('embedded/save.svg')" click="SaveManager.saveChanges();"/>
39     </mx:ApplicationControlBar>
40     
41     <mx:HDividedBox width="100%" height="100%">
42
43           <!-- Tag viewer -->
44           <potlatch2:TagViewer width="25%" height="100%" id="tagViewer"/>
45
46       <mx:Canvas width="75%" height="100%">
47         <mx:Canvas id="map_area" resize="onResizeMap()"
48             top="0" left="0" width="100%" height="100%" dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);">
49         </mx:Canvas>
50         <mx:Image source="@Embed('embedded/zoomIn.svg')" right="3" top="3" click="theMap.zoomIn();"
51             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
52         <mx:Image source="@Embed('embedded/zoomOut.svg')" right="3" top="20" click="theMap.zoomOut();"
53             rollOverEffect="glowImage" rollOutEffect="unglowImage"/>
54         <mx:TextArea id="dataWorking" text="" right="20" top="3" disabledColor="black" backgroundDisabledColor="0xFFFFEA" height="18"
55             enabled="false" borderThickness="0"
56             showEffect="{wipeIn}" hideEffect="{wipeOut}"/>
57
58     </mx:Canvas>
59
60                 <potlatch2:Toolbox id="toolbox" 
61                         height="46" width="253" 
62                         headerHeight="6" headerColors="[black, gray]" 
63                         borderThicknessRight="0" borderThicknessLeft="0" borderThicknessBottom="0" 
64                         paddingLeft="4" paddingTop="4" layout="horizontal"
65                         includeInLayout="false" >
66
67                 <mx:Button icon="@Embed('embedded/delete.svg')"
68                                 click='toolbox.doDelete();' 
69                                 enabled="{toolbox.canDo('delete')}" 
70                                 alpha="{toolbox.getAlpha('delete')}" 
71                                 toolTip="Delete item" 
72                                 width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
73                 <mx:Button icon="@Embed('embedded/direction.svg')" 
74                 click='toolbox.doReverseDirection();'
75                                 enabled="{toolbox.canDo('reverseDirection')}" 
76                                 alpha="{toolbox.getAlpha('reverseDirection')}" 
77                                 toolTip="Reverse direction" 
78                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
79                 <mx:Button icon="@Embed('embedded/cut.svg')" 
80                 click='toolbox.doSplit();'
81                                 enabled="{toolbox.canDo('split')}" 
82                                 alpha="{toolbox.getAlpha('split')}" 
83                                 toolTip="Split way" 
84                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
85                 <mx:Button icon="@Embed('embedded/straighten.svg')" 
86                                 click='toolbox.doStraighten();' 
87                                 enabled="{toolbox.canDo('straighten')}" 
88                                 alpha="{toolbox.getAlpha('straighten')}" 
89                                 toolTip="Straighten way" 
90                                 width="28" height="28" textAlign="left" paddingLeft="5" paddingRight="0" />
91                 <mx:Button icon="@Embed('embedded/circle.svg')" 
92                                 click='toolbox.doCircularise();' 
93                                 enabled="{toolbox.canDo('circularise')}" 
94                                 alpha="{toolbox.getAlpha('circularise')}" 
95                                 toolTip="Make circular" 
96                                 width="28" height="28" textAlign="left" paddingLeft="4" paddingRight="0" />
97                 <mx:Button icon="@Embed('embedded/quadrilateralise.svg')" 
98                                 click='toolbox.doQuadrilateralise();' 
99                                 enabled="{toolbox.canDo('quadrilateralise')}" 
100                                 alpha="{toolbox.getAlpha('quadrilateralise')}" 
101                                 toolTip="Make right-angled" 
102                                 width="28" height="28" textAlign="left" paddingLeft="6" paddingRight="0" />
103                 <mx:Button icon="@Embed('embedded/parallel.svg')" 
104                                 click='toolbox.doParallelise();' 
105                                 enabled="{toolbox.canDo('parallelise')}" 
106                                 alpha="{toolbox.getAlpha('parallelise')}" 
107                                 toolTip="Create parallel way" 
108                                 width="28" height="28" textAlign="left" paddingLeft="8" paddingRight="0" />
109
110                 </potlatch2:Toolbox>
111
112     </mx:HDividedBox>
113
114         <mx:Script><![CDATA[
115                 import net.systemeD.halcyon.*;
116                 import net.systemeD.halcyon.connection.*;
117                 import net.systemeD.potlatch2.*;
118                 import net.systemeD.potlatch2.save.SaveManager;
119                 import net.systemeD.potlatch2.controller.*;
120                 import net.systemeD.potlatch2.help.*;
121                 import net.systemeD.potlatch2.options.*;
122                 import net.systemeD.potlatch2.utils.*;
123                 import mx.managers.PopUpManager;
124                 import flash.system.Security;
125                 import flash.net.*;
126                 import flash.events.MouseEvent;
127                 import flash.display.Sprite;
128                 import mx.core.IChildList;
129         import mx.containers.Canvas;
130                 import mx.core.Application;
131         import mx.events.DragEvent;
132         import mx.managers.DragManager;
133         import mx.core.DragSource;
134
135         public var theMap:Map;
136         public var theController:EditController;
137
138                 private var savecount:uint=0;
139                 private var loadcount:uint=0;
140
141                 private function initApp():void {
142
143                         Globals.vars.map_area = map_area;
144                         Globals.vars.root = map_area.rawChildren;                       // set up global reference to root level
145                         var _root:IChildList = map_area.rawChildren;            // convenient local shorthand
146
147                         // map backdrop object
148             var w:uint = map_area.width;
149             var h:uint = map_area.height;
150             var b:Sprite = new Sprite();
151             b.height=h; b.width=w;
152             b.graphics.beginFill(0xFFFFEA,100); 
153             b.graphics.drawRect(0,0,w,h); 
154             b.graphics.endFill();
155                         _root.addChild(b);
156
157                         // create map and Yahoo
158                         theMap=new Map(this.loaderInfo.parameters);
159                         theMap.backdrop=b;
160                         var yahoo:Yahoo=new Yahoo(w,h,theMap);
161                         yahoo.hide();
162                         Globals.vars.yahoo = yahoo;
163                         _root.addChild(yahoo);
164                         _root.addChild(theMap);
165             theMap.updateSize(w,h);
166
167                         // add mask for map
168                         var s:Sprite=new Sprite();
169                         s.graphics.beginFill(0xFFFFFF,100);
170                         s.graphics.drawRect(0,0,w,h);
171                         s.graphics.endFill();
172                         _root.addChild(s);
173                         theMap.mask=s;
174
175                         // mouse-up handler attached to stage, so the user can release outside the map
176                         stage.addEventListener(MouseEvent.MOUSE_UP, theMap.mouseUpHandler);
177                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_MOVE, theMap.mouseMoveHandler);
178                         Globals.vars.map_area.addEventListener(MouseEvent.MOUSE_DOWN, theMap.mouseDownHandler);
179
180                         // keyboard event attached to stage
181                         stage.addEventListener(KeyboardEvent.KEY_UP, theMap.keyUpHandler);
182
183                         // load imagery XML
184                 var request:URLRequest = new URLRequest("imagery.xml?"+Math.random());
185                 var loader:URLLoader = new URLLoader();
186                 loader.addEventListener(Event.COMPLETE, onImageryLoad);
187                 loader.load(request);
188
189                         // position toolbox
190                         toolbox.x=stage.stageWidth-275;
191                         toolbox.y=stage.stageHeight-100;
192
193                         // add debug field
194                         var t:TextField=new TextField();
195                         t.width=500; t.height=150; t.border=true;
196                         t.multiline=true;
197                         _root.addChild(t);
198                         Globals.vars.debug=t;
199             t.visible = loaderInfo.parameters["show_debug"] == 'true';
200                         Globals.vars.root=theMap;       // just for the addDebug function
201
202             theController = new EditController(theMap, tagViewer, toolbox);
203             theController.setActive();
204             
205             var conn:Connection = Connection.getConnectionInstance();
206             conn.addEventListener(Connection.LOAD_STARTED, onDataStart);
207             conn.addEventListener(Connection.LOAD_COMPLETED, onDataComplete);
208             conn.addEventListener(Connection.SAVE_STARTED, onDataStart);
209             conn.addEventListener(Connection.SAVE_COMPLETED, onDataComplete);
210                 }
211                 
212         public function onResizeMap():void {
213             if ( theMap != null )
214                 theMap.updateSize(map_area.width, map_area.height);
215         }
216
217         private function onDataStart(event:Event):void {
218                         switch (event.type) {
219                                 case Connection.LOAD_STARTED:   loadcount++; break;
220                                 case Connection.SAVE_STARTED:   savecount++; break;
221                         }
222                         updateDataWorking();
223         }
224         private function onDataComplete(event:Event):void {
225                         switch (event.type) {
226                                 case Connection.LOAD_COMPLETED: loadcount--; break;
227                                 case Connection.SAVE_COMPLETED: savecount--; break;
228                         }
229             updateDataWorking();
230         }
231                 private function updateDataWorking():void {
232                         if (loadcount>0 && savecount>0) { dataWorking.text="Loading/saving..."; }
233                         else if (loadcount>0)           { dataWorking.text="Loading data..."; }
234                         else if (savecount>0)           { dataWorking.text="Saving data..."; }
235                         else                            { dataWorking.text=""; }
236                         dataWorking.visible=(dataWorking.text!="");
237                 }
238         
239         private function onImageryLoad(event:Event):void {
240                         var imagery:XML = new XML(URLLoader(event.target).data);
241                         BackgroundSelector(bgButton.popUp).populate(imagery);
242                 }
243
244         
245         private function dragEnterHandler(event:DragEvent):void {
246             // Get the drop target component from the event object.
247             var dropTarget:Canvas=event.currentTarget as Canvas;
248             // Accept the drag only if the user is dragging poi with tags
249             if (event.dragSource.hasFormat('tags')) 
250             {
251                 DragManager.acceptDragDrop(dropTarget);
252             }
253         }
254         
255         private function dragDropHandler(event:DragEvent):void {
256             // Get the data identified by the color format from the drag source.
257             // Blame http://www.adobe.com/devnet/flex/quickstart/adding_drag_and_drop/#manual
258             // for whatever horrid abuse of "color format" this is doing
259             var tags:Array = event.dragSource.dataForFormat('tags') as Array;
260             var mapLoc:Point = Globals.vars.root.globalToLocal(new Point(event.stageX, event.stageY));
261             var lat:Number = Globals.vars.root.coord2lat(mapLoc.y);
262             var lon:Number = Globals.vars.root.coord2lon(mapLoc.x);
263             
264             var createAction:CompositeUndoableAction = new CompositeUndoableAction("Create POI");
265             
266             var node:Node = Connection.getConnectionInstance().createNode({}, lat, lon, createAction.push);
267             for each ( var tag:Object in tags ) {
268                 node.setTag(tag.k, tag.v, createAction.push);
269             }
270                         Connection.getConnectionInstance().registerPOI(node);
271                         MainUndoStack.getGlobalStack().addAction(createAction);
272             theController.setState(new SelectedPOINode(node));
273         }
274
275         ]]></mx:Script>
276
277 </mx:Application>
278