OSDN Git Service

8e4e21873f6504791ba869aef895cbbd4e6bd344
[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 import gnu.gcj.awt.GLightweightPeer;
18
19 /* A very incomplete placeholder. */
20
21 public abstract class Toolkit
22 {
23   static Toolkit defaultToolkit;
24   PropertyChangeSupport changeSupport = 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.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     return GLightweightPeer.INSTANCE;
76   }
77   
78   /* @deprecated Use GraphicsEnvironment.getAllFonts() */
79   protected abstract java.awt.peer.FontPeer getFontPeer(String name, int style);
80   
81   /*
82   public abstract DragSourceContextPeer 
83     createDragSourceContextPeer(DragGestureEvent dge)
84     throws InvalidDnDOperationException;
85   */
86   
87   protected void loadSystemColors(int[] systemColors)
88   {
89     // FIXME
90   }
91
92   public abstract Dimension getScreenSize();
93   public abstract int getScreenResolution();
94   public abstract ColorModel getColorModel();
95   /* @deprecated Use GraphicsEnvironment.getAvailableFontFamilyNames() */
96   public abstract String[] getFontList();
97   public abstract FontMetrics getFontMetrics(Font font);
98   public abstract void sync();
99   public abstract Image getImage(String filename);
100   public abstract Image getImage(URL url);
101   public abstract Image createImage(String filename);
102   public abstract Image createImage(URL url);
103   public abstract boolean prepareImage(Image image, int width, int height,
104                                        ImageObserver observer);
105   public abstract int checkImage(Image image, int width, int height,
106                                  ImageObserver observer);
107   public abstract Image createImage(ImageProducer producer);
108
109   public Image createImage(byte[] imagedata)
110   {
111     return createImage (imagedata, 0, imagedata.length);
112   }
113   
114   public abstract Image createImage(byte[] imagedata, int imageoffset,
115                                     int imagelength);
116   /*
117   public abstract PrintJob getPrintJob(Frame frame, String jobtitle,
118                                        Properties props);
119   public PrintJob getPrintJob(Frame frame, String jobtitle,
120                               JobAttributes jobAttributes,
121                               PageAttributes pageAttributes)
122   {
123     
124   }
125   */
126   
127   public abstract void beep();
128   public abstract Clipboard getSystemClipboard();
129
130   public int getMenuShortcutKeyMask()
131   {
132     return InputEvent.CTRL_MASK;
133   }
134
135   public boolean getLockingKeyState(int keyCode)
136   {
137     if (keyCode != KeyEvent.VK_CAPS_LOCK
138         && keyCode != KeyEvent.VK_NUM_LOCK
139         && keyCode != KeyEvent.VK_SCROLL_LOCK)
140       throw new IllegalArgumentException();
141
142     throw new UnsupportedOperationException();
143   }
144
145   public void setLockingKeyState(int keyCode, boolean on)
146   {
147     if (keyCode != KeyEvent.VK_CAPS_LOCK
148         && keyCode != KeyEvent.VK_NUM_LOCK
149         && keyCode != KeyEvent.VK_SCROLL_LOCK)
150       throw new IllegalArgumentException();
151
152     throw new UnsupportedOperationException();
153   }
154
155   protected static Container getNativeContainer(Component c)
156   {
157     while (c != null) 
158     {
159       if (!c.isLightweight ())
160         return (Container) c;
161
162       c = c.getParent();
163     }
164     return null;
165   }
166
167   public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
168     throws IndexOutOfBoundsException
169   {
170     // Presumably the only reason this isn't abstract is for backwards
171     // compatibility? FIXME?
172     return null;
173   }
174
175   public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)
176   {
177     return new Dimension (0,0);
178   }
179
180   public int getMaximumCursorColors()
181   {
182     return 0;
183   }
184
185   public static String getProperty(String key, String defaultValue)
186   {
187     // FIXME
188     return defaultValue;
189   }
190
191   public final EventQueue getSystemEventQueue()
192   {
193       return getSystemEventQueueImpl();
194   }
195
196   protected abstract EventQueue getSystemEventQueueImpl();
197
198   /*
199   public DragGestureRecognizer 
200     createDragGestureRecognizer(Class abstractRecognizerClass, DragSource ds,
201                                 Component c, int srcActions,
202                                 DragGestureListener dgl)
203   {
204     // err... FIXME
205     return null;
206   }
207   */
208
209   public final Object getDesktopProperty(String propertyName)
210   {
211     return desktopProperties.get(propertyName);
212   }
213
214   protected final void setDesktopProperty(String name, Object newValue)
215   {
216     Object oldValue = getDesktopProperty(name);
217     desktopProperties.put(name, newValue);
218     changeSupport.firePropertyChange(name, oldValue, newValue);
219   }
220
221   protected Object lazilyLoadDesktopProperty(String name)
222   {
223     // FIXME - what is this??
224     return null;
225   }
226
227   protected void initializeDesktopProperties()
228   {
229     // Overridden by toolkit implementation?
230   }
231
232   public void addPropertyChangeListener(String name,
233                                         PropertyChangeListener pcl)
234   {
235     changeSupport.addPropertyChangeListener(name, pcl);
236   }
237   
238   public void removePropertyChangeListener(String name,
239                                            PropertyChangeListener pcl)
240   {
241     changeSupport.removePropertyChangeListener(name, pcl);
242   }
243
244   public void addAWTEventListener(AWTEventListener listener, long eventMask)
245   {
246     // SecurityManager s = System.getSecurityManager();
247     // if (s != null)
248     //  s.checkPermission(AWTPermission("listenToAllAWTEvents"));
249
250     // FIXME
251   }
252
253   public void removeAWTEventListener(AWTEventListener listener)
254   {
255     // FIXME
256   }
257   
258   /*
259   public abstract Map mapInputMethodHighlight(InputMethodHighlight highlight)
260   {
261   }  
262   */
263 }