X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FAWT.java;h=1138f26ec1f7237f84466f8e0126c2e589d19645;hb=91fa07eeabb1c256410385947e6a76f1e45c8b48;hp=dac9e57b32aaf051ed674f6a3a07822e3dc1547b;hpb=c150258fc143a468aa2adc63d4e0b94b8e884580;p=org.ibex.core.git diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index dac9e57..1138f26 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -16,19 +16,18 @@ public class AWT extends JVM { protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; } protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); } - protected Picture _createPicture(int[] b, int w, int h) { return new AWTPicture(b, w, h); } + protected Picture _createPicture(Stream r) { return new AWTPicture(r); } 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 void postInit() { - System.setProperty("com.apple.mrj.application.live-resize", "true"); - System.setProperty("com.apple.mrj.application.growbox.intrudes", "false"); - if (Log.on) Log.log(Platform.class, " color depth = " + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); + if (Log.on) Log.diag(Platform.class, " color depth = " + + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); } protected void _criticalAbort(String message) { - if (Log.on) Log.log(this, message); + if (Log.on) Log.info(this, message); final Dialog d = new Dialog(new Frame(), "XWT Cannot Continue"); d.setLayout(new BorderLayout()); TextArea ta = new TextArea("XWT cannot continue because:\n\n" + message, 10, 80); @@ -115,18 +114,60 @@ public class AWT extends JVM { // Inner Classes ///////////////////////////////////////////////////////////////////////////////////// - protected static class AWTPicture extends Picture { - public int getHeight() { return i.getHeight(null); } - public int getWidth() { return i.getWidth(null); } - public int[] getData() { return data; } + protected org.xwt.Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new AWTGlyph(f, c); } + protected static class AWTGlyph extends org.xwt.Font.Glyph { + private Image i = null; + private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); - int[] data = null; + // this doesn't work on Win32 because the JVM is broken + /* + static final ColorModel cmodel = new ColorModel(8) { + public int getRed(int p) { return 0; } + public int getGreen(int p) { return 0; } + public int getBlue(int p) { return 0; } + public int getAlpha(int p) { return p & 0xFF; } + }; + */ + + public AWTGlyph(org.xwt.Font f, char c) { super(f, c); } + Image getImage() { + if (i == null && isLoaded) { + + int[] data2 = new int[data.length]; + for(int i=0; i> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff)); @@ -181,7 +223,9 @@ public class AWT extends JVM { // blacken the area we want the glyph to cover g.setPaintMode(); - drawPicture(source, dx, dy, cx1, cy1, cx2, cy2); + g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1); + g.drawImage(((AWTGlyph)source).getImage(), dx, dy, null); + g.setClip(0, 0, i.getWidth(null), i.getHeight(null)); // XOR back, turning black into the chosen rgb color g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff)); @@ -193,7 +237,7 @@ public class AWT extends JVM { } // FIXME: try to use os acceleration - public void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) { + public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) { g.setColor(new Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF))); if (x1 == x3 && x2 == x4) { g.fillRect(x1, y1, x4 - x1, y2 - y1); @@ -213,9 +257,8 @@ public class AWT extends JVM { implements MouseListener, MouseMotionListener, KeyListener, ComponentListener, WindowListener { public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) { - if (ourGraphics == null) ourGraphics = window.getGraphics(); insets = (frame == null ? window : frame).getInsets(); - ourGraphics.drawImage(((AWTPixelBuffer)s).i, + window.getGraphics().drawImage(((AWTPixelBuffer)s).i, dx + insets.left, dy + insets.top, dx2 + insets.left, @@ -230,9 +273,6 @@ public class AWT extends JVM { /** our component's insets */ protected Insets insets = new Insets(0, 0, 0, 0); - /** a Graphics context on window */ - protected Graphics ourGraphics = null; - /** some JDKs let us recycle a single Dimension object when calling getSize() */ Dimension singleSize = new Dimension(); @@ -243,10 +283,10 @@ public class AWT extends JVM { 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)); } public void setInvisible(boolean b) { window.setVisible(!b); } - protected void _setMinimized(boolean b) { if (Log.on) Log.log(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); } + protected void _setMinimized(boolean b) { if (Log.on) Log.info(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); } protected void _setMaximized(boolean b) { if (!b) { - if (Log.on) Log.log(this, "JDK 1.1 platforms cannot unmaximize windows"); + if (Log.on) Log.info(this, "JDK 1.1 platforms cannot unmaximize windows"); return; } window.setLocation(new Point(0, 0)); @@ -263,7 +303,8 @@ public class AWT extends JVM { int newwidth = Math.max(r.x - insets.left + r.width, root.width); int newheight = Math.max(r.y - insets.top + r.height, root.height); if (newwidth > root.width || newheight > root.height) - componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom); + componentResized(window.getWidth() - insets.left - insets.right, + window.getHeight() - insets.top - insets.bottom); Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); } @@ -278,17 +319,26 @@ public class AWT extends JVM { } } + public void render() { + // useful optimizatin; + window.setBackground((root.fillcolor & 0xFF000000) == 0 ? + Color.white : + new Color((root.fillcolor >> 16) & 0xff, + (root.fillcolor >> 8) & 0xff, + (root.fillcolor) & 0xff)); + super.render(); + } + AWTSurface(Box root, boolean framed) { super(root); - System.out.println("Y"); try { if (framed) window = frame = new InnerFrame(); else window = new InnerWindow(); // this is here to catch HeadlessException on jdk1.4 } catch (java.lang.UnsupportedOperationException e) { - if (Log.on) Log.log(this, "Exception thrown in AWTSurface$InnerFrame() -- this should never happen"); - if (Log.on) Log.log(this, e); + if (Log.on) Log.info(this, "Exception thrown in AWTSurface$InnerFrame() -- this should never happen"); + if (Log.on) Log.info(this, e); } insets = window.getInsets(); @@ -361,17 +411,7 @@ public class AWT extends JVM { componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom); } - public void componentResized(int newwidth, int newheight) { - int oldwidth = root.width; - int oldheight = root.height; - SizeChange(newwidth, newheight); - - // we do this because JVMs which don't clear the background won't force repaints of these areas - root.dirty(Math.min(oldwidth, newwidth), 0, Math.abs(oldwidth - newwidth), Math.max(oldheight, newheight)); - root.dirty(0, Math.min(oldheight, newheight), Math.max(oldwidth, newwidth), Math.abs(oldheight - newheight)); - - ourGraphics = null; - } + public void componentResized(int newwidth, int newheight) { SizeChange(newwidth, newheight); } public void keyTyped(KeyEvent k) { } public void keyPressed(KeyEvent k) { KeyPressed(translateKey(k)); } @@ -437,7 +477,7 @@ public class AWT extends JVM { } } - protected Picture _decodeJPEG(InputStream is, String name) { + protected void _decodeJPEG(InputStream is, Picture p) { try { Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is)); MediaTracker mediatracker = new MediaTracker(new Canvas()); @@ -449,15 +489,14 @@ public class AWT extends JVM { final int[] data = new int[width * height]; PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width); pg.grabPixels(); - if ((pg.getStatus() & ImageObserver.ABORT) != 0) { - Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name); - return null; - } - return Platform.createPicture(data, width, height); + if ((pg.getStatus() & ImageObserver.ABORT) != 0) + Log.info(this, "PixelGrabber reported an error while decoding JPEG image"); + p.width = width; + p.height = height; + p.data = data; } catch (Exception e) { - Log.log(this, "Exception caught while decoding JPEG image " + name); - Log.log(this, e); - return null; + Log.info(this, "Exception caught while decoding JPEG image"); + Log.info(this, e); } } }