X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FAWT.java;h=3dfd1536a96b037ec7c48ced9e0103dbbec46d5f;hb=8ca06b850fb51673a7cfe751643ea45ec528070d;hp=43f2fba08f6e2d464027c440c006412cb0a25caf;hpb=e58686eae8a823ed64ed0ec92c2274c41d90ec93;p=org.ibex.core.git diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index 43f2fba..3dfd153 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -1,4 +1,4 @@ -// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL] package org.xwt.plat; import org.xwt.*; @@ -10,23 +10,20 @@ import java.awt.*; import java.awt.datatransfer.*; import java.awt.image.*; import java.awt.event.*; -import java.applet.*; /** Platform subclass for all VM's providing AWT 1.1 functionality */ -public class AWT extends Platform { +public class AWT extends JVM { protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; } - protected DoubleBuffer _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 true; } 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"); } @@ -112,7 +109,7 @@ public class AWT extends Platform { 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()); } @@ -130,7 +127,7 @@ public class AWT extends Platform { public AWTPicture(int[] b, int w, int h) { data = b; Image img = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, cmodel, b, 0, w)); - MediaTracker mediatracker = new MediaTracker(new Canvas()); + MediaTracker mediatracker = new MediaTracker(new Canvas()); mediatracker.addImage(img, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(img); @@ -138,7 +135,7 @@ public class AWT extends Platform { } } - protected static class AWTDoubleBuffer extends DoubleBuffer { + protected static class AWTPixelBuffer extends PixelBuffer { protected Image i = null; protected Graphics g = null; @@ -146,9 +143,9 @@ public class AWT extends Platform { /** JDK1.1 platforms require that a component be associated with each off-screen buffer */ static Component component = null; - protected AWTDoubleBuffer() { } - public AWTDoubleBuffer(int w, int h) { - synchronized(AWTDoubleBuffer.class) { + protected AWTPixelBuffer() { } + public AWTPixelBuffer(int w, int h) { + synchronized(AWTPixelBuffer.class) { if (component == null) { component = new Frame(); component.setVisible(false); @@ -163,36 +160,52 @@ public class AWT extends Platform { public int getWidth() { return i == null ? 0 : i.getWidth(null); } public void setClip(int x, int y, int x2, int y2) { g.setClip(x, y, x2 - x, y2 - y); } - public void drawPicture(Picture source, int x, int y) { - drawPicture(source, x, y, x + source.getWidth(), y + source.getHeight(), 0, 0, source.getWidth(), source.getHeight()); - } - public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { 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 drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, int rgb) { + AWTPicture p = (AWTPicture)source; + Graphics g = p.i.getGraphics(); + g.setXORMode(new Color(rgb)); + g.fillRect(0, 0, p.i.getWidth(null), p.i.getHeight(null)); + drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); + g.fillRect(0, 0, p.i.getWidth(null), p.i.getHeight(null)); } - + 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(DoubleBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) { + 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(((AWTDoubleBuffer)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); } @@ -211,7 +224,7 @@ public class AWT extends Platform { 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)); } @@ -233,9 +246,9 @@ public class AWT extends Platform { Rectangle r = gr.getClipBounds(); // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches expansions during smooth resize - int newwidth = Math.max(r.x - insets.left + r.width, width); - int newheight = Math.max(r.y - insets.top + r.height, height); - if (newwidth > width || newheight > height) + 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); Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); @@ -322,10 +335,10 @@ public class AWT extends Platform { public void windowClosed(WindowEvent e) { } public void windowClosing(WindowEvent e) { Close(); } public void windowIconified(WindowEvent e) { Minimized(true); } - public void windowDeiconified(WindowEvent e) { dirty(0, 0, width, height); Minimized(false); } + 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 @@ -334,8 +347,8 @@ public class AWT extends Platform { } public void componentResized(int newwidth, int newheight) { - int oldwidth = width; - int oldheight = height; + 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 @@ -356,7 +369,7 @@ public class AWT extends Platform { // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches contractions during smooth resize int newwidth = window.getWidth() - insets.left - insets.right; int newheight = window.getHeight() - insets.top - insets.bottom; - if (newwidth != width || newheight != height) componentResized(newwidth, newheight); + if (newwidth != root.width || newheight != root.height) componentResized(newwidth, newheight); Move(m.getX() - insets.left, m.getY() - insets.top); } @@ -385,7 +398,7 @@ public class AWT extends Platform { 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"; @@ -409,72 +422,27 @@ public class AWT extends Platform { } } - protected ImageDecoder _decodeJPEG(InputStream is, String name) { - try { - Image i = Toolkit.getDefaultToolkit().createImage(org.xwt.Resources.isToByteArray(is)); - MediaTracker mediatracker = new MediaTracker(new Canvas()); + protected Picture _decodeJPEG(InputStream is, String name) { + try { + Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is)); + MediaTracker mediatracker = new MediaTracker(new Canvas()); mediatracker.addImage(i, 1); - try { mediatracker.waitForAll(); } catch (InterruptedException e) { } - mediatracker.removeImage(i); - final int width = i.getWidth(null); - final int height = i.getHeight(null); - 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 new ImageDecoder() { - public int getWidth() { return width; } - public int getHeight() { return height; } - public int[] getData() { return data; } - }; - } 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