floating alerts
authorRichard Fairhurst <richard@systemed.net>
Sun, 16 Jan 2011 16:53:32 +0000 (16:53 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 16 Jan 2011 16:53:32 +0000 (16:53 +0000)
net/systemeD/controls/FloatingAlert.as [new file with mode: 0644]
net/systemeD/halcyon/AttentionEvent.as [new file with mode: 0644]
potlatch2.mxml

diff --git a/net/systemeD/controls/FloatingAlert.as b/net/systemeD/controls/FloatingAlert.as
new file mode 100644 (file)
index 0000000..3fbabce
--- /dev/null
@@ -0,0 +1,69 @@
+package net.systemeD.controls {
+
+       import flash.display.Sprite;
+       import flash.display.Stage;
+       import flash.events.*;
+       import flash.text.*;
+       import flash.utils.Timer;
+
+       public class FloatingAlert extends Sprite {
+
+               private var textfield:TextField;
+               private var h:int;
+               private var w:int;
+               private var timer:Timer;
+               
+               public function FloatingAlert(message:String) {
+                       super();
+
+                       textfield=new TextField();
+                       textfield.defaultTextFormat=new TextFormat("_sans", 15, 0xFFFFFF, true);
+                       textfield.autoSize=TextFieldAutoSize.LEFT;
+                       textfield.text=message;
+                       textfield.x=10;
+                       textfield.y=3;
+                       addChild(textfield);
+
+                       w=textfield.textWidth+20;
+                       h=textfield.textHeight+10;
+
+                       graphics.lineStyle(2,0);
+            graphics.beginFill(0x6495ED,100); 
+            graphics.drawRoundRect(0,0,w,h,10);
+            graphics.endFill();
+
+                       textfield.alpha=alpha=0;
+                       addEventListener(Event.ADDED_TO_STAGE, start);
+               }
+               
+               private function start(event:Event):void {
+                       removeEventListener(Event.ADDED_TO_STAGE, start);
+                       x=(stage.stageWidth-w)/2;
+                       y=stage.stageHeight;
+
+                       timer=new Timer(20,30);
+                       timer.addEventListener(TimerEvent.TIMER, floatUpwards);
+                       timer.addEventListener(TimerEvent.TIMER_COMPLETE, floatFinished);
+                       timer.start();
+               }
+               
+               private function floatUpwards(event:TimerEvent):void {
+                       y-=2;
+                       alpha+=0.035;
+                       textfield.alpha=alpha;
+               }
+               
+               private function floatFinished(event:TimerEvent):void {
+                       timer.removeEventListener(TimerEvent.TIMER, floatUpwards);
+                       timer.removeEventListener(TimerEvent.TIMER_COMPLETE, floatFinished);
+                       stage.addEventListener(MouseEvent.MOUSE_DOWN, clear);
+                       stage.addEventListener(KeyboardEvent.KEY_DOWN, clear);
+               }
+               
+               private function clear(event:Event):void {
+                       stage.removeEventListener(MouseEvent.MOUSE_DOWN, clear);
+                       stage.removeEventListener(KeyboardEvent.KEY_DOWN, clear);
+                       parent.removeChild(this);
+               }
+       }
+}
diff --git a/net/systemeD/halcyon/AttentionEvent.as b/net/systemeD/halcyon/AttentionEvent.as
new file mode 100644 (file)
index 0000000..57828d7
--- /dev/null
@@ -0,0 +1,24 @@
+package net.systemeD.halcyon {
+
+    import flash.events.Event;
+       import net.systemeD.halcyon.connection.Entity;
+
+    public class AttentionEvent extends Event {
+
+               public static const ATTENTION:String = "attention";
+               public static const ALERT:String = "alert";
+
+               public var entity:Entity;
+               public var message:String;
+               public var priority:uint;
+
+               public var params:Object;
+
+        public function AttentionEvent(eventname:String, entity:Entity, message:String="", priority:uint=0) {
+            super(eventname);
+                       this.entity  =entity;
+                       this.message =message;
+                       this.priority=priority;
+        }
+    }
+}
index 0867a88..dafe12a 100644 (file)
@@ -84,6 +84,7 @@
                import net.systemeD.potlatch2.options.*;
                import net.systemeD.potlatch2.utils.*;
         import net.systemeD.potlatch2.mygpx.*;
+               import net.systemeD.controls.FloatingAlert;
                import mx.managers.PopUpManager;
                import flash.system.Security;
                import flash.net.*;
             conn.addEventListener(Connection.DATA_DIRTY, onDataDirty);
             conn.addEventListener(Connection.DATA_CLEAN, onDataClean);
                        conn.addEventListener(MapEvent.ERROR, onMapError);
-                       conn.addEventListener(MapEvent.ATTENTION, onAttention);
+                       conn.addEventListener(AttentionEvent.ATTENTION, onAttention);
+                       conn.addEventListener(AttentionEvent.ALERT, onAlert);
 
             // set the access token from saved cookie
             var tokenObject:SharedObject = SharedObject.getLocal("access_token");
                        });
                }
 
-               /* Highlight an entity in response to an 'attention' event */
+               /** Highlight an entity in response to an 'attention' event */
 
-               public function onAttention(mapEvent:MapEvent):void {
-                       var entity:Entity=mapEvent.params.entity;
+               public function onAttention(event:AttentionEvent):void {
+                       var entity:Entity=event.entity;
                        if (entity is Relation) {
                                // If it's a relation, just bring up the editor panel
                                var panel:RelationEditorPanel = RelationEditorPanel(
                        theController.setState(theController.findStateForSelection([entity]));
                }
 
+               /** Display floating warning in response to an 'alert' event */
+
+               public function onAlert(event:AttentionEvent):void {
+                       var alert:FloatingAlert=new FloatingAlert(event.message);
+                       stage.addChild(alert);
+               }
+
         public function onResizeMap():void {
             if ( theMap != null )
                 theMap.updateSize(map_area.width, map_area.height);