Revision: 4377 http://vexi.svn.sourceforge.net/vexi/?rev=4377&view=rev Author: mkpg2 Date: 2012-04-05 03:17:05 +0000 (Thu, 05 Apr 2012) Log Message: ----------- Feature. Desktop integration, using java.awt.Desktop. - launch email - open/print documents - open browser (deprecates old method)
Modified Paths: -------------- trunk/_ebuild/seed/version trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp trunk/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/about.t Added Paths: ----------- trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/desktop.t trunk/org.vexi-vexi.widgets/src_main/vexi/util/uri.t Removed Paths: ------------- trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/browser.t Modified: trunk/_ebuild/seed/version =================================================================== --- trunk/_ebuild/seed/version 2012-03-30 00:44:28 UTC (rev 4376) +++ trunk/_ebuild/seed/version 2012-04-05 03:17:05 UTC (rev 4377) @@ -1,2 +1,2 @@ #nofetch=true -tag=0.8.2 +tag=0.8.2a Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java =================================================================== --- trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java 2012-03-30 00:44:28 UTC (rev 4376) +++ trunk/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java 2012-04-05 03:17:05 UTC (rev 4377) @@ -39,6 +39,17 @@ "EEE MMM d HH:mm:ss yyyy" }; + // SHOULD manage temporary files (i.e. make sure they get removed, probably when vexi loads/stops) + static public Fountain.File createTempFile(JS[] args) throws JSExn { + String suffix = args.length>0?JSU.toString(args[0]):""; + try { + File f = File.createTempFile("vexi", suffix); + return new Fountain.File(f,true); + } catch (IOException e) { + throw new JSExn(e); + } + } + static private long parseDate(String remoteModified) { if (remoteModified!=null && !remoteModified.equals("")) { // Try parsing the date using each of the date formats specified in RFC2616 Added: trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java =================================================================== --- trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java (rev 0) +++ trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java 2012-04-05 03:17:05 UTC (rev 4377) @@ -0,0 +1,86 @@ +package org.vexi.plat; + +import java.io.File; +import java.io.IOException; +import java.net.URI; + +import org.ibex.js.Fountain; +import org.ibex.js.JS; +import org.ibex.js.JSExn; +import org.ibex.js.JSU; + +public class Desktop extends JS.Immutable{ + static private Desktop singleton; + static public Desktop get() throws JSExn{ + if(singleton==null){ + try{ + Class.forName("java.awt.Desktop"); + }catch(ClassNotFoundException e){ + } + if(!java.awt.Desktop.isDesktopSupported()){ + throw new JSExn("Desktop not supported"); + } + singleton = new Desktop(); + } + return singleton; + } + final java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); + + public JS get(JS jskey) throws JSExn { + String key = JSU.toString(jskey); + if("browse".equals(key)) return METHOD; + if("edit".equals(key)) return METHOD; + if("email".equals(key)) return METHOD; + if("open".equals(key)) return METHOD; + if("print".equals(key)) return METHOD; + return super.get(jskey); + } + + + public JS callMethod(JS this_, JS jsmethod, JS[] args) throws JSExn { + String method = JSU.toString(jsmethod); + if(args.length==1){ + JS arg = args[0]; + try{ + if("browse".equals(method)) { + desktop.browse(expectURI(arg)); + return null; + } + if("email".equals(method)) { + desktop.mail(expectURI(arg)); + return null; + } + if("edit".equals(method)) { + desktop.edit(expectFile(arg)); + return null; + } + if("open".equals(method)) { + desktop.open(expectFile(arg)); + return null; + } + if("print".equals(method)) { + desktop.print(expectFile(arg)); + return null; + } + }catch(IOException e){ + throw new JSExn("Could not run method: "+method,e); + } + } + return super.get(jsmethod); + } + + static private URI expectURI(JS arg) throws JSExn{ + return URI.create(JSU.toString(arg)); + } + + + static private File expectFile(JS arg) throws JSExn{ + Fountain f = JSU.getFountain(arg); + if(f instanceof Fountain.File){ + return new File(((Fountain.File)f).path); + }else{ + throw new JSExn("Expected file fountain as argument: "+JSU.toString(arg)); + } + } + +} Property changes on: trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Desktop.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp =================================================================== --- trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2012-03-30 00:44:28 UTC (rev 4376) +++ trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2012-04-05 03:17:05 UTC (rev 4377) @@ -4,6 +4,9 @@ package org.vexi.core; +import java.awt.Desktop; +import java.io.File; + import org.ibex.crypto.MD5; import org.ibex.js.*; import org.ibex.js.JSU.*; @@ -337,7 +340,8 @@ case "ui.key.name": return getSub(name); case "ui.mouse": return getSub(name); case "ui.screen": return getSub(name); - + + case "desktop": return org.vexi.plat.Desktop.get(); /* The version of the current Vexi core * @type(String) * @initial_value(varies,code=false) */ @@ -383,6 +387,7 @@ case "file.remove": return METHOD; case "file.save": return METHOD; case "file.homedir": return VexiJS.fountainForURL("file:" + System.getProperty("user.home")); + case "file.temp": return METHOD; case "file.tempdir": return VexiJS.fountainForURL("file:" + System.getProperty("java.io.tempdir")); case "global.trace": return VexiJS.script().get(JSU.S("trace")); @@ -702,12 +707,13 @@ public JS callMethod(JS this_, JS method, JS[] args) throws JSExn { try { //#switch(JSU.toString(method)) - case "bless": return bless_jsthread(this_, args[0],(args.length<2)?null:args[1]); - case "cache": return Resources.cache(args); - case "date": return new ECMADate(args); - case "file.load": return accessFile(args,false); - case "file.save": return accessFile(args,true); - case "js.eval": return Methods.eval(args); + case "bless": return bless_jsthread(this_, args[0],(args.length<2)?null:args[1]); + case "cache": return Resources.cache(args); + case "date": return new ECMADate(args); + case "file.load": return accessFile(args,false); + case "file.save": return accessFile(args,true); + case "file.temp": return Resources.createTempFile(args); + case "js.eval": return Methods.eval(args); //#end switch (args.length) { Modified: trunk/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java =================================================================== --- trunk/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java 2012-03-30 00:44:28 UTC (rev 4376) +++ trunk/org.vexi-library.js/src/main/java/org/ibex/js/Fountain.java 2012-04-05 03:17:05 UTC (rev 4377) @@ -304,7 +304,7 @@ /** a file */ public static class File extends Fountain { - String path; + final public String path; private boolean writeable; public File(String path) throws JSExn { this(path,true); } public File(String path, boolean writeable) throws JSExn { Modified: trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/about.t =================================================================== --- trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/about.t 2012-03-30 00:44:28 UTC (rev 4376) +++ trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/about.t 2012-04-05 03:17:05 UTC (rev 4377) @@ -17,7 +17,7 @@ <ui:box height="20" shrink="true" /> <ui:box text="Copyright 2008 -- The Developers" shrink="true" /> <wi:link text="http://vexi.sourceforge.net" icon="home" shrink="true"> - action ++= function(v) { vexi.ui.browser(text); return; } + action ++= function(v) { vexi.desktop.browse(text); return; } </wi:link> <ui:box /> </ui:box> @@ -54,7 +54,7 @@ <ui:box vshrink="true"> <ui:box width="20" shrink="true" /> <wi:link text="http://tango.freedesktop.org" icon="home" shrink="true"> - action ++= function(v) { vexi.ui.browser(text); return; } + action ++= function(v) { vexi.desktop.browse(text); return; } </wi:link> <ui:box /> </ui:box> Deleted: trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/browser.t =================================================================== --- trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/browser.t 2012-03-30 00:44:28 UTC (rev 4376) +++ trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/browser.t 2012-04-05 03:17:05 UTC (rev 4377) @@ -1,19 +0,0 @@ -<!-- Copyright 2007 - see COPYING for details [LGPL] --> - -<vexi xmlns:ui="vexi://ui" xmlns="vexi.widget"> - - static.name = "Browser"; - static.category = "Core Features"; - - <ui:box orient="vertical"> - <ui:box text="Enter a URL:" align="left" shrink="true"/> - <textfield id="url" vshrink="true" /> - <ui:box height="40"/> - <button id="launch" text="Launch browser" shrink="true"/> - - $launch.action ++= function(v) { - vexi.ui.browser($url.text); - } - - </ui:box> -</vexi> Copied: trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/desktop.t (from rev 4372, trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/browser.t) =================================================================== --- trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/desktop.t (rev 0) +++ trunk/org.vexi-vexi.demo/src_main/org/vexi/demo/feature/desktop.t 2012-04-05 03:17:05 UTC (rev 4377) @@ -0,0 +1,100 @@ +<!-- Copyright 2007 - see COPYING for details [LGPL] --> + +<vexi xmlns:ui="vexi://ui" xmlns="vexi.widget" xmlns:lay="vexi.layout"> + + static.name = "Desktop Integration"; + static.category = "Core Features"; + + <lay:pad orient="vertical" padding="10"> + <ui:Box/> + <ui:box vshrink="true" orient="horizontal"> + <ui:box text="Enter a URL:" align="left" shrink="true"/> + <textfield id="url" vshrink="true" /> + <button id="browser_launch" text="Launch browser" shrink="true"/> + + $browser_launch.action ++= function(v) { + vexi.desktop.browse($url.text); + }; + </ui:box> + <ui:Box/> + <separator vshrink="true"/> + <ui:Box/> + <ui:Box orient="horizontal" vshrink="true"> + <lay:grid id="grid" cols="2"> + <ui:Box text="To:" shrink="true"/> + <textfield id="email_to"/> + <ui:Box text="Cc:" shrink="true"/> + <textfield id="email_cc"/> + <ui:Box text="Subject:" shrink="true"/> + <textfield id="email_subject"/> + </lay:grid> + <ui:Box orient="vertical"> + <ui:Box text="Body:" shrink="true"/> + <textarea id="email_body"/> + </ui:Box> + <button text="Launch Email Client" id="email_launch"/> + const mailto = vexi..vexi.util.uri..mailto; + + $email_launch.action ++= function(v) { + vexi.desktop.email(mailto({ + "to": $email_to.text, + "cc": $email_cc.text, + "subject": $email_subject.text, + "body": $email_body.text + })); + }; + + </ui:Box> + <ui:Box/> + <separator vshrink="true"/> + <ui:Box/> + <ui:Box orient="horizontal" vshrink="true"> + <button text="Open File" id="open_file"/> + <textfield id="file_path" enabled="false"/> + <ui:Box orient="vertical" hshrink="true"> + <button text="Edit" id="file_edit" hshrink="false" display="false"/> /* DISABLE - usually editer not associated, and you want to open */ + <button text="Open" id="file_open" hshrink="false"/> + <button text="Print" id="file_print" hshrink="false"/> + </ui:Box> + var file; + $open_file.action ++= function(v){ + file = vexi.file.load(); + $file_open.enabled = + $file_edit.enabled = + $file_print.enabled = file!=null; + + // cleanup string (SHOULD most probably find better way to get paths ... etc.) + var str = ""; + if(file!=null){ + str += file; + if("file://"==str.substring(0, 7)){ + str = str.substring(7); + } + var dollar = str.lastIndexOf("$"); + if(dollar!=-1){ + str = str.substring(0,dollar); + } + } + $file_path.text = str; + return; + }; + + $file_open.action ++= function(v){ + vexi.desktop.open(file); + return; + }; + $file_edit.action ++= function(v){ + vexi.desktop.edit(file); + return; + }; + $file_print.action ++= function(v){ + vexi.desktop.print(file); + return; + }; + + </ui:Box> + <ui:Box/> + + + </lay:pad> +</vexi> Added: trunk/org.vexi-vexi.widgets/src_main/vexi/util/uri.t =================================================================== --- trunk/org.vexi-vexi.widgets/src_main/vexi/util/uri.t (rev 0) +++ trunk/org.vexi-vexi.widgets/src_main/vexi/util/uri.t 2012-04-05 03:17:05 UTC (rev 4377) @@ -0,0 +1,28 @@ +<!-- Copyright 2011 - see COPYING for details [LGPL] --> + +<vexi xmlns:js="vexi://js"> + + <js:Object /> + + const encodeURI = vexi.string.encodeURIComponent; + + static.encodeParams = function(params){ + var r = []; + var encodeParam = function(k){ + var s = params[k]; + if(s!=null) + r.push(k+"="+encodeURI(s)); + } + + for(var k in params){ + encodeParam(k); + } + return r.join("&"); + }; + + /* params */ + static.mailto = function(params){ + return "mailto:?"+encodeParams(params); + } + +</vexi> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Better than sec? Nothing is better than sec when it comes to monitoring Big Data applications. Try Boundary one-second resolution app monitoring today. Free. http://p.sf.net/sfu/Boundary-dev2dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn