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