public AWTPicture(int[] b, int w, int h) {
data = b;
Image img = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, cmodel, b, 0, w));
- MediaTracker mediatracker = new MediaTracker(new Canvas());
+ MediaTracker mediatracker = new MediaTracker(new Canvas());
mediatracker.addImage(img, 1);
try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
mediatracker.removeImage(img);
}
protected ImageDecoder _decodeJPEG(InputStream is, String name) {
- try {
- Image i = Toolkit.getDefaultToolkit().createImage(org.xwt.Resources.isToByteArray(is));
- MediaTracker mediatracker = new MediaTracker(new Canvas());
+ try {
+ Image i = Toolkit.getDefaultToolkit().createImage(org.xwt.Resources.isToByteArray(is));
+ MediaTracker mediatracker = new MediaTracker(new Canvas());
mediatracker.addImage(i, 1);
- try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
- mediatracker.removeImage(i);
- final int width = i.getWidth(null);
- final int height = i.getHeight(null);
- final int[] data = new int[width * height];
- PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
- pg.grabPixels();
- if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
- Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name);
- return null;
- }
- return new ImageDecoder() {
- public int getWidth() { return width; }
- public int getHeight() { return height; }
- public int[] getData() { return data; }
- };
- } catch (Exception e) {
- Log.log(this, "Exception caught while decoding JPEG image " + name);
- Log.log(this, e);
- return null;
- }
+ try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
+ mediatracker.removeImage(i);
+ final int width = i.getWidth(null);
+ final int height = i.getHeight(null);
+ final int[] data = new int[width * height];
+ PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
+ pg.grabPixels();
+ if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
+ Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name);
+ return null;
+ }
+ return new ImageDecoder() {
+ public int getWidth() { return width; }
+ public int getHeight() { return height; }
+ public int[] getData() { return data; }
+ };
+ } catch (Exception e) {
+ Log.log(this, "Exception caught while decoding JPEG image " + name);
+ Log.log(this, e);
+ return null;
+ }
}
// Font Handling Stuff //////////////////////////////////////////////////////////
/** Platform implementation for Carbon UI on a POSIX-compliant OS (ie Mac OS X) */
public class Carbon extends POSIX {
- /** hashtable of all OS X fonts; key is an XWT font name, value is WrappedRawData which stores an ATSFontRef.
- * Initialized by natInit(). */
- static Hashtable nativeFontCache = new Hashtable();
+ /** hashtable of all OS X fonts; key is an XWT font name, value is WrappedRawData which stores an ATSFontRef.
+ * Initialized by natInit(). */
+ static Hashtable nativeFontCache = new Hashtable();
- /** Cache of ATSUStyle objects; key is an XWT font spec, value is WrappedRawData which stores an ATSUStyle.
- * According to an Apple technote, caching the style bjects can really increase performance. */
- static Hashtable atsuStyleCache = new Hashtable();
+ /** Cache of ATSUStyle objects; key is an XWT font spec, value is WrappedRawData which stores an ATSUStyle.
+ * According to an Apple technote, caching the style bjects can really increase performance. */
+ static Hashtable atsuStyleCache = new Hashtable();
- /** List of all XWT font specs. Initialized by init(). */
- static String[] fontList = null;
+ /** List of all XWT font specs. Initialized by init(). */
+ static String[] fontList = null;
// General Methods ///////////////////////////////////////////////////////
protected native int _getScreenHeight();
protected native String _getClipBoard();
protected native void _setClipBoard(String s);
- static String defaultFontName = "lucida_grande";
+ static String defaultFontName = "lucida_grande";
protected String _getDefaultFont() { return defaultFontName + "13"; }
- protected native int _stringWidth(String fontSpec, String text);
+ protected native int _stringWidth(String fontSpec, String text);
protected native int _getMaxAscent(String font);
protected native int _getMaxDescent(String font);
protected boolean _needsAutoDoubleClick() { return false; }
- /** Returns the ATSUStyle associated with the given XWT font spec.
- * This method first checks its internal cache before creating the
- * ATSUStyle object from scratch. */
- protected RawData _getATSUStyle( String fontSpec ) {
- WrappedRawData ret = null;
- ret = (WrappedRawData) atsuStyleCache.get( fontSpec );
- if (ret != null) return ret.wrapee;
-
- Platform.ParsedFont pf = new Platform.ParsedFont( fontSpec );
-
- // Find the font
- if (pf.name.equals("serif")) pf.name = "lucida_grande";
- else if (pf.name.equals("sansserif")) pf.name = "helvetica";
- else if (pf.name.equals("monospace")) pf.name = "courier";
- else if (pf.name.equals("dialog")) pf.name = "lucida_grande";
- else if (pf.name.equals("tty")) pf.name = "courier";
-
- // Find the ATSFontRef
- WrappedRawData fontRef = (WrappedRawData) nativeFontCache.get( pf.name );
- // If we couldn't find the font, use the default font
- if ( fontRef == null ) fontRef = (WrappedRawData) nativeFontCache.get( defaultFontName );
- if ( fontRef == null ) throw new Error( "Default font cannot be found" );
-
- // Create the ATSUStyle object
- ret = new WrappedRawData( _createATSUStyle( fontRef.wrapee, pf.size, pf.bold, pf.italic, pf.underline ) );
-
- // Map this font spec to the ATSFontRef to optimize future requests
- atsuStyleCache.put( fontSpec, ret );
+ /** Returns the ATSUStyle associated with the given XWT font spec.
+ * This method first checks its internal cache before creating the
+ * ATSUStyle object from scratch. */
+ protected RawData _getATSUStyle( String fontSpec ) {
+ WrappedRawData ret = null;
+ ret = (WrappedRawData) atsuStyleCache.get( fontSpec );
+ if (ret != null) return ret.wrapee;
+
+ Platform.ParsedFont pf = new Platform.ParsedFont( fontSpec );
+
+ // Find the font
+ if (pf.name.equals("serif")) pf.name = "lucida_grande";
+ else if (pf.name.equals("sansserif")) pf.name = "helvetica";
+ else if (pf.name.equals("monospace")) pf.name = "courier";
+ else if (pf.name.equals("dialog")) pf.name = "lucida_grande";
+ else if (pf.name.equals("tty")) pf.name = "courier";
+
+ // Find the ATSFontRef
+ WrappedRawData fontRef = (WrappedRawData) nativeFontCache.get( pf.name );
+ // If we couldn't find the font, use the default font
+ if ( fontRef == null ) fontRef = (WrappedRawData) nativeFontCache.get( defaultFontName );
+ if ( fontRef == null ) throw new Error( "Default font cannot be found" );
+
+ // Create the ATSUStyle object
+ ret = new WrappedRawData( _createATSUStyle( fontRef.wrapee, pf.size, pf.bold, pf.italic, pf.underline ) );
+
+ // Map this font spec to the ATSFontRef to optimize future requests
+ atsuStyleCache.put( fontSpec, ret );
return ret.wrapee;
- }
+ }
- /** Creates an ATSUStyle object with the specified attributes. */
- protected native RawData _createATSUStyle( RawData fontRef, int fontSize, boolean isBold, boolean isItalic, boolean isUnderline );
+ /** Creates an ATSUStyle object with the specified attributes. */
+ protected native RawData _createATSUStyle( RawData fontRef, int fontSize, boolean isBold, boolean isItalic, boolean isUnderline );
- /** Called once XWT is initialized and the application is running. On Mac OS X this calls
- * RunApplicationEventLoop(). */
- protected native void _running();
-
- /** dumps a list of Mac OS X font strings. TODO: Will this be sufficient? */
+ /** Called once XWT is initialized and the application is running. On Mac OS X this calls
+ * RunApplicationEventLoop(). */
+ protected native void _running();
+
+ /** dumps a list of Mac OS X font strings. TODO: Will this be sufficient? */
//private native String[] listNativeFonts();
- /** translates a font string into an ATSUFontRef? TODO: Will this be sufficient? */
+ /** translates a font string into an ATSUFontRef? TODO: Will this be sufficient? */
//public static native gnu.gcj.RawData fontStringToStruct(String s);
public Carbon() { }
public void init() {
- natInit();
+ natInit();
- // nativeFontCache contains font NAMES. Each font exists as an outline font
- // which can be any size, plus can have real or simulated bold or italic
+ // nativeFontCache contains font NAMES. Each font exists as an outline font
+ // which can be any size, plus can have real or simulated bold or italic
fontList = new String[nativeFontCache.size()*4];
Enumeration e = nativeFontCache.keys();
for(int i=0; e.hasMoreElements(); i+=4) {
- String fontName = (String)e.nextElement() + "0";
-
- fontList[i] = fontName;
- fontList[i+1] = fontName + "i";
- fontList[i+2] = fontName + "b";
- fontList[i+3] = fontName + "bi";
- }
-
- // Make sure that the default font exists
- if ( _getATSUStyle( _getDefaultFont() ) == null ) throw new Error( "Default font does not exist" );
- }
- private native void natInit();
-
- /** so we can put ATSUStyles and ATSFontRefs into Hashtables */
+ String fontName = (String)e.nextElement() + "0";
+
+ fontList[i] = fontName;
+ fontList[i+1] = fontName + "i";
+ fontList[i+2] = fontName + "b";
+ fontList[i+3] = fontName + "bi";
+ }
+
+ // Make sure that the default font exists
+ if ( _getATSUStyle( _getDefaultFont() ) == null ) throw new Error( "Default font does not exist" );
+ }
+ private native void natInit();
+
+ /** so we can put ATSUStyles and ATSFontRefs into Hashtables */
private static class WrappedRawData {
public RawData wrapee = null;
public WrappedRawData(RawData r) { wrapee = r; }
/** Implements a Surface as an Carbon Window */
public static class CarbonSurface extends Surface {
- /** The WindowRef that implements this Surface. */
- gnu.gcj.RawData window = null;
- /** The CGContextRef. TODO: How do we get this??? */
+ /** The WindowRef that implements this Surface. */
+ gnu.gcj.RawData window = null;
+ /** The CGContextRef. TODO: How do we get this??? */
gnu.gcj.RawData gc = null;
public native void setInvisible(boolean i);
int height;
int[] data = null;
- /** A CGImageRef of the picture. */
- RawData image = null;
-
+ /** A CGImageRef of the picture. */
+ RawData image = null;
+
public int getWidth() { return width; }
public int getHeight() { return height; }
- public native void natInit();
- public native void finalize();
-
+ public native void natInit();
+ public native void finalize();
+
public CarbonPicture(int[] data, int w, int h) {
this.data = data;
this.width = w;
this.height = h;
- natInit();
+ natInit();
}
}
int width;
int height;
- /** A pointer to the raw bitmap data. */
- RawData bitmapData;
- /** A CGBitmapContextRef. */
- RawData gc;
- /** A CGImageRef which represents the CGBitmapContext. */
- RawData image;
-
+ /** A pointer to the raw bitmap data. */
+ RawData bitmapData;
+ /** A CGBitmapContextRef. */
+ RawData gc;
+ /** A CGImageRef which represents the CGBitmapContext. */
+ RawData image;
+
public int getWidth() { return width; }
public int getHeight() { return height; }
public CarbonDoubleBuffer(int w, int h) {
- this.width = w;
- this.height = h;
- natInit();
- }
+ this.width = w;
+ this.height = h;
+ natInit();
+ }
public native void setClip(int x, int y, int x2, int y2);
public native void drawPicture(Picture source, int x, int y);
public native void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2);
public native void fillRect(int x, int y, int x2, int y2, int color);
public native void drawString(String font, String text, int x, int y, int color);
- public native void natInit();
+ public native void natInit();
public native void finalize();
}
private boolean isJava14 = false;
protected boolean _supressDirtyOnResize() {
- return (isJava14 && !System.getProperty("os.name", "").equals("Mac OS X"))? false : true;
+ return (isJava14 && !System.getProperty("os.name", "").equals("Mac OS X"))? false : true;
}
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, 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.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.log(this, "Exception while trying to enable AWT Dynamic Layout");
+ Log.log(this, e);
+ }
+ }
javax.swing.FocusManager.setCurrentManager(new javax.swing.FocusManager() {
public void processKeyEvent(Component focusedComponent, KeyEvent anEvent) { }
public void focusPreviousComponent(Component aComponent) { }
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, new Boolean(framed) });
- } catch (Exception e) {
- Log.log(this, e);
- throw new LinkageError("error: " + e);
- }
- } else {
- return new Java2Surface(root, framed);
- }
- }
+ 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.log(this, e);
+ throw new LinkageError("error: " + e);
+ }
+ } else {
+ return new Java2Surface(root, framed);
+ }
+ }
});
}
protected String getDescriptiveName() { return isJava14 ? "Java 1.4+ JVM" : "Java 1.2+ JVM"; }
protected void _newBrowserWindow(String url) {
- /*
- FIXME
+ /*
+ FIXME
if (Main.applet == null) {
if (Log.on) Log.log(this, "Main.applet is null; cannot invoke showDocument()");
return;
} catch (MalformedURLException e) {
if (Log.on) Log.log(this, e);
}
- */
+ */
}
}