Revision: 4298 http://vexi.svn.sourceforge.net/vexi/?rev=4298&view=rev Author: mkpg2 Date: 2011-11-29 10:27:58 +0000 (Tue, 29 Nov 2011) Log Message: ----------- Feature. Year field. (SHOULD probably have a single datefield widget which handles different date schemes).
Added Paths: ----------- trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/yearfield.t trunk/org.vexi-vexi.widgets/src_main/vexi/widget/yearfield.t trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_year.t Added: trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/yearfield.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/yearfield.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/yearfield.t 2011-11-29 10:27:58 UTC (rev 4298) @@ -0,0 +1,252 @@ +<!-- Copyright 2011 - see COPYING for details [LGPL] --> + +<vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.theme" + xmlns:conf="vexi.conf" + xmlns:lib="org.vexi.lib" + xmlns:lay="vexi.layout" + xmlns:util="vexi.util" + xmlns:classic="org.vexi.theme.classic" > + + <meta:doc> + <author>Charles Goodwin</author> + </meta:doc> + + <lib:role.popupable /> + <lib:role.focusable /> + <bevel blockPress="true" form="down" margin="3" shrink="true"> + <ui:box layout="layer" hshrink="true"> + <classic:button id="select" cursor="hand" fill="#d4d0c8" 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 id="bg" fill="white" orient="vertical" padding="3" shrink="true"> + <ui:box id="dateview"> + <util:digit id="year" period="year" fieldsize="4" /> + </ui:box> + <ui:box id="editview" display="false"> + <lib:text.default id="edit" textalign="left" /> + </ui:box> + </lay:pad> + <ui:box 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> + + thisbox.datepicker = $datepicker; + thisbox.dateview = $dateview; + thisbox.sep = $sep; + thisbox.v_popbox = $popbox; + thisbox.v_textbox = false; + + thisbox.value; ///> vexi.js.Date + + + thisbox.value ++= function(v) { + cascade = v; + $year.text = v?.year; + } + + //////// + // button actionsmhhht + + thisbox.focused ++= .timefield..focusWrite; + thisbox.selected ++= .timefield..selectWrite; + + var selectPart = function(v) { selected = trapee; cascade = v; } + $year.Press1 ++= selectPart; + + var incrementTrap = function(v){ + if(selected==null || value==null) return; + var amount = trapee==$more?1:-1; + var period = selected.period; + 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.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; + $select.enabled = v; + $more.enabled = v; + $less.enabled = v; + $more.maxwidth = v ? vexi.ui.maxdim : 0; + $less.maxwidth = v ? vexi.ui.maxdim : 0; + $bg.fill = v ? "white" : "#d4d0c8"; + } + + 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; + } + } + // 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) { + if(selected==null) return; + // 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("YQ"); + } 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> + + 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 monthview wants to popdown */ + datepicker_box.action ++= function(v) { + datefield.day = null; + datefield.value = new vexi.js.Date("Y", datepicker_box.year); + 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; + } + + static.textRead = function() { + return trapee.value+""; + } + + static.textWrite = function(v) { + var d = new vexi.js.Date(); + trapee.value = d.tryParseString(v); + } + +</vexi> Added: trunk/org.vexi-vexi.widgets/src_main/vexi/widget/yearfield.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/vexi/widget/yearfield.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_main/vexi/widget/yearfield.t 2011-11-29 10:27:58 UTC (rev 4298) @@ -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 year</desc> + <usage> + * value should always be a vexi.js.Date + i.e. typeof(value) === "date" + </usage> + </meta:doc> + + <margin /> + <theme:yearfield redirect="null" /> + <container /> +</vexi> Added: trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_year.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_year.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield_year.t 2011-11-29 10:27:58 UTC (rev 4298) @@ -0,0 +1,44 @@ +<vexi xmlns:ui="vexi://ui" xmlns:w="vexi.widget" xmlns:poke="poke"> + <w:surface /> + <ui:box orient="vertical"> + <!--ui:box> + <w:datefield id="date1" inputformat="DDMMYYYY" valueformat="DD-MM-YYYY" /> + <w:datefield id="date2" inputformat="DDMMYYYY" valueformat="YY-MM-DD" /> + </ui:box--> + <ui:box> + <w:yearfield id="date3"/> + <w:button id="put" text="- Put ->" /> + <w:yearfield id="date4"/> + </ui:box> + <ui:box> + <ui:box> + <w:button id="clear3" text="Clear" /> + </ui:box> + <ui:box /> + <ui:box> + <w:button id="clear4" text="Clear" /> + </ui:box> + </ui:box> + <ui:box> + <ui:box id="date3_label" /> + <ui:box /> + <ui:box id="date4_label" /> + </ui:box> + + $clear3.action ++= function(v) { $date3.value = null; return; } + $clear4.action ++= function(v) { $date4.value = null; return; } + + $put.action ++= function(v) { $date4.value = $date3.value; return; } + + $date3.value ++= function(v) { + cascade = v; $date3_label.text = v; + }; + $date4.value ++= function(v) { + cascade = v; + $date4_label.text = v; + }; + + vexi.ui.frame = thisbox; + + </ui:box> +</vexi> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn