Revision: 4165 http://vexi.svn.sourceforge.net/vexi/?rev=4165&view=rev Author: clrg Date: 2011-06-29 21:01:58 +0000 (Wed, 29 Jun 2011)
Log Message: ----------- vexi.widget.monthfield - basic month selection widget wrapped around a vexi.js.Date() Modified Paths: -------------- trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield.t Added Paths: ----------- trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/monthfield.t trunk/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t Added: trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/monthfield.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/monthfield.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_main/org/vexi/theme/classic/monthfield.t 2011-06-29 21:01:58 UTC (rev 4165) @@ -0,0 +1,295 @@ +<!-- Copyright 2009 - 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 /> + <util:date /> + <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="month" /> + <util:digit id="sep" fieldsize="1" text="/" /> + <util:digit id="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.v_date; ///> vexi.js.Date + + //////// + // internal behaviour + + thisbox.month ++= static.partWrite; + thisbox.year ++= static.partWrite; + + thisbox.v_date ++= function(v) { + cascade = v; + assert(v!=null); + $month.text = v.month; + $year.text = v.year; + } + + thisbox.value ++= static.valueRead; + thisbox.value ++= static.valueWrite; + + //////// + // button actions + + thisbox.focused ++= .timefield..focusWrite; + thisbox.selected ++= .timefield..selectWrite; + + var selectPart = function(v) { selected = trapee; cascade = v; } + $month.Press1 ++= selectPart; + $year.Press1 ++= selectPart; + + var setToday = function() { + date = new vexi.js.Date(); + value = v_date; + } + + $more.action ++= function(v) { + if (year == null) { + setToday(); + } else if (selected == $month) { + month = month==null ? 1 : month+1; + } else if (selected == $year) { + year = year+1; + } + return; + } + + $less.action ++= function(v) { + if (year == null) { + setToday(); + } else if (selected == $month) { + month = month==null ? 12 : month-1; + } else if (selected == $year) { + year = year-1; + } + return; + } + + //////// + // 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.month = month; + $datepicker.year = 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; + $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) { + // 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) { + setToday(); + } else { + value = v_date; + } + 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 = $month; + + </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.month = datepicker_box.month; + datefield.year = datepicker_box.year; + cascade = v; + } + + /** popdown when datepicker requests it */ + datepicker_box.popdown ++= function(v) { datefield.popdown = true; return; } + } + + static.partWrite = function(v) { + cascade = v; + trapee.value = new vexi.js.Date(trapee.year, trapee.month); + } + + static.popupWrite = function(v) { + initDatePicker(trapee, trapee.datepicker); + trapee.popup --= callee; + cascade = v; + } + + static.popdownWrite = function(v) { + cascade = v; + trapee.value = trapee.v_date; + } + + static.textRead = function() { + return trapee.v_date+""; + } + + static.textWrite = function(v) { + var d = new vexi.js.Date(); + trapee.value = d.tryParseString(v); + } + + static.valueRead = function() { + return trapee.v_date; + } + + static.valueWrite = function(v) { + assert(typeof(v)=="date"); + trapee.v_date = v; + return; + } + +</vexi> Added: trunk/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_main/vexi/widget/monthfield.t 2011-06-29 21:01:58 UTC (rev 4165) @@ -0,0 +1,18 @@ +<!-- Copyright 2009 - 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: trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield.t 2011-06-29 19:03:39 UTC (rev 4164) +++ trunk/org.vexi-vexi.widgets/src_poke/poke/widgets/datefield.t 2011-06-29 21:01:58 UTC (rev 4165) @@ -1,13 +1,13 @@ <vexi xmlns:ui="vexi://ui" xmlns:w="vexi.widget" xmlns:poke="poke"> <w:surface /> <ui:box orient="vertical"> - <ui:box> + <!--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--> <ui:box> - <w:datefield id="date3" inputformat="MMYYYY" valueformat="MM-YYYY" /> - <w:datefield id="date4" inputformat="YYYYMM" valueformat="01-MM-YYYY" /> + <w:monthfield id="date3" inputformat="MMYYYY" valueformat="MM-YYYY" /> + <w:monthfield id="date4" inputformat="YYYYMM" valueformat="01-MM-YYYY" /> </ui:box> vexi.ui.frame = thisbox; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ All of the data generated in your IT infrastructure is seriously valuable. Why? It contains a definitive record of 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-d2d-c2 _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn