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