X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Forg%2Fxwt%2Fplat%2FAWT.java;h=43f2fba08f6e2d464027c440c006412cb0a25caf;hb=ec3ce7739bc84c0641fc57efc8da9af89372013f;hp=5f12430625c92e0a4e6a1195d5146b08f4762704;hpb=7fbe59aa53c35d9c8e18c576a7ef63ce40675219;p=org.ibex.core.git diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index 5f12430..43f2fba 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -3,7 +3,6 @@ package org.xwt.plat; import org.xwt.*; import org.xwt.util.*; -import org.mozilla.javascript.*; import java.net.*; import java.io.*; import java.util.*; @@ -28,8 +27,7 @@ public class AWT extends Platform { protected boolean _supressDirtyOnResize() { return true; } protected void postInit() { - if (Log.on) Log.log(Platform.class, " color depth = " + - Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); + if (Log.on) Log.log(Platform.class, " color depth = " + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); } protected void _criticalAbort(String message) { @@ -69,8 +67,16 @@ public class AWT extends Platform { /** some platforms (cough, cough, NetscapeVM) have totally broken modifier masks; they will need to override this */ protected static int modifiersToButtonNumber(int modifiers) { if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) return 1; - if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) return 3; - if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) return 2; + if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { + // ugh, MacOSX reports the right mouse button as BUTTON2_MASK... + if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 2; + return 3; + } + if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { + // ugh, MacOSX reports the right mouse button as BUTTON2_MASK... + if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 3; + return 2; + } return 0; } @@ -112,19 +118,19 @@ public class AWT extends Platform { // Inner Classes ///////////////////////////////////////////////////////////////////////////////////// - protected static class AWTPicture implements Picture { + 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; } int[] data = null; public Image i = null; - private static MediaTracker mediatracker = new MediaTracker(new Canvas()); private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); 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.addImage(img, 1); try { mediatracker.waitForAll(); } catch (InterruptedException e) { } mediatracker.removeImage(img); @@ -132,7 +138,7 @@ public class AWT extends Platform { } } - protected static class AWTDoubleBuffer implements DoubleBuffer { + protected static class AWTDoubleBuffer extends DoubleBuffer { protected Image i = null; protected Graphics g = null; @@ -233,9 +239,6 @@ public class AWT extends Platform { 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); - - // this is safe because AWT's low-level drawing functions are threadsafe - blitDirtyScreenRegions(); } } @@ -245,9 +248,6 @@ public class AWT extends Platform { public void paint(Graphics gr) { Rectangle r = gr.getClipBounds(); Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); - - // this is safe because AWT's low-level drawing functions are threadsafe - blitDirtyScreenRegions(); } } @@ -273,9 +273,10 @@ public class AWT extends Platform { // IMPORTANT: this must be called before render() to ensure // that our peer has been created - window.setVisible(true); - + makeVisible(); } + + protected void makeVisible() { window.setVisible(true); } public void _dispose() { window.removeMouseListener(this); @@ -324,7 +325,7 @@ public class AWT extends Platform { public void windowDeiconified(WindowEvent e) { dirty(0, 0, width, 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, window.getLocation().y); } + 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 @@ -343,7 +344,7 @@ public class AWT extends Platform { ourGraphics = null; } - + public void keyTyped(KeyEvent k) { } public void keyPressed(KeyEvent k) { KeyPressed(translateKey(k)); } public void keyReleased(KeyEvent k) { KeyReleased(translateKey(k)); } @@ -408,6 +409,34 @@ 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()); + 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; } @@ -430,7 +459,11 @@ public class AWT extends Platform { if (ret == null) { pf.parse(font); if (pf.name.equals("tty")) pf.name = "monospace"; - ret = new MetricatedFont(pf.name, (pf.bold ? Font.BOLD : 0) | (pf.italic ? Font.ITALIC : 0), pf.size); + + // 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;