Author: hqm
Date: 2007-07-27 08:53:10 -0700 (Fri, 27 Jul 2007)
New Revision: 5826

Modified:
   
openlaszlo/branches/wafflecone/lps/components/utils/replicator/lazyreplicator.lzx
Log:
lfc'ify lazyreplicator.lzx

Modified: 
openlaszlo/branches/wafflecone/lps/components/utils/replicator/lazyreplicator.lzx
===================================================================
--- 
openlaszlo/branches/wafflecone/lps/components/utils/replicator/lazyreplicator.lzx
   2007-07-27 09:58:24 UTC (rev 5825)
+++ 
openlaszlo/branches/wafflecone/lps/components/utils/replicator/lazyreplicator.lzx
   2007-07-27 15:53:10 UTC (rev 5826)
@@ -3,186 +3,198 @@
     <include href="replicator.lzx"/>
     <!-- A replicator which creates as many clones as are necessary to fill in
     a masked region, similar to the lazy replication option in OpenLaszlo. Also
-    similar to OL's lazy replication, the lazyreplicator must have a clipped
+    similar to OL''s lazy replication, the lazyreplicator must have a clipped
     view as a parent. -->
-    <class name="lazyreplicator" extends="replicator">
-        <!-- mostly copied from LzLazyReplicationManager -->
-        <!--- @keywords private -->
-        <attribute name="clonesoffset" value="0"/>
+    <interface name="lazyreplicator" extends="replicator">
 
-        <!--- @keywords private -->
-        <attribute name="__emptyArray" />
-
         <!--- The size of the replicated clone in the replication axis -->
         <attribute name="replicatedsize" value="null"/>
-        <!--- @keywords private -->
-        <attribute name="clonedel" />
+    </interface>
 
-        <!--- @keywords private -->
-        <method name="construct" args="p,a">
-            super.construct( p, a );
-            this.__emptyArray = [];
-            this.clonedel = new LzDelegate( this, '__adjustVisibleClones');
-        </method>
+  <script when="immediate">
+    <![CDATA[
 
-        <!--- @keywords private -->
-        <method name="init">
-            clonedel.register( mask , "on" + _sizes[ axis ] );
-            clonedel.register( this , "on" + axis );
-            super.init();
-        </method>
+class lazyreplicator extends replicator {
 
-        <!--- @keywords private -->
-        <attribute name="_lastNodesLength" value="0"/>
+    static var tagname = 'lazyreplicator';
 
-        <!--- @keywords private -->
-        <method name="__adjustVisibleClones"><![CDATA[
-            if ( ! this.nodes ) {
-                while ( clones.length ) this.poolClone( clones.pop() );
-                return;
-            }
+    // mostly copied from LzLazyReplicationManager
+    // @keywords private
+    var clonesoffset = 0;
+    // @keywords private
+    var __emptyArray = null;
 
-            if ( !replicatedsize ) this._setSize();
+    // The size of the replicated clone in the replication axis
+    var replicatedsize = null;
+    // @keywords private
+    var clonedel = null;
+    
 
+    //  @keywords private
+    function construct (p,a) {
+        super.construct( p, a );
+        this.__emptyArray = [];
+        this.clonedel = new LzDelegate( this, '__adjustVisibleClones');
+    }
 
-            var sax =_sizes[ axis ];
-            if ( this.nodes.length != null ){
-                this._lastNodesLength = this.nodes.length;
-            } 
-            var s = this._lastNodesLength * this.replicatedsize;
+    //  @keywords private
+    function init () {
+        this.clonedel.register( this.mask , "on" + this._sizes[ this.axis ] );
+        this.clonedel.register( this , "on" + this.axis );
+        super.init();
+    }
 
-            if ( this[ sax ] != s ){
-                //Debug.write( sax, s, this[ sax ] );
-                this.setAttribute( sax, s );
-            }
+    //  @keywords private
+    var _lastNodesLength = 0;
 
+    //  @keywords private
+    function __adjustVisibleClones () {
+        if ( ! this.nodes ) {
+            while ( this.clones.length ) this.poolClone( this.clones.pop() );
+            return;
+        }
 
-            if (! this.mask )
-                Debug.warn("lazyreplicator _adjustVisibleClones: cannot find 
clipping parent");
+        if ( !this.replicatedsize ) this._setSize();
 
-            if (! this.mask[ "hasset" + sax ] ) 
-                return;
+
+        var sax =this._sizes[ this.axis ];
+        if ( this.nodes.length != null ){
+            this._lastNodesLength = this.nodes.length;
+        } 
+        var s = this._lastNodesLength * this.replicatedsize;
+
+        if ( this[ sax ] != s ){
+            //Debug.write( sax, s, this[ sax ] );
+            this.setAttribute( sax, s );
+        }
+
+
+        if (! this.mask )
+            Debug.warn("lazyreplicator _adjustVisibleClones: cannot find 
clipping parent");
+
+        if (! this.mask[ "hasset" + sax ] ) 
+            return;
             
-            //Here's the idea. Coming in, we have an old list of clones that
-            //represents some window into the dataset. Let's say the nodes are
-            //labelled alphabetically so to start, we have
-            //this.clones=[ m , n , o , p ]
-            //When the situation changes, we end up with a situation where we
-            //want the window to be like
-            //this.clones=[ l , m , n , o ]
+        //Here's the idea. Coming in, we have an old list of clones that
+        //represents some window into the dataset. Let's say the nodes are
+        //labelled alphabetically so to start, we have
+        //this.clones=[ m , n , o , p ]
+        //When the situation changes, we end up with a situation where we
+        //want the window to be like
+        //this.clones=[ l , m , n , o ]
             
-            //This algorithm moves the old list of clones to a temporary
-            //identifier and then constructs a new array for the clones going
-            //through one by one It keeps an offset, which represents the
-            //difference in position of the old new data windows. In the case
-            //above, the offset would be -2.
+        //This algorithm moves the old list of clones to a temporary
+        //identifier and then constructs a new array for the clones going
+        //through one by one It keeps an offset, which represents the
+        //difference in position of the old new data windows. In the case
+        //above, the offset would be -2.
 
-            var newstart = Math.floor( -this[ this.axis ] / 
-                                         this.replicatedsize );
+        var newstart = Math.floor( -this[ this.axis ] / 
+                                   this.replicatedsize );
 
-            if ( 0 > newstart  ) newstart = 0;
+        if ( 0 > newstart  ) newstart = 0;
 
-            var oldptr = 0;
-            var oldlength = this.clones.length;
-            var offset = newstart - this.clonesoffset;
+        var oldptr = 0;
+        var oldlength = this.clones.length;
+        var offset = newstart - this.clonesoffset;
 
-            var remainder = ( newstart * this.replicatedsize ) + 
-                            this[ this.axis ];
+        var remainder = ( newstart * this.replicatedsize ) + 
+            this[ this.axis ];
 
-            var newlength= Math.ceil( 
-                 Math.min( (this.mask[ sax ] - remainder )/this.replicatedsize 
,
-                           this[ sax ] /this.replicatedsize ) );
+        var newlength= Math.ceil( 
+            Math.min( (this.mask[ sax ] - remainder )/this.replicatedsize ,
+                      this[ sax ] /this.replicatedsize ) );
 
-            //newstart is the new absolute lowerbound of the data window
-            //newlength is the new length of the data window
-            if ( newlength + newstart >  this.nodes.length ) {
-                newlength = this.nodes.length - newstart;
-            }
+        //newstart is the new absolute lowerbound of the data window
+        //newlength is the new length of the data window
+        if ( newlength + newstart >  this.nodes.length ) {
+            newlength = this.nodes.length - newstart;
+        }
 
-            //no change
-            if ( offset == 0 && newlength == oldlength ) return;
+        //no change
+        if ( offset == 0 && newlength == oldlength ) return;
 
-            //_root.LzInstantiator.enableDataReplicationQueuing( );
-            var oldclones = this.clones;
-            //TODO: instead of allocating a new array, use two arrays and
-            //ping-pong
-            this.clones = this.__emptyArray;
+        //_root.LzInstantiator.enableDataReplicationQueuing( );
+        var oldclones = this.clones;
+        //TODO: instead of allocating a new array, use two arrays and
+        //ping-pong
+        this.clones = this.__emptyArray;
 
-            for ( var i = 0 ; i < newlength; i++ ){
-                //before the new beginning
-                var cl = null;
-                if ( i + offset < 0 ){
-                    //this comes before the old data window
-                    if ( newlength + offset < oldlength  && oldlength > 0){
-                        //pull the clone off the end
-                        cl = oldclones[ --oldlength ];
-                    } else {
-                        cl = this.getClone();
-                    }
-                } else if ( i + offset >= oldlength ){
-                    //this comes after the old data window
-                    if ( oldptr < offset && oldptr < oldlength  ){
-                        //pull the clone off the end
-                        cl = oldclones[ oldptr++ ];
-                    } else {
-                        cl = this.getClone();
-                    }
+        for ( var i = 0 ; i < newlength; i++ ){
+            //before the new beginning
+            var cl = null;
+            if ( i + offset < 0 ){
+                //this comes before the old data window
+                if ( newlength + offset < oldlength  && oldlength > 0){
+                    //pull the clone off the end
+                    cl = oldclones[ --oldlength ];
+                } else {
+                    cl = this.getClone();
                 }
-
-                if ( cl ){
-                    this.clones[ i ] = cl;
-                    cl.setAttribute( this.axis , 
-                                    ( i + newstart ) * this.replicatedsize );
-                    this.unbind( cl );
-                    this.bind( cl, newstart + i );
+            } else if ( i + offset >= oldlength ){
+                //this comes after the old data window
+                if ( oldptr < offset && oldptr < oldlength  ){
+                    //pull the clone off the end
+                    cl = oldclones[ oldptr++ ];
                 } else {
-                    //otherwise, the oldclone and the newclone match
-                    this.clones[ i ] = oldclones[ i + offset ];
+                    cl = this.getClone();
                 }
             }
 
-            while ( oldptr < offset  && oldptr < oldlength ){
-                var v = oldclones[ oldptr++ ];
-                this.poolClone( v );
+            if ( cl ){
+                this.clones[ i ] = cl;
+                cl.setAttribute( this.axis , 
+                                 ( i + newstart ) * this.replicatedsize );
+                this.unbind( cl );
+                this.bind( cl, newstart + i );
+            } else {
+                //otherwise, the oldclone and the newclone match
+                this.clones[ i ] = oldclones[ i + offset ];
             }
+        }
 
-            while ( oldlength > newlength + offset && oldlength > 0 ){
-                var v = oldclones[ --oldlength ];
-                this.poolClone( v );
-            }
+        while ( oldptr < offset  && oldptr < oldlength ){
+            var v = oldclones[ oldptr++ ];
+            this.poolClone( v );
+        }
 
-            this.clonesoffset = newstart;
+        while ( oldlength > newlength + offset && oldlength > 0 ){
+            var v = oldclones[ --oldlength ];
+            this.poolClone( v );
+        }
 
-            while ( oldclones.length ) oldclones.pop();
-            this.__emptyArray = oldclones;
+        this.clonesoffset = newstart;
 
-            //_root.LzInstantiator.clearDataReplicationQueue( );
+        while ( oldclones.length ) oldclones.pop();
+        this.__emptyArray = oldclones;
 
-            ]]>
-        </method>
+        //_root.LzInstantiator.clearDataReplicationQueue( );
 
-        <!--- @keywords private -->
-        <method name="_setSize">
-            var c = this.getClone();
-            this.setAttribute( "replicatedsize", c[ _sizes[ axis ] ] );
-            this.poolClone( c );
-        </method>
+    }
 
-        <!--- @keywords private -->
-        <method name="getCloneIfVisible" args="n">
-            <![CDATA[
-            var off = Number( n ) - clonesoffset;
-            if ( off >= 0 && off < clones.length ) return clones[ off ];
-            else return null;
-            ]]>
-        </method>
+    //  @keywords private
+    function _setSize () {
+        var c = this.getClone();
+        this.setAttribute( "replicatedsize", c[ this._sizes[ this.axis ] ] );
+        this.poolClone( c );
+    }
 
-        <!--- @keywords private (override)-->
-        <method name="getCloneForOffset" args="n">
-            this.ensureInView( n );
-            return this.clones[ n-clonesoffset];
-        </method>
+    //  @keywords private
+    function getCloneIfVisible (n){
+        var off = Number( n ) - this.clonesoffset;
+        if ( off >= 0 && off < this.clones.length ) return this.clones[ off ];
+        else return null;
+    }
 
+    //  @keywords private (override)
+    function getCloneForOffset (n) {
+        this.ensureInView( n );
+        return this.clones[ n-this.clonesoffset];
+    }
+}
 
-    </class>
+    ]]>
+  </script>
+
+
 </library>


_______________________________________________
Laszlo-checkins mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins

Reply via email to