1 /*
   2  * Copyright (c) 2011, 2015, 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 java.awt.*;
  29 import java.awt.datatransfer.Clipboard;
  30 import java.awt.dnd.DragGestureListener;
  31 import java.awt.dnd.DragGestureRecognizer;
  32 import java.awt.dnd.DragSource;
  33 import java.awt.im.InputMethodHighlight;
  34 import java.awt.im.spi.InputMethodDescriptor;
  35 import java.awt.image.ColorModel;
  36 import java.awt.peer.FramePeer;
  37 import java.awt.peer.KeyboardFocusManagerPeer;
  38 import java.awt.peer.SystemTrayPeer;
  39 import java.awt.peer.TrayIconPeer;
  40 import java.util.Map;
  41 import java.util.Properties;
  42 
  43 /*
  44  * HToolkit is a platform independent Toolkit used
  45  * with the HeadlessToolkit.  It is primarily used
  46  * in embedded JRE's that do not have sun/awt/X11 classes.
  47  */
  48 public class HToolkit extends SunToolkit
  49     implements ComponentFactory {
  50 
  51     private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {
  52         @Override
  53         public void setCurrentFocusedWindow(Window win) {}
  54         @Override
  55         public Window getCurrentFocusedWindow() { return null; }
  56         @Override
  57         public void setCurrentFocusOwner(Component comp) {}
  58         @Override
  59         public Component getCurrentFocusOwner() { return null; }
  60         @Override
  61         public void clearGlobalFocusOwner(Window activeWindow) {}
  62     };
  63 
  64     public HToolkit() {
  65     }
  66 
  67     /*
  68      * Component peer objects - unsupported.
  69      */
  70 
  71     @Override
  72     public FramePeer createLightweightFrame(LightweightFrame target)
  73         throws HeadlessException {
  74         throw new HeadlessException();
  75     }
  76 
  77     @Override
  78     public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {
  79         // See 6833019.
  80         return kfmPeer;
  81     }
  82 
  83     @Override
  84     public TrayIconPeer createTrayIcon(TrayIcon target)
  85       throws HeadlessException {
  86         throw new HeadlessException();
  87     }
  88 
  89     @Override
  90     public SystemTrayPeer createSystemTray(SystemTray target)
  91       throws HeadlessException {
  92         throw new HeadlessException();
  93     }
  94 
  95     @Override
  96     public boolean isTraySupported() {
  97         return false;
  98     }
  99 
 100     public GlobalCursorManager getGlobalCursorManager()
 101         throws HeadlessException {
 102         throw new HeadlessException();
 103     }
 104 
 105     /*
 106      * Headless toolkit - unsupported.
 107      */
 108     @Override
 109     protected void loadSystemColors(int[] systemColors)
 110         throws HeadlessException {
 111         throw new HeadlessException();
 112     }
 113 
 114     @Override
 115     public ColorModel getColorModel()
 116         throws HeadlessException {
 117         throw new HeadlessException();
 118     }
 119 
 120     @Override
 121     public int getScreenResolution()
 122         throws HeadlessException {
 123         throw new HeadlessException();
 124     }
 125 
 126     @Override
 127     public Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
 128             InputMethodHighlight highlight)
 129         throws HeadlessException {
 130         throw new HeadlessException();
 131     }
 132 
 133     @Override
 134     public int getMenuShortcutKeyMask()
 135         throws HeadlessException {
 136         throw new HeadlessException();
 137     }
 138 
 139     @Override
 140     public boolean getLockingKeyState(int keyCode)
 141         throws UnsupportedOperationException {
 142         throw new HeadlessException();
 143     }
 144 
 145     @Override
 146     public void setLockingKeyState(int keyCode, boolean on)
 147         throws UnsupportedOperationException {
 148         throw new HeadlessException();
 149     }
 150 
 151     @Override
 152     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
 153         throws IndexOutOfBoundsException, HeadlessException {
 154         throw new HeadlessException();
 155     }
 156 
 157     @Override
 158     public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)
 159         throws HeadlessException {
 160         throw new HeadlessException();
 161     }
 162 
 163     @Override
 164     public int getMaximumCursorColors()
 165         throws HeadlessException {
 166         throw new HeadlessException();
 167     }
 168 
 169     @Override
 170     public <T extends DragGestureRecognizer> T
 171         createDragGestureRecognizer(Class<T> abstractRecognizerClass,
 172                                     DragSource ds, Component c,
 173                                     int srcActions, DragGestureListener dgl)
 174     {
 175         return null;
 176     }
 177 
 178     @Override
 179     public int getScreenHeight()
 180         throws HeadlessException {
 181         throw new HeadlessException();
 182     }
 183 
 184     @Override
 185     public int getScreenWidth()
 186         throws HeadlessException {
 187         throw new HeadlessException();
 188     }
 189 
 190     @Override
 191     public Dimension getScreenSize()
 192         throws HeadlessException {
 193         throw new HeadlessException();
 194     }
 195 
 196     @Override
 197     public Insets getScreenInsets(GraphicsConfiguration gc)
 198         throws HeadlessException {
 199         throw new HeadlessException();
 200     }
 201 
 202     @Override
 203     public void setDynamicLayout(boolean dynamic)
 204         throws HeadlessException {
 205         throw new HeadlessException();
 206     }
 207 
 208     @Override
 209     protected boolean isDynamicLayoutSet()
 210         throws HeadlessException {
 211         throw new HeadlessException();
 212     }
 213 
 214     @Override
 215     public boolean isDynamicLayoutActive()
 216         throws HeadlessException {
 217         throw new HeadlessException();
 218     }
 219 
 220     @Override
 221     public Clipboard getSystemClipboard()
 222         throws HeadlessException {
 223         throw new HeadlessException();
 224     }
 225 
 226     /*
 227      * Printing
 228      */
 229     @Override
 230     public PrintJob getPrintJob(Frame frame, String jobtitle,
 231         JobAttributes jobAttributes,
 232         PageAttributes pageAttributes) {
 233         if (frame != null) {
 234             // Should never happen
 235             throw new HeadlessException();
 236         }
 237         throw new IllegalArgumentException(
 238                 "PrintJob not supported in a headless environment");
 239     }
 240 
 241     @Override
 242     public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)
 243     {
 244         if (frame != null) {
 245             // Should never happen
 246             throw new HeadlessException();
 247         }
 248         throw new IllegalArgumentException(
 249                 "PrintJob not supported in a headless environment");
 250     }
 251 
 252     /*
 253      * Headless toolkit - supported.
 254      */
 255 
 256     @Override
 257     public void sync() {
 258         // Do nothing
 259     }
 260 
 261     @Override
 262     protected boolean syncNativeQueue(final long timeout) {
 263         return false;
 264     }
 265 
 266     @Override
 267     public void beep() {
 268         // Send alert character
 269         System.out.write(0x07);
 270     }
 271 
 272     /*
 273      * Modality
 274      */
 275     @Override
 276     public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {
 277         return false;
 278     }
 279 
 280     @Override
 281     public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {
 282         return false;
 283     }
 284 
 285     @Override
 286     public boolean isDesktopSupported() {
 287         return false;
 288     }
 289 
 290     public boolean isWindowOpacityControlSupported() {
 291         return false;
 292     }
 293 
 294     @Override
 295     public boolean isWindowShapingSupported() {
 296         return false;
 297     }
 298 
 299     @Override
 300     public boolean isWindowTranslucencySupported() {
 301         return false;
 302     }
 303 
 304     @Override
 305     public  void grab(Window w) { }
 306 
 307     @Override
 308     public void ungrab(Window w) { }
 309 
 310     protected boolean syncNativeQueue() { return false; }
 311 
 312     @Override
 313     public InputMethodDescriptor getInputMethodAdapterDescriptor()
 314         throws AWTException
 315     {
 316         return (InputMethodDescriptor)null;
 317     }
 318 }