protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
- protected int _stringWidth(String font, String text) { return getFont(font).metrics.stringWidth(text); }
- protected int _getMaxAscent(String font) { return getFont(font).metrics.getMaxAscent(); }
- protected int _getMaxDescent(String font) { return getFont(font).metrics.getMaxDescent(); }
protected boolean _supressDirtyOnResize() { return false; }
protected void postInit() {
g.drawImage(((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
}
- public void drawString(String font, String text, int x, int y, int argb) {
- // FEATURE: use an LRU cache for Color objects
- g.setColor(new Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
- g.setFont(getFont(font));
- g.drawString(text, x, y + 2);
- }
-
public void fillRect(int x, int y, int x2, int y2, int argb) {
// FEATURE: use an LRU cache for Color objects
g.setColor(new Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
}
- protected static class AWTSurface extends Surface
+ protected static class AWTSurface extends Surface.DoubleBufferedSurface
implements MouseListener, MouseMotionListener, KeyListener, ComponentListener, WindowListener {
public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
public void toBack() { if (window != null) window.toBack(); }
public void toFront() { if (window != null) window.toFront(); }
- public void setLocation(int x, int y) { window.setLocation(x, y); }
+ public void setLocation() { window.setLocation(root.x, root.y); }
public void setTitleBarText(String s) { if (frame != null) frame.setTitle(s); }
public void setIcon(Picture i) { if (frame != null) frame.setIconImage(((AWTPicture)i).i); }
public void setSize(int width, int height) { window.setSize(width + (insets.left + insets.right), height + (insets.top + insets.bottom)); }
}
}
- protected ImageDecoder _decodeJPEG(InputStream is, String name) {
+ protected Picture _decodeJPEG(InputStream is, String name) {
try {
- Image i = Toolkit.getDefaultToolkit().createImage(org.xwt.Resources.isToByteArray(is));
+ Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is));
MediaTracker mediatracker = new MediaTracker(new Canvas());
mediatracker.addImage(i, 1);
try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name);
return null;
}
- return new ImageDecoder() {
- public int getWidth() { return width; }
- public int getHeight() { return height; }
- public int[] getData() { return data; }
- };
+ return Platform.createPicture(data, width, height);
} catch (Exception e) {
Log.log(this, "Exception caught while decoding JPEG image " + name);
Log.log(this, e);
return null;
}
}
-
- // Font Handling Stuff //////////////////////////////////////////////////////////
-
- protected String[] _listFonts() { return fontList; }
- private static String[] fontList;
- static {
- /*
- String[] awtfonts = Toolkit.getDefaultToolkit().getFontList();
- fontList = new String[awtfonts.length * 4];
- for(int i=0; i<awtfonts.length; i++) {
- fontList[i * 4] = awtfonts[i] + "*";
- fontList[i * 4 + 1] = awtfonts[i] + "*b";
- fontList[i * 4 + 2] = awtfonts[i] + "*i";
- fontList[i * 4 + 3] = awtfonts[i] + "*bi";
- }
- */
- fontList = new String[] { };
- }
-
- private static Hash fontCache = new Hash();
- private static ParsedFont pf = new ParsedFont();
- private static MetricatedFont getFont(String font) {
- MetricatedFont ret = (MetricatedFont)fontCache.get(font);
- if (ret == null) {
- pf.parse(font);
- if (pf.name.equals("tty")) pf.name = "monospace";
-
- // Java's fonts tend to be, on average, two points smaller than Win32/X11 fonts. This is most acute in
- // the proxy password dialog on Linux
- ret = new MetricatedFont(pf.name, (pf.bold ? Font.BOLD : 0) | (pf.italic ? Font.ITALIC : 0), pf.size + 2);
-
- fontCache.put(font, ret);
- }
- return ret;
- }
-
- private static class MetricatedFont extends Font {
- public FontMetrics metrics = null;
- public MetricatedFont(String name, int size, int style) {
- super(name, size, style);
- metrics = Toolkit.getDefaultToolkit().getFontMetrics(this);
- }
- }
-
}