SuperPanel.as
上传用户:jqyjoan
上传日期:2018-02-02
资源大小:1773k
文件大小:9k
源码类别:

Ajax

开发平台:

Flex

  1. /********************************************
  2.  title   : SuperPanel
  3.  version : 1.5
  4.  author  : Wietse Veenstra
  5.  website : http://www.wietseveenstra.nl
  6.  date    : 2007-03-30
  7. ********************************************/
  8. package nl.wv.extenders.panel {
  9. import mx.containers.Panel;
  10. import mx.controls.Button;
  11. import mx.core.EdgeMetrics;
  12. import mx.core.UIComponent;
  13. import mx.core.Application;
  14. import mx.events.DragEvent;
  15. import mx.events.EffectEvent;
  16. import mx.effects.Resize;
  17. import mx.managers.CursorManager;
  18. import flash.display.DisplayObject;
  19. import flash.geom.Point;
  20. import flash.geom.Rectangle;
  21. import flash.events.MouseEvent;
  22. public class SuperPanel extends Panel {
  23. [Bindable] public var showControls:Boolean = false;
  24. [Bindable] public var enableResize:Boolean = false;
  25. [Embed(source="../../../../blue_plastic.swf", symbol="resize_arrow")]
  26. private static var resizeCursor:Class;
  27. private var pTitleBar:UIComponent;
  28. private var oW:Number;
  29. private var oH:Number;
  30. private var oX:Number;
  31. private var oY:Number;
  32. private var normalMaxButton:Button = new Button();
  33. private var closeButton:Button = new Button();
  34. private var resizeHandler:Button = new Button();
  35. public  var backButton:Button;
  36. private var upMotion:Resize = new Resize();
  37. private var downMotion:Resize = new Resize();
  38. private var oPoint:Point  = new Point();
  39. private var resizeCur:Number = 0;
  40. public function SuperPanel() {}
  41. override protected function createChildren():void {
  42. super.createChildren();
  43. this.pTitleBar = super.titleBar;
  44. this.setStyle("headerColors", [0xC3D1D9, 0xD2DCE2]);
  45. this.setStyle("borderColor", 0xD2DCE2);
  46. this.doubleClickEnabled = true;
  47. if (enableResize) {
  48. this.resizeHandler.width     = 18;
  49. this.resizeHandler.height    = 18;
  50. this.resizeHandler.styleName = "resizeHndlr";
  51. this.rawChildren.addChild(resizeHandler);
  52. this.initPos();
  53. }
  54. if (showControls) {
  55. this.normalMaxButton.width      = 10;
  56. this.normalMaxButton.height     = 10;
  57. this.normalMaxButton.styleName  = "increaseBtn";
  58. this.closeButton.width      = 10;
  59. this.closeButton.height     = 10;
  60. this.closeButton.styleName  = "closeBtn";
  61. this.pTitleBar.addChild(this.normalMaxButton);
  62. this.pTitleBar.addChild(this.closeButton);
  63. }
  64. this.positionChildren();
  65. this.addListeners();
  66. }
  67. public function initPos():void {
  68. this.oW = this.width;
  69. this.oH = this.height;
  70. this.oX = this.x;
  71. this.oY = this.y;
  72. }
  73. public function positionChildren():void {
  74. if (showControls) {
  75. this.normalMaxButton.buttonMode    = true;
  76. this.normalMaxButton.useHandCursor = true;
  77. this.normalMaxButton.x = this.unscaledWidth - this.normalMaxButton.width - 38;
  78. this.normalMaxButton.y = 6;
  79. this.closeButton.buttonMode    = true;
  80. this.closeButton.useHandCursor = true;
  81. this.closeButton.x = this.unscaledWidth - this.closeButton.width - 20;
  82. this.closeButton.y = 6;
  83. }
  84. if (enableResize) {
  85. this.resizeHandler.y = this.unscaledHeight - resizeHandler.height - 8;
  86. this.resizeHandler.x = this.unscaledWidth - resizeHandler.width - 8;
  87. }
  88. }
  89. public function addListeners():void {
  90. this.addEventListener(MouseEvent.CLICK, panelClickHandler);
  91. this.pTitleBar.addEventListener(MouseEvent.MOUSE_DOWN, titleBarDownHandler);
  92. this.pTitleBar.addEventListener(MouseEvent.DOUBLE_CLICK, titleBarDoubleClickHandler);
  93. if (showControls) {
  94. this.closeButton.addEventListener(MouseEvent.CLICK, closeClickHandler);
  95. this.normalMaxButton.addEventListener(MouseEvent.CLICK, normalMaxClickHandler);
  96. }
  97. if (enableResize) {
  98. this.resizeHandler.addEventListener(MouseEvent.MOUSE_OVER, resizeOverHandler);
  99. this.resizeHandler.addEventListener(MouseEvent.MOUSE_OUT, resizeOutHandler);
  100. this.resizeHandler.addEventListener(MouseEvent.MOUSE_DOWN, resizeDownHandler);
  101. }
  102. }
  103. public function panelClickHandler(event:MouseEvent):void {
  104. this.pTitleBar.removeEventListener(MouseEvent.MOUSE_MOVE, titleBarMoveHandler);
  105. this.parent.setChildIndex(this, this.parent.numChildren - 1);
  106. this.panelFocusCheckHandler();
  107. }
  108. public function titleBarDownHandler(event:MouseEvent):void {
  109. this.pTitleBar.addEventListener(MouseEvent.MOUSE_MOVE, titleBarMoveHandler);
  110. }
  111. public function titleBarMoveHandler(event:MouseEvent):void {
  112. if (this.width < screen.width) {
  113. Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, titleBarDragDropHandler);
  114. this.pTitleBar.addEventListener(DragEvent.DRAG_DROP,titleBarDragDropHandler);
  115. this.parent.setChildIndex(this, this.parent.numChildren - 1);
  116. this.panelFocusCheckHandler();
  117. this.alpha = 0.5;
  118. this.startDrag(false, new Rectangle(0, 0, screen.width - this.width, screen.height - this.height));
  119. }
  120. }
  121. public function titleBarDragDropHandler(event:MouseEvent):void {
  122. this.pTitleBar.removeEventListener(MouseEvent.MOUSE_MOVE, titleBarMoveHandler);
  123. this.alpha = 1.0;
  124. this.stopDrag();
  125. }
  126. public function panelFocusCheckHandler():void {
  127. for (var i:int = 0; i < this.parent.numChildren; i++) {
  128. var child:UIComponent = UIComponent(this.parent.getChildAt(i));
  129. if (this.parent.getChildIndex(child) < this.parent.numChildren - 1) {
  130. child.setStyle("headerColors", [0xC3D1D9, 0xD2DCE2]);
  131. child.setStyle("borderColor", 0xD2DCE2);
  132. } else if (this.parent.getChildIndex(child) == this.parent.numChildren - 1) {
  133. child.setStyle("headerColors", [0xC3D1D9, 0x5A788A]);
  134. child.setStyle("borderColor", 0x5A788A);
  135. }
  136. }
  137. }
  138. public function titleBarDoubleClickHandler(event:MouseEvent):void {
  139. this.pTitleBar.removeEventListener(MouseEvent.MOUSE_MOVE, titleBarMoveHandler);
  140. Application.application.parent.removeEventListener(MouseEvent.MOUSE_UP, resizeUpHandler);
  141. this.upMotion.target = this;
  142. this.upMotion.duration = 300;
  143. this.upMotion.heightFrom = oH;
  144. this.upMotion.heightTo = 28;
  145. this.upMotion.end();
  146. this.downMotion.target = this;
  147. this.downMotion.duration = 300;
  148. this.downMotion.heightFrom = 28;
  149. this.downMotion.heightTo = oH;
  150. this.downMotion.end();
  151. if (this.width < screen.width) {
  152. if (this.height == oH) {
  153. this.upMotion.play();
  154. this.resizeHandler.visible = false;
  155. } else {
  156. this.downMotion.play();
  157. this.downMotion.addEventListener(EffectEvent.EFFECT_END, endEffectEventHandler);
  158. }
  159. }
  160. }
  161. public function endEffectEventHandler(event:EffectEvent):void {
  162. this.resizeHandler.visible = true;
  163. }
  164. public function normalMaxClickHandler(event:MouseEvent):void {
  165. if (this.normalMaxButton.styleName == "increaseBtn") {
  166. if (this.height > 28) {
  167. this.initPos();
  168. this.x = 0;
  169. this.y = 0;
  170. this.width = screen.width;
  171. this.height = screen.height;
  172. this.normalMaxButton.styleName = "decreaseBtn";
  173. this.positionChildren();
  174. }
  175. } else {
  176. this.x = this.oX;
  177. this.y = this.oY;
  178. this.width = this.oW;
  179. this.height = this.oH;
  180. this.normalMaxButton.styleName = "increaseBtn";
  181. this.positionChildren();
  182. }
  183. }
  184. public function closeClickHandler(event:MouseEvent):void {
  185. this.removeEventListener(MouseEvent.CLICK, panelClickHandler);
  186. this.parent.addChild(backButton);
  187. this.parent.removeChild(this);
  188. }
  189. public function resizeOverHandler(event:MouseEvent):void {
  190. this.resizeCur = CursorManager.setCursor(resizeCursor);
  191. }
  192. public function resizeOutHandler(event:MouseEvent):void {
  193. CursorManager.removeCursor(CursorManager.currentCursorID);
  194. }
  195. public function resizeDownHandler(event:MouseEvent):void {
  196. Application.application.parent.addEventListener(MouseEvent.MOUSE_MOVE, resizeMoveHandler);
  197. Application.application.parent.addEventListener(MouseEvent.MOUSE_UP, resizeUpHandler);
  198. this.resizeHandler.addEventListener(MouseEvent.MOUSE_OVER, resizeOverHandler);
  199. this.panelClickHandler(event);
  200. this.resizeCur = CursorManager.setCursor(resizeCursor);
  201. this.oPoint.x = mouseX;
  202. this.oPoint.y = mouseY;
  203. this.oPoint = this.localToGlobal(oPoint);
  204. }
  205. public function resizeMoveHandler(event:MouseEvent):void {
  206. this.stopDragging();
  207. var xPlus:Number = Application.application.parent.mouseX - this.oPoint.x;
  208. var yPlus:Number = Application.application.parent.mouseY - this.oPoint.y;
  209. if (this.oW + xPlus > 140) {
  210. this.width = this.oW + xPlus;
  211. }
  212. if (this.oH + yPlus > 80) {
  213. this.height = this.oH + yPlus;
  214. }
  215. this.positionChildren();
  216. }
  217. public function resizeUpHandler(event:MouseEvent):void {
  218. Application.application.parent.removeEventListener(MouseEvent.MOUSE_MOVE, resizeMoveHandler);
  219. Application.application.parent.removeEventListener(MouseEvent.MOUSE_UP, resizeUpHandler);
  220. CursorManager.removeCursor(CursorManager.currentCursorID);
  221. this.resizeHandler.addEventListener(MouseEvent.MOUSE_OVER, resizeOverHandler);
  222. this.initPos();
  223. }
  224. }
  225. }