[Vexi-svn] SF.net SVN: vexi:[4633] branches/vexi4c/org.vexi-core.main/src/main
Revision: 4633 http://sourceforge.net/p/vexi/code/4633 Author: clrg Date: 2013-12-24 03:19:36 + (Tue, 24 Dec 2013) Log Message: --- Modified Paths: -- branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Resources.java branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/VMLBuilder.java branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/plat/JDesktop.java branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/plat/JPlatform.java branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/ui/Box.jpp Added Paths: --- branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Desktop.java Added: branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Desktop.java === --- branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Desktop.java (rev 0) +++ branches/vexi4c/org.vexi-core.main/src/main/java/org/vexi/core/Desktop.java 2013-12-24 03:19:36 UTC (rev 4633) @@ -0,0 +1,90 @@ +// Copyright (c) 2013 the Contributors, as shown in the revision logs. +// Licensed under the GNU General Public License version 2 ("the License"). +// You may not use this file except in compliance with the License. + +package org.vexi.core; + +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; +import org.vexi.plat.Platform; + +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 Platform.Desktop desktop; + public Desktop() throws JSExn { desktop = Platform.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 { +
[Vexi-svn] SF.net SVN: vexi:[4632] branches/vexi4c/org.vexi-core.main/src/main/jpp/org /vexi/ui/Box.jpp
Revision: 4632 http://sourceforge.net/p/vexi/code/4632 Author: clrg Date: 2013-12-24 02:20:56 + (Tue, 24 Dec 2013) Log Message: --- Modified Paths: -- branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/ui/Box.jpp Modified: branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/ui/Box.jpp === --- branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/ui/Box.jpp 2013-12-23 03:16:07 UTC (rev 4631) +++ branches/vexi4c/org.vexi-core.main/src/main/jpp/org/vexi/ui/Box.jpp 2013-12-24 02:20:56 UTC (rev 4632) @@ -216,7 +216,7 @@ // useful debugging //private final int depth() { return parent==null ? 0 : parent.depth()+1; } -private final String name() { try { return get(JSU.S("name")).toString(); } catch (JSExn e) { throw new Error(); } } +private final String name() { try { JS str = get(JSU.S("name")); return str==null?"null":str.toString(); } catch (JSExn e) { throw new Error(); } } private static final int min(int a, int b) { return (ab) ? a : b; } @@ -798,7 +798,8 @@ // our layout lies somewhere between the min and max size, // loop over the children attempting to set their width to // targetsize and adjust until it meets the parent width -float targetsize = (float)(width - box_spacing) / (float)treeSize(); +int packingspace = width - box_spacing; +float targetsize = (float)(packingspace) / (float)treeSize(); float totalsize = 0; for (int j=0; j<100; j++) { totalsize = 0; @@ -841,27 +842,27 @@ // test to see if targetsize produces a solution that rounds // to match the width, adjusting appropriately if it does not int totalsize_int = (int)(totalsize+0.5); -if (totalsize_int - box_spacing > width) { +if (totalsize_int > packingspace) { if (num_nolimit>0) { -targetsize -= (totalsize-(float)width)/(float)num_nolimit; +targetsize -= (totalsize-(float)packingspace)/(float)num_nolimit; } else { if (num_minsize+num_passive==num_active) { // no solution required - available min-sizes over-consume width targetsize = width; break; } -targetsize = (float)max_maxsize - (totalsize-(float)width)/(float)num_maxsize; +targetsize = (float)max_maxsize - (totalsize-(float)packingspace)/(float)num_maxsize; } -} else if (totalsize_int - box_spacing < width) { +} else if (totalsize_int < packingspace) { if (num_nolimit>0) { -targetsize += ((float)width-totalsize)/(float)num_nolimit; +targetsize += ((float)packingspace-totalsize)/(float)num_nolimit; } else { if (num_maxsize+num_passive==num_active) { // no solution required - available max-sizes do not consume width targetsize = width; break; } -targetsize = (float)min_minsize + ((float)width-totalsize)/(float)num_minsize; +targetsize = (float)min_minsize + ((float)packingspace-totalsize)/(float)num_minsize; } } else { break; @@ -944,7 +945,8 @@ // our layout lies somewhere between the min and max size, // loop over the children attempting to set their width to // targetsize and adjust until it meets the parent width -float targetsize = (float)(height - box_spacing) / (float)treeSize(); + int packingspace = height - box_spacing; +float targetsize = (float)packingspace / (float)treeSize(); float totalsize = 0; for (int j=0; j<100; j++) { totalsize = 0; @@ -987,27 +989,27 @@ // test to see if targetsize produces a solution