Merge branch 'master' of github.com:systemed/potlatch2
[potlatch2.git] / net / systemeD / potlatch2 / TasksPalette.mxml
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Panel
3     xmlns:fx="http://ns.adobe.com/mxml/2009"
4         xmlns:mx="library://ns.adobe.com/flex/mx"
5         xmlns:s="library://ns.adobe.com/flex/spark"
6         xmlns:potlatch2="net.systemeD.potlatch2.*"
7         height="50" width="220" layout="absolute" verticalScrollPolicy="off"
8         styleName="tasksPalette">
9
10         <mx:Image data="@Embed('../../../embedded/close_small.png')"
11                 includeInLayout="false" id="paletteClose" click="toggle();" 
12                 y="-6" x="206" />
13
14         <s:Button icon="@Embed('../../../embedded/task_previous.svg')"
15                 id="previousTaskButton"
16                 click='previousTask();'
17                 toolTip="Go to previous task" 
18                 width="28" height="28" y="4" x="6" />
19         <s:Button icon="@Embed('../../../embedded/task_next.svg')"
20                 id="nextTaskButton"
21                 click='nextTask();'
22                 toolTip="Go to next task" 
23                 width="28" height="28" y="4" x="36" />
24
25         <s:Label id="taskDescription" width="145" height="38" y="4" x="71" text="" />
26
27         <fx:Script><![CDATA[
28
29                 import flash.events.Event;
30                 import flash.events.MouseEvent;
31                 import net.systemeD.halcyon.AttentionEvent;
32                 import net.systemeD.halcyon.connection.*;
33                 import net.systemeD.halcyon.connection.actions.*;
34                 import net.systemeD.potlatch2.controller.*;
35                 import net.systemeD.potlatch2.tools.*;
36                 import embedded.*;      // for FXG icons
37
38                 private var controller:EditController;
39                 private var tasks:Array;                                // array of { lat:.., lon:.., text:.. }
40                 private var taskNumber:uint=0;
41                 public var allowControllerKeyboardEvents:Boolean = true;
42
43                 public function init(controller:EditController):void {
44                         this.controller=controller;
45                 }
46                 public function resetTasks():void { tasks=[]; taskNumber=0; }
47                 public function addTask(obj:Object):void { tasks.push(obj); }
48                 public function hasTasks():Boolean { return (tasks.length>0); }
49                 public function updateText():void {
50                         taskDescription.text=tasks[taskNumber].text || "("+taskNumber+" of "+tasks.length()+")";
51                         controller.map.moveMapFromLatLon(tasks[taskNumber].lat, tasks[taskNumber].lon);
52                 }
53
54                 public function previousTask():void {
55                         taskNumber = (taskNumber==0) ? tasks.length-1 : taskNumber-1;
56                         updateText();
57                 }
58                 public function nextTask():void {
59                         taskNumber += 1;
60                         if (taskNumber==tasks.length) taskNumber=0;
61                         updateText();
62                 }
63
64                 override protected function createChildren():void {
65                         super.createChildren();
66                         super.titleBar.addEventListener(MouseEvent.MOUSE_DOWN,handleDown);
67                 }
68
69                 private function handleDown(e:Event):void {
70                         this.startDrag();
71                         stage.addEventListener(MouseEvent.MOUSE_UP,handleUp);
72                 }
73
74                 private function handleUp(e:Event):void {
75                         this.stopDrag();
76                         stage.removeEventListener(MouseEvent.MOUSE_UP,handleUp);
77                 }
78                 
79                 public function toggle():void { this.visible=!this.visible; }
80
81         ]]>
82 </fx:Script>
83 </mx:Panel>