1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59: import ;
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69: import ;
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82: import ;
83: import ;
84: import ;
85: import ;
86: import ;
87: import ;
88: import ;
89: import ;
90: import ;
91: import ;
92: import ;
93: import ;
94: import ;
95: import ;
96: import ;
97: import ;
98: import ;
99: import ;
100: import ;
101: import ;
102: import ;
103: import ;
104: import ;
105: import ;
106: import ;
107: import ;
108: import ;
109: import ;
110: import ;
111: import ;
112: import ;
113: import ;
114:
115: import ;
116:
117: import ;
118: import ;
119: import ;
120: import ;
121: import ;
122: import ;
123: import ;
124: import ;
125:
126: public class XToolkit
127: extends ClasspathToolkit
128: {
129:
130:
133: static boolean DEBUG = false;
134:
135:
138: HashMap colorMap = new HashMap();
139:
140:
143: private EventQueue eventQueue;
144:
145:
148: private ColorModel colorModel;
149:
150:
153: private HashMap imageCache = new HashMap();
154:
155:
158: private WeakHashMap fontCache = new WeakHashMap();
159:
160: public XToolkit()
161: {
162: SystemProperties.setProperty("gnu.javax.swing.noGraphics2D", "true");
163: SystemProperties.setProperty("java.awt.graphicsenv",
164: "gnu.java.awt.peer.x.XGraphicsEnvironment");
165: }
166:
167: public GraphicsEnvironment getLocalGraphicsEnvironment()
168: {
169: return new XGraphicsEnvironment();
170: }
171:
172:
180: public ClasspathFontPeer getClasspathFontPeer(String name, Map attrs)
181: {
182: String canonical = XFontPeer.encodeFont(name, attrs);
183: ClasspathFontPeer font;
184: if (!fontCache.containsKey(canonical))
185: {
186: String graphics2d =
187: SystemProperties.getProperty("gnu.xawt.graphics2d");
188: if (graphics2d != null && graphics2d.equals("gl"))
189: font = new XFontPeer2(name, attrs);
190: else
191: font = new XFontPeer(name, attrs);
192: fontCache.put(canonical, font);
193: }
194: else
195: {
196: font = (ClasspathFontPeer) fontCache.get(canonical);
197: }
198: return font;
199: }
200:
201: public Font createFont(int format, InputStream stream)
202: {
203: return null;
204: }
205:
206: public RobotPeer createRobot(GraphicsDevice screen) throws AWTException
207: {
208:
209: throw new UnsupportedOperationException("Not yet implemented.");
210: }
211:
212: public EmbeddedWindowPeer createEmbeddedWindow(EmbeddedWindow w)
213: {
214:
215: throw new UnsupportedOperationException("Not yet implemented.");
216: }
217:
218: protected ButtonPeer createButton(Button target)
219: {
220:
221: throw new UnsupportedOperationException("Not yet implemented.");
222: }
223:
224: protected TextFieldPeer createTextField(TextField target)
225: {
226:
227: throw new UnsupportedOperationException("Not yet implemented.");
228: }
229:
230: protected LabelPeer createLabel(Label target)
231: {
232: return new SwingLabelPeer(target);
233: }
234:
235: protected ListPeer createList(List target)
236: {
237:
238: throw new UnsupportedOperationException("Not yet implemented.");
239: }
240:
241: protected CheckboxPeer createCheckbox(Checkbox target)
242: {
243:
244: throw new UnsupportedOperationException("Not yet implemented.");
245: }
246:
247: protected ScrollbarPeer createScrollbar(Scrollbar target)
248: {
249:
250: throw new UnsupportedOperationException("Not yet implemented.");
251: }
252:
253: protected ScrollPanePeer createScrollPane(ScrollPane target)
254: {
255:
256: throw new UnsupportedOperationException("Not yet implemented.");
257: }
258:
259: protected TextAreaPeer createTextArea(TextArea target)
260: {
261:
262: throw new UnsupportedOperationException("Not yet implemented.");
263: }
264:
265: protected ChoicePeer createChoice(Choice target)
266: {
267:
268: throw new UnsupportedOperationException("Not yet implemented.");
269: }
270:
271: protected FramePeer createFrame(Frame target)
272: {
273: XFramePeer frame = new XFramePeer(target);
274: return frame;
275: }
276:
277: protected CanvasPeer createCanvas(Canvas target)
278: {
279: return new SwingCanvasPeer(target);
280: }
281:
282: protected PanelPeer createPanel(Panel target)
283: {
284: return new SwingPanelPeer(target);
285: }
286:
287: protected WindowPeer createWindow(Window target)
288: {
289: return new XWindowPeer(target);
290: }
291:
292: protected DialogPeer createDialog(Dialog target)
293: {
294: return new XDialogPeer(target);
295: }
296:
297: protected MenuBarPeer createMenuBar(MenuBar target)
298: {
299:
300: throw new UnsupportedOperationException("Not yet implemented.");
301: }
302:
303: protected MenuPeer createMenu(Menu target)
304: {
305:
306: throw new UnsupportedOperationException("Not yet implemented.");
307: }
308:
309: protected PopupMenuPeer createPopupMenu(PopupMenu target)
310: {
311:
312: throw new UnsupportedOperationException("Not yet implemented.");
313: }
314:
315: protected MenuItemPeer createMenuItem(MenuItem target)
316: {
317:
318: throw new UnsupportedOperationException("Not yet implemented.");
319: }
320:
321: protected FileDialogPeer createFileDialog(FileDialog target)
322: {
323:
324: throw new UnsupportedOperationException("Not yet implemented.");
325: }
326:
327: protected CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)
328: {
329:
330: throw new UnsupportedOperationException("Not yet implemented.");
331: }
332:
333: protected FontPeer getFontPeer(String name, int style)
334: {
335:
336: throw new UnsupportedOperationException("Not yet implemented.");
337: }
338:
339: public Dimension getScreenSize()
340: {
341:
342: return new Dimension(1024, 768);
343: }
344:
345: public int getScreenResolution()
346: {
347:
348: throw new UnsupportedOperationException("Not yet implemented.");
349: }
350:
351:
356: public ColorModel getColorModel()
357: {
358:
359: if (colorModel == null)
360: colorModel = new DirectColorModel(24, 0xFF0000, 0xFF00, 0xFF);
361: return colorModel;
362: }
363:
364: public String[] getFontList()
365: {
366:
367: throw new UnsupportedOperationException("Not yet implemented.");
368: }
369:
370: public FontMetrics getFontMetrics(Font name)
371: {
372: ClasspathFontPeer peer = (ClasspathFontPeer) name.getPeer();
373: return peer.getFontMetrics(name);
374: }
375:
376: public void sync()
377: {
378:
379: throw new UnsupportedOperationException("Not yet implemented.");
380: }
381:
382:
391: public Image getImage(String name)
392: {
393: Image image;
394: try
395: {
396: File file = new File(name);
397: image = getImage(file.toURL());
398: }
399: catch (MalformedURLException ex)
400: {
401:
402: image = null;
403: }
404: return image;
405: }
406:
407:
416: public Image getImage(URL url)
417: {
418: Image image;
419: if (imageCache.containsKey(url))
420: {
421: image = (Image) imageCache.get(url);
422: }
423: else
424: {
425: image = createImage(url);
426: imageCache.put(url, image);
427: }
428: return image;
429: }
430:
431:
440: public Image createImage(String filename)
441: {
442: Image im;
443: try
444: {
445: File file = new File(filename);
446: URL url = file.toURL();
447: im = createImage(url);
448: }
449: catch (MalformedURLException ex)
450: {
451: im = createErrorImage();
452: }
453: return im;
454: }
455:
456:
465: public Image createImage(URL url)
466: {
467: Image image;
468: try
469: {
470: image = createImage(url.openStream());
471: }
472: catch (IOException ex)
473: {
474: image = createErrorImage();
475: }
476: return image;
477: }
478:
479:
486: private Image createErrorImage()
487: {
488:
489: return new XImage(1, 1);
490: }
491:
492: public boolean prepareImage(Image image, int width, int height, ImageObserver observer)
493: {
494:
495: return true;
496: }
497:
498: public int checkImage(Image image, int width, int height, ImageObserver observer)
499: {
500:
501: throw new UnsupportedOperationException("Not yet implemented.");
502: }
503:
504: public Image createImage(ImageProducer producer)
505: {
506: ImageConverter conv = new ImageConverter();
507: producer.startProduction(conv);
508: Image image = conv.getXImage();
509: return image;
510: }
511:
512: public Image createImage(byte[] data, int offset, int len)
513: {
514: Image image;
515: try
516: {
517: ByteArrayInputStream i = new ByteArrayInputStream(data, offset, len);
518: image = createImage(i);
519: }
520: catch (IOException ex)
521: {
522: image = createErrorImage();
523: }
524: return image;
525: }
526:
527: private Image createImage(InputStream i)
528: throws IOException
529: {
530: Image image;
531: BufferedImage buffered = ImageIO.read(i);
532:
533:
534: if (buffered != null && buffered.getTransparency() == Transparency.OPAQUE)
535: {
536: ImageProducer source = buffered.getSource();
537: image = createImage(source);
538: }
539: else if (buffered != null)
540: {
541: image = buffered;
542: }
543: else
544: {
545: image = createErrorImage();
546: }
547: return image;
548: }
549:
550: public PrintJob getPrintJob(Frame frame, String title, Properties props)
551: {
552:
553: throw new UnsupportedOperationException("Not yet implemented.");
554: }
555:
556: public void beep()
557: {
558:
559: throw new UnsupportedOperationException("Not yet implemented.");
560: }
561:
562: public Clipboard getSystemClipboard()
563: {
564:
565: throw new UnsupportedOperationException("Not yet implemented.");
566: }
567:
568:
573: protected EventQueue getSystemEventQueueImpl()
574: {
575: if (eventQueue == null)
576: eventQueue = new EventQueue();
577: return eventQueue;
578: }
579:
580: public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent e)
581: {
582:
583: throw new UnsupportedOperationException("Not yet implemented.");
584: }
585:
586: public Map mapInputMethodHighlight(InputMethodHighlight highlight)
587: {
588:
589: throw new UnsupportedOperationException("Not yet implemented.");
590: }
591:
592:
597: static XGraphicsDevice getDefaultDevice()
598: {
599: XGraphicsEnvironment env = (XGraphicsEnvironment)
600: XGraphicsEnvironment.getLocalGraphicsEnvironment();
601: return (XGraphicsDevice) env.getDefaultScreenDevice();
602: }
603:
604: protected LightweightPeer createComponent(Component c)
605: {
606: return new XLightweightPeer(c);
607: }
608: }