/********************************************************************** * * Dragable, resizable panel * * Source = http://blogs.adobe.com/flexdoc/2007/03/creating_resizable_and_dragga.. * * Modified 01/01/2009 mjc1 * - to draw resize icon on top of panel so that it can * be used with opaque surrounds * *********************************************************************/ package myComponents { import mx.containers.Panel; import mx.core.UIComponent; import mx.core.SpriteAsset; import mx.events.FlexEvent; import flash.events.MouseEvent; import flash.events.Event; public class DragPanel extends Panel { // Add the creationCOmplete event handler. public function DragPanel() { super(); addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler); } // Expose the title bar property for draggin and dropping. [Bindable] public var myTitleBar:UIComponent; private function creationCompleteHandler(event:Event):void { myTitleBar = titleBar; } protected var minShape:SpriteAsset; protected var restoreShape:SpriteAsset; protected var resizeShape:SpriteAsset;//added by mjc1 override protected function createChildren():void { super.createChildren(); // Create the SpriteAsset's for the min/restore icons and // add the event handlers for them. minShape = new SpriteAsset(); minShape.addEventListener(MouseEvent.MOUSE_DOWN, minPanelSizeHandler); titleBar.addChild(minShape); restoreShape = new SpriteAsset(); restoreShape.addEventListener(MouseEvent.MOUSE_DOWN, restorePanelSizeHandler); titleBar.addChild(restoreShape); //added by mjc1 resizeShape = new SpriteAsset(); resizeShape.addEventListener(MouseEvent.MOUSE_DOWN, resizeIconMouseDownHandler); titleBar.addChild(resizeShape); } override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); // Create invisible rectangle to increase the hit area of the min icon. minShape.graphics.clear(); minShape.graphics.lineStyle(0, 0, 0); minShape.graphics.beginFill(0xFFFFFF, 0.0); minShape.graphics.drawRect(unscaledWidth - 35, 12, 8, 8); // Draw min icon. minShape.graphics.lineStyle(2,0xFFFFFF,1); minShape.graphics.beginFill(0xFFFFFF, 0.0); minShape.graphics.drawRect(unscaledWidth - 35, 18, 8, 2); // Draw restore icon. restoreShape.graphics.clear(); restoreShape.graphics.lineStyle(2,0xFFFFFF,1); restoreShape.graphics.beginFill(0xFFFFFF, 0.0); restoreShape.graphics.drawRect(unscaledWidth - 20, 12, 8, 8); restoreShape.graphics.moveTo(unscaledWidth - 20, 15); restoreShape.graphics.lineTo(unscaledWidth - 12, 15); // Draw resize graphics if not minimzed. resizeShape.graphics.clear() if (isMinimized == false) { /*commented out by mjc1: graphics.lineStyle(1,0xFF0000,1); graphics.moveTo(unscaledWidth - 6, unscaledHeight - 1) graphics.curveTo(unscaledWidth - 3, unscaledHeight - 3, unscaledWidth - 1, unscaledHeight - 6); graphics.moveTo(unscaledWidth - 6, unscaledHeight - 4) graphics.curveTo(unscaledWidth - 5, unscaledHeight - 5, unscaledWidth - 4, unscaledHeight - 6); */ //added by mjc1: resizeShape.x=unscaledWidth - 6; resizeShape.y=unscaledHeight - 6; resizeShape.graphics.lineStyle(2,0xFFFFFF,1); resizeShape.graphics.moveTo(0, 5) resizeShape.graphics.curveTo(3, 3, 5, 0); resizeShape.graphics.moveTo(0, 2) resizeShape.graphics.curveTo(1, 1, 2, 0); } } private var myRestoreHeight:int; private var isMinimized:Boolean = false; // Minimize panel event handler. private function minPanelSizeHandler(event:Event):void { if (isMinimized != true) { myRestoreHeight = height; height = titleBar.height; isMinimized = true; // Don't allow resizing when in the minimized state. resizeShape.removeEventListener(MouseEvent.MOUSE_DOWN, resizeIconMouseDownHandler); } } // Restore panel event handler. private function restorePanelSizeHandler(event:Event):void { if (isMinimized == true){ height = myRestoreHeight; isMinimized = false; // Allow resizing in restored state. resizeShape.addEventListener(MouseEvent.MOUSE_DOWN, resizeIconMouseDownHandler); } } // Define static constant for event type. public static const RESIZE_CLICK:String = "resizeClick"; private function resizeIconMouseDownHandler(event:MouseEvent):void { event.stopPropagation(); var rbEvent:MouseEvent = new MouseEvent(RESIZE_CLICK, true); // Pass stage coords to so all calculations using global coordinates. rbEvent.localX = event.stageX; rbEvent.localY = event.stageY; dispatchEvent(rbEvent); } } }