Path: blob/master/src/java.desktop/share/classes/sun/awt/HeadlessToolkit.java
41152 views
/*1* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt;2627import java.awt.*;28import java.awt.datatransfer.Clipboard;29import java.awt.dnd.DragGestureListener;30import java.awt.dnd.DragGestureRecognizer;31import java.awt.dnd.DragSource;32import java.awt.event.AWTEventListener;33import java.awt.event.InputEvent;34import java.awt.font.TextAttribute;35import java.awt.im.InputMethodHighlight;36import java.awt.image.ColorModel;37import java.awt.image.ImageObserver;38import java.awt.image.ImageProducer;39import java.awt.peer.FontPeer;40import java.awt.peer.KeyboardFocusManagerPeer;41import java.awt.peer.SystemTrayPeer;42import java.awt.peer.TrayIconPeer;43import java.beans.PropertyChangeListener;44import java.net.URL;45import java.util.Map;46import java.util.Properties;4748public final class HeadlessToolkit extends Toolkit49implements ComponentFactory, KeyboardFocusManagerPeerProvider {5051private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {52@Override53public void setCurrentFocusedWindow(Window win) {}54@Override55public Window getCurrentFocusedWindow() { return null; }56@Override57public void setCurrentFocusOwner(Component comp) {}58@Override59public Component getCurrentFocusOwner() { return null; }60@Override61public void clearGlobalFocusOwner(Window activeWindow) {}62};6364private final Toolkit tk;65private ComponentFactory componentFactory;6667public HeadlessToolkit(Toolkit tk) {68this.tk = tk;69if (tk instanceof ComponentFactory) {70componentFactory = (ComponentFactory)tk;71}72}7374public Toolkit getUnderlyingToolkit() {75return tk;76}7778@Override79public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {80// See 6833019.81return kfmPeer;82}8384public TrayIconPeer createTrayIcon(TrayIcon target)85throws HeadlessException {86throw new HeadlessException();87}8889public SystemTrayPeer createSystemTray(SystemTray target)90throws HeadlessException {91throw new HeadlessException();92}9394public boolean isTraySupported() {95return false;96}9798public GlobalCursorManager getGlobalCursorManager()99throws HeadlessException {100throw new HeadlessException();101}102103/*104* Headless toolkit - unsupported.105*/106@Override107protected void loadSystemColors(int[] systemColors)108throws HeadlessException {109throw new HeadlessException();110}111112@Override113public ColorModel getColorModel()114throws HeadlessException {115throw new HeadlessException();116}117118@Override119public int getScreenResolution()120throws HeadlessException {121throw new HeadlessException();122}123124@Override125public Map<TextAttribute, ?> mapInputMethodHighlight(InputMethodHighlight highlight)126throws HeadlessException {127throw new HeadlessException();128}129130@Override131@Deprecated(since = "10")132public int getMenuShortcutKeyMask()133throws HeadlessException {134throw new HeadlessException();135}136137@Override138public int getMenuShortcutKeyMaskEx()139throws HeadlessException {140throw new HeadlessException();141}142143@Override144public boolean getLockingKeyState(int keyCode)145throws UnsupportedOperationException {146throw new HeadlessException();147}148149@Override150public void setLockingKeyState(int keyCode, boolean on)151throws UnsupportedOperationException {152throw new HeadlessException();153}154155@Override156public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)157throws IndexOutOfBoundsException, HeadlessException {158throw new HeadlessException();159}160161@Override162public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)163throws HeadlessException {164throw new HeadlessException();165}166167@Override168public int getMaximumCursorColors()169throws HeadlessException {170throw new HeadlessException();171}172173@Override174public <T extends DragGestureRecognizer> T175createDragGestureRecognizer(Class<T> abstractRecognizerClass,176DragSource ds, Component c,177int srcActions, DragGestureListener dgl)178{179return null;180}181182@Override183public Dimension getScreenSize()184throws HeadlessException {185throw new HeadlessException();186}187188@Override189public Insets getScreenInsets(GraphicsConfiguration gc)190throws HeadlessException {191throw new HeadlessException();192}193194@Override195public void setDynamicLayout(boolean dynamic)196throws HeadlessException {197throw new HeadlessException();198}199200@Override201protected boolean isDynamicLayoutSet()202throws HeadlessException {203throw new HeadlessException();204}205206@Override207public boolean isDynamicLayoutActive()208throws HeadlessException {209throw new HeadlessException();210}211212@Override213public Clipboard getSystemClipboard()214throws HeadlessException {215throw new HeadlessException();216}217218/*219* Printing220*/221@Override222public PrintJob getPrintJob(Frame frame, String jobtitle,223JobAttributes jobAttributes,224PageAttributes pageAttributes) {225if (frame != null) {226// Should never happen227throw new HeadlessException();228}229throw new NullPointerException("frame must not be null");230}231232@Override233public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)234{235if (frame != null) {236// Should never happen237throw new HeadlessException();238}239throw new NullPointerException("frame must not be null");240}241242/*243* Headless toolkit - supported.244*/245246@Override247public void sync() {248// Do nothing249}250251@Override252public void beep() {253// Send alert character254System.out.write(0x07);255}256257/*258* Event Queue259*/260@Override261public EventQueue getSystemEventQueueImpl() {262return SunToolkit.getSystemEventQueueImplPP();263}264265/*266* Images.267*/268@Override269public int checkImage(Image img, int w, int h, ImageObserver o) {270return tk.checkImage(img, w, h, o);271}272273@Override274public boolean prepareImage(275Image img, int w, int h, ImageObserver o) {276return tk.prepareImage(img, w, h, o);277}278279@Override280public Image getImage(String filename) {281return tk.getImage(filename);282}283284@Override285public Image getImage(URL url) {286return tk.getImage(url);287}288289@Override290public Image createImage(String filename) {291return tk.createImage(filename);292}293294@Override295public Image createImage(URL url) {296return tk.createImage(url);297}298299@Override300public Image createImage(byte[] data, int offset, int length) {301return tk.createImage(data, offset, length);302}303304@Override305public Image createImage(ImageProducer producer) {306return tk.createImage(producer);307}308309@Override310public Image createImage(byte[] imagedata) {311return tk.createImage(imagedata);312}313314315/*316* Fonts317*/318@Override319public FontPeer getFontPeer(String name, int style) {320if (componentFactory != null) {321return componentFactory.getFontPeer(name, style);322}323return null;324}325326@Override327@SuppressWarnings("deprecation")328public FontMetrics getFontMetrics(Font font) {329return tk.getFontMetrics(font);330}331332@Override333@SuppressWarnings("deprecation")334public String[] getFontList() {335return tk.getFontList();336}337338/*339* Desktop properties340*/341342@Override343public void addPropertyChangeListener(String name,344PropertyChangeListener pcl) {345tk.addPropertyChangeListener(name, pcl);346}347348@Override349public void removePropertyChangeListener(String name,350PropertyChangeListener pcl) {351tk.removePropertyChangeListener(name, pcl);352}353354/*355* Modality356*/357@Override358public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {359return false;360}361362@Override363public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {364return false;365}366367/*368* Always on top369*/370@Override371public boolean isAlwaysOnTopSupported() {372return false;373}374375/*376* AWT Event listeners377*/378379@Override380public void addAWTEventListener(AWTEventListener listener,381long eventMask) {382tk.addAWTEventListener(listener, eventMask);383}384385@Override386public void removeAWTEventListener(AWTEventListener listener) {387tk.removeAWTEventListener(listener);388}389390@Override391public AWTEventListener[] getAWTEventListeners() {392return tk.getAWTEventListeners();393}394395@Override396public AWTEventListener[] getAWTEventListeners(long eventMask) {397return tk.getAWTEventListeners(eventMask);398}399400public boolean isDesktopSupported() {401return false;402}403404@Override405public boolean areExtraMouseButtonsEnabled() throws HeadlessException{406throw new HeadlessException();407}408}409410411