1 /* Copyright (C) 2000, 2002, 2003 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
.peer
.ClasspathFontPeer
;
30 import gnu
.java
.awt
.peer
.ClasspathTextLayoutPeer
;
32 public class XToolkit
extends ClasspathToolkit
34 static XToolkit INSTANCE
;
41 XGraphicsConfiguration defaultConfig
;
46 display
= new Display();
47 synchronized (display
)
49 queue
= new XEventQueue(display
);
50 eventLoop
= new XEventLoop(display
, queue
);
54 public void flushIfIdle()
56 eventLoop
.flushIfIdle();
59 protected ButtonPeer
createButton(Button frontend
)
61 // FIXME: Stubbed out, needs Swing:
63 XCanvasPeer realPeer = new XCanvasPeer(frontend);
64 SButtonPeer sbPeer = new SButtonPeer(frontend, realPeer);
70 protected TextFieldPeer
createTextField(TextField frontend
)
75 protected LabelPeer
createLabel(Label frontend
)
80 protected ListPeer
createList(List frontend
)
85 protected CheckboxPeer
createCheckbox(Checkbox frontend
)
90 protected ScrollbarPeer
createScrollbar(Scrollbar frontend
)
95 protected ScrollPanePeer
createScrollPane(ScrollPane frontend
)
100 protected TextAreaPeer
createTextArea(TextArea frontend
)
102 return null; // FIXME
105 protected ChoicePeer
createChoice(Choice frontend
)
107 return null; // FIXME
110 protected FramePeer
createFrame(Frame frontend
) {
111 return new XFramePeer(frontend
);
114 protected CanvasPeer
createCanvas(Canvas frontend
) {
115 XCanvasPeer peer
= new XCanvasPeer(frontend
);
119 protected PanelPeer
createPanel(Panel frontend
) {
120 return new XPanelPeer(frontend
);
123 protected WindowPeer
createWindow(Window frontend
)
125 return null; // FIXME
128 protected DialogPeer
createDialog(Dialog frontend
)
130 return null; // FIXME
133 protected MenuBarPeer
createMenuBar(MenuBar frontend
)
135 return null; // FIXME
138 protected MenuPeer
createMenu(Menu frontend
)
140 return null; // FIXME
143 protected PopupMenuPeer
createPopupMenu(PopupMenu frontend
)
145 return null; // FIXME
148 protected MenuItemPeer
createMenuItem(MenuItem frontend
)
150 return null; // FIXME
153 protected FileDialogPeer
createFileDialog(FileDialog frontend
)
155 return null; // FIXME
158 protected CheckboxMenuItemPeer
159 createCheckboxMenuItem(CheckboxMenuItem frontend
)
161 return null; // FIXME
164 protected java
.awt
.peer
.FontPeer
getFontPeer(String name
, int style
)
166 return new XFontPeer (name
,style
);
169 public Dimension
getScreenSize()
171 throw new UnsupportedOperationException("not implemented yet");
174 public int getScreenResolution()
176 throw new UnsupportedOperationException("not implemented yet");
179 public java
.awt
.image
.ColorModel
getColorModel()
181 return getDefaultXGraphicsConfiguration().getColorModel();
184 public String
[] getFontList()
186 throw new UnsupportedOperationException("not implemented yet");
189 public FontMetrics
getFontMetrics(Font font
)
191 return getDefaultXGraphicsConfiguration().getXFontMetrics(font
);
197 // FIXME: should instead wait for eventLoop to go idle
198 // (perhaps send a dummy event there and block till it makes
199 // it through the queue)
202 public Image
getImage(String filename
)
204 return createImage(filename
);
207 public Image
getImage(URL url
)
209 throw new UnsupportedOperationException("not implemented yet");
212 public Image
createImage(String filename
)
214 // FIXME: Stubbed out. We need a proper image I/O API.
218 FileInputStream fis = openFile(filename);
222 BasicRasterImageConsumer consumer = new BasicRasterImageConsumer();
223 JPEGImageDecoder jid = new JPEGImageDecoder(fis);
225 jid.startProduction(consumer);
226 jpeg = consumer.getImage();
228 int w = jpeg.getWidth();
229 int h = jpeg.getHeight();
232 getDefaultXGraphicsConfiguration().createCompatibleImage(w, h);
234 Renderers renderers = Renderers.getInstance();
236 RasterOp renderer = renderers.createRenderer(jpeg.getColorModel(),
237 jpeg.getSampleModel(),
239 img.getSampleModel());
241 if (renderer == null)
243 throw new UnsupportedOperationException("couldn't find renderer");
246 renderer.filter(jpeg.getRaster(), img.getRaster());
254 public Image
createImage(URL url
)
256 throw new UnsupportedOperationException("not implemented yet");
259 public boolean prepareImage(Image image
,
262 ImageObserver observer
)
264 throw new UnsupportedOperationException("not implemented yet");
267 public int checkImage(Image image
,
270 ImageObserver observer
)
272 throw new UnsupportedOperationException("not implemented yet");
275 public Image
createImage(ImageProducer producer
)
277 throw new UnsupportedOperationException("not implemented yet");
280 public Image
createImage(byte[] imagedata
,
284 throw new UnsupportedOperationException("not implemented yet");
288 public PrintJob getPrintJob(Frame frame,
295 throw new UnsupportedOperationException("not implemented yet");
298 public Clipboard
getSystemClipboard()
300 return null; // FIXME
303 protected EventQueue
getSystemEventQueueImpl()
308 public PrintJob
getPrintJob (Frame frame
, String title
, Properties props
)
310 return null; // FIXME
313 XGraphicsConfiguration
getDefaultXGraphicsConfiguration()
315 if (defaultConfig
== null)
317 Screen screen
= display
.getDefaultScreen();
318 Visual visual
= screen
.getRootVisual();
319 defaultConfig
= new XGraphicsConfiguration(visual
);
322 if (!defaultConfig
.getVisual().getScreen().equals(screen
))
324 String msg
= "screen of graphics configuration is not " +
326 throw new Error(msg
);
330 return defaultConfig
;
333 public DragSourceContextPeer
334 createDragSourceContextPeer(DragGestureEvent dge
)
335 throws InvalidDnDOperationException
337 throw new UnsupportedOperationException("not implemented");
340 public DragGestureRecognizer
341 createDragGestureRecognizer(Class abstractRecognizerClass
,
342 DragSource ds
, Component c
,
343 int srcActions
, DragGestureListener dgl
)
345 throw new UnsupportedOperationException("not implemented");
349 public Map
mapInputMethodHighlight(InputMethodHighlight highlight
)
351 throw new UnsupportedOperationException("not implemented");
354 /** Returns a shared instance of the local, platform-specific
355 * graphics environment.
357 * <p>This method is specific to GNU Classpath. It gets called by
358 * the Classpath implementation of {@link
359 * GraphicsEnvironment.getLocalGraphcisEnvironment()}.
361 public GraphicsEnvironment
getLocalGraphicsEnvironment ()
363 throw new java
.lang
.UnsupportedOperationException ();
366 /** Acquires an appropriate {@link ClasspathFontPeer}, for use in
367 * classpath's implementation of {@link java.awt.Font}.
369 * @param name The logical name of the font. This may be either a face
370 * name or a logical font name, or may even be null. A default
371 * implementation of name decoding is provided in
372 * {@link ClasspathFontPeer}, but may be overridden in other toolkits.
374 * @param attrs Any extra {@link java.awt.font.TextAttribute} attributes
375 * this font peer should have, such as size, weight, family name, or
378 public ClasspathFontPeer
getClasspathFontPeer (String name
, Map attrs
)
380 int style
= Font
.PLAIN
;
383 if (attrs
.containsKey (TextAttribute
.WEIGHT
))
385 Float weight
= (Float
) attrs
.get (TextAttribute
.WEIGHT
);
386 if (weight
.floatValue () >= TextAttribute
.WEIGHT_BOLD
.floatValue ())
390 if (attrs
.containsKey (TextAttribute
.POSTURE
))
392 Float posture
= (Float
) attrs
.get (TextAttribute
.POSTURE
);
393 if (posture
.floatValue () >= TextAttribute
.POSTURE_OBLIQUE
.floatValue ())
394 style
+= Font
.ITALIC
;
397 if (attrs
.containsKey (TextAttribute
.SIZE
))
399 Float fsize
= (Float
) attrs
.get (TextAttribute
.SIZE
);
400 size
= fsize
.floatValue ();
403 return new XFontPeer (name
,style
,size
);
406 public ClasspathTextLayoutPeer
407 getClasspathTextLayoutPeer (AttributedString str
, FontRenderContext frc
)
409 throw new Error("not implemented");
412 /** Creates a font, reading the glyph definitions from a stream.
414 * <p>This method provides the platform-specific implementation for
415 * the static factory method {@link Font#createFont(int,
416 * java.io.InputStream)}.
418 * @param format the format of the font data, such as {@link
419 * Font#TRUETYPE_FONT}. An implementation may ignore this argument
420 * if it is able to automatically recognize the font format from the
423 * @param stream an input stream from where the font data is read
424 * in. The stream will be advanced to the position after the font
425 * data, but not closed.
427 * @throws IllegalArgumentException if <code>format</code> is
430 * @throws FontFormatException if <code>stream</code> does not
431 * contain data in the expected format, or if required tables are
432 * missing from a font.
434 * @throws IOException if a problem occurs while reading in the
435 * contents of <code>stream</code>.
437 public Font
createFont (int format
, InputStream stream
)
439 throw new java
.lang
.UnsupportedOperationException ();
442 public RobotPeer
createRobot (GraphicsDevice screen
) throws AWTException
444 throw new java
.lang
.UnsupportedOperationException ();
449 public boolean nativeQueueEmpty()
451 return eventLoop
.isIdle();
454 public void wakeNativeQueue()
457 eventLoop
.interrupt();
460 public void iterateNativeQueue(java
.awt
.EventQueue locked
, boolean block
)
464 eventLoop
.postNextEvent(block
);