private String text = null;
private Font font = DEFAULT_FONT;
- private Picture texture;
+ private Picture texture = null;
private short strokewidth = 1;
private int fillcolor = 0x00000000;
private int strokecolor = 0xFF000000;
/** invoked when a resource needed to render ourselves finishes loading */
- public void perform() {
+ public void perform() throws JSExn {
+ // as external events have occured, check the state of box
+ if (texture != null) {
+ if (texture.isLoaded) { minwidth = texture.width; minheight = texture.height; }
+ else { Res res = texture.res; texture = null; throw new JSExn("image not found: "+res); }
+ }
+
MARK_REPACK;
MARK_REFLOW;
MARK_RESIZE;
}
if (!(value instanceof Res)) return;
-
- // FIXME
texture = Picture.load((Res)value, this);
- if (texture.isLoaded) {
- minwidth = texture.width;
- minheight = texture.height;
- MARK_REFLOW;
- dirty();
- return;
- }
- texture = Picture.load((Res)value, new Scheduler.Task() { public void perform() {
- // FIXME pass this instead of a new Task?
- minwidth = texture.width;
- minheight = texture.height;
- Box b = Box.this; MARK_REFLOW_b;
- dirty();
- } });
}
private void mouseEvent(String name, Object value) {
final Picture p = ret;
if (!ret.isLoaded && callback != null)
new java.lang.Thread() { public void run() {
+ // get the InputStream for the image
+ InputStream in = null;
+ try { in = r.getInputStream(); }
+ catch (IOException e) {
+ in = null;
+ if (r instanceof Res.Ref) {
+ // add extensions to the resource, looking for the image
+ Res.Ref ref = (Res.Ref)r;
+ Res newr;
+
+ String[] exts = new String[] { ".png", ".jpg", ".jpeg", ".gif" };
+ for (int i=0; i < exts.length && in == null; i++) {
+ newr = ref.addExtension(exts[i]);
+ try { in = newr.getInputStream(); }
+ catch (IOException f) { in = null; }
+ }
+ }
+ }
+
+ if (in == null) return; // could not find image
+
try {
- PushbackInputStream pbis = new PushbackInputStream(r.getInputStream());
+ PushbackInputStream pbis = new PushbackInputStream(in);
int firstByte = pbis.read();
if (firstByte == -1) throw new JSExn("empty stream reading image");
pbis.unread(firstByte);
Log.log(this, e);
}
} }.start();
+
return ret;
}
}
break;
}
} catch (RuntimeException e) {
+ // FIXME: maybe JSExn should take a second argument, Exception
+ Log.log(this, "xwt."+name+"() threw: "+e);
throw new JSExn("invalid argument for xwt object method "+name+"()");
}