From 0576e58bcc481543333aeb0233c04416ddde6a9b Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 9 Jan 2005 09:04:12 +0000 Subject: [PATCH] split Java2 into Java2/Java4 darcs-hash:20050109090412-5007d-8ef39dc70caf6f482197ebf2c2ead2c51ff3e972.gz --- src/org/ibex/plat/Java2.java | 161 +++++++++++---------------------------- src/org/ibex/plat/Java4.java | 57 ++++++++++++++ src/org/ibex/plat/Platform.java | 2 +- 3 files changed, 104 insertions(+), 116 deletions(-) create mode 100644 src/org/ibex/plat/Java4.java diff --git a/src/org/ibex/plat/Java2.java b/src/org/ibex/plat/Java2.java index 5129f64..346c2eb 100644 --- a/src/org/ibex/plat/Java2.java +++ b/src/org/ibex/plat/Java2.java @@ -18,25 +18,9 @@ import org.ibex.net.*; /** Platform class for most reasonable Java1.2+ Java2s */ public class Java2 extends AWT { - private boolean isJava14 = false; - + protected String getDescriptiveName() { return "Java 1.2+ JVM"; } public Java2() { // disable the focus manager so we can intercept the tab key - String versionString = System.getProperty("java.version", ""); - int secondDecimal = versionString.substring(versionString.indexOf('.') + 1).indexOf('.'); - if (secondDecimal != -1) versionString = versionString.substring(0, versionString.indexOf('.') + 1 + 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.TYPE }); - 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) { } @@ -44,67 +28,58 @@ public class Java2 extends AWT { }); } - /** 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 */ + /** this is done with reflection in case a new plugin comes out that doesn't let us pull the sun.plugin.* trick */ protected synchronized org.ibex.net.HTTP.Proxy _detectProxy() { return (org.ibex.net.HTTP.Proxy)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - public Object run() { - try { - org.ibex.net.HTTP.Proxy pi = new org.ibex.net.HTTP.Proxy(); - - Class PluginProxyHandler = Class.forName("sun.plugin.protocol.PluginProxyHandler"); - Method getDefaultProxyHandler = PluginProxyHandler.getMethod("getDefaultProxyHandler", new Class[] { }); - Object proxyHandler = getDefaultProxyHandler.invoke(null, new Object[] { }); - - Class ProxyHandler = Class.forName("sun.plugin.protocol.ProxyHandler"); - Method getProxyInfo = ProxyHandler.getMethod("getProxyInfo", new Class[] { URL.class }); - Object proxyInfo = getProxyInfo.invoke(proxyHandler, new Object[] { new URL("http://www.ibex.org") }); - - Class ProxyInfo = Class.forName("sun.plugin.protocol.ProxyInfo"); - - if (((Boolean)ProxyInfo.getMethod("isSocksUsed", new Class[] { }).invoke(proxyInfo, new Object[] { })).booleanValue()) { - pi.socksProxyHost = - (String)ProxyInfo.getMethod("getSocksProxy", new Class[] { }).invoke(proxyInfo, new Object[] { }); - pi.socksProxyPort = - ((Integer)ProxyInfo.getMethod("getSocksPort", new Class[] { }).invoke(proxyInfo, new Object[] { })).intValue(); - } - - if (((Boolean)ProxyInfo.getMethod("isProxyUsed", new Class[] { }).invoke(proxyInfo, new Object[] { })).booleanValue()) { - pi.httpProxyHost = - (String)ProxyInfo.getMethod("getProxy", new Class[] { }).invoke(proxyInfo, new Object[] { }); - pi.httpProxyPort = - ((Integer)ProxyInfo.getMethod("getPort", new Class[] { }).invoke(proxyInfo, new Object[] { })).intValue(); - } - - if (pi.httpProxyHost != null || pi.socksProxyHost != null) return pi; - else return null; - - } catch (Throwable e) { - if (Log.on) Log.info(this, "No proxy information found in Java Plugin classes"); - return null; + public Object run() { try { + org.ibex.net.HTTP.Proxy pi = new org.ibex.net.HTTP.Proxy(); + + Class PluginProxyHandler = Class.forName("sun.plugin.protocol.PluginProxyHandler"); + Method getDefaultProxyHandler = PluginProxyHandler.getMethod("getDefaultProxyHandler", new Class[] { }); + Object proxyHandler = getDefaultProxyHandler.invoke(null, new Object[] { }); + + Class ProxyHandler = Class.forName("sun.plugin.protocol.ProxyHandler"); + Method getProxyInfo = ProxyHandler.getMethod("getProxyInfo", new Class[] { URL.class }); + Object proxyInfo = getProxyInfo.invoke(proxyHandler, new Object[] { new URL("http://www.ibex.org") }); + + Class ProxyInfo = Class.forName("sun.plugin.protocol.ProxyInfo"); + + if (((Boolean)ProxyInfo.getMethod("isSocksUsed", + new Class[] { }).invoke(proxyInfo, new Object[] { })).booleanValue()) { + pi.socksProxyHost = + (String)ProxyInfo.getMethod("getSocksProxy", + new Class[] { }).invoke(proxyInfo, new Object[] { }); + pi.socksProxyPort = + ((Integer)ProxyInfo.getMethod("getSocksPort", + new Class[] { }).invoke(proxyInfo, new Object[] { })).intValue(); } + + if (((Boolean)ProxyInfo.getMethod("isProxyUsed", + new Class[] { }).invoke(proxyInfo, new Object[] { })).booleanValue()) { + pi.httpProxyHost = + (String)ProxyInfo.getMethod("getProxy", + new Class[] { }).invoke(proxyInfo, new Object[] { }); + pi.httpProxyPort = + ((Integer)ProxyInfo.getMethod("getPort", + new Class[] { }).invoke(proxyInfo, new Object[] { })).intValue(); + } + + if (pi.httpProxyHost != null || pi.socksProxyHost != null) return pi; + else return null; + + } catch (Throwable e) { + if (Log.on) Log.info(this, "No proxy information found in Java Plugin classes"); + return null; + } }}); } protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new Java2PixelBuffer(w, h); } + protected Surface __createSurface(final Box root, final boolean framed) { return new Java2Surface(root, framed); } protected Surface _createSurface(final Box root, final boolean framed) { return (Surface)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() { - public Object run() { - 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, Boolean.valueOf(framed) }); - } catch (Exception e) { - Log.info(this, e); - throw new LinkageError("error: " + e); - } - } else { - return new Java2Surface(root, framed); - } - } - }); - } + public Object run() { return __createSurface(root, framed); } }); } + // Inner Classes ////////////////////////////////////////////////////////////////// @@ -112,8 +87,7 @@ public class Java2 extends AWT { Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB), new Point(1, 1), "invisible"); - protected static class Java2Surface extends AWTSurface { - + public static class Java2Surface extends AWTSurface { public Java2Surface(Box root, boolean framed) { super(root, framed); } protected void _setMinimized(boolean b) { @@ -121,53 +95,12 @@ public class Java2 extends AWT { else if (b) frame.setState(java.awt.Frame.ICONIFIED); else frame.setState(java.awt.Frame.NORMAL); } - public void syncCursor() { if (cursor.equals("invisible")) window.setCursor(invisibleCursor); else super.syncCursor(); } } - 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 makeVisible() { } - - protected void _setMaximized(boolean m) { - if (frame == null) { - 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.info(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); - } - } - - public void mouseWheelMoved(MouseWheelEvent m) { - if (m.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) - VScroll(m.getUnitsToScroll()); - } - } - protected static class Java2PixelBuffer extends AWTPixelBuffer { private static ColorModel cm = Toolkit.getDefaultToolkit().getColorModel(); private static Hashtable emptyHashtable = new Hashtable(); @@ -194,6 +127,7 @@ public class Java2 extends AWT { } public Java2PixelBuffer(int w, int h) { + super(w,h); sm = cm.createCompatibleSampleModel(w, h); int numSamples = w * h * sm.getNumDataElements(); if (sm.getDataType() == DataBuffer.TYPE_USHORT) { @@ -235,7 +169,4 @@ public class Java2 extends AWT { g = i.getGraphics(); } } - - protected String getDescriptiveName() { return isJava14 ? "Java 1.4+ JVM" : "Java 1.2+ JVM"; } - } diff --git a/src/org/ibex/plat/Java4.java b/src/org/ibex/plat/Java4.java new file mode 100644 index 0000000..1611d4f --- /dev/null +++ b/src/org/ibex/plat/Java4.java @@ -0,0 +1,57 @@ +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +package org.ibex.plat; + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import java.awt.geom.*; +import java.net.*; +import java.util.*; +import org.ibex.util.*; +import java.lang.reflect.*; +import org.ibex.graphics.*; +import org.ibex.core.*; +import org.ibex.net.*; + +/** Platform class for Java 1.4 AWT implementations */ +public class Java4 extends Java2 { + protected String getDescriptiveName() { return "Java 1.4+ JVM"; } + public Java4() { + java.awt.Toolkit.getDefaultToolkit().setDynamicLayout(true); + + // Properties for Apple JDK 1.4 + System.setProperty("apple.awt.showGrowBox", "false"); + System.setProperty("apple.awt.graphics.EnableLazyDrawing", "40"); + System.setProperty("apple.awt.graphics.EnableLazyDrawing", "true"); + System.setProperty("apple.awt.window.position.forceSafeUserPositioning", "true"); + System.setProperty("apple.awt.window.position.forceSafeCreation", "true"); + } + protected Surface __createSurface(final Box root, final boolean framed) { return new Java4Surface(root, framed); } + public static class Java4Surface extends Java2Surface implements WindowStateListener, MouseWheelListener { + public Java4Surface(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 makeVisible() { } + protected void _setMaximized(boolean m) { + if (frame == null) Log.info(this, "JDK 1.4 can only maximize frames, not windows"); + else frame.setExtendedState(m ? Frame.MAXIMIZED_BOTH : (minimized ? Frame.ICONIFIED : Frame.NORMAL)); + } + protected void _setMinimized(boolean m) { + if (frame == null) Log.info(this, "JDK 1.4 can only minimize frames, not windows"); + else frame.setExtendedState(m ? Frame.ICONIFIED : (maximized ? Frame.MAXIMIZED_BOTH : Frame.NORMAL)); + } + public void windowStateChanged(WindowEvent e) { + if (e.getOldState() == e.getNewState()) return; + 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); + } + public void mouseWheelMoved(MouseWheelEvent m) { + if (m.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) VScroll(m.getUnitsToScroll()); } + } +} diff --git a/src/org/ibex/plat/Platform.java b/src/org/ibex/plat/Platform.java index 857a877..cc9eff9 100644 --- a/src/org/ibex/plat/Platform.java +++ b/src/org/ibex/plat/Platform.java @@ -60,8 +60,8 @@ public abstract class Platform { else if (os_name.startsWith("Darwin")) platform_class = "Darwin"; else platform_class = "X11"; } + else if (version.startsWith("1.4")) platform_class = "Java4"; else if (!version.startsWith("1.0") && !version.startsWith("1.1")) platform_class = "Java2"; - if (platform_class == null) { Log.error(Platform.class, "Unable to detect JVM"); criticalAbort("Unable to detect JVM"); -- 1.7.10.4