Hi! This patch implements an ImageProducer for XImage.getSource. It also fix XGraphicsDevice to use the latest Escher stuff.
Thanks, Mario 2008-09-01 Mario Torre <[EMAIL PROTECTED]> * gnu/java/awt/peer/x/XGraphicsDevice.java (getDisplay): fix to support new Escher API. * gnu/java/awt/peer/x/XImage.java (getSource): method implemented. * gnu/java/awt/peer/x/XImage.java (XImageProducer): implement ImageProducer for getSource. -- Mario Torre, Software Developer, http://www.jroller.com/neugens/ aicas Allerton Interworks Computer Automated Systems GmbH Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany http://www.aicas.com * Tel: +49-721-663 968-53 pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF Fingerprint: BA39 9666 94EC 8B73 27FA FC7C 4086 63E3 80F2 40CF USt-Id: DE216375633, Handelsregister HRB 109481, AG Mannheim Geschäftsführer: Dr. James J. Hunt Please, support open standards: http://opendocumentfellowship.org/petition/ http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0 #P classpath Index: gnu/java/awt/peer/x/XImage.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/XImage.java,v retrieving revision 1.4 diff -u -r1.4 XImage.java --- gnu/java/awt/peer/x/XImage.java 30 Apr 2007 20:30:56 -0000 1.4 +++ gnu/java/awt/peer/x/XImage.java 1 Sep 2008 16:06:38 -0000 @@ -39,13 +39,19 @@ package gnu.java.awt.peer.x; import gnu.x11.Pixmap; +import gnu.x11.image.ZPixmap; import java.awt.Graphics; import java.awt.GraphicsEnvironment; import java.awt.Image; + +import java.awt.image.ColorModel; +import java.awt.image.ImageConsumer; import java.awt.image.ImageObserver; import java.awt.image.ImageProducer; + import java.util.Hashtable; +import java.util.Vector; public class XImage extends Image @@ -75,8 +81,7 @@ public ImageProducer getSource() { - // TODO: Implement this. - throw new UnsupportedOperationException("Not yet implemented."); + return new XImageProducer(); } /** @@ -108,4 +113,71 @@ { pixmap.free(); } + + protected class XImageProducer implements ImageProducer + { + private Vector<ImageConsumer> consumers = new Vector<ImageConsumer>(); + + @Override + public void addConsumer(ImageConsumer ic) + { + if (ic != null && !isConsumer(ic)) + this.consumers.add(ic); + } + + @Override + public boolean isConsumer(ImageConsumer ic) + { + return this.consumers.contains(ic); + } + + @Override + public void removeConsumer(ImageConsumer ic) + { + if (ic != null) + this.consumers.remove(ic); + } + + @Override + public void requestTopDownLeftRightResend(ImageConsumer ic) + { + /* just ignore the call */ + } + + @Override + public void startProduction(ImageConsumer ic) + { + this.addConsumer(ic); + + for (ImageConsumer consumer : this.consumers) + { + int width = XImage.this.getWidth(null); + int height = XImage.this.getHeight(null); + + XGraphics2D graphics = (XGraphics2D) getGraphics(); + ColorModel model = graphics.getColorModel(); + graphics.dispose(); + + ZPixmap zpixmap = (ZPixmap) + XImage.this.pixmap.image(0, 0, width, height, + 0xffffffff, + gnu.x11.image.Image.Format.ZPIXMAP); + + int size = zpixmap.get_data_length(); + System.out.println("size: " + size + ", w = " + width + ", h = " + height); + + int [] pixel = new int[size]; + for (int i = 0; i < size; i++) + pixel[i] = zpixmap.get_data_element(i); + + consumer.setHints(ImageConsumer.SINGLEPASS); + + consumer.setDimensions(width, height); + consumer.setPixels(0, 0, width, height, model, pixel, 0, width); + consumer.imageComplete(ImageConsumer.STATICIMAGEDONE); + } + + System.out.println("done!"); + } + } } Index: gnu/java/awt/peer/x/XGraphicsDevice.java =================================================================== RCS file: /sources/classpath/classpath/gnu/java/awt/peer/x/XGraphicsDevice.java,v retrieving revision 1.2 diff -u -r1.2 XGraphicsDevice.java --- gnu/java/awt/peer/x/XGraphicsDevice.java 30 Apr 2007 20:30:56 -0000 1.2 +++ gnu/java/awt/peer/x/XGraphicsDevice.java 1 Sep 2008 16:06:38 -0000 @@ -39,6 +39,7 @@ import gnu.classpath.SystemProperties; import gnu.x11.Display; +import gnu.x11.EscherServerConnectionException; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; @@ -127,9 +128,16 @@ Socket socket = createLocalSocket(); if (socket != null) { - display = new Display(socket, "localhost", - displayName.display_no, - displayName.screen_no); + try + { + display = new Display(socket, "localhost", + displayName.display_no, + displayName.screen_no); + } + catch (EscherServerConnectionException e) + { + throw new RuntimeException(e.getCause()); + } } } @@ -137,8 +145,17 @@ // when the connection is probably remote or when we couldn't load // the LocalSocket class stuff. if (display == null) - display = new Display(displayName); - + { + try + { + display = new Display(displayName); + } + catch (EscherServerConnectionException e) + { + throw new RuntimeException(e.getCause()); + } + } + eventPump = new XEventPump(display); } return display;