X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FAWT.java;h=43168fd97ba0da85d5218b5ba99ec72f6fbb518c;hb=027607da259f292060d80e0ed90d2b0e896acd86;hp=6a55e92d8140af224fb8a36c7903352541eab1ea;hpb=6242c991f365dbd67eba62ecfa5df769a83fcbc6;p=org.ibex.core.git diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index 6a55e92..43168fd 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -25,6 +25,7 @@ public class AWT extends Platform { 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 String _getClipBoard() { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); @@ -48,6 +49,37 @@ public class AWT extends Platform { return 0; } + static class Open extends FileDialog implements WindowListener, ComponentListener { + Semaphore s; + public Open(String suggestedFileName, Semaphore s, boolean write) { + super(new Frame(), suggestedFileName, write ? FileDialog.SAVE : FileDialog.LOAD); + this.s = s; + } + public void windowActivated(WindowEvent e) { } + public void windowClosed(WindowEvent e) { s.release(); } + public void windowClosing(WindowEvent e) { } + public void windowDeactivated(WindowEvent e) { } + public void windowDeiconified(WindowEvent e) { } + public void windowIconified(WindowEvent e) { } + public void windowOpened(WindowEvent e) { } + public void componentHidden(ComponentEvent e) { s.release(); } + public void componentMoved(ComponentEvent e) { } + public void componentResized(ComponentEvent e) { } + public void componentShown(ComponentEvent e) { } + }; + + protected String _fileDialog(String suggestedFileName, boolean write) { + Semaphore s = new Semaphore(); + Open fd = new Open(suggestedFileName, s, write); + fd.addWindowListener(fd); + fd.addComponentListener(fd); + fd.show(); + s.block(); + return fd.getDirectory() + File.separatorChar + fd.getFile(); + } + + protected void _saveFile(String suggestedFileName, ByteStream data) throws IOException { } + // Inner Classes ///////////////////////////////////////////////////////////////////////////////////// protected static class AWTPicture implements Picture { @@ -77,13 +109,16 @@ public class AWT extends Platform { /** JDK1.1 platforms require that a component be associated with each off-screen buffer */ static Component component = null; - static { - component = new Frame(); - component.setVisible(false); - component.addNotify(); - } + protected AWTDoubleBuffer() { } public AWTDoubleBuffer(int w, int h) { + synchronized(AWTDoubleBuffer.class) { + if (component == null) { + component = new Frame(); + component.setVisible(false); + component.addNotify(); + } + } i = component.createImage(w, h); g = i.getGraphics(); } @@ -154,22 +189,51 @@ public class AWT extends Platform { window.setLocation(new Point(0, 0)); window.setSize(Toolkit.getDefaultToolkit().getScreenSize()); } - + + class InnerFrame extends Frame { + public InnerFrame() throws java.lang.UnsupportedOperationException { } + public void update(Graphics gr) { paint(gr); } + public void paint(Graphics gr) { + 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) + 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(); + } + } + + class InnerWindow extends Window { + public InnerWindow() throws java.lang.UnsupportedOperationException { super(new Frame()); } + public void update(Graphics gr) { paint(gr); } + 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(); + } + } + AWTSurface(Box root, boolean framed) { super(root); - - if (framed) window = frame = new Frame() { - public void update(Graphics gr) { paint(gr); } - public void paint(Graphics gr) { - Rectangle r = gr.getClipBounds(); - Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); - } }; - else window = new Window(new Frame()) { - public void update(Graphics gr) { paint(gr); } - public void paint(Graphics gr) { - Rectangle r = gr.getClipBounds(); - Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); - } }; + 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); + } + + insets = window.getInsets(); window.addMouseListener(this); window.addKeyListener(this); @@ -181,7 +245,6 @@ public class AWT extends Platform { // that our peer has been created window.setVisible(true); - insets = window.getInsets(); } public void _dispose() { @@ -232,10 +295,22 @@ public class AWT extends Platform { 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 componentResized(ComponentEvent e) { // we have to periodically do this; I don't know why insets = window.getInsets(); - SizeChange(window.getWidth(), window.getHeight()); + componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom); + } + + public void componentResized(int newwidth, int newheight) { + int oldwidth = width; + int oldheight = 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; } @@ -245,7 +320,15 @@ public class AWT extends Platform { public void mouseExited(MouseEvent m) { mouseMoved(m); } public void mouseEntered(MouseEvent m) { mouseMoved(m); } public void mouseDragged(MouseEvent m) { mouseMoved(m); } - public void mouseMoved(MouseEvent m) { Move(m.getX() - insets.left, m.getY() - insets.top); } + public void mouseMoved(MouseEvent m) { + + // 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); + + Move(m.getX() - insets.left, m.getY() - insets.top); + } public void mousePressed(MouseEvent m) { Press(modifiersToButtonNumber(m.getModifiers())); } public void mouseReleased(MouseEvent m) { Release(modifiersToButtonNumber(m.getModifiers())); } public void mouseClicked(MouseEvent m) {