mdimanager.as
来自「flex的一些小例子」· AS 代码 · 共 1,077 行 · 第 1/3 页
AS
1,077 行
{ if(this.isGlobal) { PopUpManager.bringToFront(window as IFlexDisplayObject); } else { for each(var win:MDIWindow in windowList) { if(win != window && win.hasFocus) { win.dispatchEvent(new MDIWindowEvent(MDIWindowEvent.FOCUS_END, win)); } if(win == window && !window.hasFocus) { win.dispatchEvent(new MDIWindowEvent(MDIWindowEvent.FOCUS_START, win)); } } } } /** * Positions a window in the center of the available screen. * * @param window:MDIWindow to center * */ public function center(window:MDIWindow):void { window.x = this.container.width / 2 - window.width; window.y = this.container.height / 2 - window.height; } /** * Removes all windows from managed window stack; * */ public function removeAll():void { for each(var window:MDIWindow in windowList) { if(this.isGlobal) { PopUpManager.removePopUp(window as IFlexDisplayObject); } else { container.removeChild(window); } this.removeListeners(window); } this.windowList = new Array(); } /** * @private * * Adds listeners * @param window:MDIWindow */ private function addListeners(window:MDIWindow):void { window.addEventListener(MDIWindowEvent.MINIMIZE, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.RESTORE, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.MAXIMIZE, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.CLOSE, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.FOCUS_START, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.FOCUS_END, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.DRAG_START, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.DRAG, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.DRAG_END, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.RESIZE_START, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.RESIZE, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); window.addEventListener(MDIWindowEvent.RESIZE_END, windowEventProxy, false, EventPriority.DEFAULT_HANDLER); } /** * @private * * Removes listeners * @param window:MDIWindow */ private function removeListeners(window:MDIWindow):void { window.removeEventListener(MDIWindowEvent.MINIMIZE, windowEventProxy); window.removeEventListener(MDIWindowEvent.RESTORE, windowEventProxy); window.removeEventListener(MDIWindowEvent.MAXIMIZE, windowEventProxy); window.removeEventListener(MDIWindowEvent.CLOSE, windowEventProxy); window.removeEventListener(MDIWindowEvent.FOCUS_START, windowEventProxy); window.removeEventListener(MDIWindowEvent.FOCUS_END, windowEventProxy); window.removeEventListener(MDIWindowEvent.DRAG_START, windowEventProxy); window.removeEventListener(MDIWindowEvent.DRAG, windowEventProxy); window.removeEventListener(MDIWindowEvent.DRAG_END, windowEventProxy); window.removeEventListener(MDIWindowEvent.RESIZE_START, windowEventProxy); window.removeEventListener(MDIWindowEvent.RESIZE, windowEventProxy); window.removeEventListener(MDIWindowEvent.RESIZE_END, windowEventProxy); } /** * Removes a window instance from the managed window stack * @param window:MDIWindow Window to remove */ public function remove(window:MDIWindow):void { var index:int = ArrayUtil.getItemIndex(window, this.windowList); windowList.splice(index, 1); if(this.isGlobal) { PopUpManager.removePopUp(window as IFlexDisplayObject); } else { container.removeChild(window); } removeListeners(window); // set focus to newly-highest depth window for(var i:int = container.numChildren - 1; i > -1; i--) { var dObj:DisplayObject = container.getChildAt(i); if(dObj is MDIWindow) { bringToFront(MDIWindow(dObj)); return; } } } /** * Pushes a window onto the managed window stack * * @param win Window:MDIWindow to push onto managed windows stack * */ public function manage(window:MDIWindow):void { if(window != null) windowList.push(window); } /** * Positions a window in an absolute position * * @param win:MDIWindow Window to position * * @param x:int The x position of the window * * @param y:int The y position of the window */ public function absPos(window:MDIWindow,x:int,y:int):void { window.x = x; window.y = y; } /** * Gets a list of open windows for scenarios when only open windows need to be managed * * @return Array */ public function getOpenWindowList():Array { var array:Array = []; for(var i:int = 0; i < windowList.length; i++) { if(!MDIWindow(windowList[i]).minimized) { array.push(windowList[i]); } } return array; } /** * Tiles the window across the screen * * <p>By default, windows will be tiled to all the same size and use only the space they can accomodate. * If you set fillAvailableSpace = true, tile will use all the space available to tile the windows with * the windows being arranged by varying heights and widths. * </p> * * @param fillAvailableSpace:Boolean Variable to determine whether to use the fill the entire available screen * */ public function tile(fillAvailableSpace:Boolean = false,gap:Number = 0):void { var openWinList:Array = getOpenWindowList(); var numWindows:int = openWinList.length; if(numWindows == 1) { MDIWindow(openWinList[0]).maximizeRestore(); } else if(numWindows > 1) { var sqrt:int = Math.round(Math.sqrt(numWindows)); var numCols:int = Math.ceil(numWindows / sqrt); var numRows:int = Math.ceil(numWindows / numCols); var col:int = 0; var row:int = 0; var availWidth:Number = this.container.width; var availHeight:Number = this.container.height if(showMinimizedTiles) availHeight = availHeight - getBottomOffsetHeight(this.tiledWindows.length, openWinList[0].minimizeHeight, this.minTilePadding); var targetWidth:Number = availWidth / numCols - ((gap * (numCols - 1)) / numCols); var targetHeight:Number = availHeight / numRows - ((gap * (numRows - 1)) / numRows); var effectItems:Array = []; for(var i:int = 0; i < openWinList.length; i++) { var win:MDIWindow = openWinList[i]; bringToFront(win) var item:MDIGroupEffectItem = new MDIGroupEffectItem(win); item.widthTo = targetWidth; item.heightTo = targetHeight; if(i % numCols == 0 && i > 0) { row++; col = 0; } else if(i > 0) { col++; } item.moveTo = new Point((col * targetWidth), (row * targetHeight)); //pushing out by gap if(col > 0) item.moveTo.x += gap * col; if(row > 0) item.moveTo.y += gap * row; effectItems.push(item); } if(col < numCols && fillAvailableSpace) { var numOrphans:int = numWindows % numCols; var orphanWidth:Number = availWidth / numOrphans - ((gap * (numOrphans - 1)) / numOrphans); //var orphanWidth:Number = availWidth / numOrphans; var orphanCount:int = 0 for(var j:int = numWindows - numOrphans; j < numWindows; j++) { //var orphan:MDIWindow = openWinList[j]; var orphan:MDIGroupEffectItem = effectItems[j]; orphan.widthTo = orphanWidth; //orphan.window.width = orphanWidth; orphan.moveTo.x = (j - (numWindows - numOrphans)) * orphanWidth; if(orphanCount > 0) orphan.moveTo.x += gap * orphanCount; orphanCount++; } } dispatchEvent(new MDIManagerEvent(MDIManagerEvent.TILE, null, this, null, effectItems)); } } // set a min. width/height public function resize(window:MDIWindow):void { var w:int = this.container.width * .6; var h:int = this.container.height * .6 if(w > window.width) window.width = w; if(h > window.height) window.height=h; } /** * Cascades all managed windows from top left to bottom right * */ public function cascade():void { var effectItems:Array = []; var windows:Array = getOpenWindowList(); var xIndex:int = 0; var yIndex:int = -1; for(var i:int = 0; i < windows.length; i++) { var window:MDIWindow = windows[i] as MDIWindow; bringToFront(window); var item:MDIGroupEffectItem = new MDIGroupEffectItem(window); item.widthFrom = window.width; item.widthTo = container.width * .5; item.heightFrom = window.height; item.heightTo = container.height * .5; if(yIndex * 40 + item.heightTo + 25 >= container.height) { yIndex = 0; xIndex++; } else { yIndex++; } var destX:int = xIndex * 40 + yIndex * 20; var destY:int = yIndex * 40; item.moveTo = new Point(destX, destY); effectItems.push(item); } dispatchEvent(new MDIManagerEvent(MDIManagerEvent.CASCADE, null, this, null, effectItems)); } public function showAllWindows():void { // this prevents retiling of windows yet to be unMinimized() tiledWindows.removeAll(); for each(var window:MDIWindow in windowList) { if(window.minimized) { window.unMinimize(); } } } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?