2003/06/16 08:03:16
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:01:17 +0000 (07:01 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:01:17 +0000 (07:01 +0000)
darcs-hash:20040130070117-2ba56-a0274a5eaf53b487003439223a5c9cf395bbaa53.gz

src/org/xwt/plat/AWT.java
src/org/xwt/plat/Carbon.java
src/org/xwt/plat/GCJ.java
src/org/xwt/plat/Java2.java
src/org/xwt/plat/Win32.java
src/org/xwt/plat/X11.java
src/org/xwt/util/Vec.java

index 43f2fba..7849cf7 100644 (file)
@@ -130,7 +130,7 @@ public class AWT extends Platform {
         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);
@@ -410,31 +410,31 @@ public class AWT extends Platform {
     }
 
     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 //////////////////////////////////////////////////////////
index e7a6125..77d4dd9 100644 (file)
@@ -15,16 +15,16 @@ import org.xwt.*;
 /** 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 ///////////////////////////////////////////////////////
 
@@ -38,81 +38,81 @@ public class Carbon extends POSIX {
     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; }
@@ -123,9 +123,9 @@ public class Carbon extends POSIX {
     /** 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);
@@ -156,20 +156,20 @@ public class Carbon extends POSIX {
         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();
         }
 
     }
@@ -179,28 +179,28 @@ public class Carbon extends POSIX {
         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();
     }
 
index 38d9ec9..2db7961 100644 (file)
@@ -26,27 +26,27 @@ public abstract class GCJ extends Platform {
         
     // FIXME
     protected ImageDecoder _decodeJPEG(InputStream is, String name) {
-       try {
-           return new JPEG(is);
-       } catch (Exception e) {
-           Log.log(this, "Exception while decoding JPEG image " + name);
-           Log.log(this, e);
-           return null;
-       }
+        try {
+            return new JPEG(is);
+        } catch (Exception e) {
+            Log.log(this, "Exception while decoding JPEG image " + name);
+            Log.log(this, e);
+            return null;
+        }
     }
 
     /** Converts an InputStream carrying a JPEG image into an ARGB int[] */
     private static class JPEG implements ImageDecoder {
-       int[] data;
-       byte[] buffer;
-       int width, height;
-       InputStream is;
-       
-       public final int[] getData() { return data; }
-       public final int getWidth() { return width; }
-       public final int getHeight() { return height; }
-       private JPEG(InputStream is) { this.is = is; nativeDecompress(); buffer = null; }
-       private native void nativeDecompress();
+        int[] data;
+        byte[] buffer;
+        int width, height;
+        InputStream is;
+        
+        public final int[] getData() { return data; }
+        public final int getWidth() { return width; }
+        public final int getHeight() { return height; }
+        private JPEG(InputStream is) { this.is = is; nativeDecompress(); buffer = null; }
+        private native void nativeDecompress();
     }
 
 }
index 1b54053..9b413ff 100644 (file)
@@ -18,26 +18,26 @@ public class Java2 extends AWT {
 
     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) { }
@@ -107,20 +107,20 @@ public class Java2 extends AWT {
     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);
+                    }
+                }
             });
     }
 
@@ -282,8 +282,8 @@ public class Java2 extends AWT {
     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;
@@ -294,7 +294,7 @@ public class Java2 extends AWT {
         } catch (MalformedURLException e) {
             if (Log.on) Log.log(this, e);
         }
-       */
+        */
     }
 
 }
index 36652fd..0260252 100644 (file)
@@ -84,13 +84,13 @@ public class Win32 extends GCJ {
         int maxDescent;
     }
 
-       /** Called once XWT is initialized and the application is running. On Win32, we need to block the main thread
-       *       on a semaphore because if the main thread exits, the whole application quits. */
-       protected void _running() {
-               // gcj-win32 exit()'s when the original thread dies, so we have to deadlock ourselves
-               if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore");
-               new org.xwt.util.Semaphore().block();
-       }
+        /** Called once XWT is initialized and the application is running. On Win32, we need to block the main thread
+        *       on a semaphore because if the main thread exits, the whole application quits. */
+        protected void _running() {
+                // gcj-win32 exit()'s when the original thread dies, so we have to deadlock ourselves
+                if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore");
+                new org.xwt.util.Semaphore().block();
+        }
 
     /** takes a parsed font and finds the closest platform-specific font */
     static native Win32Font mapFont(Platform.ParsedFont pf);
index c6b42ad..49fd258 100644 (file)
@@ -54,7 +54,7 @@ public class X11 extends POSIX {
 
     public X11() { }
     public void init() {
-       natInit();
+        natInit();
         (new Thread() { public void run() { eventThread(); } }).start();
         initFonts();
     }
index 23f196f..803ce3f 100644 (file)
@@ -47,7 +47,7 @@ public final class Vec implements Serializable {
     }
 
     public Object peek() {
-       return lastElement();
+        return lastElement();
     }
 
     public Object elementAt(int i) {
@@ -61,9 +61,9 @@ public final class Vec implements Serializable {
 
     public void push(Object o) { addElement(o); }
     public Object pop() {
-       Object ret = lastElement();
-       if (size > 0) store[size--] = null;
-       return ret;
+        Object ret = lastElement();
+        if (size > 0) store[size--] = null;
+        return ret;
     }
 
     public int size() { return size; }