2003/12/03 16:07:05
[org.ibex.core.git] / src / org / xwt / plat / Java2.java
index d2785a9..10b003f 100644 (file)
@@ -117,7 +117,7 @@ public class Java2 extends AWT {
                                                        new Point(1, 1), "invisible");
 
     protected static class Java2Surface extends AWTSurface {
-        
+
         public Java2Surface(Box root, boolean framed) { super(root, framed); }
 
         protected void _setMinimized(boolean b) {
@@ -132,12 +132,13 @@ public class Java2 extends AWT {
         }
     }
 
-    protected static class Java14Surface extends Java2Surface implements WindowStateListener {
+    protected static class Java14Surface extends Java2Surface implements WindowStateListener, MouseWheelListener {
         public Java14Surface(Box root, boolean framed) {
             super(root, true);
             // JDK1.4 doesn't like java.lang.Window's...
             if (!framed) ((Frame)window).setUndecorated(true);
             window.addWindowStateListener(this);
+            window.addMouseWheelListener(this);
             window.setVisible(true);
         }
 
@@ -164,6 +165,11 @@ public class Java2 extends AWT {
                     Maximized(false);
             }
         }
+
+        public void mouseWheelMoved(MouseWheelEvent m) {
+            // TODO: Uncomment this once Scroll is implemented in the core
+            //if(m.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { Scroll(m.getUnitsToScroll()); }
+        }
     }
 
     protected static class Java2PixelBuffer extends AWTPixelBuffer {
@@ -173,11 +179,26 @@ public class Java2 extends AWT {
         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;
+
+        public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+            AWTPicture src = (AWTPicture)source;
+            Graphics2D g2 = (Graphics2D)i.getGraphics();
+            g2.setComposite(AlphaComposite.DstOut);
+            g2.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
+            g2.drawImage(src.i, dx, dy, null);
+            g2.setComposite(AlphaComposite.DstOver);
+            g2.setColor(new Color((rgb & 0x00FF0000) >> 16, (rgb & 0x0000FF00) >> 8, (rgb & 0x000000FF)));
+            g2.fillRect(dx, dy, cx2 - dx, cy2 - dy);
+            g2.drawImage(i, 0, 0, null);
+            g2.setClip(0, 0, i.getWidth(null), i.getHeight(null));
+        }
 
         public Java2PixelBuffer(int w, int h) {
-            SampleModel sm = cm.createCompatibleSampleModel(w, h);
+            sm = cm.createCompatibleSampleModel(w, h);
             int numSamples = w * h * sm.getNumDataElements();
-            DataBuffer buf = null;
             if (sm.getDataType() == DataBuffer.TYPE_USHORT) {
                 if (sbank == null || numSamples > 512 * 512 / 3) {
                     buf = new DataBufferUShort(numSamples);
@@ -212,7 +233,8 @@ public class Java2 extends AWT {
                     bank_start += numSamples;
                 }
             }
-            i = new BufferedImage(cm, Raster.createWritableRaster(sm, buf, null), false,  emptyHashtable);
+            raster = Raster.createWritableRaster(sm, buf, null);
+            i = new BufferedImage(cm, raster, false,  emptyHashtable);
             g = i.getGraphics();
         }
     }