2
* Copyright (c) 2008, 2009 Flowplayer Oy
4
* This file is part of Flowplayer.
6
* Flowplayer is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Flowplayer is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Flowplayer. If not, see <http://www.gnu.org/licenses/>.
20
package org.flowplayer.view {
21
import org.flowplayer.model.DisplayPropertiesImpl;
23
import flash.display.DisplayObject;
24
import flash.display.Sprite;
25
import flash.events.Event;
26
import flash.geom.Rectangle;
27
import flash.utils.Dictionary;
29
import org.flowplayer.layout.DrawWrapper;
30
import org.flowplayer.layout.Layout;
31
import org.flowplayer.layout.MarginLayout;
32
import org.flowplayer.model.DisplayProperties;
33
import org.flowplayer.util.Log;
38
internal class Panel extends Sprite {
40
private var log:Log = new Log(this);
41
private var layout:Layout;
42
// private var displayProperties:Dictionary = new Dictionary();
44
public function Panel() {
45
addEventListener(Event.ADDED_TO_STAGE, createLayout);
48
public function addView(view:DisplayObject, resizeListener:Object = null, properties:DisplayProperties = null):void {
50
properties = new DisplayPropertiesImpl();
53
properties.width = view.width || "50%";
54
properties.height = view.height || "50%";
56
if (! properties.dimensions.height.hasValue()) {
57
properties.height = view.height;
59
if (! properties.dimensions.width.hasValue()) {
60
properties.width = view.width;
62
if (! (properties.position.left.hasValue() || properties.position.right.hasValue())) {
63
properties.left = "50%";
65
if (! (properties.position.top.hasValue() || properties.position.bottom.hasValue())) {
66
properties.top = "50%";
69
if (properties.zIndex < 0) {
70
properties.zIndex = 1;
72
var listener:Function;
74
listener = resizeListener is Function ? resizeListener as Function : view[resizeListener];
76
listener = new DrawWrapper(view).draw;
77
view.alpha = properties.alpha;
79
properties.setDisplayObject(view);
80
addChildView(properties);
82
layout.addView(view, listener, properties);
85
override public function addChild(child:DisplayObject):DisplayObject {
86
log.debug("addChild " + child);
87
if (child is Preloader) {
88
log.warn("adding Preloader to panel??");
90
return super.addChild(child);
93
override public function swapChildren(child1:DisplayObject, child2:DisplayObject):void {
94
log.warn("swapChildren on Panel called, overridden here and does nothing");
97
private function addChildView(properties:DisplayProperties):void {
98
log.info("updating Z index of " + properties + ", target Z index is " + properties.zIndex + ", numChildreb " + numChildren);
100
for (var i:int = 0; i < numChildren; i++) {
101
log.debug(getChildAt(i) + " at " + i);
104
if (properties.zIndex < numChildren) {
105
log.debug("adding child at " + properties.zIndex);
106
var currentChild:DisplayObject = getChildAt(properties.zIndex);
107
addChildAt(properties.getDisplayObject(), properties.zIndex);
109
addChild(properties.getDisplayObject());
111
properties.zIndex = getChildIndex(properties.getDisplayObject());
112
log.debug("Z index updated to " + properties.zIndex);
114
log.debug("child indexes are now: ");
116
for (var j:int = 0; j < numChildren; j++) {
117
log.debug(getChildAt(j) + " at " + j);
121
public function getZIndex(view:DisplayObject):int {
123
return getChildIndex(view);
125
// view not added in this panel
130
public function update(view:DisplayObject, properties:DisplayProperties):Rectangle {
131
log.debug("updating zIndex to " + properties.zIndex);
132
if (properties.zIndex >= 0) {
133
setChildIndex(view, properties.zIndex < numChildren ? properties.zIndex : numChildren - 1);
135
return layout.update(view, properties);
138
private function removeView(view:DisplayObject):void {
139
log.debug("removeView " + view);
140
if (! getChildByName(view.name)) {
143
super.removeChild(view);
144
layout.removeView(view);
147
public override function removeChild(child:DisplayObject):DisplayObject {
152
private function createLayout(event:Event):void {
153
layout = new MarginLayout(stage);
158
* @param disp if specified only this display object is redrawn
160
public function draw(disp:DisplayObject = null):void {