/** 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();
}
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);
// that our peer has been created
window.setVisible(true);
- insets = window.getInsets();
}
public void _dispose() {
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;
}
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) {