Revision: 3461
          http://vexi.svn.sourceforge.net/vexi/?rev=3461&view=rev
Author:   clrg
Date:     2009-03-27 13:54:07 +0000 (Fri, 27 Mar 2009)

Log Message:
-----------
Improvement to examples
- move examples under src, org/vexi/ structure superfluous
- some easy-to-implement feature enhancements
- .vexipath

Modified Paths:
--------------
    trunk/widgets/org.vexi.examples/.vexipath
    trunk/widgets/org.vexi.examples/src/compimg/main.t
    trunk/widgets/org.vexi.examples/src/evalscript/main.t
    trunk/widgets/org.vexi.examples/src/textconvert/main.t

Added Paths:
-----------
    trunk/widgets/org.vexi.examples/src/compimg/
    trunk/widgets/org.vexi.examples/src/evalscript/
    trunk/widgets/org.vexi.examples/src/textconvert/

Removed Paths:
-------------
    trunk/widgets/org.vexi.examples/src/org/

Modified: trunk/widgets/org.vexi.examples/.vexipath
===================================================================
--- trunk/widgets/org.vexi.examples/.vexipath   2009-03-27 03:20:35 UTC (rev 
3460)
+++ trunk/widgets/org.vexi.examples/.vexipath   2009-03-27 13:54:07 UTC (rev 
3461)
@@ -1,8 +1,7 @@
 {
   "source" : [
-    "F/org.vexi.examples/src"
+    "F/org.vexi.examples/src",
+    "LVexi Platform"
   ],
-  "projects" : [
-    "P/org.vexi.widgets"
-  ]
+  "projects" : [ ]
 }
\ No newline at end of file

Modified: trunk/widgets/org.vexi.examples/src/compimg/main.t
===================================================================
--- trunk/widgets/org.vexi.examples/src/org/vexi/compimg/main.t 2009-03-27 
02:19:23 UTC (rev 3458)
+++ trunk/widgets/org.vexi.examples/src/compimg/main.t  2009-03-27 13:54:07 UTC 
(rev 3461)
@@ -1,7 +1,7 @@
 <!-- Copyright 2008 - see COPYING for details [LGPL] -->
 
 <vexi xmlns:ui="vexi://ui" xmlns:meta="vexi://meta" xmlns="vexi.widget"
-    xmlns:lay="vexi.layout" xmlns:comp="org.vexi.compimg">
+    xmlns:lay="vexi.layout" xmlns:comp="compimg">
     <meta:doc>
         <author>Charles Goodwin</author>
         <name>Compare Images</name>
@@ -19,8 +19,8 @@
     <surface />
     <ui:box orient="vertical" frametitle="Compare Images">
        <ui:box vshrink="true">
-           <textfield enabled="false" id="res1" />
-           <textfield enabled="false" id="res2" />
+           <textfield enabled="false" id="left" />
+           <textfield enabled="false" id="right" />
        </ui:box>
        <bevel form="down">
            <scrollpane align="topleft" autohide="true">
@@ -42,12 +42,26 @@
            return res;
        }
        
-       { // constructor
-           var r1 = vexi.params["res1"];
-           $res1.text = r1;
+       // use an anonymous function so we can return if we
+       // encounter an error; avoids nesting if statements
+       
+       /** constructor */
+       function() {
+           var r1 = vexi.params["left_dir"];
+           if (r1==null) {
+               text = "Please specify a folder to fetch images to display on 
the left"
+                   +" using the parameter 'left_dir'";
+               return;
+           }
+           $left.text = r1;
            r1 = getResource(r1);
-           var r2 = vexi.params["res2"];
-           $res2.text = r2;
+           var r2 = vexi.params["right_dir"];
+           if (r2==null) {
+               text = "Please specify a folder to fetch images to display on 
the right"
+                   +" using the parameter 'right_dir'";
+               return;
+           }
+           $right.text = r2;
            r2 = getResource(r2);
            var images = {};
            // mark images
@@ -64,7 +78,7 @@
                    vexi.thread.yield();
                }
            }
-       } // end constructor
+       }.apply();
        
     </ui:box>
 </vexi>
\ No newline at end of file

Modified: trunk/widgets/org.vexi.examples/src/evalscript/main.t
===================================================================
--- trunk/widgets/org.vexi.examples/src/org/vexi/evalscript/main.t      
2009-03-27 02:19:23 UTC (rev 3458)
+++ trunk/widgets/org.vexi.examples/src/evalscript/main.t       2009-03-27 
13:54:07 UTC (rev 3461)
@@ -23,13 +23,27 @@
 
         vexi.ui.frame = thisbox;
 
+        /** the action fired when the user activates the evaluate button */
         $eval.action ++= function(v) {
             try {
                 var scr = $script.text;
+                // as the script text is evaluated, it returns a
+                // value that gets displayed in the output area
                 if ($wrap.selected) {
                     scr = "return "+scr+";\n";
                 }
-                var res = vexi.js.eval(scr);
+                // this gives the script access to the vexi object
+                // and if it looks a bit intimidating, try to think
+                // of it as shorthand for:
+                //     var scope = {};
+                //     scope["vexi"] = vexi;
+                var scope = {vexi:vexi};
+                // vexi.js.eval takes a string and an object that
+                // represents the scope, evaluates the string as
+                // a script with access to the given scope
+                var res = vexi.js.eval(scr, scope);
+                // result needs to be converted back in to a form
+                // that is useful for feedback i.e. stringify it
                 $output.text = vexi.js.stringify(res);
             } catch(e) {
                 vexi.log.info(e);

Modified: trunk/widgets/org.vexi.examples/src/textconvert/main.t
===================================================================
--- trunk/widgets/org.vexi.examples/src/org/vexi/textconvert/main.t     
2009-03-27 02:19:23 UTC (rev 3458)
+++ trunk/widgets/org.vexi.examples/src/textconvert/main.t      2009-03-27 
13:54:07 UTC (rev 3461)
@@ -7,9 +7,11 @@
         <about>
             Applies a conversion operation on user-inputted text.
             
-            Currently it only supports one type of conversion:
+            Currently it only supports some basic conversions:
                * Capitalized text to non-capitalized text
                  e.g. TEXT A. TEXT B. -> Text a. Text b.
+               * Case inversion e.g. A->a, a->A
+               * Lowercase e.g. A->a, a->a
         </about>
     </meta:doc>
     
@@ -19,7 +21,9 @@
         <ui:box shrink="true">
             <ui:box text=" Conversion " />
             <option id="type" width="100">
-                <item text="De-caps" />
+                <item id="sanc" text="Sane case" />
+                <item id="invc" text="Invert case" />
+                <item id="lowc" text="Lowercase" />
             </option>
             <button id="doit" text="Convert Text" />
         </ui:box>
@@ -28,28 +32,72 @@
         vexi.ui.frame = thisbox;
 
         $doit.action ++= function(v) {
-            var o = vexi.string;
-            var t = $orig.text;
-            var s = "";
-            var n = "";
+            /**
+             *  The way this works it that each item in the option
+             *  has a value and instead of using e.g. a string and
+             *  a switch based on the string, we bypass that logic
+             *  and assign a function as the value.  This allows us
+             *  to simply call the value of the option which points
+             *  to the value of the selected item.
+             */
+            $conv.text = $type.value($orig.text);
+            return;
+        }
+        
+        // shorthand
+        var stro = vexi.string;
+        
+        $sanc.value = function(t) {
             var cap = true;
+            var newtext = [];
+            var nlength = 0;
             for (var i=0; t.length>i; i++) {
                 var s = t.charAt(i);
                 var c = t.charCodeAt(i);
-                vexi.log.info(s+", "+c);
                 if (c >= 65 and 90 >= c) {
-                    n += cap ? s : o.fromCharCode(c+32);
+                    newtext[nlength++] = cap ? s : stro.fromCharCode(c+32);
                     cap = false;
                 } else if (c >= 97 and 122 >= c) {
-                    n += cap ? o.fromCharCode(c-32) : s;
+                    newtext[nlength++] = cap ? stro.fromCharCode(c-32) : s;
                     cap = false;
                 } else {
-                    n += s;
+                    newtext[nlength++] = s;
                     if (c == 46 or c == 10 or c == 13) cap = true;
                 }
             }
-            $conv.text = n;
+            return newtext.join("");
         }
+        
+        $invc.value = function(t) {
+            var newtext = [];
+            var nlength = 0;
+            for (var i=0; t.length>i; i++) {
+                var s = t.charAt(i);
+                var c = t.charCodeAt(i);
+                if (c >= 65 and 90 >= c)
+                    newtext[nlength++] = stro.fromCharCode(c+32);
+                else if (c >= 97 and 122 >= c)
+                    newtext[nlength++] = stro.fromCharCode(c-32);
+                else newtext[nlength++] = s;
+            }
+            return newtext.join("");
+        }
+        
+        $lowc.value = function(t) {
+            var newtext = [];
+            var nlength = 0;
+            for (var i=0; t.length>i; i++) {
+                var s = t.charAt(i);
+                var c = t.charCodeAt(i);
+                if (c >= 65 and 90 >= c)
+                    newtext[nlength++] = stro.fromCharCode(c+32);
+                else newtext[nlength++] = s;
+            }
+            return newtext.join("");
+        }
+        
+        // set the default converter
+        $sanc.selected = true;
 
     </ui:box>
 </vexi>


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

------------------------------------------------------------------------------
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to