From bc199d84016367dfa1ea731e2420935cf3edb87f Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 06:46:35 +0000 Subject: [PATCH] 2002/04/30 21:15:33 darcs-hash:20040130064635-2ba56-d6316879ed30c6d9c1bf21c4a71c4639688b3175.gz --- CHANGES | 7 ++++ src/org/xwt/plat/AWT.java | 89 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/CHANGES b/CHANGES index fbdb57d..8716e1f 100644 --- a/CHANGES +++ b/CHANGES @@ -106,5 +106,12 @@ 30-Apr megacz Chess.java, XServer.java: removed unused imports +30-Apr megacz AWT.java: only create reserve Component if an + AWTDoubleBuffer gets created, prep for Java14, broke out + InnerFrame/InnerWindow and added exception handler to + cope with new Java1.4 HeadlessException. + + + diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index 6a55e92..5a0b120 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -77,13 +77,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 +157,45 @@ 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); + } + } + + 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); + } + } + 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 +207,6 @@ public class AWT extends Platform { // that our peer has been created window.setVisible(true); - insets = window.getInsets(); } public void _dispose() { @@ -232,10 +257,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 +282,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) { -- 1.7.10.4