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