1 /*
   2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt;
  27 
  28 import sun.awt.datatransfer.DataTransferer;
  29 
  30 import java.awt.*;
  31 import java.awt.dnd.*;
  32 import java.awt.dnd.peer.DragSourceContextPeer;
  33 import java.awt.im.InputMethodHighlight;
  34 import java.awt.im.spi.InputMethodDescriptor;
  35 import java.awt.image.*;
  36 import java.awt.datatransfer.Clipboard;
  37 import java.awt.peer.*;
  38 import java.util.Map;
  39 import java.util.Properties;
  40 
  41 /*
  42  * HToolkit is a platform independent Toolkit used
  43  * with the HeadlessToolkit.  It is primarily used
  44  * in embedded JRE's that do not have sun/awt/X11 classes.
  45  */
  46 public class HToolkit extends SunToolkit
  47     implements ComponentFactory {
  48 
  49     private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {
  50         public void setCurrentFocusedWindow(Window win) {}
  51         public Window getCurrentFocusedWindow() { return null; }
  52         public void setCurrentFocusOwner(Component comp) {}
  53         public Component getCurrentFocusOwner() { return null; }
  54         public void clearGlobalFocusOwner(Window activeWindow) {}
  55     };
  56 
  57     public HToolkit() {
  58     }
  59 
  60     /*
  61      * Component peer objects - unsupported.
  62      */
  63 
  64     public WindowPeer createWindow(Window target)
  65         throws HeadlessException {
  66         throw new HeadlessException();
  67     }
  68 
  69     public FramePeer createLightweightFrame(LightweightFrame target)
  70         throws HeadlessException {
  71         throw new HeadlessException();
  72     }
  73 
  74     public FramePeer createFrame(Frame target)
  75         throws HeadlessException {
  76         throw new HeadlessException();
  77     }
  78 
  79     public DialogPeer createDialog(Dialog target)
  80         throws HeadlessException {
  81         throw new HeadlessException();
  82     }
  83 
  84     public ButtonPeer createButton(Button target)
  85         throws HeadlessException {
  86         throw new HeadlessException();
  87     }
  88 
  89     public TextFieldPeer createTextField(TextField target)
  90         throws HeadlessException {
  91         throw new HeadlessException();
  92     }
  93 
  94     public ChoicePeer createChoice(Choice target)
  95         throws HeadlessException {
  96         throw new HeadlessException();
  97     }
  98 
  99     public LabelPeer createLabel(Label target)
 100         throws HeadlessException {
 101         throw new HeadlessException();
 102     }
 103 
 104     public ListPeer createList(List target)
 105         throws HeadlessException {
 106         throw new HeadlessException();
 107     }
 108 
 109     public CheckboxPeer createCheckbox(Checkbox target)
 110         throws HeadlessException {
 111         throw new HeadlessException();
 112     }
 113 
 114     public ScrollbarPeer createScrollbar(Scrollbar target)
 115         throws HeadlessException {
 116         throw new HeadlessException();
 117     }
 118 
 119     public ScrollPanePeer createScrollPane(ScrollPane target)
 120         throws HeadlessException {
 121         throw new HeadlessException();
 122     }
 123 
 124     public TextAreaPeer createTextArea(TextArea target)
 125         throws HeadlessException {
 126         throw new HeadlessException();
 127     }
 128 
 129     public FileDialogPeer createFileDialog(FileDialog target)
 130         throws HeadlessException {
 131         throw new HeadlessException();
 132     }
 133 
 134     public MenuBarPeer createMenuBar(MenuBar target)
 135         throws HeadlessException {
 136         throw new HeadlessException();
 137     }
 138 
 139     public MenuPeer createMenu(Menu target)
 140         throws HeadlessException {
 141         throw new HeadlessException();
 142     }
 143 
 144     public PopupMenuPeer createPopupMenu(PopupMenu target)
 145         throws HeadlessException {
 146         throw new HeadlessException();
 147     }
 148 
 149     public MenuItemPeer createMenuItem(MenuItem target)
 150         throws HeadlessException {
 151         throw new HeadlessException();
 152     }
 153 
 154     public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)
 155         throws HeadlessException {
 156         throw new HeadlessException();
 157     }
 158 
 159     public DragSourceContextPeer createDragSourceContextPeer(
 160         DragGestureEvent dge)
 161         throws InvalidDnDOperationException {
 162         throw new InvalidDnDOperationException("Headless environment");
 163     }
 164 
 165     public RobotPeer createRobot(Robot target, GraphicsDevice screen)
 166         throws AWTException, HeadlessException {
 167         throw new HeadlessException();
 168     }
 169 
 170     public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
 171         // See 6833019.
 172         return kfmPeer;
 173     }
 174 
 175     public TrayIconPeer createTrayIcon(TrayIcon target)
 176       throws HeadlessException {
 177         throw new HeadlessException();
 178     }
 179 
 180     public SystemTrayPeer createSystemTray(SystemTray target)
 181       throws HeadlessException {
 182         throw new HeadlessException();
 183     }
 184 
 185     public boolean isTraySupported() {
 186         return false;
 187     }
 188 
 189     @Override
 190     public DataTransferer getDataTransferer() {
 191         return null;
 192     }
 193 
 194     public GlobalCursorManager getGlobalCursorManager()
 195         throws HeadlessException {
 196         throw new HeadlessException();
 197     }
 198 
 199     /*
 200      * Headless toolkit - unsupported.
 201      */
 202     protected void loadSystemColors(int[] systemColors)
 203         throws HeadlessException {
 204         throw new HeadlessException();
 205     }
 206 
 207     public ColorModel getColorModel()
 208         throws HeadlessException {
 209         throw new HeadlessException();
 210     }
 211 
 212     public int getScreenResolution()
 213         throws HeadlessException {
 214         throw new HeadlessException();
 215     }
 216 
 217     public Map mapInputMethodHighlight(InputMethodHighlight highlight)
 218         throws HeadlessException {
 219         throw new HeadlessException();
 220     }
 221 
 222     public int getMenuShortcutKeyMask()
 223         throws HeadlessException {
 224         throw new HeadlessException();
 225     }
 226 
 227     public boolean getLockingKeyState(int keyCode)
 228         throws UnsupportedOperationException {
 229         throw new HeadlessException();
 230     }
 231 
 232     public void setLockingKeyState(int keyCode, boolean on)
 233         throws UnsupportedOperationException {
 234         throw new HeadlessException();
 235     }
 236 
 237     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
 238         throws IndexOutOfBoundsException, HeadlessException {
 239         throw new HeadlessException();
 240     }
 241 
 242     public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)
 243         throws HeadlessException {
 244         throw new HeadlessException();
 245     }
 246 
 247     public int getMaximumCursorColors()
 248         throws HeadlessException {
 249         throw new HeadlessException();
 250     }
 251 
 252     public <T extends DragGestureRecognizer> T
 253         createDragGestureRecognizer(Class<T> abstractRecognizerClass,
 254                                     DragSource ds, Component c,
 255                                     int srcActions, DragGestureListener dgl)
 256     {
 257         return null;
 258     }
 259 
 260     public int getScreenHeight()
 261         throws HeadlessException {
 262         throw new HeadlessException();
 263     }
 264 
 265     public int getScreenWidth()
 266         throws HeadlessException {
 267         throw new HeadlessException();
 268     }
 269 
 270     public Dimension getScreenSize()
 271         throws HeadlessException {
 272         throw new HeadlessException();
 273     }
 274 
 275     public Insets getScreenInsets(GraphicsConfiguration gc)
 276         throws HeadlessException {
 277         throw new HeadlessException();
 278     }
 279 
 280     public void setDynamicLayout(boolean dynamic)
 281         throws HeadlessException {
 282         throw new HeadlessException();
 283     }
 284 
 285     protected boolean isDynamicLayoutSet()
 286         throws HeadlessException {
 287         throw new HeadlessException();
 288     }
 289 
 290     public boolean isDynamicLayoutActive()
 291         throws HeadlessException {
 292         throw new HeadlessException();
 293     }
 294 
 295     public Clipboard getSystemClipboard()
 296         throws HeadlessException {
 297         throw new HeadlessException();
 298     }
 299 
 300     /*
 301      * Printing
 302      */
 303     public PrintJob getPrintJob(Frame frame, String jobtitle,
 304         JobAttributes jobAttributes,
 305         PageAttributes pageAttributes) {
 306         if (frame != null) {
 307             // Should never happen
 308             throw new HeadlessException();
 309         }
 310         throw new IllegalArgumentException(
 311                 "PrintJob not supported in a headless environment");
 312     }
 313 
 314     public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)
 315     {
 316         if (frame != null) {
 317             // Should never happen
 318             throw new HeadlessException();
 319         }
 320         throw new IllegalArgumentException(
 321                 "PrintJob not supported in a headless environment");
 322     }
 323 
 324     /*
 325      * Headless toolkit - supported.
 326      */
 327 
 328     public void sync() {
 329         // Do nothing
 330     }
 331 
 332     protected boolean syncNativeQueue(final long timeout) {
 333         return false;
 334     }
 335 
 336     public void beep() {
 337         // Send alert character
 338         System.out.write(0x07);
 339     }
 340 
 341 
 342     /*
 343      * Fonts
 344      */
 345     public FontPeer getFontPeer(String name, int style) {
 346         return (FontPeer)null;
 347     }
 348 
 349     /*
 350      * Modality
 351      */
 352     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
 353         return false;
 354     }
 355 
 356     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
 357         return false;
 358     }
 359 
 360     public boolean isDesktopSupported() {
 361         return false;
 362     }
 363 
 364     public DesktopPeer createDesktopPeer(Desktop target)
 365     throws HeadlessException{
 366         throw new HeadlessException();
 367     }
 368 
 369     public boolean isWindowOpacityControlSupported() {
 370         return false;
 371     }
 372 
 373     public boolean isWindowShapingSupported() {
 374         return false;
 375     }
 376 
 377     public boolean isWindowTranslucencySupported() {
 378         return false;
 379     }
 380 
 381     public  void grab(Window w) { }
 382 
 383     public void ungrab(Window w) { }
 384 
 385     protected boolean syncNativeQueue() { return false; }
 386 
 387     public InputMethodDescriptor getInputMethodAdapterDescriptor()
 388         throws AWTException
 389     {
 390         return (InputMethodDescriptor)null;
 391     }
 392 }