reorganized file layout (part 2: edits)
[org.ibex.core.git] / src / org / ibex / plat / AWT.java
1 // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL]
2 package org.ibex.plat;
3
4 import org.ibex.*;
5 import org.ibex.util.*;
6 import java.io.*;
7 import org.ibex.js.*;
8 import java.awt.*;
9 import java.awt.datatransfer.*;
10 import java.awt.image.*;
11 import java.awt.event.*;
12 import org.ibex.graphics.*;
13 import org.ibex.core.*;
14 import org.ibex.net.*;
15
16 /** Platform subclass for all VM's providing AWT 1.1 functionality */
17 public class AWT extends JVM {
18
19     protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; }
20     protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); }
21     protected Picture _createPicture(JS r) { return new AWTPicture(r); }
22     protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
23     protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
24     protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
25
26     protected void postInit() {
27         if (Log.on) Log.diag(Platform.class, "               color depth = " +
28                             Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
29     }
30
31     protected void _criticalAbort(String message) {
32         if (Log.on) Log.info(this, message);
33         final Dialog d = new Dialog(new Frame(), "Ibex Cannot Continue");
34         d.setLayout(new BorderLayout());
35         TextArea ta = new TextArea("Ibex cannot continue because:\n\n" + message, 10, 80);
36         ta.setEditable(false);
37         d.add(ta, "Center");
38         Button b = new Button("OK");
39         b.addActionListener(new ActionListener() {
40                 public void actionPerformed(ActionEvent e) {
41                     d.dispose();
42                 }
43             });
44         d.add(b, "South");
45         d.setModal(true);
46         d.pack();
47         d.show();
48         new Semaphore().block();
49     }
50
51     protected String _getClipBoard() {
52         Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
53         if (cb == null) return null;
54         Transferable clipdata = cb.getContents(null);
55         try { return (String)clipdata.getTransferData(DataFlavor.stringFlavor); } catch (Exception ex) { return null; }
56     }
57
58     protected void _setClipBoard(String s) {
59         Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
60         if (clipboard == null) return;
61         StringSelection clipString = new StringSelection(s);
62         clipboard.setContents(clipString, clipString);
63     }
64
65     /** some platforms (cough, cough, NetscapeVM) have totally broken modifier masks; they will need to override this */
66     protected static int modifiersToButtonNumber(int modifiers) {
67         if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) return 1;
68         if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
69             // ugh, MacOSX reports the right mouse button as BUTTON2_MASK...
70             if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 2;
71             return 3;
72         }
73         if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
74             // ugh, MacOSX reports the right mouse button as BUTTON2_MASK...
75             if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 3;
76             return 2;
77         }
78         return 0;
79     }
80
81     static class FileDialogHelper extends FileDialog implements WindowListener, ComponentListener {
82         Semaphore s;
83         public FileDialogHelper(String suggestedFileName, Semaphore s, boolean write) {
84             super(new Frame(), write ? "Save" : "Open", write ? FileDialog.SAVE : FileDialog.LOAD);
85             this.s = s;
86             addWindowListener(this);
87             addComponentListener(this);
88             if (suggestedFileName.indexOf(File.separatorChar) == -1) {
89                 setFile(suggestedFileName);
90             } else {
91                 setDirectory(suggestedFileName.substring(0, suggestedFileName.lastIndexOf(File.separatorChar)));
92                 setFile(suggestedFileName.substring(suggestedFileName.lastIndexOf(File.separatorChar) + 1));
93             }
94             show();
95         }
96         public void windowActivated(WindowEvent e) { }
97         public void windowClosed(WindowEvent e) { s.release(); }
98         public void windowClosing(WindowEvent e) { }
99         public void windowDeactivated(WindowEvent e) { }
100         public void windowDeiconified(WindowEvent e) { }
101         public void windowIconified(WindowEvent e) { }
102         public void windowOpened(WindowEvent e) { }
103         public void componentHidden(ComponentEvent e) { s.release(); }
104         public void componentMoved(ComponentEvent e) { }
105         public void componentResized(ComponentEvent e) { }
106         public void componentShown(ComponentEvent e) { }
107     };
108
109     protected String _fileDialog(String suggestedFileName, boolean write) {
110         final Semaphore s = new Semaphore();
111         FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
112         s.block();
113         return fd.getDirectory() == null ? null : (fd.getDirectory() + File.separatorChar + fd.getFile());
114     }
115
116
117     // Inner Classes /////////////////////////////////////////////////////////////////////////////////////
118
119     protected org.ibex.graphics.Font.Glyph _createGlyph(org.ibex.graphics.Font f, char c) { return new AWTGlyph(f, c); }
120     protected static class AWTGlyph extends org.ibex.graphics.Font.Glyph {
121         private Image i = null;
122         private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
123
124         // this doesn't work on Win32 because the JVM is broken
125         /*
126         static final ColorModel cmodel = new ColorModel(8) {
127             public int getRed(int p) { return 0; }
128             public int getGreen(int p) { return 0; }
129             public int getBlue(int p) { return 0; }
130             public int getAlpha(int p) { return p & 0xFF; }
131         };
132         */
133
134         public AWTGlyph(org.ibex.graphics.Font f, char c) { super(f, c); }
135         Image getImage() {
136             if (i == null && isLoaded) {
137
138                 int[] data2 = new int[data.length];
139                 for(int i=0; i<data2.length; i++) data2[i] = ((data[i]) & 0xff) << 24;
140
141                 MemoryImageSource mis = new MemoryImageSource(width, height, cmodel, data2, 0, width);
142                 mis.setAnimated(true);
143                 i = Toolkit.getDefaultToolkit().createImage(mis);
144                 MediaTracker mediatracker = new MediaTracker(new Canvas());
145                 mediatracker.addImage(i, 1);
146                 try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
147                 mediatracker.removeImage(i);
148                 synchronized(AWTPixelBuffer.class) { 
149                     if (AWTPixelBuffer.component == null) {
150                         AWTPixelBuffer.component = new Frame();
151                         AWTPixelBuffer.component.setVisible(false);
152                         AWTPixelBuffer.component.addNotify();
153                     }
154                 }
155                 data = null;
156             }
157             return i;
158         }
159     }
160
161     protected static class AWTPicture extends Picture {
162         public Image i = null;
163         private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
164         
165         boolean initialized = false;
166         public AWTPicture(JS r) { super(r); }
167         public void init() {
168             if (initialized) return;
169             initialized = true;
170             MemoryImageSource mis = new MemoryImageSource(width, height, cmodel, data, 0, width);
171             mis.setAnimated(true);
172             i = Toolkit.getDefaultToolkit().createImage(mis);
173             MediaTracker mediatracker = new MediaTracker(new Canvas());
174             mediatracker.addImage(i, 1);
175             try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
176             mediatracker.removeImage(i);
177             synchronized(AWTPixelBuffer.class) { 
178                 if (AWTPixelBuffer.component == null) {
179                     AWTPixelBuffer.component = new Frame();
180                     AWTPixelBuffer.component.setVisible(false);
181                     AWTPixelBuffer.component.addNotify();
182                 }
183             }
184         }
185     }
186     
187     protected static class AWTPixelBuffer extends PixelBuffer {
188         
189         protected Image i = null;
190         protected Graphics g = null;
191         
192         /** JDK1.1 platforms require that a component be associated with each off-screen buffer */
193         static Component component = null;
194
195         protected AWTPixelBuffer() { }
196         public AWTPixelBuffer(int w, int h) {
197             synchronized(AWTPixelBuffer.class) {
198                 if (component == null) {
199                     component = new Frame();
200                     component.setVisible(false);
201                     component.addNotify();
202                 }
203             }
204             i = component.createImage(w, h);
205             g = i.getGraphics();
206         }
207         
208         public int getHeight() { return i == null ? 0 : i.getHeight(null); }
209         public int getWidth() { return i == null ? 0 : i.getWidth(null); }
210
211         public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
212             ((AWTPicture)source).init();
213             g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
214             g.drawImage(((AWTPicture)source).i, dx, dy, null);
215             g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
216         }
217
218         /** implemented with java.awt 1.1's setXORMode() */
219         public void drawGlyph(org.ibex.graphics.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
220
221             // XOR the target region
222             g.setXORMode(new java.awt.Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
223             g.setColor(new java.awt.Color(0x0, 0x0, 0x0));
224             g.fillRect(cx1, cy1, cx2 - cx1, cy2 - cy1);
225
226             // blacken the area we want the glyph to cover
227             g.setPaintMode();
228             g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
229             g.drawImage(((AWTGlyph)source).getImage(), dx, dy, null);
230             g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
231
232             // XOR back, turning black into the chosen rgb color
233             g.setXORMode(new java.awt.Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
234             g.setColor(new java.awt.Color(0x0, 0x0, 0x0));
235             g.fillRect(cx1, cy1, cx2 - cx1, cy2 - cy1);
236
237             // restore the graphics context
238             g.setPaintMode();
239         }
240
241         // FIXME: try to use os acceleration
242         public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) {
243             g.setColor(new java.awt.Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
244             if (x1 == x3 && x2 == x4) {
245                 g.fillRect(x1, y1, x4 - x1, y2 - y1);
246             } else for(int y=y1; y<y2; y++) {
247                 int _x1 = (int)Math.floor((y - y1) * (x3 - x1) / (y2 - y1) + x1);
248                 int _y1 = (int)Math.floor(y);
249                 int _x2 = (int)Math.ceil((y - y1) * (x4 - x2) / (y2 - y1) + x2);
250                 int _y2 = (int)Math.floor(y) + 1;
251                 if (_x1 > _x2) { int _x0 = _x1; _x1 = _x2; _x2 = _x0; }
252                 g.fillRect(_x1, _y1, _x2 - _x1, _y2 - _y1);
253             }
254         }
255     }
256     
257     
258     protected static class AWTSurface extends Surface.DoubleBufferedSurface
259         implements MouseListener, MouseMotionListener, KeyListener, ComponentListener, WindowListener {
260
261         public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
262             insets = (frame == null ? window : frame).getInsets();
263             window.getGraphics().drawImage(((AWTPixelBuffer)s).i,
264                                   dx + insets.left,
265                                   dy + insets.top,
266                                   dx2 + insets.left,
267                                   dy2 + insets.top,
268                                   sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null);
269         }
270         
271         /** if (component instanceof Frame) then frame == window else frame == null */
272         Frame frame = null;
273         Window window = null;
274         
275         /** our component's insets */
276         protected Insets insets = new Insets(0, 0, 0, 0);
277         
278         /** some JDKs let us recycle a single Dimension object when calling getSize() */
279         Dimension singleSize = new Dimension();
280         
281         public void toBack() { if (window != null) window.toBack(); }
282         public void toFront() { if (window != null) window.toFront(); }
283         public void setLocation() { window.setLocation(root.x, root.y); }
284         public void setTitleBarText(String s) { if (frame != null) frame.setTitle(s); }
285         public void setIcon(Picture i) { if (frame != null) frame.setIconImage(((AWTPicture)i).i); }
286         public void _setSize(int width, int height) { window.setSize(width + (insets.left + insets.right), height + (insets.top + insets.bottom)); }
287         public void setInvisible(boolean b) { window.setVisible(!b); }
288         protected void _setMinimized(boolean b) { if (Log.on) Log.info(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); }
289         protected void _setMaximized(boolean b) {
290             if (!b) {
291                 if (Log.on) Log.info(this, "JDK 1.1 platforms cannot unmaximize windows");
292                 return;
293             }
294             window.setLocation(new Point(0, 0));
295             window.setSize(Toolkit.getDefaultToolkit().getScreenSize());
296         }
297
298         class InnerFrame extends Frame {
299             public InnerFrame() throws java.lang.UnsupportedOperationException { }
300             public Dimension getMinimumSize() {
301                 return new Dimension(root == null ? 0 : root.minwidth, root == null ? 0 : root.minheight); }
302             public void update(Graphics gr) { paint(gr); }
303             public void paint(Graphics gr) {
304                 Rectangle r = gr.getClipBounds();
305
306                 // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches expansions during smooth resize
307                 int newwidth = Math.max(r.x - insets.left + r.width, root.width);
308                 int newheight = Math.max(r.y - insets.top + r.height, root.height);
309                 if (newwidth > root.width || newheight > root.height)
310                     componentResized(window.getWidth() - insets.left - insets.right,
311                                      window.getHeight() - insets.top - insets.bottom);
312
313                 Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height);
314             }
315         }
316
317         class InnerWindow extends Window {
318             public InnerWindow() throws java.lang.UnsupportedOperationException { super(new Frame()); }
319             public Dimension getMinimumSize() {
320                 return new Dimension(root == null ? 0 : root.minwidth, root == null ? 0 : root.minheight); }
321             public void update(Graphics gr) { paint(gr); }
322             public void paint(Graphics gr) {
323                 Rectangle r = gr.getClipBounds();
324                 Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height);
325             }
326         }
327
328         public void setMinimumSize(int minx, int miny, boolean resizable) { if (frame != null) frame.setResizable(resizable); }
329
330         private int oldfill = 0x0;
331         public void render() {
332             // useful optimizatin;
333             if (oldfill != root.fillcolor) {
334                 oldfill = root.fillcolor;
335                 window.setBackground((root.fillcolor & 0xFF000000) == 0 ?
336                                      java.awt.Color.white :
337                                      new java.awt.Color((root.fillcolor >> 16) & 0xff,
338                                                (root.fillcolor >> 8) & 0xff,
339                                                (root.fillcolor) & 0xff));
340             }
341             super.render();
342         }
343
344         AWTSurface(Box root, boolean framed) {
345             super(root);
346             try {
347                 if (framed) window = frame = new InnerFrame();
348                 else window = new InnerWindow();
349
350             // this is here to catch HeadlessException on jdk1.4
351             } catch (java.lang.UnsupportedOperationException e) {
352                 if (Log.on) Log.info(this, "Exception thrown in AWTSurface$InnerFrame() -- this should never happen");
353                 if (Log.on) Log.info(this, e);
354             }
355
356             insets = window.getInsets();
357             
358             window.addMouseListener(this);
359             window.addKeyListener(this);
360             window.addComponentListener(this);
361             window.addMouseMotionListener(this);
362             window.addWindowListener(this);
363
364             // IMPORTANT: this must be called before render() to ensure
365             // that our peer has been created
366             makeVisible();
367         }
368
369         protected void makeVisible() { window.setVisible(true); }
370         
371         public void _dispose() {
372             window.removeMouseListener(this);
373
374             // removed to work around a jdk1.3 bug
375             /* window.removeKeyListener(this); */
376
377             window.removeComponentListener(this);
378             window.removeMouseMotionListener(this);
379             window.removeWindowListener(this);
380             window.dispose();
381         }
382
383         public void syncCursor() {
384             if (cursor.equals("crosshair")) window.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
385             else if (cursor.equals("east")) window.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
386             else if (cursor.equals("move")) window.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
387             else if (cursor.equals("north")) window.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
388             else if (cursor.equals("northeast")) window.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
389             else if (cursor.equals("northwest")) window.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
390             else if (cursor.equals("south")) window.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
391             else if (cursor.equals("southeast")) window.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
392             else if (cursor.equals("southwest")) window.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
393             else if (cursor.equals("text")) window.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
394             else if (cursor.equals("west")) window.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
395             else if (cursor.equals("wait")) window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
396             else if (cursor.equals("hand")) window.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
397             else window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
398         }
399         
400         // AWT Message translation ////////////////////////////////////////////////////////////////
401         
402         // these functions are all executed in the AWT thread, not the
403         // MessageQueue thread. As a result, they must be *extremely*
404         // careful about invoking methods on instances of Box. Currently,
405         // they should only enqueue messages, use Box.whoIs()
406         // (unsynchronized but thought to be safe), and modify members of
407         // Surface.
408         
409         public void componentHidden(ComponentEvent e) { }
410         public void componentShown(ComponentEvent e) { }
411         public void windowOpened(WindowEvent e) { }
412         public void windowClosed(WindowEvent e) { }
413         public void windowClosing(WindowEvent e) { Close(); }
414         public void windowIconified(WindowEvent e) { Minimized(true); }
415         public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.width, root.height); Minimized(false); }
416         public void windowActivated(WindowEvent e) { Focused(true); }
417         public void windowDeactivated(WindowEvent e) { Focused(false); }
418         public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); }
419
420         public void componentResized(ComponentEvent e) {
421             // we have to periodically do this; I don't know why
422             insets = window.getInsets();
423             componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom);
424         }
425
426         public void componentResized(int newwidth, int newheight) { SizeChange(newwidth, newheight); }
427
428         public void keyTyped(KeyEvent k) { }
429         public void keyPressed(KeyEvent k) { KeyPressed(translateKey(k)); }
430         public void keyReleased(KeyEvent k) { KeyReleased(translateKey(k)); }
431         public void mouseExited(MouseEvent m) { mouseMoved(m); }
432         public void mouseEntered(MouseEvent m) { mouseMoved(m); }
433         public void mouseDragged(MouseEvent m) { mouseMoved(m); }
434         public void mouseMoved(MouseEvent m) {
435
436             // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches contractions during smooth resize
437             int newwidth = window.getWidth() - insets.left - insets.right;
438             int newheight = window.getHeight() - insets.top - insets.bottom;
439             if (newwidth != root.width || newheight != root.height) componentResized(newwidth, newheight);
440             
441             Move(m.getX() - insets.left, m.getY() - insets.top);
442         }
443         public void mousePressed(MouseEvent m) { Press(modifiersToButtonNumber(m.getModifiers())); }
444         public void mouseReleased(MouseEvent m) { Release(modifiersToButtonNumber(m.getModifiers())); }
445         public void mouseClicked(MouseEvent m) {
446             if (m.getClickCount() == 2) DoubleClick(modifiersToButtonNumber(m.getModifiers()));
447             else Click(modifiersToButtonNumber(m.getModifiers()));
448         }
449         
450         String translateKey(KeyEvent k) {
451             switch (k.getKeyCode()) {
452             case KeyEvent.VK_ALT: return "alt";
453             case KeyEvent.VK_BACK_SPACE: return "back_space";
454             case KeyEvent.VK_CONTROL: return "control";
455             case KeyEvent.VK_DELETE: return "delete";
456             case KeyEvent.VK_DOWN: return "down";
457             case KeyEvent.VK_END: return "end";
458             case KeyEvent.VK_ENTER: return "enter";
459             case KeyEvent.VK_ESCAPE: return "escape";
460             case KeyEvent.VK_F1: return "f1";
461             case KeyEvent.VK_F10: return "f10";
462             case KeyEvent.VK_F11: return "f11";
463             case KeyEvent.VK_F12: return "f12";
464             case KeyEvent.VK_F2: return "f2";
465             case KeyEvent.VK_F3: return "f3";
466             case KeyEvent.VK_F4: return "f4";
467             case KeyEvent.VK_F5: return "f5";
468             case KeyEvent.VK_F6: return "f6"; 
469             case KeyEvent.VK_F7: return "f7";
470             case KeyEvent.VK_F8: return "f8";
471             case KeyEvent.VK_F9: return "f9";
472             case KeyEvent.VK_HOME: return "home";
473             case KeyEvent.VK_INSERT: return "insert";
474             case KeyEvent.VK_LEFT: return "left";
475             case KeyEvent.VK_META: return "alt";
476             case KeyEvent.VK_PAGE_DOWN: return "page_down";
477             case KeyEvent.VK_PAGE_UP: return "page_up";
478             case KeyEvent.VK_PAUSE: return "pause";
479             case KeyEvent.VK_PRINTSCREEN: return "printscreen";
480             case KeyEvent.VK_RIGHT: return "right";
481             case KeyEvent.VK_SHIFT: return "shift";
482             case KeyEvent.VK_TAB: return "tab";
483             case KeyEvent.VK_UP: return "up";
484             default:
485                 char c = k.getKeyChar();
486                 if (c >= 1 && c <= 26) c = (char)('a' + c - 1);
487                 return String.valueOf(c);
488             }
489         }
490     }
491
492     protected void _decodeJPEG(InputStream is, Picture p) {
493         try {
494             Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is));
495             MediaTracker mediatracker = new MediaTracker(new Canvas());
496             mediatracker.addImage(i, 1);
497             try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
498             mediatracker.removeImage(i);
499             final int width = i.getWidth(null);
500             final int height = i.getHeight(null);
501             final int[] data = new int[width * height];
502             PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
503             pg.grabPixels();
504             if ((pg.getStatus() & ImageObserver.ABORT) != 0)
505                 Log.info(this, "PixelGrabber reported an error while decoding JPEG image");
506             p.width = width;
507             p.height = height;
508             p.data = data;
509         } catch (Exception e) {
510             Log.info(this, "Exception caught while decoding JPEG image");
511             Log.info(this, e);
512         }
513     }
514 }