Revision: 4569
          http://sourceforge.net/p/vexi/code/4569
Author:   mkpg2
Date:     2013-11-05 14:54:53 +0000 (Tue, 05 Nov 2013)
Log Message:
-----------
New Widget. vexi.widget.weekfield.
- probably should have a single date widget which takes a format, this is 
easier for now
JSDate fixes related to week handling.

Modified Paths:
--------------
    branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp
    branches/vexi3/org.vexi-library.value/src/main/java/org/vexi/value/Date.java
    
branches/vexi3/org.vexi-library.value/src/test/java/org/vexi/value/TestDate.java
    
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
    branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t
    branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t
    trunk/org.vexi-build.shared/meta/module.revisions

Added Paths:
-----------
    
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/weekfield.t
    branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/weekfield.t

Modified: branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp
===================================================================
--- branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp      
2013-10-25 06:46:43 UTC (rev 4568)
+++ branches/vexi3/org.vexi-library.js/src/main/jpp/org/ibex/js/JSDate.jpp      
2013-11-05 14:54:53 UTC (rev 4569)
@@ -98,7 +98,13 @@
                        return new JSDate(a.date.as(scheme));
                    case "tryParseString":
                        String s = JSU.getArg_string(args,0);
-                       Date d = Date.tryParseString(s);
+                       Date d;
+                       if(args.length>1){
+                               String scheme = JSU.getArg_string(args,1);
+                               d = Date.getScheme(scheme).tryParseString(s);
+                       }else{
+                               d = Date.tryParseString(s);                     
                
+                       }
                        if(d==null) return null;
                        return new JSDate(d);
                    case "compare":

Modified: 
branches/vexi3/org.vexi-library.value/src/main/java/org/vexi/value/Date.java
===================================================================
--- 
branches/vexi3/org.vexi-library.value/src/main/java/org/vexi/value/Date.java    
    2013-10-25 06:46:43 UTC (rev 4568)
+++ 
branches/vexi3/org.vexi-library.value/src/main/java/org/vexi/value/Date.java    
    2013-11-05 14:54:53 UTC (rev 4569)
@@ -194,6 +194,28 @@
                }
                return c;
            }
+           
+           public Date tryParseString(String s){
+               String s1 = s.replaceAll("[^\\d]+", "/");
+               String[] partStrs = s1.split("/");
+               if(partStrs.length<1) return null;
+               int[] parts = new int[partIds.length];
+               for(int i=0; i<partIds.length; i++){
+                       int partId = partIds[i];
+                       int partMin = getPartMin(partId);
+                       int partMax = getPartMax(partId);
+                       int partValue;
+                       if(i>=partStrs.length){
+                               partValue = partMin;
+                       }else{
+                               partValue = Integer.parseInt(partStrs[i]);
+                               partValue = Math.max(partMin, partValue);
+                               partValue = Math.min(partMax, partValue);       
                        
+                       }
+                       parts[i] = partValue;                   
+               }
+               return new Date(this, parts);
+           }               
        }
     
     
@@ -247,6 +269,8 @@
                throw new ValueException("Not a date '" + s + "'");
         return r;
     }
+    
+    
     static public Date tryParseString(String s){
         Matcher m = p.matcher(s);
         if (!m.matches()) {
@@ -346,6 +370,7 @@
        if(hasPart(partId)) return true;
        if(partId==PART_QUARTER) return hasPart(PART_MONTH);
        if(partId==PART_WEEKDAY) return hasPart(PART_DAY);
+       if(partId==PART_WEEK) return hasPart(PART_WEEK) || hasPart(PART_DAY);   
        
        return false;
     }
     
@@ -366,6 +391,31 @@
         int index = scheme.getPartIndex(partId);
         return parts[index]; 
     }
+    
+    static int getPartMin(int part){
+       switch(part){
+       case PART_QUARTER:
+        case PART_MONTH:
+       case PART_WEEK:
+               return 1;
+       case PART_HOUR:
+       case PART_MINUTE:
+               return 0;                       
+       }
+       return Integer.MIN_VALUE;
+    }
+    
+    static int getPartMax(int part){
+       switch(part){
+       case PART_QUARTER: return 4;
+        case PART_MONTH: return 12;
+       case PART_WEEK: return 53;
+       case PART_HOUR: return 11;
+       case PART_MINUTE: return 59;
+       }
+       return Integer.MAX_VALUE;
+    }
+    
     public int getPartDefault(int part){ 
         if (hasPart(part)) return expectPart(part);
         switch(part){
@@ -483,7 +533,7 @@
     
     
     public Date addPeriod(int part, int amount) throws ValueException{
-        if(!hasPart(part)) throw new ValueException("Cannot add 
"+partName(part)+" to "+ scheme.name); 
+        if(!hasPart(part)) throw new ValueException("Cannot add 
"+partName(part)+" to "+ scheme.name);
         Calendar c = asCalendar();
         switch(part){
         case PART_MINUTE:
@@ -510,7 +560,21 @@
         default:
                throw new Error();
         }
-        return scheme.newDate(c);
+        
+        
+        Date r = scheme.newDate(c);
+        // check smaller parts as it is possible for these to drift (e.g. 
taking years from a week date)
+        for(int i = scheme.getPartIndex(part)+1; i<parts.length; i++){
+               int diff = r.parts[i]-parts[i]; 
+               if(Math.abs(diff)==1){
+                       // try adding value back on ..., sometimes not possible 
due to leap year
+                       Date r1 = r.addPeriod(scheme.partIds[i], -diff);
+                       if(r1.parts[i-1]==r.parts[i-1]){
+                               r = r1;
+                       }                       
+               }
+        }
+        return r;
     }
     public int diff(int part, Date from) throws ValueException{
         int years = getPart(PART_YEAR)-from.getPart(PART_YEAR);

Modified: 
branches/vexi3/org.vexi-library.value/src/test/java/org/vexi/value/TestDate.java
===================================================================
--- 
branches/vexi3/org.vexi-library.value/src/test/java/org/vexi/value/TestDate.java
    2013-10-25 06:46:43 UTC (rev 4568)
+++ 
branches/vexi3/org.vexi-library.value/src/test/java/org/vexi/value/TestDate.java
    2013-11-05 14:54:53 UTC (rev 4569)
@@ -93,4 +93,13 @@
        assertEquals(2,Date.newYMD(2013,8,26).getPart(Date.PART_WEEKDAY)); // 
Mon
        assertEquals(3,Date.newYMD(2013,8,27).getPart(Date.PART_WEEKDAY)); // 
Tue
     }
+    
+    
+    public void bugsquashTakeYearFromWeekDate() throws ValueException{
+       // Taking a year was also taking a week as well (due to the vagaries of)
+       
assertEquals(Date.newYW(2011,52),Date.newYW(2012,53).addPeriod(Date.PART_YEAR,-1));
 // Sat
+       
assertEquals(Date.newYW(2010,24),Date.newYW(2011,24).addPeriod(Date.PART_YEAR,-1));
 // Sat
+    }
+    
+    
 }

Modified: 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
===================================================================
--- 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
    2013-10-25 06:46:43 UTC (rev 4568)
+++ 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/datefield.t
    2013-11-05 14:54:53 UTC (rev 4569)
@@ -316,8 +316,7 @@
     }
     
     static.textWrite = function(v) {
-        var d = new vexi.js.Date();
-        trapee.value = d.tryParseString(v);
+        trapee.value = vexi.js.Date.tryParseString(v);
     }
     
     static.viewsepWrite = function(v) {

Added: 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/weekfield.t
===================================================================
--- 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/weekfield.t
                            (rev 0)
+++ 
branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/weekfield.t
    2013-11-05 14:54:53 UTC (rev 4569)
@@ -0,0 +1,261 @@
+<!-- Copyright 2013 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui"
+      xmlns:conf="vexi.conf"
+      xmlns:lib="org.vexi.lib"
+      xmlns:lay="vexi.layout"
+      xmlns:util="vexi.util"
+      xmlns:classic="org.vexi.theme.classic"
+      xmlns="vexi.theme">
+    
+    <lib:role.popupable />
+    <lib:role.focusable />
+    <bevel blockPress="true" form="down" margin="3" shrink="true" 
type="yearfield">
+        <ui:box id="button" layout="layer" hshrink="true">
+            <classic:button id="select" cursor="hand" focusable="false" 
margin="0" shrink="false" />
+            <lay:pad padding="1 2 2 2"><ui:box shrink="true" 
fill=":.image.datepicker" /></lay:pad>
+        </ui:box>
+        <lay:pad orient="vertical" padding="3" shrink="true">
+            <ui:box id="dateview">
+                <util:digit id="year" period="year" fieldsize="4" />
+                <util:digit id="sep" fieldsize="2" text="wk" />
+                <util:digit id="week" period="week"/>                
+            </ui:box>
+            <ui:box id="editview" display="false">
+                <lib:text.default id="edit" textalign="left" />
+            </ui:box>
+        </lay:pad>
+        <ui:box id="moreless" orient="vertical" width="15">
+            <classic:button id="more" focusable="false" minheight="9" 
repeats="true" shrink="false">
+                <lay:pad padding="0 3"><ui:box fill=":.image.arrowup_small" 
shrink="true" /></lay:pad>
+            </classic:button>
+            <classic:button id="less" focusable="false" minheight="9" 
repeats="true" shrink="false">
+                <lay:pad padding="0 3"><ui:box fill=":.image.arrowdown_small" 
shrink="true" /></lay:pad>
+            </classic:button>
+        </ui:box>
+        <lay:border id="popbox" orient="vertical" border="black" depth="1" 
fill="white">
+            <!--datepicker id="datepicker" minwidth="200" minheight="160" 
shrink="true" /-->
+            <ui:box id="datepicker" />
+        </lay:border>
+        const Date = vexi.js.Date;
+        thisbox.datepicker = $datepicker;
+        thisbox.dateview  = $dateview;
+        thisbox.sep       = $sep;
+        thisbox.th_bevel  = thisbox;
+        thisbox.v_init    = .datefield..init;
+        thisbox.v_popbox  = $popbox;
+        thisbox.v_textbox = false;
+        
+        thisbox.text ++= .datefield..textRead;
+        thisbox.text ++= function(v){ 
+            trapee.value = Date.tryParseString(v, "YW");
+        };
+        
+        thisbox.value; ///> vexi.js.Date
+
+        thisbox.value ++= function(v) {
+            cascade = v;
+            // value has changed; reject text input
+            $editview.display = false;
+            //assert(v===null or v instanceof "date");
+            $week.text = v?.week;
+            $year.text = v?.year;
+        }
+        
+        ////////
+        // button actions
+        
+        thisbox.focused ++= .timefield..focusWrite;
+        thisbox.selected ++= .timefield..selectWrite;
+        
+        var selectPart = function(v) { selected = trapee; cascade = v; }
+        $week.Press1 ++= selectPart;
+        $year.Press1  ++= selectPart;
+        
+        var incrementTrap = function(v) {
+            if (selected==null || value==null) return;
+            var amount = trapee==$more?1:-1;
+            var period = selected.period;
+            trace(period, amount);
+            value = value.addPeriod(period, amount);
+            return;
+        };
+        
+        $more.action ++= incrementTrap;
+        $less.action ++= incrementTrap;
+        
+        ////////
+        // popup behaviour
+        
+        thisbox.popup ++= static.popupWrite;
+        thisbox.popdown ++= static.popdownWrite;
+        
+        var min = function(a, b) { return a>b ? b : a; }
+        
+        // set the surface position of the popbox
+        $popbox.surface_x ++= function() { return 
min(surface.frame.distanceto(thisbox).x, surface.frame.width - $popbox.width); }
+        $popbox.surface_y ++= function() { return 
min(surface.frame.distanceto(thisbox).y, surface.frame.height - 
$popbox.height); }
+        
+        /** assign date and popup */
+        $select.action ++= function(v) {
+            popup = true;
+            $datepicker.week = value?.week;
+            $datepicker.year = value?.year;
+            return; 
+        }
+        
+        ////////
+        // keyboard interaction
+        
+        var editToValue = function() {
+            try { text = $edit.v_edit.text; }
+            catch(e) { /* FEATURE: callback */ }
+            finally { $editview.display = false; }
+        }
+        
+        thisbox.enabled ++= function(v) {
+            cascade = v;
+            var max = vexi.ui.maxdim;
+            $button.maxheight = v ? max : 0;
+            $select.enabled = v;
+            $moreless.maxheight = v ? max : 0;
+            $more.enabled = v;
+            $less.enabled = v;
+        }
+        
+        thisbox.focused ++= function(v) {
+            cascade = v;
+            if (!focused and $editview.display) {
+                editToValue();
+            }
+        }
+        
+        /** makes sure we stay the same width */
+        $editview.display ++= function(v) {
+            cascade = v;
+            $edit.focused = v;
+            if (v) {
+                $edit.v_edit.text = "";
+            }
+            $dateview.maxheight = v ? 0 : vexi.ui.maxdim;
+        }
+        
+        $edit.v_edit.KeyPressed ++= function(v) {
+            if (v.length>1) {
+                if (v == "escape") {
+                    $editview.display = false;
+                } else if (v == "enter") {
+                    editToValue();
+                } else {
+                    cascade = v;
+                }
+            } else {
+                var x = v.charCodeAt(0);
+                if ((65>x or x>90) and (97>x or x>122)) {
+                    // accept all non-alpha character presses
+                    cascade = v;
+                }
+                var text = $edit.v_edit.text;
+                if(v=="w" || v=="k" and text.indexOf(v)==-1){
+                    cascade = v;
+                }
+            }
+            // cascades already decided
+            return;
+        }
+        
+        thisbox.KeyPressed ++= function(v) {
+            if (popped) {
+                // delegate to datepicker if it's open
+                $datepicker.KeyPressed = v;
+                return;
+            }
+            if ($editview.display) {
+                // delegate to editview if it's open
+                $edit.v_edit.KeyPressed = v;
+                return;
+            }
+            if (v.length>1) {
+                // timeview still on display
+                var si = dateview.indexof(selected);
+                switch(v) {
+                case "left":
+                    if (si>0) {
+                        selected = $dateview[si-2];
+                    }
+                    break;
+                case "right":
+                    if (2>si) {
+                        selected = $dateview[si+2];
+                    }
+                    break;
+                case "up":
+                    $more.action = true;
+                    break;
+                case "down":
+                    $less.action = true;
+                    break;
+                case "space":
+                    $select.action = true;
+                    break;
+                case "enter":
+                    if (value==null) {
+                        value = vexi.js.Date.today.as("YW");
+                    } else {
+                        value = value;
+                    }
+                    break;
+                case "back_space":
+                case "delete":
+                    value = null;
+                    break;
+                }
+            } else {
+                var x = v.charCodeAt(0);
+                if (x>47 and 58>x) {
+                    $editview.display = true;
+                    $edit.v_edit.KeyPressed = v;
+                }
+                return;
+            }
+        }
+        
+        // initialize
+        thisbox.selected = $year;
+        
+    </bevel>
+    <classic:lib.finalize />
+    
+    var initDatePicker = function(datefield, datepicker_box) {
+        // apply datepicker to box
+        .datepicker(datepicker_box);
+        datepicker_box.minwidth = 200;
+        datepicker_box.minheight = 160;
+        datepicker_box.shrink = true;
+        
+        /** popdown when weekview wants to popdown */
+        datepicker_box.action ++= function(v) {
+            datefield.day = null;
+            var date = new vexi.js.Date("YMD", datepicker_box.year, 
datepicker_box.month, datepicker_box.day);
+            trace(date);
+            trace(date.week);
+            datefield.value = new vexi.js.Date("YW", date.year, date.week);
+            cascade = v;
+        }
+        
+        /** popdown when datepicker requests it */
+        datepicker_box.popdown ++= function(v) { datefield.popdown = true; 
return; }
+    }
+
+    static.popupWrite = function(v) {
+        initDatePicker(trapee, trapee.datepicker);
+        trapee.popup --= callee;
+        cascade = v;
+    }
+    
+    static.popdownWrite = function(v) {
+        cascade = v;
+        trapee.value = trapee.value;
+    }
+    
+</vexi>

Modified: branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t      
2013-10-25 06:46:43 UTC (rev 4568)
+++ branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t      
2013-11-05 14:54:53 UTC (rev 4569)
@@ -3,9 +3,9 @@
 <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns:theme="vexi.theme"
     xmlns="org.vexi.lib.layout">
     <meta:doc>
-        <author>Charles Goodwin</author>
+        <author>Mike Goodwin</author>
         <name>Month Field</name>
-        <desc>For conveniently picking a month (and year)</desc>
+        <desc>For conveniently picking a week (and year)</desc>
         <usage>
             * value should always be a vexi.js.Date
               i.e. typeof(value) === "date"
@@ -13,6 +13,6 @@
     </meta:doc>
     
     <margin />
-    <theme:monthfield redirect="null" />
+    <theme:weekfield redirect="null" />
     <container />
 </vexi>

Added: branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/weekfield.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/weekfield.t       
                        (rev 0)
+++ branches/vexi3/org.vexi-vexi.widgets/src_main/vexi/widget/weekfield.t       
2013-11-05 14:54:53 UTC (rev 4569)
@@ -0,0 +1,18 @@
+<!-- Copyright 2011 - see COPYING for details [LGPL] -->
+
+<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns:theme="vexi.theme"
+    xmlns="org.vexi.lib.layout">
+    <meta:doc>
+        <author>Charles Goodwin</author>
+        <name>Month Field</name>
+        <desc>For conveniently picking a month (and year)</desc>
+        <usage>
+            * value should always be a vexi.js.Date
+              i.e. typeof(value) === "date"
+        </usage>
+    </meta:doc>
+    
+    <margin />
+    <theme:monthfield redirect="null" />
+    <container />
+</vexi>

Modified: branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t
===================================================================
--- branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t       
2013-10-25 06:46:43 UTC (rev 4568)
+++ branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/widgets/datetime.t       
2013-11-05 14:54:53 UTC (rev 4569)
@@ -8,12 +8,14 @@
                        <w:timefield fill="#ffff99" id="time"/>
                        <w:datefield fill="#ffff99" id="date"/>
                        <w:datetime fill="#ffff99" id="datetime"/>
-                       <w:monthfield fill="#ffff99" />
+                       <w:weekfield fill="#ffff99" id="week"/>
+                <w:monthfield fill="#ffff99" />
                        <w:yearfield fill="#ffff99" />
             </ui:box>
             <ui:box id="set2" orient="vertical">
                 <w:timefield />
                 <w:datefield />
+                <w:weekfield />
                 <w:datetime />
                 <w:monthfield />
                 <w:yearfield />
@@ -48,6 +50,7 @@
         $date.valuetype = "vexi.util.date";
         $time.value ++= printValueTrap;
         $date.value ++= printValueTrap;
+        $week.value ++= printValueTrap;
         $datetime.valuetype = "vexi.js.Instant";
         $datetime.value ++= printValueTrap;
         

Modified: trunk/org.vexi-build.shared/meta/module.revisions
===================================================================
--- trunk/org.vexi-build.shared/meta/module.revisions   2013-10-25 06:46:43 UTC 
(rev 4568)
+++ trunk/org.vexi-build.shared/meta/module.revisions   2013-11-05 14:54:53 UTC 
(rev 4569)
@@ -1 +1 @@
-{"https:\/\/ebuild-project.org\/svn\/ebuild\/plugins":"142"}
\ No newline at end of file
+{"https:\/\/ebuild-project.org\/svn\/ebuild\/plugins":"143"}
\ No newline at end of file

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


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to