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.desktop.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<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
 218             InputMethodHighlight highlight)
 219         throws HeadlessException {
 220         throw new HeadlessException();
 221     }
 222 
 223     public int getMenuShortcutKeyMask()
 224         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, String name)
 239         throws IndexOutOfBoundsException, HeadlessException {
 240         throw new HeadlessException();
 241     }
 242 
 243     public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)
 244         throws HeadlessException {
 245         throw new HeadlessException();
 246     }
 247 
 248     public int getMaximumCursorColors()
 249         throws HeadlessException {
 250         throw new HeadlessException();
 251     }
 252 
 253     public <T extends DragGestureRecognizer> T
 254         createDragGestureRecognizer(Class<T> abstractRecognizerClass,
 255                                     DragSource ds, Component c,
 256                                     int srcActions, DragGestureListener dgl)
 257     {
 258         return null;
 259     }
 260 
 261     public int getScreenHeight()
 262         throws HeadlessException {
 263         throw new HeadlessException();
 264     }
 265 
 266     public int getScreenWidth()
 267         throws HeadlessException {
 268         throw new HeadlessException();
 269     }
 270 
 271     public Dimension getScreenSize()
 272         throws HeadlessException {
 273         throw new HeadlessException();
 274     }
 275 
 276     public Insets getScreenInsets(GraphicsConfiguration gc)
 277         throws HeadlessException {
 278         throw new HeadlessException();
 279     }
 280 
 281     public void setDynamicLayout(boolean dynamic)
 282         throws HeadlessException {
 283         throw new HeadlessException();
 284     }
 285 
 286     protected boolean isDynamicLayoutSet()
 287         throws HeadlessException {
 288         throw new HeadlessException();
 289     }
 290 
 291     public boolean isDynamicLayoutActive()
 292         throws HeadlessException {
 293         throw new HeadlessException();
 294     }
 295 
 296     public Clipboard getSystemClipboard()
 297         throws HeadlessException {
 298         throw new HeadlessException();
 299     }
 300 
 301     /*
 302      * Printing
 303      */
 304     public PrintJob getPrintJob(Frame frame, String jobtitle,
 305         JobAttributes jobAttributes,
 306         PageAttributes pageAttributes) {
 307         if (frame != null) {
 308             // Should never happen
 309             throw new HeadlessException();
 310         }
 311         throw new IllegalArgumentException(
 312                 "PrintJob not supported in a headless environment");
 313     }
 314 
 315     public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)
 316     {
 317         if (frame != null) {
 318             // Should never happen
 319             throw new HeadlessException();
 320         }
 321         throw new IllegalArgumentException(
 322                 "PrintJob not supported in a headless environment");
 323     }
 324 
 325     /*
 326      * Headless toolkit - supported.
 327      */
 328 
 329     public void sync() {
 330         // Do nothing
 331     }
 332 
 333     protected boolean syncNativeQueue(final long timeout) {
 334         return false;
 335     }
 336 
 337     public void beep() {
 338         // Send alert character
 339         System.out.write(0x07);
 340     }
 341 
 342 
 343     /*
 344      * Fonts
 345      */
 346     public FontPeer getFontPeer(String name, int style) {
 347         return (FontPeer)null;
 348     }
 349 
 350     /*
 351      * Modality
 352      */
 353     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
 354         return false;
 355     }
 356 
 357     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
 358         return false;
 359     }
 360 
 361     public boolean isDesktopSupported() {
 362         return false;
 363     }
 364 
 365     public DesktopPeer createDesktopPeer(Desktop target)
 366     throws HeadlessException{
 367         throw new HeadlessException();
 368     }
 369 
 370     public boolean isWindowOpacityControlSupported() {
 371         return false;
 372     }
 373 
 374     public boolean isWindowShapingSupported() {
 375         return false;
 376     }
 377 
 378     public boolean isWindowTranslucencySupported() {
 379         return false;
 380     }
 381 
 382     public  void grab(Window w) { }
 383 
 384     public void ungrab(Window w) { }
 385 
 386     protected boolean syncNativeQueue() { return false; }
 387 
 388     public InputMethodDescriptor getInputMethodAdapterDescriptor()
 389         throws AWTException
 390     {
 391         return (InputMethodDescriptor)null;
 392     }
 393 }