From add9c1c1765814ff41c3ae54ec0e5496aa747c6e Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:41:48 +0000 Subject: [PATCH] 2003/11/18 10:47:25 darcs-hash:20040130074148-2ba56-ef8563e15a028671ff19e0cba16c4ccb2da43d9e.gz --- src/org/xwt/Box.java | 43 ++++++++++++--------------- src/org/xwt/HTTP.java | 72 ++++++++++++++++++++++----------------------- src/org/xwt/Picture.java | 2 +- src/org/xwt/Platform.java | 2 +- 4 files changed, 57 insertions(+), 62 deletions(-) diff --git a/src/org/xwt/Box.java b/src/org/xwt/Box.java index e8fb03d..b7512bb 100644 --- a/src/org/xwt/Box.java +++ b/src/org/xwt/Box.java @@ -39,7 +39,7 @@ import org.xwt.translators.*; * SizeChanges trigger an Surface.abort; if rendering were done in the same * pass, rendering work done prior to the Surface.abort would be wasted. */ -public final class Box extends JSScope implements JSTrap.JSTrappable { +public final class Box extends JSScope { // Macros ////////////////////////////////////////////////////////////////////// @@ -152,10 +152,6 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { } } - public void putAndTriggerJSTraps(Object key, Object value) { - JSContext.invokeTrap(this, key, value); - } - /** update MOUSEINSIDE, check for Enter/Leave/Move */ void Move(int oldmousex, int oldmousey, int mousex, int mousey) { Move(oldmousex, oldmousey, mousex, mousey, false); } void Move(int oldmousex, int oldmousey, int mousex, int mousey, boolean forceleave) { @@ -165,10 +161,10 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { if (!wasinside && !isinside) return; if (isinside && test(CURSOR)) Surface.fromBox(getRoot()).cursor = (String)boxToCursor.get(this); - if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerJSTraps("Enter", T); - else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerJSTraps("Leave", T); + if (!wasinside && isinside && getTrap("Enter") != null) putAndTriggerTraps("Enter", T); + else if (wasinside && !isinside && getTrap("Leave") != null) putAndTriggerTraps("Leave", T); else if (wasinside && isinside && (mousex != oldmousex || mousey != oldmousey) && getTrap("Move")!= null) - putAndTriggerJSTraps("Move", T); + putAndTriggerTraps("Move", T); for(Box b = getChild(numchildren - 1); b != null; b = b.prevSibling()) { b.Move(oldmousex - b.x, oldmousey - b.y, mousex - b.x, mousey - b.y, forceleave); if (b.inside(mousex - b.x, mousey - b.y)) forceleave = true; @@ -241,9 +237,9 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { boolean poschange = (this.x != x || this.y != y) && getTrap("PosChange") != null; this.width = width; this.height = height; this.x = x; this.y = y; dirty(); - try { if (sizechange) putAndTriggerJSTraps("SizeChange", T); /*Surface.abort = true;*/ } + try { if (sizechange) putAndTriggerTraps("SizeChange", T); /*Surface.abort = true;*/ } catch (Exception e) { Log.log(this, e); } - try { if (poschange) putAndTriggerJSTraps("PosChange", T); /*Surface.abort = true;*/ } + try { if (poschange) putAndTriggerTraps("PosChange", T); /*Surface.abort = true;*/ } catch (Exception e) { Log.log(this, e); } } } @@ -355,7 +351,7 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { public int localToGlobalX(int x) { return parent == null ? x : parent.globalToLocalX(x + this.x); } public int localToGlobalY(int y) { return parent == null ? y : parent.globalToLocalY(y + this.y); } - public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JS.Exn { + public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { if (nargs != 1 || !"indexof".equals(method)) return super.callMethod(method, a0, a1, a2, rest, nargs); Box b = (Box)a0; if (b.parent != this) @@ -370,15 +366,15 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { /** to be filled in by the Tree implementation */ public int numchildren = 0; - public Object get(Object name) { return get(name, false); } - public Object get(Object name, boolean ignoretraps) { + protected boolean isTrappable() { return true; } + public Object get(Object name) { if (name instanceof Number) return redirect == null ? null : redirect == this ? getChild(toInt(name)) : redirect.get(name); //#switch(name) case "indexof": return METHOD; case "text": return text; - case "path": throw new JS.Exn("cannot read from the path property"); + case "path": throw new JSExn("cannot read from the path property"); case "fill": return colorToString(fillcolor); case "strokecolor": return colorToString(strokecolor); case "textcolor": return colorToString(strokecolor); @@ -419,8 +415,7 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { return null; } - public void put(Object name, Object value) { put(name, value, false); } - public void put(Object name, Object value, boolean ignoretraps) { + public void put(Object name, Object value) { if (name instanceof Number) { put(toInt(name), value); return; } //#switch(name) @@ -556,8 +551,8 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { int mousex = globalToLocalX(surface.mousex); int mousey = globalToLocalY(surface.mousey); for(Box c = prevSibling(); c != null; c = c.prevSibling()) - if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerJSTraps(name, value); return; } - if (parent != null) parent.putAndTriggerJSTraps(name, value); + if (c.inside(mousex - c.x, mousey - c.y)) { c.putAndTriggerTraps(name, value); return; } + if (parent != null) parent.putAndTriggerTraps(name, value); } private static int stringToColor(String s) { @@ -963,7 +958,7 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { removeNode(); parent = null; if (oldparent != null) { Box b = oldparent; MARK_REFLOW_b; } - if (oldparent != null) oldparent.putAndTriggerJSTraps("childremoved", this); + if (oldparent != null) oldparent.putAndTriggerTraps("childremoved", this); } /** Returns ith child */ @@ -998,22 +993,22 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { } if (redirect == null) { - if (value == null) putAndTriggerJSTraps("childremoved", getChild(i)); + if (value == null) putAndTriggerTraps("childremoved", getChild(i)); else Log.logJS(this, "attempt to add/remove children to/from a node with a null redirect"); } else if (redirect != this) { - if (value != null) putAndTriggerJSTraps("childadded", value); + if (value != null) putAndTriggerTraps("childadded", value); redirect.put(i, value); if (value == null) { Box b = (Box)redirect.get(new Integer(i)); - if (b != null) putAndTriggerJSTraps("childremoved", b); + if (b != null) putAndTriggerTraps("childremoved", b); } } else if (value == null) { if (i < 0 || i > numchildren) return; Box b = getChild(i); b.remove(); - putAndTriggerJSTraps("childremoved", b); + putAndTriggerTraps("childremoved", b); } else { Box b = (Box)value; @@ -1049,7 +1044,7 @@ public final class Box extends JSScope implements JSTrap.JSTrappable { MARK_REFLOW; b.dirty(); - putAndTriggerJSTraps("childadded", b); + putAndTriggerTraps("childadded", b); } } diff --git a/src/org/xwt/HTTP.java b/src/org/xwt/HTTP.java index 4853a13..98f9397 100644 --- a/src/org/xwt/HTTP.java +++ b/src/org/xwt/HTTP.java @@ -283,7 +283,7 @@ public class HTTP { } /** executes the PAC script and dispatches a call to one of the other attempt methods based on the result */ - public Socket attemptPAC(org.xwt.js.JSCallable pacFunc) { + public Socket attemptPAC(org.xwt.js.JS pacFunc) { if (Log.verbose) Log.log(this, "evaluating PAC script"); String pac = null; try { @@ -704,7 +704,7 @@ public class HTTP { public String[] excluded = null; /** the PAC script */ - public JSCallable proxyAutoConfigJSFunction = null; + public JS proxyAutoConfigJSFunction = null; public static Proxy detectProxyViaManual() { Proxy ret = new Proxy(); @@ -757,7 +757,7 @@ public class HTTP { } public static JSScope proxyAutoConfigRootJSScope = new ProxyAutoConfigRootJSScope(); - public static JSCallable getProxyAutoConfigJSFunction(String url) { + public static JS getProxyAutoConfigJSFunction(String url) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new HTTP(url, true).GET())); String s = null; @@ -783,16 +783,16 @@ public class HTTP { if (Log.on) Log.log(Proxy.class, script); } - JSFunction scr = JS.parse("PAC script at " + url, 0, new StringReader(script)); - scr.cloneWithNewParentJSScope(proxyAutoConfigRootJSScope).call(null, null, null, null, 0); - return (JSCallable)proxyAutoConfigRootJSScope.get("FindProxyForURL"); + JSFunction scr = JSFunction.fromReader("PAC script at " + url, 0, new StringReader(script)); + scr.cloneWithNewParentScope(proxyAutoConfigRootJSScope).call(null, null, null, null, 0); + return (JS)proxyAutoConfigRootJSScope.get("FindProxyForURL"); } catch (Exception e) { if (Log.on) { Log.log(Platform.class, "WPAD detection failed due to:"); - if (e instanceof JS.Exn) { + if (e instanceof JSExn) { try { org.xwt.js.JSArray arr = new org.xwt.js.JSArray(); - arr.addElement(((JS.Exn)e).getObject()); + arr.addElement(((JSExn)e).getObject()); } catch (Exception e2) { Log.log(Platform.class, e); } @@ -842,7 +842,7 @@ public class HTTP { public static class ProxyAutoConfigRootJSScope extends JSScope.Global { - public ProxyAutoConfigRootJSScope() { super(null); } + public ProxyAutoConfigRootJSScope() { super(); } public Object get(Object name) { if (name.equals("isPlainHostName")) return isPlainHostName; @@ -869,28 +869,28 @@ public class HTTP { } }; - private static final JSCallable isPlainHostName = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS isPlainHostName = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { return (args.elementAt(0).toString().indexOf('.') == -1) ? Boolean.TRUE : Boolean.FALSE; } }; - private static final JSCallable dnsDomainIs = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS dnsDomainIs = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { return (args.elementAt(0).toString().endsWith(args.elementAt(1).toString())) ? Boolean.TRUE : Boolean.FALSE; } }; - private static final JSCallable localHostOrDomainIs = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS localHostOrDomainIs = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { return (args.elementAt(0).toString().equals(args.elementAt(1).toString()) || (args.elementAt(0).toString().indexOf('.') == -1 && args.elementAt(1).toString().startsWith(args.elementAt(0).toString()))) ? Boolean.TRUE : Boolean.FALSE; } }; - private static final JSCallable isResolvable = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS isResolvable = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { try { return (InetAddress.getByName(args.elementAt(0).toString()) != null) ? Boolean.TRUE : Boolean.FALSE; } catch (UnknownHostException e) { @@ -899,8 +899,8 @@ public class HTTP { } }; - private static final JSCallable isInNet = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS isInNet = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { if (args.length() != 3) return Boolean.FALSE; try { byte[] host = InetAddress.getByName(args.elementAt(0).toString()).getAddress(); @@ -912,13 +912,13 @@ public class HTTP { (host[3] & mask[3]) == net[3]) ? Boolean.TRUE : Boolean.FALSE; } catch (Exception e) { - throw new JS.Exn("exception in isInNet(): " + e); + throw new JSExn("exception in isInNet(): " + e); } } }; - private static final JSCallable dnsResolve = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS dnsResolve = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { try { return InetAddress.getByName(args.elementAt(0).toString()).getHostAddress(); } catch (UnknownHostException e) { @@ -927,8 +927,8 @@ public class HTTP { } }; - private static final JSCallable myIpAddress = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS myIpAddress = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { try { return InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { @@ -938,8 +938,8 @@ public class HTTP { } }; - private static final JSCallable dnsDomainLevels = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS dnsDomainLevels = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { String s = args.elementAt(0).toString(); int i = 0; while((i = s.indexOf('.', i)) != -1) i++; @@ -956,8 +956,8 @@ public class HTTP { return false; } - private static final JSCallable shExpMatch = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS shExpMatch = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { StringTokenizer st = new StringTokenizer(args.elementAt(1).toString(), "*", false); String[] arr = new String[st.countTokens()]; String s = args.elementAt(0).toString(); @@ -968,8 +968,8 @@ public class HTTP { public static String[] days = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; - private static final JSCallable weekdayRange = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { + private static final JS weekdayRange = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { TimeZone tz = (args.length() < 3 || args.elementAt(2) == null || !args.elementAt(2).equals("GMT")) ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault(); Calendar c = new GregorianCalendar(); c.setTimeZone(tz); @@ -994,15 +994,15 @@ public class HTTP { } }; - private static final JSCallable dateRange = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { - throw new JS.Exn("XWT does not support dateRange() in PAC scripts"); + private static final JS dateRange = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { + throw new JSExn("XWT does not support dateRange() in PAC scripts"); } }; - private static final JSCallable timeRange = new JSCallable() { - public Object call(org.xwt.js.JSArray args) throws JS.Exn { - throw new JS.Exn("XWT does not support timeRange() in PAC scripts"); + private static final JS timeRange = new JS() { + public Object call(org.xwt.js.JSArray args) throws JSExn { + throw new JSExn("XWT does not support timeRange() in PAC scripts"); } }; diff --git a/src/org/xwt/Picture.java b/src/org/xwt/Picture.java index 13440f9..426266c 100644 --- a/src/org/xwt/Picture.java +++ b/src/org/xwt/Picture.java @@ -57,7 +57,7 @@ public abstract class Picture { if ((b[0] & 0xff) == 'G') p = gif.fromInputStream(pbis, "some picture"); else if ((b[0] & 0xff) == 137) p = new PNG().fromInputStream(pbis, "some picture"); else if ((b[0] & 0xff) == 0xff) p = Platform.decodeJPEG(pbis, "some picture"); - else throw new JS.Exn("couldn't figure out image type from first byte"); + else throw new JSExn("couldn't figure out image type from first byte"); p.res = r; holder.picture = p; Scheduler.add(callback); diff --git a/src/org/xwt/Platform.java b/src/org/xwt/Platform.java index efc2731..aada999 100644 --- a/src/org/xwt/Platform.java +++ b/src/org/xwt/Platform.java @@ -213,7 +213,7 @@ public class Platform { /** displays a platform-specific "open file" dialog and returns the chosen filename, or null if the user hit cancel */ protected String _fileDialog(String suggestedFileName, boolean write) { return null; } - public static String fileDialog(String suggestedFileName, boolean write) throws org.xwt.js.JS.Exn { + public static String fileDialog(String suggestedFileName, boolean write) throws org.xwt.js.JSExn { return platform._fileDialog(suggestedFileName, write); } -- 1.7.10.4