1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43:
44: import ;
45: import ;
46: import ;
47:
48: import ;
49: import ;
50: import ;
51: import ;
52:
53: import ;
54: import ;
55:
56: public class XImage
57: extends Image
58: {
59:
60: Pixmap pixmap;
61:
62: private Hashtable properties;
63:
64: XImage(int w, int h)
65: {
66: GraphicsEnvironment env =
67: GraphicsEnvironment.getLocalGraphicsEnvironment();
68: XGraphicsDevice dev = (XGraphicsDevice) env.getDefaultScreenDevice();
69: pixmap = new Pixmap(dev.getDisplay(), w, h);
70: }
71:
72: public int getWidth(ImageObserver observer)
73: {
74: return pixmap.width;
75: }
76:
77: public int getHeight(ImageObserver observer)
78: {
79: return pixmap.height;
80: }
81:
82: public ImageProducer getSource()
83: {
84: return new XImageProducer();
85: }
86:
87:
92: public Graphics getGraphics()
93: {
94: XGraphics2D g = new XGraphics2D(pixmap);
95: return g;
96: }
97:
98: public Object getProperty(String name, ImageObserver observer)
99: {
100: Object val = null;
101: if (properties != null)
102: val = properties.get(val);
103: return val;
104: }
105:
106: public void flush()
107: {
108:
109: throw new UnsupportedOperationException("Not yet implemented.");
110: }
111:
112: protected void finalize()
113: {
114: pixmap.free();
115: }
116:
117: protected class XImageProducer implements ImageProducer
118: {
119: private Vector<ImageConsumer> consumers = new Vector<ImageConsumer>();
120:
121: public void addConsumer(ImageConsumer ic)
122: {
123: if (ic != null && !isConsumer(ic))
124: this.consumers.add(ic);
125: }
126:
127: public boolean isConsumer(ImageConsumer ic)
128: {
129: return this.consumers.contains(ic);
130: }
131:
132: public void removeConsumer(ImageConsumer ic)
133: {
134: if (ic != null)
135: this.consumers.remove(ic);
136: }
137:
138: public void requestTopDownLeftRightResend(ImageConsumer ic)
139: {
140:
141: }
142:
143: public void startProduction(ImageConsumer ic)
144: {
145: this.addConsumer(ic);
146:
147: for (ImageConsumer consumer : this.consumers)
148: {
149: int width = XImage.this.getWidth(null);
150: int height = XImage.this.getHeight(null);
151:
152: XGraphics2D graphics = (XGraphics2D) getGraphics();
153: ColorModel model = graphics.getColorModel();
154: graphics.dispose();
155:
156: ZPixmap zpixmap = (ZPixmap)
157: XImage.this.pixmap.image(0, 0, width, height,
158: 0xffffffff,
159: gnu.x11.image.Image.Format.ZPIXMAP);
160:
161: int size = zpixmap.get_data_length();
162: System.out.println("size: " + size + ", w = " + width + ", h = " + height);
163:
164: int [] pixel = new int[size];
165: for (int i = 0; i < size; i++)
166: pixel[i] = zpixmap.get_data_element(i);
167:
168: consumer.setHints(ImageConsumer.SINGLEPASS);
169:
170: consumer.setDimensions(width, height);
171: consumer.setPixels(0, 0, width, height, model, pixel, 0, width);
172: consumer.imageComplete(ImageConsumer.STATICIMAGEDONE);
173: }
174:
175: System.out.println("done!");
176: }
177: }
178: }