import java.util.*;
import org.xwt.util.*;
import org.xwt.*;
+import java.lang.reflect.*;
-// FEATURE: Java 1.4 allows undecorated frames and can maximize windows
/** Platform class for most reasonable Java1.2+ JVMs */
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 {
+ /** 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 HTTP.ProxyInfo _detectProxy() {
+ return (HTTP.ProxyInfo)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
+ public Object run() {
+ try {
+ HTTP.ProxyInfo pi = new HTTP.ProxyInfo();
+
+ 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.xwt.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.log(this, "exception while querying sun.plugin.protocol.PluginProxyHandler: " + e);
+ 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() {
public Object run() {
try {
- return __getSocket(host, port, ssl);
+ return __getSocket(host, port, ssl, negotiate);
} catch (Exception e) {
if (Log.on) Log.log(Java12.class, "Error attempting to create socket");
if (Log.on) Log.log(Java12.class, e);
/** used to avoid garbage creation with getClipBounds() */
private static Rectangle clipBounds = new Rectangle();
- // FEATURE: performance hits here are a result of getSubimage() -- if we don't call it, Graphics2D will. It creates tons of int[]s, as well as
- // BufferedImage instances which get stored in an array deep inside Graphics2D, which the JDK does a LINEAR SCAN through. Aarrgh.
- // This is rumored to be fixed in JDK 1.4.
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;
-
- if (dx2 - dx1 != sx2 - sx1 || dy2 - dy1 != sy2 - sy1)
- g.drawImage(i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, o);
- else {
- // fastpath for images that do not need to be scaled
- if (i instanceof BufferedImage) {
- BufferedImage b = (BufferedImage)i;
-
- if (dx2 - dx1 != b.getWidth(null) || dy2 - dy1 != b.getHeight(null)) {
- b = b.getSubimage(sx1, sy1, sx2 - sx1, sy2 - sy1);
- sx2 = sx2 - sx1;
- sy2 = sy2 - sy1;
- sx1 = 0;
- sy1 = 0;
- }
- g.drawImage(b, dx1, dy1, o);
-
- } else {
-
- // workaround for a wierd JDK bug
- boolean skip = false;
- try { g.getClipBounds(clipBounds); } catch (NullPointerException n) { skip = true; }
-
- g.clipRect(dx1, dy1, dx2 - dx1, dy2 - dy1);
- g.drawImage(i, dx1 - sx1, dy1 - sy1, o);
-
- if (!skip) g.setClip(clipBounds.x, clipBounds.y, clipBounds.x + clipBounds.width, clipBounds.y + clipBounds.height);
- }
- }
+ g.drawImage(i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, o);
}
protected org.xwt.Weak _getWeak(Object o) { return new Java12Weak(o); }