// FEATURE: Java 1.4 allows undecorated frames and can maximize windows
/** Platform class for most reasonable Java1.2+ JVMs */
-public class Java2 extends AWT {
+public class Java12 extends AWT {
protected Socket __getSocket(String host, int port, boolean ssl) throws IOException { return super._getSocket(host, port, ssl); }
protected Socket _getSocket(final String host, final int port, final boolean ssl) throws IOException {
try {
return __getSocket(host, port, ssl);
} catch (Exception e) {
- if (Log.on) Log.log(Java2.class, "Error attempting to create socket");
- if (Log.on) Log.log(Java2.class, e);
+ if (Log.on) Log.log(Java12.class, "Error attempting to create socket");
+ if (Log.on) Log.log(Java12.class, e);
return null;
}
}
});
}
- protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new Java2DoubleBuffer(w, h); }
+ protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new Java12DoubleBuffer(w, h); }
protected Surface _createSurface(final Box root, final boolean framed) {
return (Surface)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
- public Object run() { return new Java2Surface(root, framed); }
+ public Object run() { return new Java12Surface(root, framed); }
});
}
// Inner Classes //////////////////////////////////////////////////////////////////
- protected static class Java2Surface extends AWTSurface {
+ protected static class Java12Surface extends AWTSurface {
- public Java2Surface(Box root, boolean framed) { super(root, framed); }
+ public Java12Surface(Box root, boolean framed) { super(root, framed); }
public void blit(DoubleBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
- if (ourGraphics == null) ourGraphics = window.getGraphics();
+ if (ourGraphics == null) {
+ ourGraphics = window.getGraphics();
+
+ // sometimes jdk1.4 doesn't set the clip properly when we're in the middle of a resize
+ ourGraphics.setClip(insets.left, insets.top, width + insets.left, height + insets.top);
+ }
_doDrawImage(ourGraphics, ((AWTDoubleBuffer)s).i, dx + insets.left, dy + insets.top, dx2 + insets.left, dy2 + insets.top,
sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null);
}
}
}
- protected static class Java2DoubleBuffer extends AWTDoubleBuffer {
+ protected static class Java12DoubleBuffer extends AWTDoubleBuffer {
private static ColorModel cm = Toolkit.getDefaultToolkit().getColorModel();
private static Hashtable emptyHashtable = new Hashtable();
private static short[] sbank = null;
_doDrawImage(g, ((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
}
- public Java2DoubleBuffer(int w, int h) {
- super(w, h);
+ public Java12DoubleBuffer(int w, int h) {
SampleModel sm = cm.createCompatibleSampleModel(w, h);
+ int numSamples = w * h * sm.getNumDataElements();
DataBuffer buf = null;
if (sm.getDataType() == DataBuffer.TYPE_USHORT) {
- if (sbank == null || w * h > 512 * 512 / 3) {
- buf = new DataBufferUShort(w * h);
+ if (sbank == null || numSamples > 512 * 512 / 3) {
+ buf = new DataBufferUShort(numSamples);
} else {
- if (w * h > sbank.length - bank_start) {
+ if (numSamples > sbank.length - bank_start) {
bank_start = 0;
sbank = new short[512 * 512];
}
- buf = new DataBufferUShort(sbank, w * h, bank_start);
- bank_start += w * h;
+ buf = new DataBufferUShort(sbank, numSamples, bank_start);
+ bank_start += numSamples;
}
} else if (sm.getDataType() == DataBuffer.TYPE_BYTE) {
- if (bbank == null || w * h > 512 * 512 / 3) {
- buf = new DataBufferByte(w * h);
+ if (bbank == null || numSamples > 512 * 512 / 3) {
+ buf = new DataBufferByte(numSamples);
} else {
- if (w * h > bbank.length - bank_start) {
+ if (numSamples > bbank.length - bank_start) {
bank_start = 0;
bbank = new byte[512 * 512];
}
- buf = new DataBufferByte(bbank, w * h, bank_start);
- bank_start += w * h;
+ buf = new DataBufferByte(bbank, numSamples, bank_start);
+ bank_start += numSamples;
}
} else if (sm.getDataType() == DataBuffer.TYPE_INT) {
- if (ibank == null || w * h > 512 * 512 / 3) {
- buf = new DataBufferInt(w * h);
+ if (ibank == null || numSamples > 512 * 512 / 3) {
+ buf = new DataBufferInt(numSamples);
} else {
- if (w * h > ibank.length - bank_start) {
+ if (numSamples > ibank.length - bank_start) {
bank_start = 0;
ibank = new int[512 * 512];
}
- buf = new DataBufferInt(ibank, w * h, bank_start);
- bank_start += w * h;
+ buf = new DataBufferInt(ibank, numSamples, bank_start);
+ bank_start += numSamples;
}
}
i = new BufferedImage(cm, Raster.createWritableRaster(sm, buf, null), false, emptyHashtable);
}
}
- protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); }
- private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
- public Java2Weak(Object o) { super(o); }
+ protected org.xwt.Weak _getWeak(Object o) { return new Java12Weak(o); }
+ private static class Java12Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
+ public Java12Weak(Object o) { super(o); }
}
private String __getClipBoard() { return super._getClipBoard(); }
--- /dev/null
+// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+package org.xwt.plat;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.datatransfer.*;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import org.xwt.util.*;
+import org.xwt.*;
+
+/** Platform class for most reasonable Java1.4+ JVMs */
+public class Java14 extends Java12 {
+
+ protected String getDescriptiveName() { return "Java 1.4+ JVM"; }
+ protected boolean _supressDirtyOnResize() { return false; }
+
+ public Java14() {
+ java.awt.Toolkit.getDefaultToolkit().setDynamicLayout(true);
+ }
+
+ protected Surface _createSurface(final Box root, final boolean framed) {
+ return (Surface)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
+ public Object run() { return new Java14Surface(root, framed); }
+ });
+ }
+
+ protected static class Java14Surface extends Java12Surface implements WindowStateListener {
+ public Java14Surface(Box root, boolean framed) {
+ super(root, framed);
+ window.addWindowStateListener(this);
+ }
+ protected void _setMaximized(boolean m) {
+ if (frame == null) {
+ if (Log.on) Log.log(this, "JDK 1.4 can only maximize frames, not windows");
+ return;
+ }
+ frame.setExtendedState(m ? Frame.MAXIMIZED_BOTH : (minimized ? Frame.ICONIFIED : Frame.NORMAL));
+ }
+ protected void _setMinimized(boolean m) {
+ if (frame == null) {
+ if (Log.on) Log.log(this, "JDK 1.4 can only minimize frames, not windows");
+ return;
+ }
+ frame.setExtendedState(m ? Frame.ICONIFIED : (maximized ? Frame.MAXIMIZED_BOTH : Frame.NORMAL));
+ }
+ public void windowStateChanged(WindowEvent e) {
+ if (e.getOldState() != e.getNewState()) {
+ if ((e.getNewState() & Frame.MAXIMIZED_BOTH) != 0) Maximized(true);
+ else if (((e.getOldState() & Frame.MAXIMIZED_BOTH) != 0) && (e.getNewState() & Frame.MAXIMIZED_BOTH) == 0)
+ Maximized(false);
+ }
+ }
+ }
+
+}