1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the GNU General Public License version 2 ("the License").
3 // You may not use this file except in compliance with the License.
7 import org.ibex.util.*;
11 import java.awt.datatransfer.*;
12 import java.awt.image.*;
13 import java.awt.event.*;
14 import org.ibex.graphics.*;
15 import org.ibex.core.*;
16 import org.ibex.net.*;
18 /** Platform subclass for all VM's providing AWT 1.1 functionality */
19 public class AWT extends JVM {
21 protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; }
22 protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); }
23 protected Picture _createPicture(JS r) { return new AWTPicture(r); }
24 protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
25 protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
26 protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
28 protected void postInit() {
29 if (Log.on) Log.diag(Platform.class, " color depth = " +
30 Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); }
32 protected void _criticalAbort(String message) {
33 if (Log.on) Log.info(this, message);
34 final Dialog d = new Dialog(new Frame(), "Ibex Cannot Continue");
35 d.setLayout(new BorderLayout());
36 TextArea ta = new TextArea("Ibex cannot continue because:\n\n" + message, 10, 80);
37 ta.setEditable(false);
39 Button b = new Button("OK");
40 b.addActionListener(new ActionListener() {
41 public void actionPerformed(ActionEvent e) {
49 new Semaphore().block();
52 protected String _getClipBoard() {
53 Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
54 if (cb == null) return null;
55 Transferable clipdata = cb.getContents(null);
56 try { return (String)clipdata.getTransferData(DataFlavor.stringFlavor); } catch (Exception ex) { return null; }
59 protected void _setClipBoard(String s) {
60 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
61 if (clipboard == null) return;
62 StringSelection clipString = new StringSelection(s);
63 clipboard.setContents(clipString, clipString);
66 /** some platforms (cough, cough, NetscapeVM) have totally broken modifier masks; they will need to override this */
67 protected static int modifiersToButtonNumber(int modifiers) {
68 if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) return 1;
69 if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
70 // ugh, MacOSX reports the right mouse button as BUTTON2_MASK...
71 if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 2;
74 if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
75 // ugh, MacOSX reports the right mouse button as BUTTON2_MASK...
76 if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 3;
82 static class FileDialogHelper extends FileDialog implements WindowListener, ComponentListener {
84 public FileDialogHelper(String suggestedFileName, Semaphore s, boolean write) {
85 super(new Frame(), write ? "Save" : "Open", write ? FileDialog.SAVE : FileDialog.LOAD);
87 addWindowListener(this);
88 addComponentListener(this);
89 if (suggestedFileName.indexOf(File.separatorChar) == -1) {
90 setFile(suggestedFileName);
92 setDirectory(suggestedFileName.substring(0, suggestedFileName.lastIndexOf(File.separatorChar)));
93 setFile(suggestedFileName.substring(suggestedFileName.lastIndexOf(File.separatorChar) + 1));
97 public void windowActivated(WindowEvent e) { }
98 public void windowClosed(WindowEvent e) { s.release(); }
99 public void windowClosing(WindowEvent e) { }
100 public void windowDeactivated(WindowEvent e) { }
101 public void windowDeiconified(WindowEvent e) { }
102 public void windowIconified(WindowEvent e) { }
103 public void windowOpened(WindowEvent e) { }
104 public void componentHidden(ComponentEvent e) { s.release(); }
105 public void componentMoved(ComponentEvent e) { }
106 public void componentResized(ComponentEvent e) { }
107 public void componentShown(ComponentEvent e) { }
110 protected String _fileDialog(String suggestedFileName, boolean write) {
111 final Semaphore s = new Semaphore();
112 FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
114 return fd.getDirectory() == null ? null : (fd.getDirectory() + File.separatorChar + fd.getFile());
118 // Inner Classes /////////////////////////////////////////////////////////////////////////////////////
120 protected org.ibex.graphics.Font.Glyph _createGlyph(org.ibex.graphics.Font f, char c) { return new AWTGlyph(f, c); }
121 protected static class AWTGlyph extends org.ibex.graphics.Font.Glyph {
124 private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
126 // this doesn't work on Win32 because the JVM is broken
128 static final ColorModel cmodel = new ColorModel(8) {
129 public int getRed(int p) { return 0; }
130 public int getGreen(int p) { return 0; }
131 public int getBlue(int p) { return 0; }
132 public int getAlpha(int p) { return p & 0xFF; }
136 public AWTGlyph(org.ibex.graphics.Font f, char c) { super(f, c); }
138 if (i == null && isLoaded) {
140 int[] data2 = new int[data.length];
141 for(int i=0; i<data2.length; i++) data2[i] = ((data[i]) & 0xff) << 24;
143 MemoryImageSource mis = new MemoryImageSource(width, height, cmodel, data2, 0, width);
144 mis.setAnimated(true);
145 i = Toolkit.getDefaultToolkit().createImage(mis);
146 MediaTracker mediatracker = new MediaTracker(new Canvas());
147 mediatracker.addImage(i, 1);
148 try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
149 mediatracker.removeImage(i);
150 synchronized(AWTPixelBuffer.class) {
151 if (AWTPixelBuffer.component == null) {
152 AWTPixelBuffer.component = new Frame();
153 AWTPixelBuffer.component.setVisible(false);
154 AWTPixelBuffer.component.addNotify();
163 protected static class AWTPicture extends Picture {
164 public Image i = null;
165 private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
167 boolean initialized = false;
168 public AWTPicture(JS r) { super(r); }
170 if (initialized) return;
172 MemoryImageSource mis = new MemoryImageSource(width, height, cmodel, data, 0, width);
173 mis.setAnimated(true);
174 i = Toolkit.getDefaultToolkit().createImage(mis);
175 MediaTracker mediatracker = new MediaTracker(new Canvas());
176 mediatracker.addImage(i, 1);
177 try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
178 mediatracker.removeImage(i);
179 synchronized(AWTPixelBuffer.class) {
180 if (AWTPixelBuffer.component == null) {
181 AWTPixelBuffer.component = new Frame();
182 AWTPixelBuffer.component.setVisible(false);
183 AWTPixelBuffer.component.addNotify();
189 protected static class AWTPixelBuffer implements PixelBuffer {
191 private int[] xpoints = new int[3];
192 private int[] ypoints = new int[3];
193 public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) {
200 Graphics g = getGraphics();
201 g.setColor(new java.awt.Color((argb & 0x00ff0000) >> 16,
202 (argb & 0x0000ff00) >> 8,
204 (argb & 0xff000000) >> 24*/));
205 g.fillPolygon(xpoints, ypoints, 3);
208 public void drawPicture(Picture p, Affine a, Mesh h) {
209 throw new Error("drawPicture() not implemented");
212 protected Image i = null;
213 protected Graphics g = null;
214 protected AWTSurface surface = null;
216 /** JDK1.1 platforms require that a component be associated with each off-screen buffer */
217 static Component component = null;
219 public AWTPixelBuffer(Image i) { this.i = i; }
220 public AWTPixelBuffer(AWTSurface s) { this.surface = s; }
221 public AWTPixelBuffer(int w, int h) {
222 synchronized(AWTPixelBuffer.class) {
223 if (component == null) {
224 component = new Frame();
225 component.setVisible(false);
226 component.addNotify();
229 i = component.createImage(w, h);
231 Graphics getGraphics() {
232 if (surface != null) return surface.getGraphics();
233 if (g != null) return g;
234 if (i != null) { g = i.getGraphics(); return g; }
238 public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
239 ((AWTPicture)source).init();
240 Graphics g = getGraphics();
241 g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
242 g.drawImage(((AWTPicture)source).i, dx, dy, null);
243 if (i != null) g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
246 public void drawLine(int x1, int y1, int x2, int y2, int rgb) {
247 Graphics g = getGraphics();
248 ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
249 g.setColor(new java.awt.Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
250 g.drawLine(x1, y1, x2, y2);
253 //public void stroke(org.ibex.graphics.Mesh p, int color) { /*p.stroke(this, color);*/ }
254 //public void fill(org.ibex.graphics.Mesh p, org.ibex.graphics.Paint paint) { /*p.fill(this, paint);*/ }
256 private static int[] xa = new int[4];
257 private static int[] ya = new int[4];
258 public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) {
259 Graphics g = getGraphics();
260 ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
261 g.setColor(new java.awt.Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
270 g.fillPolygon(xa, ya, 4);
273 // this doens't seem to work on Windows
274 public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Mesh h, int argb, int bg) {
275 //throw new Error("drawGlyph() not implemented");
277 Image i = ((AWTGlyph)source).getImage();
278 if (((AWTGlyph)source).i2 == null)
279 ((AWTGlyph)source).i2 = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB);
280 Image i2 = ((AWTGlyph)source).i2;
281 Graphics g2 = i2.getGraphics();
282 g2.setColor(new java.awt.Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
283 g2.fillRect(0, 0, i2.getWidth(null), i2.getHeight(null));
284 g2.drawImage(i, 0, 0, null);
285 Graphics g = getGraphics();
286 g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
287 g.drawImage(i2, dx, dy, i2.getWidth(null), i2.getHeight(null), null);
288 g.setColor(new java.awt.Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
289 g.fillRect(cx1, cy1, dx - cx1, cy2 - cy1);
290 g.fillRect(cx1, cy1, cx2 - cx1, dy - cy1);
291 g.fillRect(dx+i2.getWidth(null), cy1, cx2 - (dx+i2.getWidth(null)), cy2 - cy1);
292 g.fillRect(cx1, dy+i2.getHeight(null), cx2 - cx1, cy2 - (dy+i2.getHeight(null)));
293 g.setClip(0, 0, 1000, 1000);
299 protected static class AWTSurface extends Surface // extends Surface.DoubleBufferedSurface
300 implements MouseListener, MouseMotionListener, KeyListener, ComponentListener, WindowListener {
302 protected AWTPixelBuffer pb = null;
303 private Graphics g = null;
305 Window window = null;
307 public PixelBuffer getPixelBuffer() { return pb==null?(pb=new AWTPixelBuffer(this)):pb; }
309 public void blit(PixelBuffer source, int sx, int sy, int dx, int dy, int dx2, int dy2) {
310 getGraphics().drawImage(((AWTPixelBuffer)source).i, sx, sy, sx+(dx2-dx), sy+(dy2-dy), dx, dy, dx2, dy2, null);
313 /** our component's insets */
314 protected Insets insets = new Insets(0, 0, 0, 0);
315 Graphics getGraphics() { if (g==null) g=window==null ? frame.getGraphics() : window.getGraphics(); return g; }
316 public void _fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color) {
317 if (pb ==null) pb = new AWTPixelBuffer(this);
318 pb.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
320 //public PixelBuffer getPixelBuffer() { return pb != null ? pb : (pb = new AWTPixelBuffer(this)); }
321 public void setMinimumSize(int minx, int miny, boolean resizable) { if (frame != null) frame.setResizable(resizable); }
322 public void toBack() { if (window != null) window.toBack(); }
323 public void toFront() { if (window != null) window.toFront(); }
324 public void setLocation() { /*window.setLocation(root.x, root.y); FIXME */ }
325 public void setTitleBarText(String s) { if (frame != null) frame.setTitle(s); }
326 public void setIcon(Picture i) { if (frame != null) frame.setIconImage(((AWTPicture)i).i); }
327 public void _setSize(int width, int height) {
329 window.setSize(width + (insets.left + insets.right), height + (insets.top + insets.bottom));
331 public void setInvisible(boolean b) { window.setVisible(!b); }
332 protected void _setMinimized(boolean b) { if (Log.on) Log.info(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); }
333 protected void _setMaximized(boolean b) {
335 if (Log.on) Log.info(this, "JDK 1.1 platforms cannot unmaximize windows");
338 window.setLocation(new Point(0, 0));
339 window.setSize(Toolkit.getDefaultToolkit().getScreenSize());
343 class InnerFrame extends Frame {
344 public InnerFrame() throws java.lang.UnsupportedOperationException { }
345 public Dimension getMinimumSize() { return new Dimension(root.minwidth, root.minheight); }
346 public void update(Graphics gr) {
347 Rectangle r = gr.getClipBounds();
351 public void paint(Graphics gr) {
352 // Mac OS X Jdk1.4 Bug: after a componentResized(), you must wait for the paint() before you redraw
353 Rectangle r = gr.getClipBounds();
357 private void dirtify(java.awt.Rectangle r) {
359 Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height);
362 Math.max(getWidth() - insets.left - insets.right, root.getRootWidth()),
363 Math.min(getHeight() - insets.top - insets.bottom, root.getRootHeight()));
365 // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches expansions during smooth resize
366 int newwidth = Math.max(getWidth() - insets.left - insets.right, root.getRootWidth());
367 int newheight = Math.max(getHeight() - insets.top - insets.bottom, root.getRootHeight());
368 if (newwidth != root.getRootWidth() || newheight != root.getRootHeight()) componentResized(newwidth, newheight);
372 class InnerWindow extends Window {
373 public InnerWindow() throws java.lang.UnsupportedOperationException { super(new Frame()); }
374 public Dimension getMinimumSize() { return new Dimension(root.minwidth, root.minheight); }
375 public void update(Graphics gr) { paint(gr); }
376 public void paint(Graphics gr) {
378 Rectangle r = gr.getClipBounds();
379 Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height);
383 private int oldfill = 0x0;
384 public void render() {
385 // useful optimizatin;
387 if (oldfill != root.fillcolor) {
388 oldfill = root.fillcolor;
389 window.setBackground((root.fillcolor & 0xFF000000) == 0 ?
390 java.awt.Color.white :
391 new java.awt.Color((root.fillcolor >> 16) & 0xff,
392 (root.fillcolor >> 8) & 0xff,
393 (root.fillcolor) & 0xff));
400 Insets ret = window.getInsets();
401 if (System.getProperty("os.name", "").equals("Mac OS X")) ret.bottom = -1 * ret.top;
405 AWTSurface(Box root, boolean framed) {
408 if (framed) window = frame = new InnerFrame();
409 else window = new InnerWindow();
411 // this is here to catch HeadlessException on jdk1.4
412 } catch (java.lang.UnsupportedOperationException e) {
413 if (Log.on) Log.info(this, "Exception thrown in AWTSurface$InnerFrame() -- this should never happen");
414 if (Log.on) Log.info(this, e);
417 insets = getInsets();
419 window.addMouseListener(this);
420 window.addKeyListener(this);
421 window.addComponentListener(this);
422 window.addMouseMotionListener(this);
423 window.addWindowListener(this);
425 // IMPORTANT: this must be called before render() to ensure
426 // that our peer has been created
430 protected void makeVisible() { window.setVisible(true); }
432 public void _dispose() {
433 window.removeMouseListener(this);
435 // removed to work around a jdk1.3 bug
436 /* window.removeKeyListener(this); */
438 window.removeComponentListener(this);
439 window.removeMouseMotionListener(this);
440 window.removeWindowListener(this);
444 public void syncCursor() {
445 if (cursor.equals("crosshair")) window.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
446 else if (cursor.equals("east")) window.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
447 else if (cursor.equals("move")) window.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
448 else if (cursor.equals("north")) window.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
449 else if (cursor.equals("northeast")) window.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
450 else if (cursor.equals("northwest")) window.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
451 else if (cursor.equals("south")) window.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
452 else if (cursor.equals("southeast")) window.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
453 else if (cursor.equals("southwest")) window.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
454 else if (cursor.equals("text")) window.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
455 else if (cursor.equals("west")) window.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
456 else if (cursor.equals("wait")) window.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
457 else if (cursor.equals("hand")) window.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
458 else window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
461 // AWT Message translation ////////////////////////////////////////////////////////////////
463 // these functions are all executed in the AWT thread, not the
464 // MessageQueue thread. As a result, they must be *extremely*
465 // careful about invoking methods on instances of Box. Currently,
466 // they should only enqueue messages, use Box.whoIs()
467 // (unsynchronized but thought to be safe), and modify members of
470 public void componentHidden(ComponentEvent e) { }
471 public void componentShown(ComponentEvent e) { }
472 public void windowOpened(WindowEvent e) { }
473 public void windowClosed(WindowEvent e) { }
474 public void windowClosing(WindowEvent e) { Close(); }
475 public void windowIconified(WindowEvent e) { Minimized(true); }
476 public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.getRootWidth(), root.getRootHeight()); Minimized(false); }
477 public void windowActivated(WindowEvent e) { Focused(true); }
478 public void windowDeactivated(WindowEvent e) { Focused(false); }
479 public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); }
481 public void componentResized(ComponentEvent e) {
482 // we have to periodically do this; I don't know why
483 insets = getInsets();
484 componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom);
487 public void componentResized(int newwidth, int newheight) {
488 SizeChange(newwidth, newheight);
489 if (newwidth > root.getRootWidth()) Dirty(root.getRootWidth(), 0, newwidth-root.getRootWidth(), newheight);
490 if (newheight > root.getRootHeight()) Dirty(0, root.getRootHeight(), newwidth, newheight-root.getRootHeight());
494 public void keyTyped(KeyEvent k) { }
495 public void keyPressed(KeyEvent k) { KeyPressed(translateKey(k)); }
496 public void keyReleased(KeyEvent k) { KeyReleased(translateKey(k)); }
497 public void mouseExited(MouseEvent m) { mouseMoved(m); }
498 public void mouseEntered(MouseEvent m) { mouseMoved(m); }
499 public void mouseDragged(MouseEvent m) { mouseMoved(m); }
500 public void mouseMoved(MouseEvent m) {
502 // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches contractions during smooth resize
503 int newwidth = window.getWidth() - insets.left - insets.right;
504 int newheight = window.getHeight() - insets.top - insets.bottom;
505 if (newwidth != root.getRootWidth() || newheight != root.getRootHeight()) componentResized(newwidth, newheight);
507 Move(m.getX() - insets.left, m.getY() - insets.top);
509 public void mousePressed(MouseEvent m) { Press(modifiersToButtonNumber(m.getModifiers())); }
510 public void mouseReleased(MouseEvent m) { Release(modifiersToButtonNumber(m.getModifiers())); }
511 public void mouseClicked(MouseEvent m) {
512 if (m.getClickCount() == 2) DoubleClick(modifiersToButtonNumber(m.getModifiers()));
513 else Click(modifiersToButtonNumber(m.getModifiers()));
516 String translateKey(KeyEvent k) {
517 switch (k.getKeyCode()) {
518 case KeyEvent.VK_ALT: return "alt";
519 case KeyEvent.VK_BACK_SPACE: return "back_space";
520 case KeyEvent.VK_CONTROL: return "control";
521 case KeyEvent.VK_DELETE: return "delete";
522 case KeyEvent.VK_DOWN: return "down";
523 case KeyEvent.VK_END: return "end";
524 case KeyEvent.VK_ENTER: return "enter";
525 case KeyEvent.VK_ESCAPE: return "escape";
526 case KeyEvent.VK_F1: return "f1";
527 case KeyEvent.VK_F10: return "f10";
528 case KeyEvent.VK_F11: return "f11";
529 case KeyEvent.VK_F12: return "f12";
530 case KeyEvent.VK_F2: return "f2";
531 case KeyEvent.VK_F3: return "f3";
532 case KeyEvent.VK_F4: return "f4";
533 case KeyEvent.VK_F5: return "f5";
534 case KeyEvent.VK_F6: return "f6";
535 case KeyEvent.VK_F7: return "f7";
536 case KeyEvent.VK_F8: return "f8";
537 case KeyEvent.VK_F9: return "f9";
538 case KeyEvent.VK_HOME: return "home";
539 case KeyEvent.VK_INSERT: return "insert";
540 case KeyEvent.VK_LEFT: return "left";
541 case KeyEvent.VK_META: return "alt";
542 case KeyEvent.VK_PAGE_DOWN: return "page_down";
543 case KeyEvent.VK_PAGE_UP: return "page_up";
544 case KeyEvent.VK_PAUSE: return "pause";
545 case KeyEvent.VK_PRINTSCREEN: return "printscreen";
546 case KeyEvent.VK_RIGHT: return "right";
547 case KeyEvent.VK_SHIFT: return "shift";
548 case KeyEvent.VK_TAB: return "tab";
549 case KeyEvent.VK_UP: return "up";
551 char c = k.getKeyChar();
552 if (c >= 1 && c <= 26) c = (char)('a' + c - 1);
553 return String.valueOf(c);
558 protected void _decodeJPEG(InputStream is, Picture p) {
560 Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is));
561 MediaTracker mediatracker = new MediaTracker(new Canvas());
562 mediatracker.addImage(i, 1);
563 try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
564 mediatracker.removeImage(i);
565 final int width = i.getWidth(null);
566 final int height = i.getHeight(null);
567 final int[] data = new int[width * height];
568 PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
570 if ((pg.getStatus() & ImageObserver.ABORT) != 0)
571 Log.info(this, "PixelGrabber reported an error while decoding JPEG image");
575 } catch (Exception e) {
576 Log.info(this, "Exception caught while decoding JPEG image");