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