Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/awt/HeadlessToolkit.java
38827 views
/*1* Copyright (c) 2000, 2012, 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 sun.awt.datatransfer.DataTransferer;2829import java.awt.*;30import java.awt.dnd.*;31import java.awt.dnd.peer.DragSourceContextPeer;32import java.awt.event.*;33import java.awt.im.InputMethodHighlight;34import java.awt.image.*;35import java.awt.datatransfer.Clipboard;36import java.awt.peer.*;37import java.beans.PropertyChangeListener;38import java.net.URL;39import java.util.Map;40import java.util.Properties;4142public class HeadlessToolkit extends Toolkit43implements ComponentFactory, KeyboardFocusManagerPeerProvider {4445private static final KeyboardFocusManagerPeer kfmPeer = new KeyboardFocusManagerPeer() {46public void setCurrentFocusedWindow(Window win) {}47public Window getCurrentFocusedWindow() { return null; }48public void setCurrentFocusOwner(Component comp) {}49public Component getCurrentFocusOwner() { return null; }50public void clearGlobalFocusOwner(Window activeWindow) {}51};5253private Toolkit tk;54private ComponentFactory componentFactory;5556public HeadlessToolkit(Toolkit tk) {57this.tk = tk;58if (tk instanceof ComponentFactory) {59componentFactory = (ComponentFactory)tk;60}61}6263public Toolkit getUnderlyingToolkit() {64return tk;65}6667/*68* Component peer objects.69*/7071/* Lightweight implementation of Canvas and Panel */7273public CanvasPeer createCanvas(Canvas target) {74return (CanvasPeer)createComponent(target);75}7677public PanelPeer createPanel(Panel target) {78return (PanelPeer)createComponent(target);79}8081/*82* Component peer objects - unsupported.83*/8485public WindowPeer createWindow(Window target)86throws HeadlessException {87throw new HeadlessException();88}8990public FramePeer createFrame(Frame target)91throws HeadlessException {92throw new HeadlessException();93}9495public DialogPeer createDialog(Dialog target)96throws HeadlessException {97throw new HeadlessException();98}99100public ButtonPeer createButton(Button target)101throws HeadlessException {102throw new HeadlessException();103}104105public TextFieldPeer createTextField(TextField target)106throws HeadlessException {107throw new HeadlessException();108}109110public ChoicePeer createChoice(Choice target)111throws HeadlessException {112throw new HeadlessException();113}114115public LabelPeer createLabel(Label target)116throws HeadlessException {117throw new HeadlessException();118}119120public ListPeer createList(List target)121throws HeadlessException {122throw new HeadlessException();123}124125public CheckboxPeer createCheckbox(Checkbox target)126throws HeadlessException {127throw new HeadlessException();128}129130public ScrollbarPeer createScrollbar(Scrollbar target)131throws HeadlessException {132throw new HeadlessException();133}134135public ScrollPanePeer createScrollPane(ScrollPane target)136throws HeadlessException {137throw new HeadlessException();138}139140public TextAreaPeer createTextArea(TextArea target)141throws HeadlessException {142throw new HeadlessException();143}144145public FileDialogPeer createFileDialog(FileDialog target)146throws HeadlessException {147throw new HeadlessException();148}149150public MenuBarPeer createMenuBar(MenuBar target)151throws HeadlessException {152throw new HeadlessException();153}154155public MenuPeer createMenu(Menu target)156throws HeadlessException {157throw new HeadlessException();158}159160public PopupMenuPeer createPopupMenu(PopupMenu target)161throws HeadlessException {162throw new HeadlessException();163}164165public MenuItemPeer createMenuItem(MenuItem target)166throws HeadlessException {167throw new HeadlessException();168}169170public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target)171throws HeadlessException {172throw new HeadlessException();173}174175public DragSourceContextPeer createDragSourceContextPeer(176DragGestureEvent dge)177throws InvalidDnDOperationException {178throw new InvalidDnDOperationException("Headless environment");179}180181public RobotPeer createRobot(Robot target, GraphicsDevice screen)182throws AWTException, HeadlessException {183throw new HeadlessException();184}185186public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() {187// See 6833019.188return kfmPeer;189}190191public TrayIconPeer createTrayIcon(TrayIcon target)192throws HeadlessException {193throw new HeadlessException();194}195196public SystemTrayPeer createSystemTray(SystemTray target)197throws HeadlessException {198throw new HeadlessException();199}200201public boolean isTraySupported() {202return false;203}204205public GlobalCursorManager getGlobalCursorManager()206throws HeadlessException {207throw new HeadlessException();208}209210/*211* Headless toolkit - unsupported.212*/213protected void loadSystemColors(int[] systemColors)214throws HeadlessException {215throw new HeadlessException();216}217218public ColorModel getColorModel()219throws HeadlessException {220throw new HeadlessException();221}222223public int getScreenResolution()224throws HeadlessException {225throw new HeadlessException();226}227228public Map mapInputMethodHighlight(InputMethodHighlight highlight)229throws HeadlessException {230throw new HeadlessException();231}232233public int getMenuShortcutKeyMask()234throws HeadlessException {235throw new HeadlessException();236}237238public boolean getLockingKeyState(int keyCode)239throws UnsupportedOperationException {240throw new HeadlessException();241}242243public void setLockingKeyState(int keyCode, boolean on)244throws UnsupportedOperationException {245throw new HeadlessException();246}247248public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)249throws IndexOutOfBoundsException, HeadlessException {250throw new HeadlessException();251}252253public Dimension getBestCursorSize(int preferredWidth, int preferredHeight)254throws HeadlessException {255throw new HeadlessException();256}257258public int getMaximumCursorColors()259throws HeadlessException {260throw new HeadlessException();261}262263public <T extends DragGestureRecognizer> T264createDragGestureRecognizer(Class<T> abstractRecognizerClass,265DragSource ds, Component c,266int srcActions, DragGestureListener dgl)267{268return null;269}270271public int getScreenHeight()272throws HeadlessException {273throw new HeadlessException();274}275276public int getScreenWidth()277throws HeadlessException {278throw new HeadlessException();279}280281public Dimension getScreenSize()282throws HeadlessException {283throw new HeadlessException();284}285286public Insets getScreenInsets(GraphicsConfiguration gc)287throws HeadlessException {288throw new HeadlessException();289}290291public void setDynamicLayout(boolean dynamic)292throws HeadlessException {293throw new HeadlessException();294}295296protected boolean isDynamicLayoutSet()297throws HeadlessException {298throw new HeadlessException();299}300301public boolean isDynamicLayoutActive()302throws HeadlessException {303throw new HeadlessException();304}305306public Clipboard getSystemClipboard()307throws HeadlessException {308throw new HeadlessException();309}310311/*312* Printing313*/314public PrintJob getPrintJob(Frame frame, String jobtitle,315JobAttributes jobAttributes,316PageAttributes pageAttributes) {317if (frame != null) {318// Should never happen319throw new HeadlessException();320}321throw new NullPointerException("frame must not be null");322}323324public PrintJob getPrintJob(Frame frame, String doctitle, Properties props)325{326if (frame != null) {327// Should never happen328throw new HeadlessException();329}330throw new NullPointerException("frame must not be null");331}332333/*334* Headless toolkit - supported.335*/336337public void sync() {338// Do nothing339}340341public void beep() {342// Send alert character343System.out.write(0x07);344}345346/*347* Event Queue348*/349public EventQueue getSystemEventQueueImpl() {350return SunToolkit.getSystemEventQueueImplPP();351}352353/*354* Images.355*/356public int checkImage(Image img, int w, int h, ImageObserver o) {357return tk.checkImage(img, w, h, o);358}359360public boolean prepareImage(361Image img, int w, int h, ImageObserver o) {362return tk.prepareImage(img, w, h, o);363}364365public Image getImage(String filename) {366return tk.getImage(filename);367}368369public Image getImage(URL url) {370return tk.getImage(url);371}372373public Image createImage(String filename) {374return tk.createImage(filename);375}376377public Image createImage(URL url) {378return tk.createImage(url);379}380381public Image createImage(byte[] data, int offset, int length) {382return tk.createImage(data, offset, length);383}384385public Image createImage(ImageProducer producer) {386return tk.createImage(producer);387}388389public Image createImage(byte[] imagedata) {390return tk.createImage(imagedata);391}392393394/*395* Fonts396*/397@SuppressWarnings("deprecation")398public FontPeer getFontPeer(String name, int style) {399if (componentFactory != null) {400return componentFactory.getFontPeer(name, style);401}402return null;403}404405@Override406public DataTransferer getDataTransferer() {407return null;408}409410@SuppressWarnings("deprecation")411public FontMetrics getFontMetrics(Font font) {412return tk.getFontMetrics(font);413}414415@SuppressWarnings("deprecation")416public String[] getFontList() {417return tk.getFontList();418}419420/*421* Desktop properties422*/423424public void addPropertyChangeListener(String name,425PropertyChangeListener pcl) {426tk.addPropertyChangeListener(name, pcl);427}428429public void removePropertyChangeListener(String name,430PropertyChangeListener pcl) {431tk.removePropertyChangeListener(name, pcl);432}433434/*435* Modality436*/437public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) {438return false;439}440441public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) {442return false;443}444445/*446* Always on top447*/448public boolean isAlwaysOnTopSupported() {449return false;450}451452/*453* AWT Event listeners454*/455456public void addAWTEventListener(AWTEventListener listener,457long eventMask) {458tk.addAWTEventListener(listener, eventMask);459}460461public void removeAWTEventListener(AWTEventListener listener) {462tk.removeAWTEventListener(listener);463}464465public AWTEventListener[] getAWTEventListeners() {466return tk.getAWTEventListeners();467}468469public AWTEventListener[] getAWTEventListeners(long eventMask) {470return tk.getAWTEventListeners(eventMask);471}472473public boolean isDesktopSupported() {474return false;475}476477public DesktopPeer createDesktopPeer(Desktop target)478throws HeadlessException{479throw new HeadlessException();480}481482public boolean areExtraMouseButtonsEnabled() throws HeadlessException{483throw new HeadlessException();484}485}486487488