// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the GNU General Public License version 2 ("the License"). // You may not use this file except in compliance with the License. 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 most reasonable Java1.2+ Java2s */ public class Java2 extends AWT { protected String getDescriptiveName() { return "Java 1.2+ JVM"; } public Java2() { // disable the focus manager so we can intercept the tab key javax.swing.FocusManager.setCurrentManager(new javax.swing.FocusManager() { public void processKeyEvent(Component focusedComponent, KeyEvent anEvent) { } public void focusPreviousComponent(Component aComponent) { } public void focusNextComponent(Component aComponent) { } }); } /** 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; } }}); } 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() { return __createSurface(root, framed); } }); } // Inner Classes ////////////////////////////////////////////////////////////////// private static Cursor invisibleCursor = Toolkit.getDefaultToolkit().createCustomCursor(new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB), new Point(1, 1), "invisible"); public static class Java2Surface extends AWTSurface { public Java2Surface(Box root, boolean framed) { super(root, framed); } public PixelBuffer getPixelBuffer() { return pb==null?(pb=new Java2PixelBuffer(this)):pb; } protected void _setMinimized(boolean b) { 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); } public void syncCursor() { if (cursor.equals("invisible")) window.setCursor(invisibleCursor); else super.syncCursor(); } } 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; private WritableRaster raster = null; private SampleModel sm = null; private DataBuffer buf = null; private static int[] xs = new int[65535]; private static int[] ys = new int[65535]; private static GeneralPath gp = new GeneralPath(); // this doens't seem to work on Windows public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Mesh h, int rgb, int bg) { Image i = ((AWTGlyph)source).getImage(); Image i2 = ((AWTGlyph)source).i2; if (((AWTGlyph)source).i2 == null) { ((AWTGlyph)source).i2 = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB); i2 = ((AWTGlyph)source).i2; i2.getGraphics().drawImage(i, 0, 0, null); } Graphics2D g = (Graphics2D)((AWTGlyph)source).i2.getGraphics(); g.setComposite(AlphaComposite.SrcIn); g.setColor(new java.awt.Color((rgb & 0x00FF0000) >> 16, (rgb & 0x0000FF00) >> 8, (rgb & 0x000000FF))); g.fillRect(0, 0, i2.getWidth(null), i2.getHeight(null)); Graphics2D g2 = (Graphics2D)getGraphics(); if (a!=null) g2.drawImage(i2, new java.awt.geom.AffineTransform(a.a, a.b, a.c, a.d, a.e, a.f), null); else g2.drawImage(i2, 0, 0, null); } public void fill(Mesh p, org.ibex.graphics.Paint paint) { fillStroke(p, paint, true, false); } public void stroke(Mesh p, org.ibex.graphics.Paint paint) { fillStroke(p, paint, false, true); } public void fillStroke(Mesh p, org.ibex.graphics.Paint paint, boolean fill, boolean stroke) {/* if (g == null) g = getGraphics(); ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); int argb = ((org.ibex.graphics.Paint.SingleColorPaint)paint).color; g.setColor(new java.awt.Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF))); gp.reset(); gp.setWindingRule(GeneralPath.WIND_EVEN_ODD); for(int j=0; j 512 * 512 / 3) { buf = new DataBufferUShort(numSamples); } else { if (numSamples > sbank.length - bank_start) { bank_start = 0; sbank = new short[512 * 512]; } buf = new DataBufferUShort(sbank, numSamples, bank_start); bank_start += numSamples; } } else if (sm.getDataType() == DataBuffer.TYPE_BYTE) { if (bbank == null || numSamples > 512 * 512 / 3) { buf = new DataBufferByte(numSamples); } else { if (numSamples > bbank.length - bank_start) { bank_start = 0; bbank = new byte[512 * 512]; } buf = new DataBufferByte(bbank, numSamples, bank_start); bank_start += numSamples; } } else if (sm.getDataType() == DataBuffer.TYPE_INT) { if (ibank == null || numSamples > 512 * 512 / 3) { buf = new DataBufferInt(numSamples); } else { if (numSamples > ibank.length - bank_start) { bank_start = 0; ibank = new int[512 * 512]; } buf = new DataBufferInt(ibank, numSamples, bank_start); bank_start += numSamples; } } raster = Raster.createWritableRaster(sm, buf, null); i = new BufferedImage(cm, raster, false, emptyHashtable); g = i.getGraphics(); } } }