001: /*
002: * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt;
027:
028: import java.awt.*;
029: import java.awt.dnd.*;
030: import java.awt.dnd.peer.DragSourceContextPeer;
031: import java.awt.event.*;
032: import java.awt.im.InputMethodHighlight;
033: import java.awt.im.spi.InputMethodDescriptor;
034: import java.awt.image.*;
035: import java.awt.datatransfer.Clipboard;
036: import java.awt.peer.*;
037: import java.beans.PropertyChangeListener;
038: import java.lang.reflect.Constructor;
039: import java.lang.reflect.InvocationTargetException;
040: import java.net.URL;
041: import java.util.Map;
042: import java.util.Properties;
043: import sun.awt.im.InputContext;
044: import sun.awt.image.ImageRepresentation;
045:
046: public class HeadlessToolkit extends Toolkit implements
047: ComponentFactory {
048:
049: private Toolkit tk;
050: private ComponentFactory componentFactory;
051:
052: public HeadlessToolkit(Toolkit tk) {
053: this .tk = tk;
054: if (tk instanceof ComponentFactory) {
055: componentFactory = (ComponentFactory) tk;
056: }
057: }
058:
059: public Toolkit getUnderlyingToolkit() {
060: return tk;
061: }
062:
063: /*
064: * Component peer objects.
065: */
066:
067: /* Lightweight implementation of Canvas and Panel */
068:
069: public CanvasPeer createCanvas(Canvas target) {
070: return (CanvasPeer) createComponent(target);
071: }
072:
073: public PanelPeer createPanel(Panel target) {
074: return (PanelPeer) createComponent(target);
075: }
076:
077: /*
078: * Component peer objects - unsupported.
079: */
080:
081: public WindowPeer createWindow(Window target)
082: throws HeadlessException {
083: throw new HeadlessException();
084: }
085:
086: public FramePeer createFrame(Frame target) throws HeadlessException {
087: throw new HeadlessException();
088: }
089:
090: public DialogPeer createDialog(Dialog target)
091: throws HeadlessException {
092: throw new HeadlessException();
093: }
094:
095: public ButtonPeer createButton(Button target)
096: throws HeadlessException {
097: throw new HeadlessException();
098: }
099:
100: public TextFieldPeer createTextField(TextField target)
101: throws HeadlessException {
102: throw new HeadlessException();
103: }
104:
105: public ChoicePeer createChoice(Choice target)
106: throws HeadlessException {
107: throw new HeadlessException();
108: }
109:
110: public LabelPeer createLabel(Label target) throws HeadlessException {
111: throw new HeadlessException();
112: }
113:
114: public ListPeer createList(List target) throws HeadlessException {
115: throw new HeadlessException();
116: }
117:
118: public CheckboxPeer createCheckbox(Checkbox target)
119: throws HeadlessException {
120: throw new HeadlessException();
121: }
122:
123: public ScrollbarPeer createScrollbar(Scrollbar target)
124: throws HeadlessException {
125: throw new HeadlessException();
126: }
127:
128: public ScrollPanePeer createScrollPane(ScrollPane target)
129: throws HeadlessException {
130: throw new HeadlessException();
131: }
132:
133: public TextAreaPeer createTextArea(TextArea target)
134: throws HeadlessException {
135: throw new HeadlessException();
136: }
137:
138: public FileDialogPeer createFileDialog(FileDialog target)
139: throws HeadlessException {
140: throw new HeadlessException();
141: }
142:
143: public MenuBarPeer createMenuBar(MenuBar target)
144: throws HeadlessException {
145: throw new HeadlessException();
146: }
147:
148: public MenuPeer createMenu(Menu target) throws HeadlessException {
149: throw new HeadlessException();
150: }
151:
152: public PopupMenuPeer createPopupMenu(PopupMenu target)
153: throws HeadlessException {
154: throw new HeadlessException();
155: }
156:
157: public MenuItemPeer createMenuItem(MenuItem target)
158: throws HeadlessException {
159: throw new HeadlessException();
160: }
161:
162: public CheckboxMenuItemPeer createCheckboxMenuItem(
163: CheckboxMenuItem target) throws HeadlessException {
164: throw new HeadlessException();
165: }
166:
167: public DragSourceContextPeer createDragSourceContextPeer(
168: DragGestureEvent dge) throws InvalidDnDOperationException {
169: throw new InvalidDnDOperationException("Headless environment");
170: }
171:
172: public RobotPeer createRobot(Robot target, GraphicsDevice screen)
173: throws AWTException, HeadlessException {
174: throw new HeadlessException();
175: }
176:
177: public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(
178: KeyboardFocusManager manager) throws HeadlessException {
179: KeyboardFocusManagerPeerImpl peer = new KeyboardFocusManagerPeerImpl(
180: manager);
181: return peer;
182: }
183:
184: public TrayIconPeer createTrayIcon(TrayIcon target)
185: throws HeadlessException {
186: throw new HeadlessException();
187: }
188:
189: public SystemTrayPeer createSystemTray(SystemTray target)
190: throws HeadlessException {
191: throw new HeadlessException();
192: }
193:
194: public boolean isTraySupported() {
195: return false;
196: }
197:
198: public GlobalCursorManager getGlobalCursorManager()
199: throws HeadlessException {
200: throw new HeadlessException();
201: }
202:
203: /*
204: * Headless toolkit - unsupported.
205: */
206: protected void loadSystemColors(int[] systemColors)
207: throws HeadlessException {
208: throw new HeadlessException();
209: }
210:
211: public ColorModel getColorModel() throws HeadlessException {
212: throw new HeadlessException();
213: }
214:
215: public int getScreenResolution() throws HeadlessException {
216: throw new HeadlessException();
217: }
218:
219: public Map mapInputMethodHighlight(InputMethodHighlight highlight)
220: throws HeadlessException {
221: throw new HeadlessException();
222: }
223:
224: public int getMenuShortcutKeyMask() throws HeadlessException {
225: throw new HeadlessException();
226: }
227:
228: public boolean getLockingKeyState(int keyCode)
229: throws UnsupportedOperationException {
230: throw new HeadlessException();
231: }
232:
233: public void setLockingKeyState(int keyCode, boolean on)
234: throws UnsupportedOperationException {
235: throw new HeadlessException();
236: }
237:
238: public Cursor createCustomCursor(Image cursor, Point hotSpot,
239: String name) throws IndexOutOfBoundsException,
240: HeadlessException {
241: throw new HeadlessException();
242: }
243:
244: public Dimension getBestCursorSize(int preferredWidth,
245: int preferredHeight) throws HeadlessException {
246: throw new HeadlessException();
247: }
248:
249: public int getMaximumCursorColors() throws HeadlessException {
250: throw new HeadlessException();
251: }
252:
253: public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
254: Class<T> abstractRecognizerClass, DragSource ds,
255: Component c, int srcActions, DragGestureListener dgl) {
256: return null;
257: }
258:
259: public int getScreenHeight() throws HeadlessException {
260: throw new HeadlessException();
261: }
262:
263: public int getScreenWidth() throws HeadlessException {
264: throw new HeadlessException();
265: }
266:
267: public Dimension getScreenSize() throws HeadlessException {
268: throw new HeadlessException();
269: }
270:
271: public Insets getScreenInsets(GraphicsConfiguration gc)
272: throws HeadlessException {
273: throw new HeadlessException();
274: }
275:
276: public void setDynamicLayout(boolean dynamic)
277: throws HeadlessException {
278: throw new HeadlessException();
279: }
280:
281: protected boolean isDynamicLayoutSet() throws HeadlessException {
282: throw new HeadlessException();
283: }
284:
285: public boolean isDynamicLayoutActive() throws HeadlessException {
286: throw new HeadlessException();
287: }
288:
289: public Clipboard getSystemClipboard() throws HeadlessException {
290: throw new HeadlessException();
291: }
292:
293: /*
294: * Printing
295: */
296: public PrintJob getPrintJob(Frame frame, String jobtitle,
297: JobAttributes jobAttributes, PageAttributes pageAttributes) {
298: if (frame != null) {
299: // Should never happen
300: throw new HeadlessException();
301: }
302: throw new IllegalArgumentException(
303: "PrintJob not supported in a headless environment");
304: }
305:
306: public PrintJob getPrintJob(Frame frame, String doctitle,
307: Properties props) {
308: if (frame != null) {
309: // Should never happen
310: throw new HeadlessException();
311: }
312: throw new IllegalArgumentException(
313: "PrintJob not supported in a headless environment");
314: }
315:
316: /*
317: * Headless toolkit - supported.
318: */
319:
320: public void sync() {
321: // Do nothing
322: }
323:
324: public void beep() {
325: // Send alert character
326: System.out.write(0x07);
327: }
328:
329: /*
330: * Event Queue
331: */
332: public EventQueue getSystemEventQueueImpl() {
333: return SunToolkit.getSystemEventQueueImplPP();
334: }
335:
336: /*
337: * Images.
338: */
339: public int checkImage(Image img, int w, int h, ImageObserver o) {
340: return tk.checkImage(img, w, h, o);
341: }
342:
343: public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
344: return tk.prepareImage(img, w, h, o);
345: }
346:
347: public Image getImage(String filename) {
348: return tk.getImage(filename);
349: }
350:
351: public Image getImage(URL url) {
352: return tk.getImage(url);
353: }
354:
355: public Image createImage(String filename) {
356: return tk.createImage(filename);
357: }
358:
359: public Image createImage(URL url) {
360: return tk.createImage(url);
361: }
362:
363: public Image createImage(byte[] data, int offset, int length) {
364: return tk.createImage(data, offset, length);
365: }
366:
367: public Image createImage(ImageProducer producer) {
368: return tk.createImage(producer);
369: }
370:
371: public Image createImage(byte[] imagedata) {
372: return tk.createImage(imagedata);
373: }
374:
375: /*
376: * Fonts
377: */
378: public FontPeer getFontPeer(String name, int style) {
379: if (componentFactory != null) {
380: return componentFactory.getFontPeer(name, style);
381: }
382: return null;
383: }
384:
385: public FontMetrics getFontMetrics(Font font) {
386: return tk.getFontMetrics(font);
387: }
388:
389: public String[] getFontList() {
390: return tk.getFontList();
391: }
392:
393: /*
394: * Desktop properties
395: */
396:
397: public void addPropertyChangeListener(String name,
398: PropertyChangeListener pcl) {
399: tk.addPropertyChangeListener(name, pcl);
400: }
401:
402: public void removePropertyChangeListener(String name,
403: PropertyChangeListener pcl) {
404: tk.removePropertyChangeListener(name, pcl);
405: }
406:
407: /*
408: * Modality
409: */
410: public boolean isModalityTypeSupported(
411: Dialog.ModalityType modalityType) {
412: return false;
413: }
414:
415: public boolean isModalExclusionTypeSupported(
416: Dialog.ModalExclusionType exclusionType) {
417: return false;
418: }
419:
420: /*
421: * Always on top
422: */
423: public boolean isAlwaysOnTopSupported() {
424: return false;
425: }
426:
427: /*
428: * AWT Event listeners
429: */
430:
431: public void addAWTEventListener(AWTEventListener listener,
432: long eventMask) {
433: tk.addAWTEventListener(listener, eventMask);
434: }
435:
436: public void removeAWTEventListener(AWTEventListener listener) {
437: tk.removeAWTEventListener(listener);
438: }
439:
440: public AWTEventListener[] getAWTEventListeners() {
441: return tk.getAWTEventListeners();
442: }
443:
444: public boolean isDesktopSupported() {
445: return false;
446: }
447:
448: public DesktopPeer createDesktopPeer(Desktop target)
449: throws HeadlessException {
450: throw new HeadlessException();
451: }
452: }
|