| 1 | /* Copyright (C) 2000, 2002, 2003 Free Software Foundation
|
|---|
| 2 |
|
|---|
| 3 | This file is part of libgcj.
|
|---|
| 4 |
|
|---|
| 5 | This software is copyrighted work licensed under the terms of the
|
|---|
| 6 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|---|
| 7 | details. */
|
|---|
| 8 |
|
|---|
| 9 | package gnu.awt.xlib;
|
|---|
| 10 |
|
|---|
| 11 | import java.awt.*;
|
|---|
| 12 | import java.awt.dnd.*;
|
|---|
| 13 | import java.awt.dnd.peer.*;
|
|---|
| 14 | import java.awt.im.*;
|
|---|
| 15 | import java.awt.peer.*;
|
|---|
| 16 | import java.awt.image.ImageProducer;
|
|---|
| 17 | import java.awt.image.ImageObserver;
|
|---|
| 18 | import java.net.*;
|
|---|
| 19 | import java.awt.datatransfer.Clipboard;
|
|---|
| 20 | import java.util.Properties;
|
|---|
| 21 | import java.util.Map;
|
|---|
| 22 |
|
|---|
| 23 | import gnu.gcj.xlib.Display;
|
|---|
| 24 | import gnu.gcj.xlib.Screen;
|
|---|
| 25 | import gnu.gcj.xlib.Visual;
|
|---|
| 26 |
|
|---|
| 27 | public class XToolkit extends Toolkit
|
|---|
| 28 | {
|
|---|
| 29 | static XToolkit INSTANCE;
|
|---|
| 30 |
|
|---|
| 31 | Display display;
|
|---|
| 32 |
|
|---|
| 33 | EventQueue queue;
|
|---|
| 34 | XEventLoop eventLoop;
|
|---|
| 35 |
|
|---|
| 36 | XGraphicsConfiguration defaultConfig;
|
|---|
| 37 |
|
|---|
| 38 | public XToolkit()
|
|---|
| 39 | {
|
|---|
| 40 | INSTANCE = this;
|
|---|
| 41 | display = new Display();
|
|---|
| 42 | synchronized (display)
|
|---|
| 43 | {
|
|---|
| 44 | queue = new XEventQueue(display);
|
|---|
| 45 | eventLoop = new XEventLoop(display, queue);
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | public void flushIfIdle()
|
|---|
| 50 | {
|
|---|
| 51 | eventLoop.flushIfIdle();
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | protected ButtonPeer createButton(Button frontend)
|
|---|
| 55 | {
|
|---|
| 56 | // FIXME: Stubbed out, needs Swing:
|
|---|
| 57 | /*
|
|---|
| 58 | XCanvasPeer realPeer = new XCanvasPeer(frontend);
|
|---|
| 59 | SButtonPeer sbPeer = new SButtonPeer(frontend, realPeer);
|
|---|
| 60 | return sbPeer;
|
|---|
| 61 | */
|
|---|
| 62 | return null;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | protected TextFieldPeer createTextField(TextField frontend)
|
|---|
| 66 | {
|
|---|
| 67 | return null; // FIXME
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | protected LabelPeer createLabel(Label frontend)
|
|---|
| 71 | {
|
|---|
| 72 | return null; // FIXME
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | protected ListPeer createList(List frontend)
|
|---|
| 76 | {
|
|---|
| 77 | return null; // FIXME
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | protected CheckboxPeer createCheckbox(Checkbox frontend)
|
|---|
| 81 | {
|
|---|
| 82 | return null; // FIXME
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | protected ScrollbarPeer createScrollbar(Scrollbar frontend)
|
|---|
| 86 | {
|
|---|
| 87 | return null; // FIXME
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | protected ScrollPanePeer createScrollPane(ScrollPane frontend)
|
|---|
| 91 | {
|
|---|
| 92 | return null; // FIXME
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | protected TextAreaPeer createTextArea(TextArea frontend)
|
|---|
| 96 | {
|
|---|
| 97 | return null; // FIXME
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | protected ChoicePeer createChoice(Choice frontend)
|
|---|
| 101 | {
|
|---|
| 102 | return null; // FIXME
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | protected FramePeer createFrame(Frame frontend) {
|
|---|
| 106 | return new XFramePeer(frontend);
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | protected CanvasPeer createCanvas(Canvas frontend) {
|
|---|
| 110 | XCanvasPeer peer = new XCanvasPeer(frontend);
|
|---|
| 111 | return peer;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | protected PanelPeer createPanel(Panel frontend) {
|
|---|
| 115 | return new XPanelPeer(frontend);
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | protected WindowPeer createWindow(Window frontend)
|
|---|
| 119 | {
|
|---|
| 120 | return null; // FIXME
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | protected DialogPeer createDialog(Dialog frontend)
|
|---|
| 124 | {
|
|---|
| 125 | return null; // FIXME
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | protected MenuBarPeer createMenuBar(MenuBar frontend)
|
|---|
| 129 | {
|
|---|
| 130 | return null; // FIXME
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | protected MenuPeer createMenu(Menu frontend)
|
|---|
| 134 | {
|
|---|
| 135 | return null; // FIXME
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | protected PopupMenuPeer createPopupMenu(PopupMenu frontend)
|
|---|
| 139 | {
|
|---|
| 140 | return null; // FIXME
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | protected MenuItemPeer createMenuItem(MenuItem frontend)
|
|---|
| 144 | {
|
|---|
| 145 | return null; // FIXME
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | protected FileDialogPeer createFileDialog(FileDialog frontend)
|
|---|
| 149 | {
|
|---|
| 150 | return null; // FIXME
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | protected CheckboxMenuItemPeer
|
|---|
| 154 | createCheckboxMenuItem(CheckboxMenuItem frontend)
|
|---|
| 155 | {
|
|---|
| 156 | return null; // FIXME
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | protected java.awt.peer.FontPeer getFontPeer(String name, int style)
|
|---|
| 160 | {
|
|---|
| 161 | return null;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | public Dimension getScreenSize()
|
|---|
| 165 | {
|
|---|
| 166 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | public int getScreenResolution()
|
|---|
| 170 | {
|
|---|
| 171 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | public java.awt.image.ColorModel getColorModel()
|
|---|
| 175 | {
|
|---|
| 176 | return getDefaultXGraphicsConfiguration().getColorModel();
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | public String[] getFontList()
|
|---|
| 180 | {
|
|---|
| 181 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | public FontMetrics getFontMetrics(Font font)
|
|---|
| 185 | {
|
|---|
| 186 | return defaultConfig.getXFontMetrics(font);
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | public void sync()
|
|---|
| 190 | {
|
|---|
| 191 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | public Image getImage(String filename)
|
|---|
| 195 | {
|
|---|
| 196 | return createImage(filename);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | public Image getImage(URL url)
|
|---|
| 200 | {
|
|---|
| 201 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | public Image createImage(String filename)
|
|---|
| 205 | {
|
|---|
| 206 | // FIXME: Stubbed out. We need a proper image I/O API.
|
|---|
| 207 |
|
|---|
| 208 | /*
|
|---|
| 209 | BufferedImage jpeg;
|
|---|
| 210 | FileInputStream fis = openFile(filename);
|
|---|
| 211 | if (fis == null)
|
|---|
| 212 | return null;
|
|---|
| 213 |
|
|---|
| 214 | BasicRasterImageConsumer consumer = new BasicRasterImageConsumer();
|
|---|
| 215 | JPEGImageDecoder jid = new JPEGImageDecoder(fis);
|
|---|
| 216 |
|
|---|
| 217 | jid.startProduction(consumer);
|
|---|
| 218 | jpeg = consumer.getImage();
|
|---|
| 219 |
|
|---|
| 220 | int w = jpeg.getWidth();
|
|---|
| 221 | int h = jpeg.getHeight();
|
|---|
| 222 |
|
|---|
| 223 | BufferedImage img =
|
|---|
| 224 | getDefaultXGraphicsConfiguration().createCompatibleImage(w, h);
|
|---|
| 225 |
|
|---|
| 226 | Renderers renderers = Renderers.getInstance();
|
|---|
| 227 |
|
|---|
| 228 | RasterOp renderer = renderers.createRenderer(jpeg.getColorModel(),
|
|---|
| 229 | jpeg.getSampleModel(),
|
|---|
| 230 | img.getColorModel(),
|
|---|
| 231 | img.getSampleModel());
|
|---|
| 232 |
|
|---|
| 233 | if (renderer == null)
|
|---|
| 234 | {
|
|---|
| 235 | throw new UnsupportedOperationException("couldn't find renderer");
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | renderer.filter(jpeg.getRaster(), img.getRaster());
|
|---|
| 239 |
|
|---|
| 240 | return img;
|
|---|
| 241 | */
|
|---|
| 242 |
|
|---|
| 243 | return null;
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | public Image createImage(URL url)
|
|---|
| 247 | {
|
|---|
| 248 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | public boolean prepareImage(Image image,
|
|---|
| 252 | int width,
|
|---|
| 253 | int height,
|
|---|
| 254 | ImageObserver observer)
|
|---|
| 255 | {
|
|---|
| 256 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 257 | }
|
|---|
| 258 |
|
|---|
| 259 | public int checkImage(Image image,
|
|---|
| 260 | int width,
|
|---|
| 261 | int height,
|
|---|
| 262 | ImageObserver observer)
|
|---|
| 263 | {
|
|---|
| 264 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 265 | }
|
|---|
| 266 |
|
|---|
| 267 | public Image createImage(ImageProducer producer)
|
|---|
| 268 | {
|
|---|
| 269 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 270 | }
|
|---|
| 271 |
|
|---|
| 272 | public Image createImage(byte[] imagedata,
|
|---|
| 273 | int imageoffset,
|
|---|
| 274 | int imagelength)
|
|---|
| 275 | {
|
|---|
| 276 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | /*
|
|---|
| 280 | public PrintJob getPrintJob(Frame frame,
|
|---|
| 281 | String jobtitle,
|
|---|
| 282 | Properties props);
|
|---|
| 283 | */
|
|---|
| 284 |
|
|---|
| 285 | public void beep()
|
|---|
| 286 | {
|
|---|
| 287 | throw new UnsupportedOperationException("not implemented yet");
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | public Clipboard getSystemClipboard()
|
|---|
| 291 | {
|
|---|
| 292 | return null; // FIXME
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | protected EventQueue getSystemEventQueueImpl()
|
|---|
| 296 | {
|
|---|
| 297 | return queue;
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | public PrintJob getPrintJob (Frame frame, String title, Properties props)
|
|---|
| 301 | {
|
|---|
| 302 | return null; // FIXME
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | XGraphicsConfiguration getDefaultXGraphicsConfiguration()
|
|---|
| 306 | {
|
|---|
| 307 | if (defaultConfig == null)
|
|---|
| 308 | {
|
|---|
| 309 | Screen screen = display.getDefaultScreen();
|
|---|
| 310 | Visual visual = screen.getRootVisual();
|
|---|
| 311 | defaultConfig = new XGraphicsConfiguration(visual);
|
|---|
| 312 |
|
|---|
| 313 | // ASSERT:
|
|---|
| 314 | if (!defaultConfig.getVisual().getScreen().equals(screen))
|
|---|
| 315 | {
|
|---|
| 316 | String msg = "screen of graphics configuration is not " +
|
|---|
| 317 | "default screen";
|
|---|
| 318 | throw new Error(msg);
|
|---|
| 319 | }
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | return defaultConfig;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | public DragSourceContextPeer
|
|---|
| 326 | createDragSourceContextPeer(DragGestureEvent dge)
|
|---|
| 327 | throws InvalidDnDOperationException
|
|---|
| 328 | {
|
|---|
| 329 | throw new UnsupportedOperationException("not implemented");
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | public DragGestureRecognizer
|
|---|
| 333 | createDragGestureRecognizer(Class abstractRecognizerClass,
|
|---|
| 334 | DragSource ds, Component c,
|
|---|
| 335 | int srcActions, DragGestureListener dgl)
|
|---|
| 336 | {
|
|---|
| 337 | throw new UnsupportedOperationException("not implemented");
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 |
|
|---|
| 341 | public Map mapInputMethodHighlight(InputMethodHighlight highlight)
|
|---|
| 342 | {
|
|---|
| 343 | throw new UnsupportedOperationException("not implemented");
|
|---|
| 344 | }
|
|---|
| 345 | }
|
|---|