~mahara-contributors/mahara-adminlang/adminlang-master

« back to all changes in this revision

Viewing changes to htdocs/lib/flowplayer/src/actionscript/org/flowplayer/view/Panel.as

  • Committer: Ruslan Kabalin
  • Date: 2011-08-03 14:54:09 UTC
  • Revision ID: git-v1:a3409b53a971ec3bad8b5d1329298046d9596381
Revert back to master brach.

The adminlang-master was mistakingly based on the mahara 1.3_STABLE. This is
required for easy merge with the master.

Command used:
for i in `git rev-list
f731cf9b2cf72b61ed6a317acab23a30b9046c8a..afb5850ba246f41b624c162e8d8e6e72c534f239`;
do git revert -n $i; done

Change-Id: I9db8553a66facfaca81492cd978f974c6e7b8892

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*    
 
2
 *    Copyright (c) 2008, 2009 Flowplayer Oy
 
3
 *
 
4
 *    This file is part of Flowplayer.
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
package org.flowplayer.view {
 
21
        import org.flowplayer.model.DisplayPropertiesImpl;      
 
22
        
 
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;
 
28
        
 
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; 
 
34
 
 
35
        /**
 
36
         * @author anssi
 
37
         */
 
38
        internal class Panel extends Sprite {
 
39
 
 
40
                private var log:Log = new Log(this);
 
41
                private var layout:Layout;
 
42
//              private var displayProperties:Dictionary = new Dictionary();
 
43
 
 
44
                public function Panel() {
 
45
                        addEventListener(Event.ADDED_TO_STAGE, createLayout);
 
46
                }
 
47
 
 
48
                public function addView(view:DisplayObject, resizeListener:Object = null, properties:DisplayProperties = null):void {
 
49
                        if (!properties) {
 
50
                                properties = new DisplayPropertiesImpl();
 
51
                                properties.left = 0;
 
52
                                properties.top = 0;
 
53
                                properties.width = view.width || "50%";
 
54
                                properties.height = view.height || "50%";
 
55
                        } else {
 
56
                                if (! properties.dimensions.height.hasValue()) {
 
57
                                        properties.height = view.height;
 
58
                                }
 
59
                                if (! properties.dimensions.width.hasValue()) {
 
60
                                        properties.width = view.width;
 
61
                                }
 
62
                                if (! (properties.position.left.hasValue() || properties.position.right.hasValue())) {
 
63
                                        properties.left = "50%";
 
64
                                }
 
65
                                if (! (properties.position.top.hasValue() || properties.position.bottom.hasValue())) {
 
66
                                        properties.top = "50%";
 
67
                                }
 
68
                        }
 
69
                        if (properties.zIndex < 0) {
 
70
                                properties.zIndex = 1;
 
71
                        }
 
72
                        var listener:Function;
 
73
                        if (resizeListener)
 
74
                                 listener = resizeListener is Function ? resizeListener as Function : view[resizeListener];
 
75
                        else
 
76
                                listener = new DrawWrapper(view).draw;
 
77
                        view.alpha = properties.alpha;
 
78
                        
 
79
                        properties.setDisplayObject(view);
 
80
                        addChildView(properties);
 
81
                        
 
82
                        layout.addView(view, listener, properties);
 
83
                }
 
84
                
 
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??");
 
89
                        }
 
90
                        return super.addChild(child);
 
91
                }
 
92
                
 
93
                override public function swapChildren(child1:DisplayObject, child2:DisplayObject):void {
 
94
                        log.warn("swapChildren on Panel called, overridden here and does nothing");
 
95
                }
 
96
                
 
97
                private function addChildView(properties:DisplayProperties):void {
 
98
                        log.info("updating Z index of " + properties + ", target Z index is " + properties.zIndex + ", numChildreb " + numChildren);
 
99
 
 
100
                        for (var i:int = 0; i < numChildren; i++) {
 
101
                                log.debug(getChildAt(i) + " at " + i);
 
102
                        }
 
103
 
 
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);
 
108
                        } else {
 
109
                                addChild(properties.getDisplayObject());
 
110
                        }
 
111
                        properties.zIndex = getChildIndex(properties.getDisplayObject());
 
112
                        log.debug("Z index updated to  " + properties.zIndex);
 
113
                        
 
114
                        log.debug("child indexes are now: ");
 
115
 
 
116
                        for (var j:int = 0; j < numChildren; j++) {
 
117
                                log.debug(getChildAt(j) + " at " + j);
 
118
                        }
 
119
                }
 
120
 
 
121
                public function getZIndex(view:DisplayObject):int {
 
122
                        try {
 
123
                                return getChildIndex(view);
 
124
                        } catch (e:Error) {
 
125
                                // view not added in this panel
 
126
                        }
 
127
                        return -1;
 
128
                }
 
129
 
 
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);
 
134
                        }
 
135
                        return layout.update(view, properties);
 
136
                }
 
137
 
 
138
                private function removeView(view:DisplayObject):void {
 
139
                        log.debug("removeView " + view);
 
140
                        if (! getChildByName(view.name)) {
 
141
                                return;
 
142
                        }
 
143
                        super.removeChild(view);
 
144
                        layout.removeView(view);
 
145
                }
 
146
                
 
147
                public override function removeChild(child:DisplayObject):DisplayObject {
 
148
                        removeView(child);
 
149
                        return child;
 
150
                }
 
151
 
 
152
                private function createLayout(event:Event):void {
 
153
                        layout = new MarginLayout(stage);
 
154
                }
 
155
                
 
156
                /**
 
157
                 * Redraw the panel.
 
158
                 * @param disp if specified only this display object is redrawn
 
159
                 */
 
160
                public function draw(disp:DisplayObject = null):void {
 
161
                        layout.draw(disp);
 
162
                }
 
163
        }
 
164
}