2 var _Box = _AbstractUINode.inherits(
\r
4 X.Class.PRIVATE_DATA,
\r
8 forContainer : false,
\r
10 Constructor : function( layout, args ){
\r
11 if( !this.User.instanceOf( Box ) ){
\r
12 //throw new Error( 'Box を継承したインスタンスだけが _Box のオーナーになれます' );
\r
18 for( ; i < l; ++i ){
\r
20 if( arg.instanceOf && arg.instanceOf( AbstractUINode ) ){
\r
21 _data = X.Class._getPrivate( arg );
\r
22 nodes[ nodes.length ] = _data;
\r
24 //throw new Error( 'インスタンスはすでに親に追加されています ' + arg );
\r
27 if( arg.instanceOf && arg.instanceOf( LayoutManagerBase ) ){
\r
30 if( X.Type.isObject( arg ) === true ){
\r
33 //throw new Error( 'AbstractUINode を継承したインスタンスを渡してください ' + arg );
\r
36 this.layout = layout;
\r
40 initialize : function( root, rootData, parent, parentData ){
\r
41 var nodes = this.nodes,
\r
44 this.rootData = rootData;
\r
45 this.parent = parent;
\r
46 this.parentData = parentData;
\r
47 this.rawElement = X.Dom.Node.create( 'div' );
\r
50 nodes[ --i ].initialize( root, rootData, this.User, this );
\r
53 this.styleData.initialize();
\r
56 this.User.dispatch( { type : X.UI.Event.INIT } );
\r
59 addToParent : function( parentElement ){
\r
60 var nodes = this.nodes,
\r
64 parentElement && parentElement.append( this.rawElement );
\r
66 for( ; i < l; ++i ){
\r
67 nodes[ i ].addToParent( this.rawElement );
\r
71 this.User.dispatch( { type : X.UI.Event.ADDED } );
\r
75 afterAddition : function(){
\r
76 var nodes = this.nodes,
\r
79 nodes[ --i ].afterAddition();
\r
81 this.styleData.afterAddition();
\r
84 this.User.dispatch( { type : X.UI.Event.CREATION_COMPLETE } );
\r
87 calculate : function( x, y, w, h ){
\r
88 this.layout.calculate( this, x, y, w, h );
\r
92 commitUpdate : function(){
\r
96 addAt : function( index, _nodes ){
\r
97 //console.log( '# AddAt ' + this.phase )
\r
98 var nodes = this.nodes,
\r
100 p1 = 1 <= this.phase,
\r
101 p2 = 2 <= this.phase,
\r
102 p3 = 3 <= this.phase,
\r
106 //console.log( '### AddAt ' + this.phase )
\r
107 for( l = _nodes.length; i < l; ++i ){
\r
108 data = X.Class._getPrivate( _nodes[ i ] );
\r
109 _p1 = p1 && data.phase < 1;
\r
110 _p2 = p2 && data.phase < 2;
\r
111 _p1 && data.initialize( this.root, this.rootData, this.User, this );
\r
112 if( index <= num ){
\r
113 // _p2 && this.rawElement.insertBefore( data.rawElement, nodes[ index + i ].rawElement );
\r
114 _p2 && nodes[ index + i ].rawElement.before( data.rawElement );
\r
115 _p2 && data.addToParent( null );
\r
116 nodes.splice( index + i, 0, data );
\r
118 _p2 && data.addToParent( this.rawElement );
\r
119 nodes[ nodes.length ] = data;
\r
121 p3 && data.phase < 3 && data.afterAddition();
\r
122 p3 && data.phase < 4 && data.creationComplete();
\r
124 4 <= this.phase && this.rootData.reserveCalc();
\r
127 remove : function( _nodes ){
\r
128 //console.log( '# AddAt ' + this.phase )
\r
129 var nodes = this.nodes,
\r
133 //console.log( '### AddAt ' + this.phase )
\r
135 node = X.Class._getPrivate( _nodes[ --i ] );
\r
136 if( ( n = nodes.indexOf( node ) ) !== -1 ){
\r
137 nodes.splice( n, 1 );
\r
141 4 <= this.phase && this.rootData.reserveCalc();
\r
144 removeAt : function( from, length ){
\r
145 var nodes = this.nodes,
\r
147 to = from + ( X.Type.isNumber( length ) && 1 <= length ? length : 1 ),
\r
150 node = nodes[ --i ];
\r
151 if( from <= i && i < to ){
\r
152 nodes.splice( i, 1 );
\r
156 4 <= this.phase && this.rootData.reserveCalc();
\r
159 _remove : function(){
\r
160 var nodes = this.nodes,
\r
162 for( ; i; ){ nodes[ --i ]._remove(); };
\r
164 switch( this.phase ){
\r
167 //this.styleData.afterAddition();
\r
169 //this.styleData.initialize();
\r
170 this.rawElement.remove();
\r
173 delete this.rootData;
\r
174 delete this.parent;
\r
175 delete this.parentData;
\r
176 delete this.rawElement;
\r
183 var BasicLayoutManager = ( new LayoutManagerBase() ).define( {
\r
197 calculate : function( data, x, y, w, h ){
\r
198 var nodes = data.nodes,
\r
199 i = 0, l = nodes.length, node;
\r
200 for( ; i < l; ++i ){
\r
202 if( node.instanceOf( _Box ) ){
\r
203 node.calculate( x, y, w, h );
\r
205 //node.styleData.layout( x, y, w, h );
\r
208 data.styleData.layout( x, y, w, h );
\r
212 var Box = AbstractUINode.inherits(
\r
214 X.Class.SUPER_ACCESS,
\r
217 Constructor : function(){
\r
218 this.style = DisplayNodeStyle( this, X.Class._newPrivate( this, BasicLayoutManager, arguments ) );
\r
219 this.style.addName( 'Box' );
\r
222 add : function( node /* , node, node ... */ ){
\r
223 X.Class._getPrivate( this ).addAt( this.numNodes() + 1, Array.prototype.slice.call( arguments ) );
\r
226 addAt : function( index, node /* , node, node ... */ ){
\r
227 if( index < 0 ) index = 0;
\r
228 X.Class._getPrivate( this ).addAt( arguments[ 0 ], Array.prototype.slice.call( arguments, 1 ) );
\r
231 remove : function( node /* , node, node ... */ ){
\r
232 X.Class._getPrivate( this ).remove( Array.prototype.slice.call( arguments ) );
\r
235 removeAt : function( from, length ){
\r
236 X.Class._getPrivate( this ).removeAt( from, length );
\r
239 getNodesByClass : function( klass ){
\r
241 nodes = X.Class._getPrivate( this ).nodes,
\r
243 if( !nodes || nodes.length === 0 ) return ret;
\r
244 for( i = 0, l = nodes.length; i < l; ++i ){
\r
245 node = nodes[ i ].User;
\r
246 if( node.instanceOf( klass ) ) ret[ ret.length ] = node;
\r
250 getFirstChild : function(){
\r
251 return this.getNodeAt( 0 );
\r
253 getLastChild : function(){
\r
254 var nodes = X.Class._getPrivate( this ).nodes;
\r
255 return nodes && nodes.length && nodes[ nodes.length - 1 ].User || null;
\r
257 getNodeByUID : function( uid ){
\r
259 getNodeAt : function( index ){
\r
260 if( index < 0 ) return null;
\r
261 var nodes = X.Class._getPrivate( this ).nodes;
\r
262 return nodes && nodes[ index ].User || null;
\r
264 numNodes : function(){
\r
265 var nodes = X.Class._getPrivate( this ).nodes;
\r
266 return nodes && nodes.length || 0;
\r