Revision: 2587
          http://vexi.svn.sourceforge.net/vexi/?rev=2587&view=rev
Author:   clrg
Date:     2007-11-19 19:07:25 -0800 (Mon, 19 Nov 2007)

Log Message:
-----------
Refactor datepicker/monthview to work out of contrib

Modified Paths:
--------------
    trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/datepicker.t
    trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/monthview.t

Added Paths:
-----------
    trunk/widgets/org.vexi.widgets/src/vexi/contrib/datepicker.t
    trunk/widgets/org.vexi.widgets/src/vexi/contrib/monthview.t

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/datepicker.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/datepicker.t    
2007-11-20 02:47:41 UTC (rev 2586)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/datepicker.t    
2007-11-20 03:07:25 UTC (rev 2587)
@@ -1,19 +1,21 @@
 <!-- Copyright 2007 - see COPYING for details [LGPL] -->
 
-<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.util" 
xmlns:lib="org.vexi.lib.role" xmlns:widg="vexi.widget">
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.contrib"
+    xmlns:role="org.vexi.lib.role"
+    xmlns:wi="vexi.widget">
     <meta:doc>
         <author>Charles Goodwin</author>
     </meta:doc>
     
-    <lib:popupable />
-    <widg:bevel blockPress="true" fill="white" form="down" margin="3" 
shrink="true">
-        <widg:pad padding="3 0">
+    <role:popupable />
+    <wi:bevel blockPress="true" fill="white" form="down" margin="3" 
shrink="true">
+        <wi:pad padding="3 0">
             <ui:box id="date" align="center">
                 minwidth = 12*vexi.ui.font.width(font,fontsize,"0");
             </ui:box>
-        </widg:pad>
-        <widg:button id="button" fill="#d4d0c8" margin="0" padding="1 5" 
text="Choose" />
-        <date.monthview id="monthview" minwidth="200" minheight="160" 
shrink="true" />
+        </wi:pad>
+        <wi:button id="button" fill="#d4d0c8" margin="0" padding="1 5" 
text="Choose" />
+        <monthview id="monthview" minwidth="200" minheight="160" shrink="true" 
/>
         
         thisbox.th_popbox = $monthview;
         thisbox.date      = null;
@@ -28,16 +30,13 @@
         var clearDate = function() { $date.text = ""; }
         
         /** shows the date in the display */
-        var displayDate = function()
-        {
-            if (!day or !month or !year)
-            {
+        var displayDate = function() {
+            if (!day or !month or !year) {
                 clearDate();
                 return;
             }
             
-            switch (format)
-            {
+            switch (format) {
                 case "DDMMYYYY":
                 $date.text = day + " / " + month + " / " + year;
                 break;
@@ -56,8 +55,7 @@
         $button.action ++= function(v) { popup = true; cascade = v; }
         
         /** popdown when monthview wants to popdown */
-        $monthview.popdown ++= function(v)
-        {
+        $monthview.popdown ++= function(v) {
             popdown = true;
             date = vexi.date(year, month-1, day);
             displayDate();
@@ -65,36 +63,29 @@
         }
         
         /** date read trap */
-        thisbox.date ++= function()
-        {
+        thisbox.date ++= function() {
             if ($date.text == "") return null;
             try { return vexi.date(year, month-1, day); }
             catch (e) { return null; }
         }
         
         /** date write trap */
-        thisbox.date ++= function(v)
-        {
+        thisbox.date ++= function(v) {
             if (popped) return;
             
-            if (v)
-            {
-                if (typeof(v) == "string")
-                {
-                       if (v.toLowerCase() == "today")
-                       {
+            if (v) {
+                if (typeof(v) == "string") {
+                       if (v.toLowerCase() == "today") {
                                date = vexi.date();
                                return;
                        }
                        
                        var s = v.split('/');
-                       if (s.length == 3)
-                       {
+                       if (s.length == 3) {
                                var s0 = vexi.string.parseFloat(s[0]);
                                var s1 = vexi.string.parseFloat(s[1]);
                                var s2 = vexi.string.parseFloat(s[2]);
-                               switch (format)
-                               {
+                               switch (format) {
                                        case "DDMMYYYY":
                                                day = s0; month = s1; year = 
s2; break;
                                        case "MMDDYYYY":
@@ -104,33 +95,23 @@
                                        default:
                                                throw "Unsupported date format: 
"+v;
                                }
-                       }
-                       else
-                       {
-                        try
-                        {
+                       } else {
+                        try {
                             var d = vexi.date(v);
                                day   = d.getDate();
                             month = d.getMonth()+1;
                             year  = d.getFullYear();
-                        }
-                        catch (e) { throw "Unsupported date format: "+v; }
+                        } catch (e) { throw "Unsupported date format: "+v; }
                     }
-                }
-                else // if (typeof(v) == "date")
-                {
-                   try
-                   {
+                } else { // if (typeof(v) == "date")
+                   try {
                         day   = v.getDate();
                         month = v.getMonth()+1;
                         year  = v.getFullYear();
-                    }
-                    catch (e) { throw "Unsupported date type: "+typeof(v); }
+                    } catch (e) { throw "Unsupported date type: "+typeof(v); }
                 }
-                
                 displayDate();
-            }
-            else clearDate();
+            } else clearDate();
         }
         
         /** read trap to apply to monthview day/month/year */
@@ -140,12 +121,10 @@
         thisbox.year  ++= readFunc;
         thisbox.month ++= readFunc;
         
-        thisbox.getDateString = function(f, s)
-        {
+        thisbox.getDateString = function(f, s) {
             if (!f) f = format;
             if (!s) f = separator;
-            switch (f)
-            {
+            switch (f) {
                 case "DDMMYYYY":
                 return (10>day?'0':'') + day + s + (10>month?'0':'') + month + 
s + year;
                 break;
@@ -160,8 +139,7 @@
             }
         }
         
-        var updateFunc = function(v)
-        {
+        var updateFunc = function(v) {
             cascade = v;
             displayDate();
         }
@@ -170,8 +148,7 @@
         thisbox.separator ++= updateFunc;
         
         /** write trap to apply to monthview day/month/year */
-        var writeFunc = function(v)
-        {
+        var writeFunc = function(v) {
             while (v.charAt(0) == '0') v = v.substring(1);
             $monthview[trapname] = (typeof(v) == "string") ? 
vexi.string.parseInt(v) : v;
             displayDate();
@@ -182,11 +159,13 @@
         thisbox.year  ++= writeFunc;
         thisbox.month ++= writeFunc;
         
+        var min = function(a, b) { return a>b ? b : a; }
+        
         /** set the surface position of the popbox */
-        $monthview.surface_x ++= function() { return 
.math..min(surface.distanceto(thisbox).x, surface.width - $monthview.width); }
-        $monthview.surface_y ++= function() { return 
.math..min(surface.distanceto(thisbox).y, surface.height - $monthview.height); }
+        $monthview.surface_x ++= function() { return 
min(surface.distanceto(thisbox).x, surface.width - $monthview.width); }
+        $monthview.surface_y ++= function() { return 
min(surface.distanceto(thisbox).y, surface.height - $monthview.height); }
         
         text ++= function(v) { return true; }
         
-    </widg:bevel>
+    </wi:bevel>
 </vexi>

Modified: trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/monthview.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/monthview.t     
2007-11-20 02:47:41 UTC (rev 2586)
+++ trunk/widgets/org.vexi.widgets/src/org/vexi/contrib/monthview.t     
2007-11-20 03:07:25 UTC (rev 2587)
@@ -1,28 +1,29 @@
 <!-- Copyright 2007 - see COPYING for details [LGPL] -->
 
-<vexi xmlns:ui="vexi://ui" xmlns:layout="vexi.layout" xmlns:meta="vexi://meta" 
xmlns:theme="vexi.theme.image" xmlns="vexi.widget">
-    <layout:border orient="vertical" border="black" depth="1" fill="white">
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.widget"
+    xmlns:lay="vexi.layout" xmlns:img="vexi.theme.image">
+    <lay:border orient="vertical" border="black" depth="1" fill="white">
         <ui:box fill="white" vshrink="true">
             <button id="decmonth" fill="#d4d0c8" hshrink="true" margin="0" 
padding="4 2">
-                <ui:box fill=":theme.arrowleft" />
+                <ui:box fill=":img.arrowleft" />
             </button>
             <ui:box id="month" align="center" />
             <button id="incmonth" fill="#d4d0c8" hshrink="true" margin="0" 
padding="4 2">
-                <ui:box fill=":theme.arrowright" />
+                <ui:box fill=":img.arrowright" />
             </button>
             <button id="decyear" fill="#d4d0c8" hshrink="true" margin="0" 
padding="4 2">
-                <ui:box fill=":theme.arrowleft" />
+                <ui:box fill=":img.arrowleft" />
             </button>
             <ui:box id="year" align="center" />
             <button id="incyear" fill="#d4d0c8" hshrink="true" margin="0" 
padding="4 2">
-                <ui:box fill=":theme.arrowright" />
+                <ui:box fill=":img.arrowright" />
             </button>
             <button id="close" fill="#d4d0c8" hshrink="true" margin="0" 
padding="4 2">
-                <ui:box fill=":theme.close" />
+                <ui:box fill=":img.close" />
             </button>
         </ui:box>
         <ui:box fill="black" height="1" vshrink="true" />
-        <layout:pad padding="5 0 5 10" vshrink="true">
+        <lay:pad padding="5 0 5 10" vshrink="true">
             <ui:box text="S" />
             <ui:box text="M" />
             <ui:box text="T" />
@@ -30,11 +31,11 @@
             <ui:box text="T" />
             <ui:box text="F" />
             <ui:box text="S" />
-        </layout:pad>
+        </lay:pad>
         <ui:box fill="black" height="1" vshrink="true" />
-        <layout:pad padding="5 0 5 10">
-            <layout:grid id="dategrid" cols="7" />
-        </layout:pad>
+        <lay:pad padding="5 0 5 10">
+            <lay:grid id="dategrid" cols="7" />
+        </lay:pad>
         
         $year.width = vexi.ui.font.width(font, fontsize, "000000");
         $month.width = vexi.ui.font.width(font, fontsize, "0000000000");
@@ -56,10 +57,8 @@
         var tmpyear  = null;
         
         /** get the name of a month */
-        thisbox.toName = function(m)
-        {
-            switch (m)
-            {
+        thisbox.toName = function(m) {
+            switch (m) {
                 case 1: return "January";
                 case 2: return "February";
                 case 3: return "March";
@@ -80,14 +79,12 @@
         var ready = false;
         
         /** test and return whether date v represents the current date */
-        var isCurrent = function(v)
-        {
+        var isCurrent = function(v) {
             return (curdate != null and curdate == (year+""+month+""+v));
         }
         
         /** set the dates shown according to the month/year properties */
-        var setDates = function()
-        {
+        var setDates = function() {
             // establish starting day
             weekday = vexi.date(year, month-1, 1).getDay();
             // establish month length
@@ -105,51 +102,42 @@
             $month.text = toName(month);
             $year.text = year;
             
-            if (olddate)
-            {
+            if (olddate) {
                 olddate.fill = "white";
                 olddate.textcolor = "black";
             }
             
             olddate = $dategrid[weekday+day-1];
-            if (olddate and isCurrent(day))
-            {
+            if (olddate and isCurrent(day)) {
                 olddate.fill = "darkblue";
                 olddate.textcolor = "white";
             }
         }
         
-        var activeFunc = function(v)
-        {
+        var activeFunc = function(v) {
             trapee.fill = trapee.text == "" ? "white" : "lightblue";
             trapee.textcolor = "black";
             cascade = v;
         }
         
-        var hoverFunc = function(v)
-        {
+        var hoverFunc = function(v) {
             trapee.fill = trapee.text == "" ? "white" : "lightgreen";
             trapee.textcolor = "black";
             cascade = v;
         }
         
-        var normalFunc = function(v)
-        {
-            if (trapee.text != "" and isCurrent(trapee.text))
-            {
+        var normalFunc = function(v) {
+            if (trapee.text != "" and isCurrent(trapee.text)) {
                 trapee.fill = "darkblue";
                 trapee.textcolor = "white";
-            }
-            else
-            {
+            } else {
                 trapee.fill = "white";
                 trapee.textcolor = "black";
             }
             cascade = v;
         }
         
-        var actionFunc = function(v)
-        {
+        var actionFunc = function(v) {
             if (trapee.text == "") return;
             day = trapee.text;
             month = month;
@@ -159,8 +147,7 @@
         }
         
         // create boxes to contain the dates
-        for (var i=0; 42>i; i++)
-        {
+        for (var i=0; 42>i; i++) {
             var tmp = vexi..org.vexi.lib.role.clickable(vexi.box);
             tmp.text = "";
             tmp.align = "left";
@@ -172,22 +159,18 @@
         }
         
         /** initialise the current date if it is *null* */
-        thisbox.curdate ++= function()
-        {
+        thisbox.curdate ++= function() {
             if (cascade == null) return year+""+month+""+day;
         }
         
         /** if 'day' is null, use current day */
-        thisbox.day ++= function()
-        {
+        thisbox.day ++= function() {
             return cascade != null ? cascade : vexi.date().getDate();
         }
         
         /** resets the yellow bg on the previously selected day */
-        thisbox.day ++= function(v)
-        {
-            if (typeof(v) == "string")
-            {
+        thisbox.day ++= function(v) {
+            if (typeof(v) == "string") {
                 if (v.charAt(0) == '0' and v.length>1)
                     v = v.substring(1);
                 v = vexi.string.parseInt(v);
@@ -207,24 +190,19 @@
         }
         
         /** if 'month' is null, use current month */
-        thisbox.month ++= function()
-        {
+        thisbox.month ++= function() {
             return (tmpmonth!=null) ? tmpmonth : (cascade ? cascade : 
vexi.date().getMonth()+1);
         }
         
         /** validate month v and sync the date view */
-        thisbox.month ++= function(v)
-        {
-            if (typeof(v) == "string")
-            {
+        thisbox.month ++= function(v) {
+            if (typeof(v) == "string") {
                 if (v.charAt(0) == '0' and v.length>1)
                     v = v.substring(1);
                 v = vexi.string.parseInt(v);
             }
-            if (typeof(v) == "number" and 13 > v and v > 0)
-            {
-                if (tmpmonth != null)
-                {
+            if (typeof(v) == "number" and 13 > v and v > 0) {
+                if (tmpmonth != null) {
                     cascade = v;
                     setDates();
                 }
@@ -232,16 +210,13 @@
         }
         
         /** if 'year' is null, use current year */
-        thisbox.year ++= function()
-        {
+        thisbox.year ++= function() {
             return (tmpyear!=null) ? tmpyear : (cascade ? cascade : 
vexi.date().getFullYear());
         }
         
         /** sync the date view */
-        thisbox.year ++= function(v)
-        {
-            if (tmpyear != null)
-            {
+        thisbox.year ++= function(v) {
+            if (tmpyear != null) {
                 cascade = v;
                 setDates();
             }
@@ -254,8 +229,7 @@
         }
         
         /** decrease month, and iff switching from jan to dec, decrease year */
-        $decmonth.action ++= function(v)
-        {
+        $decmonth.action ++= function(v) {
             if (!tmpmonth) tmpmonth = month;
             if (!tmpyear) tmpyear = year;
             if (month > 1) tmpmonth = month-1;
@@ -265,8 +239,7 @@
         }
         
         /** increase month, and iff switching from dec to jan, increase year */
-        $incmonth.action ++= function(v)
-        {
+        $incmonth.action ++= function(v) {
             if (!tmpmonth) tmpmonth = month;
             if (!tmpyear) tmpyear = year;
             if (12 > month) tmpmonth = month+1;
@@ -276,8 +249,7 @@
         }
         
         /** decrease year value */
-        $decyear.action ++= function(v)
-        {
+        $decyear.action ++= function(v) {
             if (!tmpmonth) tmpmonth = month;
             if (!tmpyear) tmpyear = year;
             tmpmonth = month;
@@ -287,8 +259,7 @@
         }
         
         /** increase year value */
-        $incyear.action ++= function(v)
-        {
+        $incyear.action ++= function(v) {
             if (!tmpmonth) tmpmonth = month;
             if (!tmpyear) tmpyear = year;
             tmpmonth = month;
@@ -298,20 +269,18 @@
         }
         
         /** drop tmp values on display */
-        thisbox.display ++= function(v)
-        {
+        thisbox.display ++= function(v) {
             if (!v) { tmpmonth = null; tmpyear = null; }
             else curdate = year+""+month+""+day;
             cascade = v;
         }
         
         /** initializer */
-        thisbox.surface ++= function(v)
-        {
+        thisbox.surface ++= function(v) {
             setDates();
             trapee.surface --= callee;
             cascade = v;
         }
         
-    </layout:border>
+    </lay:border>
 </vexi>

Added: trunk/widgets/org.vexi.widgets/src/vexi/contrib/datepicker.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/vexi/contrib/datepicker.t                
                (rev 0)
+++ trunk/widgets/org.vexi.widgets/src/vexi/contrib/datepicker.t        
2007-11-20 03:07:25 UTC (rev 2587)
@@ -0,0 +1,33 @@
+<!-- Copyright 2007 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.contrib"
+    xmlns:role="org.vexi.lib.role">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+        <name>Date Picker</name>
+        <desc>For conveniently picking a date</desc>
+        <usage>
+            * format - YY[YY] MM[M] DD[D] in any order e.g. "YYYYMMDD"
+            * separator - a character or string e.g. '-'
+                These affect how a date string will be parsed if put to
+                the 'date' property, and will determine the output of
+                the getDateString() function.
+            
+            * date
+                put a string or date object to the date property to set
+                the date represented by this date object.  If no date
+                is set then when a user opens the date picker, it will
+                default to today's date.  
+                
+            * getDateString()
+                returns the date string constructed using the specified
+                format and separator.
+                
+                e.g. for format:"YYYYMMDD", separator:"-"
+                getDateString() will return a date as "YYYY-MM-DD"
+        </usage>
+    </meta:doc>
+    
+    <datepicker />
+    <role:focusable />
+</vexi>

Added: trunk/widgets/org.vexi.widgets/src/vexi/contrib/monthview.t
===================================================================
--- trunk/widgets/org.vexi.widgets/src/vexi/contrib/monthview.t                 
        (rev 0)
+++ trunk/widgets/org.vexi.widgets/src/vexi/contrib/monthview.t 2007-11-20 
03:07:25 UTC (rev 2587)
@@ -0,0 +1,20 @@
+<!-- Copyright 2007 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="org.vexi.contrib"
+    xmlns:role="org.vexi.lib.role">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+        <name>Month View</name>
+        <desc>A reusable component of datepicker for viewing months</desc>
+        <usage>
+            The monthview widget does not have the versatility of the
+            datepicker, so it's interface is more basic.
+            * year
+            * month
+            * date
+        </usage>
+    </meta:doc>
+    
+    <monthview />
+    <role:focusable />
+</vexi>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to