X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FAWT.java;h=e186789eb67088c180360684a56597678205f245;hb=1019725cfa88d9ad5dfabaf178e87da79c9c3e17;hp=6e013528ff0752dede0397e9456c0f24e4cad7b8;hpb=c6069948906645d974f46bdb96617a9a6a504636;p=org.ibex.core.git diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index 6e01352..e186789 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -15,17 +15,15 @@ import java.awt.event.*; public class AWT extends JVM { protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; } - protected PixelBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new AWTDoubleBuffer(w, h); } + 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 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() { + 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"); } @@ -111,7 +109,7 @@ public class AWT extends JVM { final Semaphore s = new Semaphore(); FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write); s.block(); - return fd.getDirectory() + File.separatorChar + fd.getFile(); + return fd.getDirectory() == null ? null : (fd.getDirectory() + File.separatorChar + fd.getFile()); } @@ -137,7 +135,7 @@ public class AWT extends JVM { } } - protected static class AWTPixelBuffer extends DoubleBuffer { + protected static class AWTPixelBuffer extends PixelBuffer { protected Image i = null; protected Graphics g = null; @@ -170,28 +168,38 @@ public class AWT extends JVM { 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))); - g.fillRect(x, y, x2 - x, y2 - y); } + // FIXME: try to use os acceleration + 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); + } else for(int y=y1; y _x2) { int _x0 = _x1; _x1 = _x2; _x2 = _x0; } + g.fillRect(_x1, _y1, _x2 - _x1, _y2 - _y1); + } + } } - 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) { if (ourGraphics == null) ourGraphics = window.getGraphics(); - ourGraphics.drawImage(((AWTPixelBuffer)s).i, dx + insets.left, dy + insets.top, dx2 + insets.left, dy2 + insets.top, + insets = (frame == null ? window : frame).getInsets(); + ourGraphics.drawImage(((AWTPixelBuffer)s).i, + dx + insets.left, + dy + insets.top, + dx2 + insets.left, + dy2 + insets.top, sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null); } @@ -210,7 +218,7 @@ public class AWT extends JVM { 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)); } @@ -324,7 +332,7 @@ public class AWT extends JVM { public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.width, root.height); Minimized(false); } public void windowActivated(WindowEvent e) { Focused(true); } public void windowDeactivated(WindowEvent e) { Focused(false); } - public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); } + public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); } public void componentResized(ComponentEvent e) { // we have to periodically do this; I don't know why @@ -384,7 +392,7 @@ public class AWT extends JVM { case KeyEvent.VK_F3: return "f3"; case KeyEvent.VK_F4: return "f4"; case KeyEvent.VK_F5: return "f5"; - case KeyEvent.VK_F6: return "f6"; + case KeyEvent.VK_F6: return "f6"; case KeyEvent.VK_F7: return "f7"; case KeyEvent.VK_F8: return "f8"; case KeyEvent.VK_F9: return "f9"; @@ -408,9 +416,9 @@ public class AWT extends JVM { } } - 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) { } @@ -424,59 +432,11 @@ public class AWT extends JVM { 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