1 43 44 package swingwt.awt; 45 46 import java.net.URL ; 47 import java.util.Hashtable ; 48 49 import swingwt.awt.datatransfer.Clipboard; 50 import swingwt.awt.event.KeyEvent; 51 import swingwt.awt.image.ColorModel; 52 import swingwt.awt.image.ImageConsumer; 53 import swingwt.awt.image.ImageProducer; 54 55 public class Toolkit { 56 57 private static Toolkit toolkit = new Toolkit(); 58 private static Object retval; 59 private static Hashtable desktopProperties = new Hashtable (); 60 61 protected Toolkit() {} 62 63 public static Toolkit getDefaultToolkit() { 64 return toolkit; 65 } 66 67 public static Toolkit getToolkit() { 68 return toolkit; 69 } 70 71 public Image getImage(String filename) { 72 return new swingwtx.swing.ImageIcon(filename).getImage(); 73 } 74 75 public Image getImage(URL url) { 76 return new swingwtx.swing.ImageIcon(url).getImage(); 77 } 78 79 public int getScreenResolution() { 80 return swingwtx.swing.SwingWTUtils.getDisplay().getDepth(); 81 } 82 83 public Insets getScreenInsets(GraphicsConfiguration gc) throws HeadlessException { 84 if (this != Toolkit.getDefaultToolkit()) 85 return Toolkit.getDefaultToolkit().getScreenInsets(gc); 86 else 87 return new Insets(0,0,0,0); 88 } 89 90 public FontMetrics getFontMetrics(Font f) { 91 return new FontMetrics(f); 92 } 93 94 public int getMenuShortcutKeyMask() throws HeadlessException { 95 return KeyEvent.CTRL_MASK; 96 } 97 98 public Dimension getScreenSize() { 99 swingwtx.swing.SwingUtilities.invokeSync(new Runnable () { 100 public void run() { 101 retval = new Dimension( 102 swingwtx.swing.SwingWTUtils.getDisplay().getBounds().width, 103 swingwtx.swing.SwingWTUtils.getDisplay().getBounds().height); 104 } 105 }); 106 return (Dimension) retval; 107 } 108 109 public Image createImage(ImageProducer producer) { 110 ToolkitImageConsumer tki = new ToolkitImageConsumer(); 111 producer.startProduction(tki); 112 return tki.awtImage; 113 114 } 115 116 public Image createImage(byte[] imagedata) { 117 return new swingwtx.swing.ImageIcon(imagedata).getImage(); 118 } 119 120 public Image createImage(byte[] imagedata, int imageoffset, int imagelength) { 121 byte[] im2 = new byte[imagelength]; 122 for (int i = imageoffset; i < imagelength; i++) 123 im2[i - imageoffset] = imagedata[i]; 124 return new swingwtx.swing.ImageIcon(im2).getImage(); 125 } 126 127 public Image createImage(String filename) { 128 return getImage(filename); 129 } 130 131 public Image createImage(URL url) { 132 return getImage(url); 133 } 134 135 public Clipboard getSystemClipboard() { 136 return new swingwt.awt.datatransfer.Clipboard(); 137 } 138 139 public void beep() { 140 } 141 142 public final Object getDesktopProperty(String propertyName) { 143 return desktopProperties.get(propertyName); 144 } 145 146 protected final void setDesktopProperty(String propertyName, Object value) { 147 desktopProperties.put(propertyName, value); 148 } 149 150 155 private class ToolkitImageConsumer implements ImageConsumer { 156 157 158 public Image awtImage = new Image(); 159 public boolean imageComplete = false; 160 public void imageComplete(int status) { imageComplete = true; } 161 public void setColorModel(ColorModel model) {} 162 public void setDimensions(int width, int height) { 163 awtImage.image = new org.eclipse.swt.graphics.Image(swingwtx.swing.SwingWTUtils.getDisplay(), width, height); 164 } 165 public void setHints(int hintflags) {} 166 public void setProperties(java.util.Hashtable props) {} 167 public void setPixels(int x, int y, int w, int h, ColorModel model, int[] pixels, int off, int scansize) { 168 byte[] bytes = new byte[pixels.length]; 169 for (int i = 0; i < pixels.length; i++) 170 bytes[i] = (byte) pixels[i]; 171 setPixels(x, y, w, h, model, bytes, off, scansize); 172 } 173 public void setPixels(int x, int y, int w, int h, ColorModel model, byte[] pixels, int off, int scansize) { 174 awtImage.image = 176 new org.eclipse.swt.graphics.Image( 177 swingwtx.swing.SwingWTUtils.getDisplay(), 178 new org.eclipse.swt.graphics.ImageData( w, h, 16, 179 new org.eclipse.swt.graphics.PaletteData(255, 255, 255) 180 , scansize, pixels)); 181 } 182 } 183 184 public static String getProperty(String key, 185 String defaultValue) { 186 return defaultValue; 187 } 188 } 189 | Popular Tags |