OSDN Git Service

* Makefile.am: Add new AWT stubs.
[pf3gnuchains/gcc-fork.git] / libjava / java / awt / Toolkit.java
1 /* Copyright (C) 1999, 2000  Free Software Foundation
2
3    This file is part of libjava.
4
5 This software is copyrighted work licensed under the terms of the
6 Libjava License.  Please consult the file "LIBJAVA_LICENSE" for
7 details.  */
8
9 package java.awt;
10 import java.awt.peer.*;
11 import java.awt.event.*;
12 import java.net.URL;
13 import java.beans.*;
14 import java.awt.image.*;
15 import java.awt.datatransfer.Clipboard;
16 import java.util.Hashtable;
17
18 /* A very incomplete placeholder. */
19
20 public abstract class Toolkit
21 {
22   static Toolkit defaultToolkit;
23   static EventQueue systemEventQueue = new EventQueue();
24   PropertyChangeSupport pcsupport = new PropertyChangeSupport(this);
25   Hashtable desktopProperties = new Hashtable();
26
27   public static Toolkit getDefaultToolkit()
28   {
29     if (defaultToolkit != null)
30       return defaultToolkit;
31       
32     Class toolkit_class;
33     String tk_class_name = System.getProperty("awt.toolkit");
34     if (tk_class_name == null)
35       tk_class_name = "gnu.awt.peer.gtk.GTKToolkit";
36
37     try
38     {
39       toolkit_class = Class.forName(tk_class_name);
40       defaultToolkit = (Toolkit) toolkit_class.newInstance();
41     }
42     catch (Exception x)
43     {
44       throw new AWTError("Toolkit class " + tk_class_name + 
45                          " could not be initialized:\n  " + x);
46     }
47
48     return defaultToolkit;
49   }
50
51   protected abstract ButtonPeer createButton(Button target);
52   protected abstract TextFieldPeer createTextField(TextField target);
53   protected abstract LabelPeer createLabel(Label target);
54   protected abstract ListPeer createList(List target);
55   protected abstract CheckboxPeer createCheckbox(Checkbox target);
56   protected abstract ScrollbarPeer createScrollbar(Scrollbar target);
57   protected abstract ScrollPanePeer createScrollPane(ScrollPane target);
58   protected abstract TextAreaPeer createTextArea(TextArea target);
59   protected abstract ChoicePeer createChoice(Choice target);
60   protected abstract FramePeer createFrame(Frame target);
61   protected abstract CanvasPeer createCanvas(Canvas target);
62   protected abstract PanelPeer createPanel(Panel target);
63   protected abstract WindowPeer createWindow(Window target);
64   protected abstract DialogPeer createDialog(Dialog target);
65   protected abstract MenuBarPeer createMenuBar(MenuBar target);
66   protected abstract MenuPeer createMenu(Menu target);
67   protected abstract PopupMenuPeer createPopupMenu(PopupMenu target);
68   protected abstract MenuItemPeer createMenuItem(MenuItem target);
69   protected abstract FileDialogPeer createFileDialog(FileDialog target);
70   protected abstract CheckboxMenuItemPeer 
71     createCheckboxMenuItem(CheckboxMenuItem target);
72
73   protected LightweightPeer createComponent(Component target)
74   {
75     // FIXME
76     return null;
77   }
78   
79   /* @deprecated Use GraphicsEnvironment.getAllFonts() */
80   protected abstract java.awt.peer.FontPeer getFontPeer(String name, int style);
81   
82   /*
83   public abstract DragSourceContextPeer 
84     createDragSourceContextPeer(DragGestureEvent dge)
85     throws InvalidDnDOperationException;
86   */
87   
88   protected void loadSystemColors(int[] systemColors)
89   {
90     // FIXME
91   }
92
93   public abstract Dimension getScreenSize();
94   public abstract int getScreenResolution();
95   public abstract ColorModel getColorModel();
96   /* @deprecated Use GraphicsEnvironment.getAvailableFontFamilyNames() */
97   public abstract String[] getFontList();
98   public abstract FontMetrics getFontMetrics(Font font);
99   public abstract void sync();
100   public abstract Image getImage(String filename);
101   public abstract Image getImage(URL url);
102   public abstract Image createImage(String filename);
103   public abstract Image createImage(URL url);
104   public abstract boolean prepareImage(Image image, int width, int height,
105                                        ImageObserver observer);
106   public abstract int checkImage(Image image, int width, int height,
107                                  ImageObserver observer);
108   public abstract Image createImage(ImageProducer producer);
109
110   public Image createImage(byte[] imagedata)
111   {
112     return createImage (imagedata, 0, imagedata.length);
113   }
114   
115   public abstract Image createImage(byte[] imagedata, int imageoffset,
116                                     int imagelength);
117   /*
118   public abstract PrintJob getPrintJob(Frame frame, String jobtitle,
119                                        Properties props);
120   public PrintJob getPrintJob(Frame frame, String jobtitle,
121                               JobAttributes jobAttributes,
122                               PageAttributes pageAttributes)
123   {
124     
125   }
126   */
127   
128   public abstract void beep();
129   public abstract Clipboard getSystemClipboard();
130
131   public int getMenuShortcutKeyMask()
132   {
133     return InputEvent.CTRL_MASK;
134   }
135
136   public boolean getLockingKeyState(int keyCode)
137   {
138     if (keyCode != KeyEvent.VK_CAPS_LOCK
139         && keyCode != KeyEvent.VK_NUM_LOCK
140         && keyCode != KeyEvent.VK_SCROLL_LOCK)
141       throw new IllegalArgumentException();
142
143     throw new UnsupportedOperationException();
144   }
145
146   public void setLockingKeyState(int keyCode, boolean on)
147   {
148     if (keyCode != KeyEvent.VK_CAPS_LOCK
149         && keyCode != KeyEvent.VK_NUM_LOCK
150         && keyCode != KeyEvent.VK_SCROLL_LOCK)
151       throw new IllegalArgumentException();
152
153     throw new UnsupportedOperationException();
154   }
155
156   protected static Container getNativeContainer(Component c)
157   {
158     while (c != null) 
159     {
160       if (!c.isLightweight ())
161         return (Container) c;
162
163       c = c.getParent();
164     }
165     return null;
166   }
167
168   public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
169     throws IndexOutOfBoundsException
170   {
171     // Presumably the only reason this isn't abstract is for backwards
172     // compatibility? FIXME?
173     return null;
174   }
175
176   public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)
177   {
178     return new Dimension (0,0);
179   }
180
181   public int getMaximumCursorColors()
182   {
183     return 0;
184   }
185
186   public static String getProperty(String key, String defaultValue)
187   {
188     // FIXME
189     return defaultValue;
190   }
191
192   public final EventQueue getSystemEventQueue()
193   {
194       return systemEventQueue;
195   }
196
197   protected abstract EventQueue getSystemEventQueueImpl();
198
199   /*
200   public DragGestureRecognizer 
201     createDragGestureRecognizer(Class abstractRecognizerClass, DragSource ds,
202                                 Component c, int srcActions,
203                                 DragGestureListener dgl)
204   {
205     // err... FIXME
206     return null;
207   }
208   */
209
210   public final Object getDesktopProperty(String propertyName)
211   {
212     return desktopProperties.get(propertyName);
213   }
214
215   protected final void setDesktopProperty(String name, Object newValue)
216   {
217     Object oldValue = getDesktopProperty(name);
218     desktopProperties.put(name, newValue);
219     pcsupport.firePropertyChange(name, oldValue, newValue);
220   }
221
222   protected Object lazilyLoadDesktopProperty(String name)
223   {
224     // FIXME - what is this??
225     return null;
226   }
227
228   protected void initializeDesktopProperties()
229   {
230     // Overridden by toolkit implementation?
231   }
232
233   public void addPropertyChangeListener(String name,
234                                         PropertyChangeListener pcl)
235   {
236     pcsupport.addPropertyChangeListener(name, pcl);
237   }
238   
239   public void removePropertyChangeListener(String name,
240                                            PropertyChangeListener pcl)
241   {
242     pcsupport.removePropertyChangeListener(name, pcl);
243   }
244
245   public void addAWTEventListener(AWTEventListener listener, long eventMask)
246   {
247     // SecurityManager s = System.getSecurityManager();
248     // if (s != null)
249     //  s.checkPermission(AWTPermission("listenToAllAWTEvents"));
250
251     // FIXME
252   }
253
254   public void removeAWTEventListener(AWTEventListener listener)
255   {
256     // FIXME
257   }
258   
259   /*
260   public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight)
261   {
262   }  
263   */
264 }