| 1 | /* Toolkit.java -- AWT Toolkit superclass
|
|---|
| 2 | Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt;
|
|---|
| 40 |
|
|---|
| 41 | import java.awt.datatransfer.Clipboard;
|
|---|
| 42 | import java.awt.dnd.DragGestureEvent;
|
|---|
| 43 | import java.awt.dnd.DragGestureListener;
|
|---|
| 44 | import java.awt.dnd.DragGestureRecognizer;
|
|---|
| 45 | import java.awt.dnd.DragSource;
|
|---|
| 46 | import java.awt.dnd.peer.DragSourceContextPeer;
|
|---|
| 47 | import java.awt.event.AWTEventListener;
|
|---|
| 48 | import java.awt.event.KeyEvent;
|
|---|
| 49 | import java.awt.im.InputMethodHighlight;
|
|---|
| 50 | import java.awt.image.ColorModel;
|
|---|
| 51 | import java.awt.image.ImageObserver;
|
|---|
| 52 | import java.awt.image.ImageProducer;
|
|---|
| 53 | import java.awt.peer.ButtonPeer;
|
|---|
| 54 | import java.awt.peer.CanvasPeer;
|
|---|
| 55 | import java.awt.peer.CheckboxPeer;
|
|---|
| 56 | import java.awt.peer.CheckboxMenuItemPeer;
|
|---|
| 57 | import java.awt.peer.ChoicePeer;
|
|---|
| 58 | import java.awt.peer.DialogPeer;
|
|---|
| 59 | import java.awt.peer.FileDialogPeer;
|
|---|
| 60 | import java.awt.peer.FontPeer;
|
|---|
| 61 | import java.awt.peer.FramePeer;
|
|---|
| 62 | import java.awt.peer.LabelPeer;
|
|---|
| 63 | import java.awt.peer.LightweightPeer;
|
|---|
| 64 | import java.awt.peer.ListPeer;
|
|---|
| 65 | import java.awt.peer.MenuPeer;
|
|---|
| 66 | import java.awt.peer.MenuBarPeer;
|
|---|
| 67 | import java.awt.peer.MenuItemPeer;
|
|---|
| 68 | import java.awt.peer.PanelPeer;
|
|---|
| 69 | import java.awt.peer.PopupMenuPeer;
|
|---|
| 70 | import java.awt.peer.ScrollbarPeer;
|
|---|
| 71 | import java.awt.peer.ScrollPanePeer;
|
|---|
| 72 | import java.awt.peer.TextAreaPeer;
|
|---|
| 73 | import java.awt.peer.TextFieldPeer;
|
|---|
| 74 | import java.awt.peer.WindowPeer;
|
|---|
| 75 | import java.beans.PropertyChangeListener;
|
|---|
| 76 | import java.beans.PropertyChangeSupport;
|
|---|
| 77 | import java.net.URL;
|
|---|
| 78 | import java.util.Map;
|
|---|
| 79 | import java.util.Properties;
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | * The AWT system uses a set of native peer objects to implement its
|
|---|
| 83 | * widgets. These peers are provided by a peer toolkit, that is accessed
|
|---|
| 84 | * via a subclass of this superclass. The system toolkit is retrieved
|
|---|
| 85 | * by the static methods <code>getDefaultToolkit</code>. This method
|
|---|
| 86 | * determines the system toolkit by examining the system property
|
|---|
| 87 | * <code>awt.toolkit</code>. That property is set to the name of the
|
|---|
| 88 | * <code>Toolkit</code> subclass for the specified peer set. If the
|
|---|
| 89 | * <code>awt.toolkit</code> property is not set, then the default
|
|---|
| 90 | * toolkit <code>gnu.java.awt.peer.gtk.GtkToolkit</code> is used. This
|
|---|
| 91 | * toolkit creates its peers using the GTK+ toolkit.
|
|---|
| 92 | *
|
|---|
| 93 | * @author Aaron M. Renn <[email protected]>
|
|---|
| 94 | */
|
|---|
| 95 | public abstract class Toolkit
|
|---|
| 96 | {
|
|---|
| 97 | /** The default toolkit name. */
|
|---|
| 98 | private static String default_toolkit_name
|
|---|
| 99 | = "gnu.awt.gtk.GtkToolkit";
|
|---|
| 100 |
|
|---|
| 101 | /**
|
|---|
| 102 | * The toolkit in use. Once we load it, we don't ever change it
|
|---|
| 103 | * if the awt.toolkit property is set.
|
|---|
| 104 | */
|
|---|
| 105 | private static Toolkit toolkit;
|
|---|
| 106 |
|
|---|
| 107 | /** The toolkit properties. */
|
|---|
| 108 | private static Properties props = new Properties();
|
|---|
| 109 |
|
|---|
| 110 | protected final Map desktopProperties = new Properties();
|
|---|
| 111 |
|
|---|
| 112 | protected final PropertyChangeSupport desktopPropsSupport
|
|---|
| 113 | = new PropertyChangeSupport(this);
|
|---|
| 114 |
|
|---|
| 115 | /**
|
|---|
| 116 | * Default constructor for subclasses.
|
|---|
| 117 | */
|
|---|
| 118 | public Toolkit()
|
|---|
| 119 | {
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /**
|
|---|
| 123 | * Creates a peer object for the specified <code>Button</code>.
|
|---|
| 124 | *
|
|---|
| 125 | * @param target The <code>Button</code> to create the peer for.
|
|---|
| 126 | *
|
|---|
| 127 | * @return The peer for the specified <code>Button</code> object.
|
|---|
| 128 | *
|
|---|
| 129 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 130 | */
|
|---|
| 131 | protected abstract ButtonPeer createButton(Button target);
|
|---|
| 132 |
|
|---|
| 133 | /**
|
|---|
| 134 | * Creates a peer object for the specified <code>TextField</code>.
|
|---|
| 135 | *
|
|---|
| 136 | * @param target The <code>TextField</code> to create the peer for.
|
|---|
| 137 | * @return The peer for the specified <code>TextField</code> object.
|
|---|
| 138 | *
|
|---|
| 139 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 140 | */
|
|---|
| 141 | protected abstract TextFieldPeer createTextField(TextField target);
|
|---|
| 142 |
|
|---|
| 143 | /**
|
|---|
| 144 | * Creates a peer object for the specified <code>Label</code>.
|
|---|
| 145 | *
|
|---|
| 146 | * @param target The <code>Label</code> to create the peer for.
|
|---|
| 147 | * @return The peer for the specified <code>Label</code> object.
|
|---|
| 148 | *
|
|---|
| 149 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 150 | */
|
|---|
| 151 | protected abstract LabelPeer createLabel(Label target);
|
|---|
| 152 |
|
|---|
| 153 | /**
|
|---|
| 154 | * Creates a peer object for the specified <code>List</code>.
|
|---|
| 155 | *
|
|---|
| 156 | * @param target The <code>List</code> to create the peer for.
|
|---|
| 157 | * @return The peer for the specified <code>List</code> object.
|
|---|
| 158 | *
|
|---|
| 159 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 160 | */
|
|---|
| 161 | protected abstract ListPeer createList(List target);
|
|---|
| 162 |
|
|---|
| 163 | /**
|
|---|
| 164 | * Creates a peer object for the specified <code>Checkbox</code>.
|
|---|
| 165 | *
|
|---|
| 166 | * @param target The <code>Checkbox</code> to create the peer for.
|
|---|
| 167 | * @return The peer for the specified <code>Checkbox</code> object.
|
|---|
| 168 | *
|
|---|
| 169 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 170 | */
|
|---|
| 171 | protected abstract CheckboxPeer createCheckbox(Checkbox target);
|
|---|
| 172 |
|
|---|
| 173 | /**
|
|---|
| 174 | * Creates a peer object for the specified <code>Scrollbar</code>.
|
|---|
| 175 | *
|
|---|
| 176 | * @param target The <code>Scrollbar</code> to create the peer for.
|
|---|
| 177 | * @return The peer for the specified <code>Scrollbar</code> object.
|
|---|
| 178 | *
|
|---|
| 179 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 180 | */
|
|---|
| 181 | protected abstract ScrollbarPeer createScrollbar(Scrollbar target);
|
|---|
| 182 |
|
|---|
| 183 | /**
|
|---|
| 184 | * Creates a peer object for the specified <code>ScrollPane</code>.
|
|---|
| 185 | *
|
|---|
| 186 | * @param target The <code>ScrollPane</code> to create the peer for.
|
|---|
| 187 | * @return The peer for the specified <code>ScrollPane</code> object.
|
|---|
| 188 | *
|
|---|
| 189 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 190 | */
|
|---|
| 191 | protected abstract ScrollPanePeer createScrollPane(ScrollPane target);
|
|---|
| 192 |
|
|---|
| 193 | /**
|
|---|
| 194 | * Creates a peer object for the specified <code>TextArea</code>.
|
|---|
| 195 | *
|
|---|
| 196 | * @param target The <code>TextArea</code> to create the peer for.
|
|---|
| 197 | * @return The peer for the specified <code>TextArea</code> object.
|
|---|
| 198 | *
|
|---|
| 199 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 200 | */
|
|---|
| 201 | protected abstract TextAreaPeer createTextArea(TextArea target);
|
|---|
| 202 |
|
|---|
| 203 | /**
|
|---|
| 204 | * Creates a peer object for the specified <code>Choice</code>.
|
|---|
| 205 | *
|
|---|
| 206 | * @param target The <code>Choice</code> to create the peer for.
|
|---|
| 207 | * @return The peer for the specified <code>Choice</code> object.
|
|---|
| 208 | *
|
|---|
| 209 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 210 | */
|
|---|
| 211 | protected abstract ChoicePeer createChoice(Choice target);
|
|---|
| 212 |
|
|---|
| 213 | /**
|
|---|
| 214 | * Creates a peer object for the specified <code>Frame</code>.
|
|---|
| 215 | *
|
|---|
| 216 | * @param target The <code>Frame</code> to create the peer for.
|
|---|
| 217 | * @return The peer for the specified <code>Frame</code> object.
|
|---|
| 218 | *
|
|---|
| 219 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 220 | */
|
|---|
| 221 | protected abstract FramePeer createFrame(Frame target);
|
|---|
| 222 |
|
|---|
| 223 | /**
|
|---|
| 224 | * Creates a peer object for the specified <code>Canvas</code>.
|
|---|
| 225 | *
|
|---|
| 226 | * @param target The <code>Canvas</code> to create the peer for.
|
|---|
| 227 | * @return The peer for the specified <code>Canvas</code> object.
|
|---|
| 228 | */
|
|---|
| 229 | protected abstract CanvasPeer createCanvas(Canvas target);
|
|---|
| 230 |
|
|---|
| 231 | /**
|
|---|
| 232 | * Creates a peer object for the specified <code>Panel</code>.
|
|---|
| 233 | *
|
|---|
| 234 | * @param target The <code>Panel</code> to create the peer for.
|
|---|
| 235 | * @return The peer for the specified <code>Panel</code> object.
|
|---|
| 236 | */
|
|---|
| 237 | protected abstract PanelPeer createPanel(Panel target);
|
|---|
| 238 |
|
|---|
| 239 | /**
|
|---|
| 240 | * Creates a peer object for the specified <code>Window</code>.
|
|---|
| 241 | *
|
|---|
| 242 | * @param target The <code>Window</code> to create the peer for.
|
|---|
| 243 | * @return The peer for the specified <code>Window</code> object.
|
|---|
| 244 | *
|
|---|
| 245 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 246 | */
|
|---|
| 247 | protected abstract WindowPeer createWindow(Window target);
|
|---|
| 248 |
|
|---|
| 249 | /**
|
|---|
| 250 | * Creates a peer object for the specified <code>Dialog</code>.
|
|---|
| 251 | *
|
|---|
| 252 | * @param target The dialog to create the peer for
|
|---|
| 253 | * @return The peer for the specified font name.
|
|---|
| 254 | *
|
|---|
| 255 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 256 | */
|
|---|
| 257 | protected abstract DialogPeer createDialog(Dialog target);
|
|---|
| 258 |
|
|---|
| 259 | /**
|
|---|
| 260 | * Creates a peer object for the specified <code>MenuBar</code>.
|
|---|
| 261 | *
|
|---|
| 262 | * @param target The <code>MenuBar</code> to create the peer for.
|
|---|
| 263 | * @return The peer for the specified <code>MenuBar</code> object.
|
|---|
| 264 | *
|
|---|
| 265 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 266 | */
|
|---|
| 267 | protected abstract MenuBarPeer createMenuBar(MenuBar target);
|
|---|
| 268 |
|
|---|
| 269 | /**
|
|---|
| 270 | * Creates a peer object for the specified <code>Menu</code>.
|
|---|
| 271 | *
|
|---|
| 272 | * @param target The <code>Menu</code> to create the peer for.
|
|---|
| 273 | * @return The peer for the specified <code>Menu</code> object.
|
|---|
| 274 | *
|
|---|
| 275 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 276 | */
|
|---|
| 277 | protected abstract MenuPeer createMenu(Menu target);
|
|---|
| 278 |
|
|---|
| 279 | /**
|
|---|
| 280 | * Creates a peer object for the specified <code>PopupMenu</code>.
|
|---|
| 281 | *
|
|---|
| 282 | * @param target The <code>PopupMenu</code> to create the peer for.
|
|---|
| 283 | * @return The peer for the specified <code>PopupMenu</code> object.
|
|---|
| 284 | *
|
|---|
| 285 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 286 | */
|
|---|
| 287 | protected abstract PopupMenuPeer createPopupMenu(PopupMenu target);
|
|---|
| 288 |
|
|---|
| 289 | /**
|
|---|
| 290 | * Creates a peer object for the specified <code>MenuItem</code>.
|
|---|
| 291 | *
|
|---|
| 292 | * @param target The <code>MenuItem</code> to create the peer for.
|
|---|
| 293 | * @return The peer for the specified <code>MenuItem</code> object.
|
|---|
| 294 | *
|
|---|
| 295 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 296 | */
|
|---|
| 297 | protected abstract MenuItemPeer createMenuItem(MenuItem target);
|
|---|
| 298 |
|
|---|
| 299 | /**
|
|---|
| 300 | * Creates a peer object for the specified <code>FileDialog</code>.
|
|---|
| 301 | *
|
|---|
| 302 | * @param target The <code>FileDialog</code> to create the peer for.
|
|---|
| 303 | * @return The peer for the specified <code>FileDialog</code> object.
|
|---|
| 304 | *
|
|---|
| 305 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 306 | */
|
|---|
| 307 | protected abstract FileDialogPeer createFileDialog(FileDialog target);
|
|---|
| 308 |
|
|---|
| 309 | /**
|
|---|
| 310 | * Creates a peer object for the specified <code>CheckboxMenuItem</code>.
|
|---|
| 311 | *
|
|---|
| 312 | * @param target The <code>CheckboxMenuItem</code> to create the peer for.
|
|---|
| 313 | * @return The peer for the specified <code>CheckboxMenuItem</code> object.
|
|---|
| 314 | *
|
|---|
| 315 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 316 | */
|
|---|
| 317 | protected abstract CheckboxMenuItemPeer
|
|---|
| 318 | createCheckboxMenuItem(CheckboxMenuItem target);
|
|---|
| 319 |
|
|---|
| 320 | /**
|
|---|
| 321 | * Creates a peer object for the specified <code>Component</code>. The
|
|---|
| 322 | * peer returned by this method is not a native windowing system peer
|
|---|
| 323 | * with its own native window. Instead, this method allows the component
|
|---|
| 324 | * to draw on its parent window as a "lightweight" widget.
|
|---|
| 325 | *
|
|---|
| 326 | * XXX: FIXME
|
|---|
| 327 | *
|
|---|
| 328 | * @param target The <code>Component</code> to create the peer for.
|
|---|
| 329 | * @return The peer for the specified <code>Component</code> object.
|
|---|
| 330 | */
|
|---|
| 331 | protected LightweightPeer createComponent(Component target)
|
|---|
| 332 | {
|
|---|
| 333 | return null;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | /**
|
|---|
| 337 | * Creates a peer object for the specified font name.
|
|---|
| 338 | *
|
|---|
| 339 | * @param name The font to create the peer for.
|
|---|
| 340 | * @param style The font style to create the peer for.
|
|---|
| 341 | * @return The peer for the specified font name.
|
|---|
| 342 | */
|
|---|
| 343 | protected abstract FontPeer getFontPeer(String name, int style);
|
|---|
| 344 |
|
|---|
| 345 | /**
|
|---|
| 346 | * Copies the current system colors into the specified array. This is
|
|---|
| 347 | * the interface used by the <code>SystemColors</code> class.
|
|---|
| 348 | *
|
|---|
| 349 | * @param colors The array to copy the system colors into.
|
|---|
| 350 | *
|
|---|
| 351 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 352 | */
|
|---|
| 353 | protected void loadSystemColors(int systemColors[])
|
|---|
| 354 | {
|
|---|
| 355 | // XXX Implement.
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | /**
|
|---|
| 359 | * @since 1.4
|
|---|
| 360 | *
|
|---|
| 361 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 362 | */
|
|---|
| 363 | public void setDynamicLayout(boolean dynamic)
|
|---|
| 364 | {
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | /**
|
|---|
| 368 | * @since 1.4
|
|---|
| 369 | *
|
|---|
| 370 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 371 | */
|
|---|
| 372 | protected boolean isDynamicLayoutSet()
|
|---|
| 373 | {
|
|---|
| 374 | return false;
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | /**
|
|---|
| 378 | * @since 1.4
|
|---|
| 379 | *
|
|---|
| 380 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 381 | */
|
|---|
| 382 | public boolean isDynamicLayoutActive()
|
|---|
| 383 | {
|
|---|
| 384 | return false;
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | /**
|
|---|
| 388 | * Returns the dimensions of the screen in pixels.
|
|---|
| 389 | *
|
|---|
| 390 | * @return The dimensions of the screen in pixels.
|
|---|
| 391 | *
|
|---|
| 392 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 393 | */
|
|---|
| 394 | public abstract Dimension getScreenSize();
|
|---|
| 395 |
|
|---|
| 396 | /**
|
|---|
| 397 | * Returns the screen resolution in dots per square inch.
|
|---|
| 398 | *
|
|---|
| 399 | * @return The screen resolution in dots per square inch.
|
|---|
| 400 | *
|
|---|
| 401 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 402 | */
|
|---|
| 403 | public abstract int getScreenResolution();
|
|---|
| 404 |
|
|---|
| 405 | /**
|
|---|
| 406 | * @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
|---|
| 407 | *
|
|---|
| 408 | * @since 1.4
|
|---|
| 409 | */
|
|---|
| 410 | public Insets getScreenInsets(GraphicsConfiguration gc)
|
|---|
| 411 | {
|
|---|
| 412 | return null;
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | /**
|
|---|
| 416 | * Returns the color model of the screen.
|
|---|
| 417 | *
|
|---|
| 418 | * @return The color model of the screen.
|
|---|
|
|---|