Dead
[official-gcc.git] / gomp-20050608-branch / libjava / gnu / awt / xlib / XToolkit.java
blob6651ae789a21bb26f2e0693ad02f82a2278db759
1 /* Copyright (C) 2000, 2002, 2003, 2005 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package gnu.awt.xlib;
11 import java.awt.*;
12 import java.awt.dnd.*;
13 import java.awt.dnd.peer.*;
14 import java.awt.font.*;
15 import java.awt.im.*;
16 import java.awt.peer.*;
17 import java.awt.image.ImageProducer;
18 import java.awt.image.ImageObserver;
19 import java.net.*;
20 import java.awt.datatransfer.Clipboard;
21 import java.io.InputStream;
22 import java.text.AttributedString;
23 import java.util.Map;
24 import java.util.Properties;
25 import gnu.gcj.xlib.Display;
26 import gnu.gcj.xlib.Screen;
27 import gnu.gcj.xlib.Visual;
28 import gnu.java.awt.ClasspathToolkit;
29 import gnu.java.awt.EmbeddedWindow;
30 import gnu.java.awt.peer.ClasspathFontPeer;
31 import gnu.java.awt.peer.ClasspathTextLayoutPeer;
32 import gnu.java.awt.peer.EmbeddedWindowPeer;
34 public class XToolkit extends ClasspathToolkit
36 static XToolkit INSTANCE;
38 Display display;
40 EventQueue queue;
41 XEventLoop eventLoop;
43 XGraphicsConfiguration defaultConfig;
45 public XToolkit()
47 INSTANCE = this;
48 display = new Display();
49 synchronized (display)
51 queue = new XEventQueue(display);
52 eventLoop = new XEventLoop(display, queue);
56 public void flushIfIdle()
58 eventLoop.flushIfIdle();
61 protected ButtonPeer createButton(Button frontend)
63 // FIXME: Stubbed out, needs Swing:
65 XCanvasPeer realPeer = new XCanvasPeer(frontend);
66 SButtonPeer sbPeer = new SButtonPeer(frontend, realPeer);
67 return sbPeer;
69 return null;
72 protected TextFieldPeer createTextField(TextField frontend)
74 return null; // FIXME
77 protected LabelPeer createLabel(Label frontend)
79 return null; // FIXME
82 protected ListPeer createList(List frontend)
84 return null; // FIXME
87 protected CheckboxPeer createCheckbox(Checkbox frontend)
89 return null; // FIXME
92 protected ScrollbarPeer createScrollbar(Scrollbar frontend)
94 return null; // FIXME
97 protected ScrollPanePeer createScrollPane(ScrollPane frontend)
99 return null; // FIXME
102 protected TextAreaPeer createTextArea(TextArea frontend)
104 return null; // FIXME
107 protected ChoicePeer createChoice(Choice frontend)
109 return null; // FIXME
112 protected FramePeer createFrame(Frame frontend) {
113 return new XFramePeer(frontend);
116 protected CanvasPeer createCanvas(Canvas frontend) {
117 XCanvasPeer peer = new XCanvasPeer(frontend);
118 return peer;
121 protected PanelPeer createPanel(Panel frontend) {
122 return new XPanelPeer(frontend);
125 protected WindowPeer createWindow(Window frontend)
127 return null; // FIXME
130 protected DialogPeer createDialog(Dialog frontend)
132 return null; // FIXME
135 protected MenuBarPeer createMenuBar(MenuBar frontend)
137 return null; // FIXME
140 protected MenuPeer createMenu(Menu frontend)
142 return null; // FIXME
145 protected PopupMenuPeer createPopupMenu(PopupMenu frontend)
147 return null; // FIXME
150 protected MenuItemPeer createMenuItem(MenuItem frontend)
152 return null; // FIXME
155 protected FileDialogPeer createFileDialog(FileDialog frontend)
157 return null; // FIXME
160 protected CheckboxMenuItemPeer
161 createCheckboxMenuItem(CheckboxMenuItem frontend)
163 return null; // FIXME
166 protected java.awt.peer.FontPeer getFontPeer(String name, int style)
168 return new XFontPeer (name,style);
171 public Dimension getScreenSize()
173 throw new UnsupportedOperationException("not implemented yet");
176 public int getScreenResolution()
178 throw new UnsupportedOperationException("not implemented yet");
181 public java.awt.image.ColorModel getColorModel()
183 return getDefaultXGraphicsConfiguration().getColorModel();
186 public String[] getFontList()
188 throw new UnsupportedOperationException("not implemented yet");
191 public FontMetrics getFontMetrics(Font font)
193 return getDefaultXGraphicsConfiguration().getXFontMetrics(font);
196 public void sync()
198 flushIfIdle ();
199 // FIXME: should instead wait for eventLoop to go idle
200 // (perhaps send a dummy event there and block till it makes
201 // it through the queue)
204 public Image getImage(String filename)
206 return createImage(filename);
209 public Image getImage(URL url)
211 throw new UnsupportedOperationException("not implemented yet");
214 public Image createImage(String filename)
216 // FIXME: Stubbed out. We need a proper image I/O API.
219 BufferedImage jpeg;
220 FileInputStream fis = openFile(filename);
221 if (fis == null)
222 return null;
224 BasicRasterImageConsumer consumer = new BasicRasterImageConsumer();
225 JPEGImageDecoder jid = new JPEGImageDecoder(fis);
227 jid.startProduction(consumer);
228 jpeg = consumer.getImage();
230 int w = jpeg.getWidth();
231 int h = jpeg.getHeight();
233 BufferedImage img =
234 getDefaultXGraphicsConfiguration().createCompatibleImage(w, h);
236 Renderers renderers = Renderers.getInstance();
238 RasterOp renderer = renderers.createRenderer(jpeg.getColorModel(),
239 jpeg.getSampleModel(),
240 img.getColorModel(),
241 img.getSampleModel());
243 if (renderer == null)
245 throw new UnsupportedOperationException("couldn't find renderer");
248 renderer.filter(jpeg.getRaster(), img.getRaster());
250 return img;
253 return null;
256 public Image createImage(URL url)
258 throw new UnsupportedOperationException("not implemented yet");
261 public boolean prepareImage(Image image,
262 int width,
263 int height,
264 ImageObserver observer)
266 throw new UnsupportedOperationException("not implemented yet");
269 public int checkImage(Image image,
270 int width,
271 int height,
272 ImageObserver observer)
274 throw new UnsupportedOperationException("not implemented yet");
277 public Image createImage(ImageProducer producer)
279 throw new UnsupportedOperationException("not implemented yet");
282 public Image createImage(byte[] imagedata,
283 int imageoffset,
284 int imagelength)
286 throw new UnsupportedOperationException("not implemented yet");
290 public PrintJob getPrintJob(Frame frame,
291 String jobtitle,
292 Properties props);
295 public void beep()
297 throw new UnsupportedOperationException("not implemented yet");
300 public Clipboard getSystemClipboard()
302 return null; // FIXME
305 protected EventQueue getSystemEventQueueImpl()
307 return queue;
310 public PrintJob getPrintJob (Frame frame, String title, Properties props)
312 return null; // FIXME
315 XGraphicsConfiguration getDefaultXGraphicsConfiguration()
317 if (defaultConfig == null)
319 Screen screen = display.getDefaultScreen();
320 Visual visual = screen.getRootVisual();
321 defaultConfig = new XGraphicsConfiguration(visual);
323 // ASSERT:
324 if (!defaultConfig.getVisual().getScreen().equals(screen))
326 String msg = "screen of graphics configuration is not " +
327 "default screen";
328 throw new Error(msg);
332 return defaultConfig;
335 public DragSourceContextPeer
336 createDragSourceContextPeer(DragGestureEvent dge)
337 throws InvalidDnDOperationException
339 throw new UnsupportedOperationException("not implemented");
342 public DragGestureRecognizer
343 createDragGestureRecognizer(Class abstractRecognizerClass,
344 DragSource ds, Component c,
345 int srcActions, DragGestureListener dgl)
347 throw new UnsupportedOperationException("not implemented");
351 public Map mapInputMethodHighlight(InputMethodHighlight highlight)
353 throw new UnsupportedOperationException("not implemented");
356 /** Returns a shared instance of the local, platform-specific
357 * graphics environment.
359 * <p>This method is specific to GNU Classpath. It gets called by
360 * the Classpath implementation of {@link
361 * GraphicsEnvironment.getLocalGraphcisEnvironment()}.
363 public GraphicsEnvironment getLocalGraphicsEnvironment ()
365 return new XGraphicsEnvironment (this);
368 /** Acquires an appropriate {@link ClasspathFontPeer}, for use in
369 * classpath's implementation of {@link java.awt.Font}.
371 * @param name The logical name of the font. This may be either a face
372 * name or a logical font name, or may even be null. A default
373 * implementation of name decoding is provided in
374 * {@link ClasspathFontPeer}, but may be overridden in other toolkits.
376 * @param attrs Any extra {@link java.awt.font.TextAttribute} attributes
377 * this font peer should have, such as size, weight, family name, or
378 * transformation.
380 public ClasspathFontPeer getClasspathFontPeer (String name, Map attrs)
382 int style = Font.PLAIN;
383 float size = 12;
385 if (attrs.containsKey (TextAttribute.WEIGHT))
387 Float weight = (Float) attrs.get (TextAttribute.WEIGHT);
388 if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ())
389 style += Font.BOLD;
392 if (attrs.containsKey (TextAttribute.POSTURE))
394 Float posture = (Float) attrs.get (TextAttribute.POSTURE);
395 if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ())
396 style += Font.ITALIC;
399 if (attrs.containsKey (TextAttribute.SIZE))
401 Float fsize = (Float) attrs.get (TextAttribute.SIZE);
402 size = fsize.floatValue ();
405 return new XFontPeer (name,style,size);
408 public ClasspathTextLayoutPeer
409 getClasspathTextLayoutPeer (AttributedString str, FontRenderContext frc)
411 throw new Error("not implemented");
414 /** Creates a font, reading the glyph definitions from a stream.
416 * <p>This method provides the platform-specific implementation for
417 * the static factory method {@link Font#createFont(int,
418 * java.io.InputStream)}.
420 * @param format the format of the font data, such as {@link
421 * Font#TRUETYPE_FONT}. An implementation may ignore this argument
422 * if it is able to automatically recognize the font format from the
423 * provided data.
425 * @param stream an input stream from where the font data is read
426 * in. The stream will be advanced to the position after the font
427 * data, but not closed.
429 * @throws IllegalArgumentException if <code>format</code> is
430 * not supported.
432 * @throws FontFormatException if <code>stream</code> does not
433 * contain data in the expected format, or if required tables are
434 * missing from a font.
436 * @throws IOException if a problem occurs while reading in the
437 * contents of <code>stream</code>.
439 public Font createFont (int format, InputStream stream)
441 throw new java.lang.UnsupportedOperationException ();
444 public RobotPeer createRobot (GraphicsDevice screen) throws AWTException
446 throw new java.lang.UnsupportedOperationException ();
449 public EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w)
451 throw new java.lang.UnsupportedOperationException ();
454 public boolean nativeQueueEmpty()
456 // Tell EventQueue the native queue is empty, because XEventLoop
457 // separately ensures that native events are posted to AWT.
458 return true;
461 public void wakeNativeQueue()
463 // Not implemented, because the native queue is always awake.
464 // (i.e. it's polled in a thread separate from the AWT dispatch thread)
467 /** Checks the native event queue for events. If blocking, waits until an
468 * event is available before returning, unless interrupted by
469 * wakeNativeQueue. If non-blocking, returns immediately even if no
470 * event is available.
472 * @param locked The calling EventQueue
473 * @param block If true, waits for a native event before returning
475 public void iterateNativeQueue(java.awt.EventQueue locked, boolean block)
477 // There is nothing to do here except block, because XEventLoop
478 // iterates the queue in a dedicated thread.
479 if (block)
483 queue.wait ();
485 catch (InterruptedException ie)
487 // InterruptedException intentionally ignored