clock.lzx

<!--=======================================================================-->
<!-- clocks.lzx                                                            -->
<!--                                                                       -->
<!-- library classes for the world clocks class                            -->
<!--                                                                       -->
<!-- Copyright 2002-2007 Laszlo Systems, Inc.  All Rights Reserved.        -->
<!-- Unauthorized use, duplication or distribution is strictly prohibited. -->
<!-- This software is the proprietary information of Laszlo Systems, Inc.  -->
<!-- Use is subject to license terms.                                      -->
<!--                                                                       -->
<!--=======================================================================-->
<library>

    <!-- IMAGE RESOURCES -->
    <!--
    <resource name="clockbkgnd"     src="images/lzclock_bkgrnd_final.swf" />
    <resource name="hourhand"       src="images/lzclock_hourhand2.swf" />
    <resource name="minutehand"     src="images/lzclock_minutehand2.swf" />
    <resource name="secondhand"     src="images/lzclock_secondhand2.swf" />
    <resource name="secondhandshdw" src="images/lzclock_secondhandshdw.swf" />
    <resource name="glasshilite"         src="images/lz_clock_hilite.swf" />
    <resource name="cap"            src="images/lzclock_centercap.swf" />
    -->
    
    
    <include href="resources.lzx"/>
     
    <font name="Kgr">
        <face src="kroeger-6-plain-regular.ttf"/>
    </font>
    
    <class name="viewframe" extends="view">
        <attribute name="aframe" value="0"/>
        <method name="setAttribute" args="a,v">
            if ( a == "aframe" ) {
                this.setAttribute('frame', Math.round( v ));
            }       
            super.setAttribute( a, v );
        </method>
    </class>

    <!-- CLASS: CLOCK -->
    <class name="clock" resource="clockbkgnd">

        <attribute name="height" value="${this.width}"/>
        <attribute name="act_height" value="${this.unstretchedheight}"/>
        <attribute name="act_width" value="${this.unstretchedwidth}"/>
        <attribute name="lasthour" value="0"/>
        <attribute name="lastminute" value="0"/>
        <attribute name="lastsecond" value="0"/>
        <attribute name="timezoneoffset" value="0"/>


        <!-- AM or PM -->
        <text font="Helmet,Arial,Helvetica,sans-serif" fontsize="9" name="dayandampm" y="${parent.height/2 + 14}" visible="false">SUN  AM
            <handler name="ontext">
                this.setX(parent.width/2 - Math.floor(this.getTextWidth()/2.0));
                this.setAttribute('visible', true);
            </handler>
        </text>

        <!-- HOUR HAND -->
        <viewframe name="hh" resource="hourhand"/>

        <!-- MINUTE HAND -->
        <viewframe name="mh" resource="minutehand"/>

        <!-- SECOND HAND -->              
        <viewframe name="sh" resource="secondhand"/>

        <!-- CAP -->
        <view resource="cap"/>

        <!-- GLASS HILITE -->
        <view resource="glasshilite"/>

        <method name="setCurrentTime">
        
            // Get the current date and time local to this machine
            var currentTimeObj = new Date();

            // Tranlsate the time to the cities local time
            currentTimeObj.setTime(currentTimeObj.getTime() + currentTimeObj.getTimezoneOffset()*60*1000); // UTC time
            currentTimeObj.setTime(currentTimeObj.getTime() + + this.timezoneoffset*60*60*1000); // local to city
            var hourNum = currentTimeObj.getHours();

            // change time and get day
            var dayNum   = currentTimeObj.getDay();
            var dayArray = ["Sun","Mon","Tue","Wed","Thur","Fri","Sat"];

            // Get PM or AM
            if (hourNum > 11) {
                hourNum-=12; // for clock representation
                var hourLabel="PM";
            } else {
                var hourLabel="AM";
            }
            this.dayandampm.setText(dayArray[dayNum] + " " + hourLabel);

            // Get Minutes and Seconds
            var minNum=currentTimeObj.getMinutes();
            var secNum=currentTimeObj.getSeconds();

            // now vsiually update the hands of the clock
            this.updateHands( hourNum, minNum, secNum );

        
        </method>
 
         <method name="updateHands" args="hour, min, sec">
//             Debug.debug("updateHands:", hour, min, sec );
            
            var dur = 700;
            if ( this.lasthour != hour ){
                 this.hh.animate('aframe', hour, 1000 );
                 this.lasthour = hour;
            }

            if ( this.lastminute != min ){
                 this.mh.animate('aframe', min, 1000 );
                 this.lastminute = min;
            }

            if ( this.lastsecond != sec ){
                 this.sh.setAttribute('aframe', sec);
                 this.lastsecond = sec;
            }

            /*
            if ( this.lastminute != minNum*6 ){
                  this.lastminute = minNum*6;
                  this.mh.animate('rotation',this.lastminute,dur);
                  this.mhs.animate('rotation',this.lastminute,dur);
            }
            this.shs.setAttribute('rotation',secNum*6,dur);
            this.sh.setAttribute('rotation',secNum*6,dur);
            */
        </method>
         

        <!-- This method is called everytime the global object 'secondtimer'(see below) -->
        <!-- sends an onsecond event -->
        <handler name="onsecond" reference="secondtimer">
            this.setCurrentTime();
        </handler>


        <method name="setTimeZone" args="tzo">
            this.timezoneoffset = tzo;
        </method>

    </class>
</library>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
* Use is subject to license terms.                                            *
* X_LZ_COPYRIGHT_END ****************************************************** -->

Cross References

Includes

Classes