2002/04/30 21:16:33
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 06:46:37 +0000 (06:46 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 06:46:37 +0000 (06:46 +0000)
darcs-hash:20040130064637-2ba56-3021bed415d6745c77c795207e5ab453338ce177.gz

CHANGES
src/org/xwt/plat/Java12.java [moved from src/org/xwt/plat/Java2.java with 76% similarity]
src/org/xwt/plat/Java12.xml [moved from src/org/xwt/plat/Java2.xml with 90% similarity]
src/org/xwt/plat/Java14.java [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 8716e1f..a0e3961 100644 (file)
--- a/CHANGES
+++ b/CHANGES
               InnerFrame/InnerWindow and added exception handler to
               cope with new Java1.4 HeadlessException.
 
+30-Apr megacz Java12.java, Java12.xml, Java14.java: added Java14 support
+
 
 
               
similarity index 76%
rename from src/org/xwt/plat/Java2.java
rename to src/org/xwt/plat/Java12.java
index 1ff8764..a159eae 100644 (file)
@@ -14,7 +14,7 @@ import org.xwt.*;
 // FEATURE: Java 1.4 allows undecorated frames and can maximize windows
 
 /** Platform class for most reasonable Java1.2+ JVMs */
-public class Java2 extends AWT {
+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 {
@@ -23,28 +23,33 @@ public class Java2 extends AWT {
                     try {
                         return __getSocket(host, port, ssl);
                     } catch (Exception e) {
-                        if (Log.on) Log.log(Java2.class, "Error attempting to create socket");
-                        if (Log.on) Log.log(Java2.class, e);
+                        if (Log.on) Log.log(Java12.class, "Error attempting to create socket");
+                        if (Log.on) Log.log(Java12.class, e);
                         return null;
                     }
                 }
             });
     }
     
-    protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new Java2DoubleBuffer(w, h); }
+    protected DoubleBuffer _createDoubleBuffer(int w, int h, Surface owner) { return new Java12DoubleBuffer(w, h); }
     protected Surface _createSurface(final Box root, final boolean framed) {
         return (Surface)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
-                public Object run() { return new Java2Surface(root, framed); }
+                public Object run() { return new Java12Surface(root, framed); }
             });
     }
 
     // Inner Classes //////////////////////////////////////////////////////////////////
 
-    protected static class Java2Surface extends AWTSurface {
+    protected static class Java12Surface extends AWTSurface {
         
-        public Java2Surface(Box root, boolean framed) { super(root, framed); }
+        public Java12Surface(Box root, boolean framed) { super(root, framed); }
         public void blit(DoubleBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
-            if (ourGraphics == null) ourGraphics = window.getGraphics();
+            if (ourGraphics == null) {
+                ourGraphics = window.getGraphics();
+
+                // sometimes jdk1.4 doesn't set the clip properly when we're in the middle of a resize
+                ourGraphics.setClip(insets.left, insets.top, width + insets.left, height + insets.top);
+            }
             _doDrawImage(ourGraphics, ((AWTDoubleBuffer)s).i, dx + insets.left, dy + insets.top, dx2 + insets.left, dy2 + insets.top,
                          sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null);
         }
@@ -59,7 +64,7 @@ public class Java2 extends AWT {
         }
     }
 
-    protected static class Java2DoubleBuffer extends AWTDoubleBuffer {
+    protected static class Java12DoubleBuffer extends AWTDoubleBuffer {
         private static ColorModel cm = Toolkit.getDefaultToolkit().getColorModel();
         private static Hashtable emptyHashtable = new Hashtable();
         private static short[] sbank = null;
@@ -71,42 +76,42 @@ public class Java2 extends AWT {
             _doDrawImage(g, ((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
         }
         
-        public Java2DoubleBuffer(int w, int h) {
-            super(w, h);
+        public Java12DoubleBuffer(int w, int h) {
             SampleModel sm = cm.createCompatibleSampleModel(w, h);
+            int numSamples = w * h * sm.getNumDataElements();
             DataBuffer buf = null;
             if (sm.getDataType() == DataBuffer.TYPE_USHORT) {
-                if (sbank == null || w * h > 512 * 512 / 3) {
-                    buf = new DataBufferUShort(w * h);
+                if (sbank == null || numSamples > 512 * 512 / 3) {
+                    buf = new DataBufferUShort(numSamples);
                 } else {
-                    if (w * h > sbank.length - bank_start) {
+                    if (numSamples > sbank.length - bank_start) {
                         bank_start = 0;
                         sbank = new short[512 * 512];
                     }
-                    buf = new DataBufferUShort(sbank, w * h, bank_start);
-                    bank_start += w * h;
+                    buf = new DataBufferUShort(sbank, numSamples, bank_start);
+                    bank_start += numSamples;
                 }
             } else if (sm.getDataType() == DataBuffer.TYPE_BYTE) {
-                if (bbank == null || w * h > 512 * 512 / 3) {
-                    buf = new DataBufferByte(w * h);
+                if (bbank == null || numSamples > 512 * 512 / 3) {
+                    buf = new DataBufferByte(numSamples);
                 } else {
-                    if (w * h > bbank.length - bank_start) {
+                    if (numSamples > bbank.length - bank_start) {
                         bank_start = 0;
                         bbank = new byte[512 * 512];
                     }
-                    buf = new DataBufferByte(bbank, w * h, bank_start);
-                    bank_start += w * h;
+                    buf = new DataBufferByte(bbank, numSamples, bank_start);
+                    bank_start += numSamples;
                 }
             } else if (sm.getDataType() == DataBuffer.TYPE_INT) {
-                if (ibank == null || w * h > 512 * 512 / 3) {
-                    buf = new DataBufferInt(w * h);
+                if (ibank == null || numSamples > 512 * 512 / 3) {
+                    buf = new DataBufferInt(numSamples);
                 } else {
-                    if (w * h > ibank.length - bank_start) {
+                    if (numSamples > ibank.length - bank_start) {
                         bank_start = 0;
                         ibank = new int[512 * 512];
                     }
-                    buf = new DataBufferInt(ibank, w * h, bank_start);
-                    bank_start += w * h;
+                    buf = new DataBufferInt(ibank, numSamples, bank_start);
+                    bank_start += numSamples;
                 }
             }
             i = new BufferedImage(cm, Raster.createWritableRaster(sm, buf, null), false,  emptyHashtable);
@@ -154,9 +159,9 @@ public class Java2 extends AWT {
         }
     }
 
-    protected org.xwt.Weak _getWeak(Object o) { return new Java2Weak(o); }
-    private static class Java2Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
-        public Java2Weak(Object o) { super(o); }
+    protected org.xwt.Weak _getWeak(Object o) { return new Java12Weak(o); }
+    private static class Java12Weak extends java.lang.ref.WeakReference implements org.xwt.Weak {
+        public Java12Weak(Object o) { super(o); }
     }
 
     private String __getClipBoard() { return super._getClipBoard(); }
similarity index 90%
rename from src/org/xwt/plat/Java2.xml
rename to src/org/xwt/plat/Java12.xml
index c1b78df..cb4eafe 100644 (file)
@@ -27,7 +27,8 @@
                 <include name='org/bouncycastle/**/*.class'/>
                 <include name='jazz/**/*.class'/>
                 <include name='org/xwt/plat/AWT*.class'/>
-                <include name='org/xwt/plat/Java2*.class'/>
+                <include name='org/xwt/plat/Java12*.class'/>
+                <include name='org/xwt/plat/Java14*.class'/>
                 <include name='org/xwt/plat/MacOSX*.class'/>
             </fileset>
         </copy>
diff --git a/src/org/xwt/plat/Java14.java b/src/org/xwt/plat/Java14.java
new file mode 100644 (file)
index 0000000..cd90e8c
--- /dev/null
@@ -0,0 +1,58 @@
+// Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL]
+package org.xwt.plat;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.image.*;
+import java.awt.datatransfer.*;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import org.xwt.util.*;
+import org.xwt.*;
+
+/** Platform class for most reasonable Java1.4+ JVMs */
+public class Java14 extends Java12 {
+
+    protected String getDescriptiveName() { return "Java 1.4+ JVM"; }
+    protected boolean _supressDirtyOnResize() { return false; }
+
+    public Java14() {
+        java.awt.Toolkit.getDefaultToolkit().setDynamicLayout(true);
+    }
+
+    protected Surface _createSurface(final Box root, final boolean framed) {
+        return (Surface)java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
+                public Object run() { return new Java14Surface(root, framed); }
+            });
+    }
+
+    protected static class Java14Surface extends Java12Surface implements WindowStateListener {
+        public Java14Surface(Box root, boolean framed) {
+            super(root, framed);
+            window.addWindowStateListener(this);
+        }
+        protected void _setMaximized(boolean m) {
+            if (frame == null) {
+                if (Log.on) Log.log(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.log(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);
+            }
+        }
+    }
+        
+}