X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2FSurface.java;h=0977ada9bdd30f84027bc0505140feb15259bda1;hb=565aae615b34b3fa4d61a72d93b651ff648eb3c3;hp=36c82ee0d8b5e7eee933532daa1c596582389679;hpb=a7bc8922080f56017b141a3835c722344fa4cffc;p=org.ibex.core.git diff --git a/src/org/xwt/Surface.java b/src/org/xwt/Surface.java index 36c82ee..0977ada 100644 --- a/src/org/xwt/Surface.java +++ b/src/org/xwt/Surface.java @@ -2,6 +2,7 @@ package org.xwt; import org.bouncycastle.util.encoders.Base64; +import org.xwt.js.*; import org.xwt.util.*; import java.io.*; import java.util.*; @@ -19,18 +20,10 @@ import java.util.*; */ public abstract class Surface extends PixelBuffer { - public int getWidth() { return root == null ? 0 : root.width; } - public int getHeight() { return root == null ? 0 : root.height; } - // Static Data //////////////////////////////////////////////////////////////////////////////// - private abstract static class Message extends Scheduler.Task { - public abstract void perform(); - public Object call(Object arg) { perform(); return null; } - } - /**< the most recently enqueued Move message; used to throttle the message rate */ - private static Message lastMoveMessage = null; + private static Scheduler.Task lastMoveMessage = null; /** all instances of Surface which need to be refreshed by the Scheduler */ public static Vec allSurfaces = new Vec(); @@ -81,24 +74,31 @@ public abstract class Surface extends PixelBuffer { public abstract void setTitleBarText(String s); ///< Sets the surface's title bar text, if applicable public abstract void setIcon(Picture i); ///< Sets the surface's title bar text, if applicable public abstract void _dispose(); ///< Destroy the surface + + + + // Sizing ///////////////////////////////////////////////////////////////////////////////// + + private int width = 0; + private int height = 0; + public int getWidth() { return width; } + public int getHeight() { return height; } + public void setLimits(int min_width, int min_height, int max_width, int max_height) { } - protected abstract void _setSize(int width, int height); ///< Sets the surface's width and height. + /// should be overriden by subclasses; programmatically sets the height + protected abstract void _setSize(int width, int height); - private int platform_window_width = 0; - private int platform_window_height = 0; + public final void setWidth(int width) { setSize(width, this.height); } + public final void setHeight(int height) { setSize(this.width, height); } protected final void setSize(int width, int height) { - if (root.width != width || root.height != height) { - /* - root.dirty(0, root.height - Main.scarImage.getHeight(), Main.scarImage.getWidth(), Main.scarImage.getHeight()); - */ - root.width = Math.max(Main.scarImage.getWidth(), width); - root.height = Math.max(Main.scarImage.getHeight(), height); - } - if (root.width > 0 && root.height > 0 && platform_window_width != root.width && platform_window_height != root.height) - _setSize(root.width, root.height); + if (this.width == width && this.height == height) return; + this.width = Math.max(Main.scarImage.getWidth(), width); + this.height = Math.max(Main.scarImage.getHeight(), height); + _setSize(width, height); } + // Helper methods for subclasses //////////////////////////////////////////////////////////// protected final void Press(final int button) { @@ -113,9 +113,9 @@ public abstract class Surface extends PixelBuffer { else if (button == 2) new SimpleMessage("Press2", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); else if (button == 3) { final Box who = Box.whoIs(root, mousex, mousey); - Scheduler.add(new Message() { public void perform() { + Scheduler.add(new Scheduler.Task() { public void perform() { Platform.clipboardReadEnabled = true; - root.putAndTriggerJSTraps("Press3", Boolean.TRUE); + root.putAndTriggerTraps("Press3", Boolean.TRUE); Platform.clipboardReadEnabled = false; }}); } @@ -153,7 +153,9 @@ public abstract class Surface extends PixelBuffer { else if (button == 3) new SimpleMessage("DoubleClick3", Boolean.TRUE, Box.whoIs(root, mousex, mousey)); } - /** sends a KeyPressed message; subclasses should not add the C- or A- prefixes, nor should they capitalize alphabet characters */ + /** Sends a KeyPressed message; subclasses should not add the C- or A- prefixes, + * nor should they capitalize alphabet characters + */ protected final void KeyPressed(String key) { if (key == null) return; @@ -171,7 +173,7 @@ public abstract class Surface extends PixelBuffer { } // This is implemented as a private static class instead of an anonymous class to work around a GCJ bug - private class KMessage extends Message { + private class KMessage extends Scheduler.Task { String key = null; public KMessage(String k) { key = k; } public void perform() { @@ -180,7 +182,7 @@ public abstract class Surface extends PixelBuffer { Box b = (Box)keywatchers.elementAt(i); for(Box cur = b; cur != null; cur = cur.parent) if (!cur.test(cur.VISIBLE)) continue outer; - b.putAndTriggerJSTraps("KeyPressed", key); + b.putAndTriggerTraps("KeyPressed", key); } Platform.clipboardReadEnabled = false; } @@ -188,18 +190,19 @@ public abstract class Surface extends PixelBuffer { Vec keywatchers = new Vec(); - /** sends a KeyReleased message; subclasses should not add the C- or A- prefixes, nor should they capitalize alphabet characters */ + /** sends a KeyReleased message; subclasses should not add the C- or A- prefixes, + * nor should they capitalize alphabet characters */ protected final void KeyReleased(final String key) { if (key == null) return; if (key.toLowerCase().equals("alt")) alt = false; else if (key.toLowerCase().equals("control")) control = false; else if (key.toLowerCase().equals("shift")) shift = false; - Scheduler.add(new Message() { public void perform() { + Scheduler.add(new Scheduler.Task() { public void perform() { outer: for(int i=0; i