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
12 import java
.awt
.dnd
.*;
13 import java
.awt
.dnd
.peer
.*;
14 import java
.awt
.font
.*;
16 import java
.awt
.peer
.*;
17 import java
.awt
.image
.ImageProducer
;
18 import java
.awt
.image
.ImageObserver
;
20 import java
.awt
.datatransfer
.Clipboard
;
21 import java
.io
.InputStream
;
22 import java
.text
.AttributedString
;
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
;
43 XGraphicsConfiguration defaultConfig
;
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);
72 protected TextFieldPeer
createTextField(TextField frontend
)
77 protected LabelPeer
createLabel(Label frontend
)
82 protected ListPeer
createList(List frontend
)
87 protected CheckboxPeer
createCheckbox(Checkbox frontend
)
92 protected ScrollbarPeer
createScrollbar(Scrollbar frontend
)
97 protected ScrollPanePeer
createScrollPane(ScrollPane frontend
)
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
);
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
);
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.
220 FileInputStream fis = openFile(filename);
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();
234 getDefaultXGraphicsConfiguration().createCompatibleImage(w, h);
236 Renderers renderers = Renderers.getInstance();
238 RasterOp renderer = renderers.createRenderer(jpeg.getColorModel(),
239 jpeg.getSampleModel(),
241 img.getSampleModel());
243 if (renderer == null)
245 throw new UnsupportedOperationException("couldn't find renderer");
248 renderer.filter(jpeg.getRaster(), img.getRaster());
256 public Image
createImage(URL url
)
258 throw new UnsupportedOperationException("not implemented yet");
261 public boolean prepareImage(Image image
,
264 ImageObserver observer
)
266 throw new UnsupportedOperationException("not implemented yet");
269 public int checkImage(Image image
,
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
,
286 throw new UnsupportedOperationException("not implemented yet");
290 public PrintJob getPrintJob(Frame frame,
297 throw new UnsupportedOperationException("not implemented yet");
300 public Clipboard
getSystemClipboard()
302 return null; // FIXME
305 protected EventQueue
getSystemEventQueueImpl()
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
);
324 if (!defaultConfig
.getVisual().getScreen().equals(screen
))
326 String msg
= "screen of graphics configuration is not " +
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
380 public ClasspathFontPeer
getClasspathFontPeer (String name
, Map attrs
)
382 int style
= Font
.PLAIN
;
385 if (attrs
.containsKey (TextAttribute
.WEIGHT
))
387 Float weight
= (Float
) attrs
.get (TextAttribute
.WEIGHT
);
388 if (weight
.floatValue () >= TextAttribute
.WEIGHT_BOLD
.floatValue ())
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
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
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.
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.
485 catch (InterruptedException ie
)
487 // InterruptedException intentionally ignored