-// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+// Copyright 2003 Adam Megacz, see the COPYING file for licensing [GPL]
package org.xwt.plat;
import java.awt.*;
public class Java2 extends AWT {
private boolean isJava14 = false;
- protected boolean _supressDirtyOnResize() { return isJava14 ? false : true; }
public Java2() {
// disable the focus manager so we can intercept the tab key
- double version = Double.parseDouble(System.getProperty("java.version", ""));
- if (version >= 1.4) {
- isJava14 = true;
- try {
- Toolkit t = java.awt.Toolkit.getDefaultToolkit();
- Method m = java.awt.Toolkit.class.getMethod("setDynamicLayout", new Class[] { Boolean.class });
- m.invoke(t, new Object[] { Boolean.TRUE });
- } catch (Exception e) {
- Log.log(this, "Exception while trying to enable AWT Dynamic Layout");
- Log.log(this, e);
- }
- }
+ String versionString = System.getProperty("java.version", "");
+ int secondDecimal = versionString.substring(versionString.indexOf('.') + 1).indexOf('.');
+ if (secondDecimal != -1) versionString = versionString.substring(0, secondDecimal);
+ double version = Double.parseDouble(versionString);
+ if (version >= 1.4) {
+ isJava14 = true;
+ try {
+ Toolkit t = java.awt.Toolkit.getDefaultToolkit();
+ Method m = java.awt.Toolkit.class.getMethod("setDynamicLayout", new Class[] { Boolean.class });
+ m.invoke(t, new Object[] { Boolean.TRUE });
+ } catch (Exception e) {
+ Log.info(this, "Exception while trying to enable AWT Dynamic Layout");
+ Log.info(this, e);
+ }
+ }
javax.swing.FocusManager.setCurrentManager(new javax.swing.FocusManager() {
public void processKeyEvent(Component focusedComponent, KeyEvent anEvent) { }
public void focusPreviousComponent(Component aComponent) { }
}
/** this is done with reflection in case a new version of the plugin comes out that doesn't let us pull the sun.plugin.* trick */
- protected synchronized org.xwt.Proxy _detectProxy() {
- return (org.xwt.Proxy)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
+ protected synchronized org.xwt.HTTP.Proxy _detectProxy() {
+ return (org.xwt.HTTP.Proxy)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
try {
- org.xwt.Proxy pi = new org.xwt.Proxy();
+ org.xwt.HTTP.Proxy pi = new org.xwt.HTTP.Proxy();
Class PluginProxyHandler = Class.forName("sun.plugin.protocol.PluginProxyHandler");
Method getDefaultProxyHandler = PluginProxyHandler.getMethod("getDefaultProxyHandler", new Class[] { });
else return null;
} catch (Throwable e) {
- if (Log.on) Log.log(this, "exception while querying sun.plugin.protocol.PluginProxyHandler: " + e);
+ if (Log.on) Log.info(this, "No proxy information found in Java Plugin classes");
return null;
}
}});
}
- protected Socket __getSocket(String host, int port, boolean ssl, boolean negotiate) throws IOException {
- return super._getSocket(host, port, ssl, negotiate);
- }
- protected Socket _getSocket(final String host, final int port, final boolean ssl, final boolean negotiate) throws IOException {
- return (Socket)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
+ protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new Java2PixelBuffer(w, h); }
+ protected Surface _createSurface(final Box root, final boolean framed) {
+ return (Surface)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
- try {
- return __getSocket(host, port, ssl, negotiate);
- } catch (Exception e) {
- if (Log.on) Log.log(Java2.class, "Error attempting to create socket");
- if (Log.on) Log.log(Java2.class, e);
- return null;
+ if (isJava14) {
+ try {
+ // weaken the binding here to avoid link errors on 1.3.x
+ Class java14SurfaceClass = Class.forName(Java2.class.getName() + "$Java14Surface");
+ Constructor ctor = java14SurfaceClass.getConstructor(new Class[] { Box.class, Boolean.TYPE });
+ return (Surface)ctor.newInstance(new Object[] { root, new Boolean(framed) });
+ } catch (Exception e) {
+ Log.info(this, e);
+ throw new LinkageError("error: " + e);
+ }
+ } else {
+ return new Java2Surface(root, framed);
}
}
});
}
-
- protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new Java2DoubleBuffer(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 isJava14 ? new Java14Surface(root, framed) : new Java2Surface(root, framed); }
- });
- }
// Inner Classes //////////////////////////////////////////////////////////////////
new Point(1, 1), "invisible");
protected static class Java2Surface extends AWTSurface {
-
- public Java2Surface(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();
-
- // 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);
- }
+ public Java2Surface(Box root, boolean framed) { super(root, framed); }
protected void _setMinimized(boolean b) {
- if (frame == null) {
- if (Log.on) Log.log(this, "JDK 1.2 can only minimize frames, not windows");
- return;
- }
- if (b) frame.setState(java.awt.Frame.ICONIFIED);
+ if (frame == null) Log.info(this, "JDK 1.2 can only minimize frames, not windows");
+ else if (b) frame.setState(java.awt.Frame.ICONIFIED);
else frame.setState(java.awt.Frame.NORMAL);
}
}
}
- protected static class Java14Surface extends Java2Surface implements WindowStateListener {
+ protected static class Java14Surface extends Java2Surface implements WindowStateListener, MouseWheelListener {
public Java14Surface(Box root, boolean framed) {
super(root, true);
// JDK1.4 doesn't like java.lang.Window's...
if (!framed) ((Frame)window).setUndecorated(true);
window.addWindowStateListener(this);
+ window.addMouseWheelListener(this);
window.setVisible(true);
}
protected void _setMaximized(boolean m) {
if (frame == null) {
- if (Log.on) Log.log(this, "JDK 1.4 can only maximize frames, not windows");
+ if (Log.on) Log.info(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");
+ if (Log.on) Log.info(this, "JDK 1.4 can only minimize frames, not windows");
return;
}
frame.setExtendedState(m ? Frame.ICONIFIED : (maximized ? Frame.MAXIMIZED_BOTH : Frame.NORMAL));
Maximized(false);
}
}
+
+ public void mouseWheelMoved(MouseWheelEvent m) {
+ // TODO: Uncomment this once Scroll is implemented in the core
+ //if(m.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { Scroll(m.getUnitsToScroll()); }
+ }
}
- protected static class Java2DoubleBuffer extends AWTDoubleBuffer {
+ protected static class Java2PixelBuffer extends AWTPixelBuffer {
private static ColorModel cm = Toolkit.getDefaultToolkit().getColorModel();
private static Hashtable emptyHashtable = new Hashtable();
private static short[] sbank = null;
private static int[] ibank = null;
private static byte[] bbank = null;
private static int bank_start = 0;
-
- public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) {
- _doDrawImage(g, ((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
+ private WritableRaster raster = null;
+ private SampleModel sm = null;
+ private DataBuffer buf = null;
+
+ public void drawGlyph(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ AWTPicture src = (AWTPicture)source;
+ src.init();
+ Graphics2D g2 = (Graphics2D)i.getGraphics();
+ g2.setComposite(AlphaComposite.DstOut);
+ g2.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
+ g2.drawImage(src.i, dx, dy, null);
+ g2.setComposite(AlphaComposite.DstOver);
+ g2.setColor(new Color((rgb & 0x00FF0000) >> 16, (rgb & 0x0000FF00) >> 8, (rgb & 0x000000FF)));
+ g2.fillRect(dx, dy, cx2 - dx, cy2 - dy);
+ g2.drawImage(i, 0, 0, null);
+ g2.setClip(0, 0, i.getWidth(null), i.getHeight(null));
}
-
- public Java2DoubleBuffer(int w, int h) {
- SampleModel sm = cm.createCompatibleSampleModel(w, h);
+
+ public Java2PixelBuffer(int w, int h) {
+ sm = cm.createCompatibleSampleModel(w, h);
int numSamples = w * h * sm.getNumDataElements();
- DataBuffer buf = null;
if (sm.getDataType() == DataBuffer.TYPE_USHORT) {
if (sbank == null || numSamples > 512 * 512 / 3) {
buf = new DataBufferUShort(numSamples);
bank_start += numSamples;
}
}
- i = new BufferedImage(cm, Raster.createWritableRaster(sm, buf, null), false, emptyHashtable);
+ raster = Raster.createWritableRaster(sm, buf, null);
+ i = new BufferedImage(cm, raster, false, emptyHashtable);
g = i.getGraphics();
}
}
- /** used to avoid garbage creation with getClipBounds() */
- private static Rectangle clipBounds = new Rectangle();
-
- protected static void _doDrawImage(Graphics g, Image i, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver o) {
- if (dx1 == dx2 || dy1 == dy2) return;
- g.drawImage(i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, o);
- }
-
- 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); }
- }
-
- private String __getClipBoard() { return super._getClipBoard(); }
- protected String _getClipBoard() {
- return (String)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
- public Object run() { return __getClipBoard(); }
- });
- }
-
- private void __setClipBoard(String s) { super._setClipBoard(s); }
- protected void _setClipBoard(final String s) {
- java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
- public Object run() {
- __setClipBoard(s);
- return null;
- }
- });
- }
-
- protected String getDescriptiveName() { return "Java 1.2+ JVM"; }
-
- protected void _newBrowserWindow(String url) {
- if (Main.applet == null) {
- if (Log.on) Log.log(this, "Main.applet is null; cannot invoke showDocument()");
- return;
- }
- if (Log.on) Log.log(this, "asking browser to show URL " + url);
- try {
- Main.applet.getAppletContext().showDocument(new URL(url), "_blank");
- } catch (MalformedURLException e) {
- if (Log.on) Log.log(this, e);
- }
- }
+ protected String getDescriptiveName() { return isJava14 ? "Java 1.4+ JVM" : "Java 1.2+ JVM"; }
}