Path: blob/master/src/java.desktop/share/classes/sun/awt/ComponentFactory.java
41152 views
/*1* Copyright (c) 2000, 2020, 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.AWTException;28import java.awt.Button;29import java.awt.Canvas;30import java.awt.Checkbox;31import java.awt.CheckboxMenuItem;32import java.awt.Choice;33import java.awt.Component;34import java.awt.Desktop;35import java.awt.Dialog;36import java.awt.FileDialog;37import java.awt.Frame;38import java.awt.GraphicsDevice;39import java.awt.HeadlessException;40import java.awt.Label;41import java.awt.Menu;42import java.awt.MenuBar;43import java.awt.MenuItem;44import java.awt.Panel;45import java.awt.PopupMenu;46import java.awt.ScrollPane;47import java.awt.Scrollbar;48import java.awt.Taskbar;49import java.awt.TextArea;50import java.awt.TextField;51import java.awt.Window;52import java.awt.dnd.DragGestureEvent;53import java.awt.dnd.InvalidDnDOperationException;54import java.awt.dnd.peer.DragSourceContextPeer;55import java.awt.peer.ButtonPeer;56import java.awt.peer.CanvasPeer;57import java.awt.peer.CheckboxMenuItemPeer;58import java.awt.peer.CheckboxPeer;59import java.awt.peer.ChoicePeer;60import java.awt.peer.DesktopPeer;61import java.awt.peer.DialogPeer;62import java.awt.peer.FileDialogPeer;63import java.awt.peer.FontPeer;64import java.awt.peer.FramePeer;65import java.awt.peer.LabelPeer;66import java.awt.peer.LightweightPeer;67import java.awt.peer.ListPeer;68import java.awt.peer.MenuBarPeer;69import java.awt.peer.MenuItemPeer;70import java.awt.peer.MenuPeer;71import java.awt.peer.MouseInfoPeer;72import java.awt.peer.PanelPeer;73import java.awt.peer.PopupMenuPeer;74import java.awt.peer.RobotPeer;75import java.awt.peer.ScrollPanePeer;76import java.awt.peer.ScrollbarPeer;77import java.awt.peer.TaskbarPeer;78import java.awt.peer.TextAreaPeer;79import java.awt.peer.TextFieldPeer;80import java.awt.peer.WindowPeer;8182import sun.awt.datatransfer.DataTransferer;8384final class LightweightPeerHolder {85static final LightweightPeer lightweightMarker = new NullComponentPeer();8687private LightweightPeerHolder() {88}89}9091/**92* Interface for component creation support in toolkits.93*/94public interface ComponentFactory {9596/**97* Creates a peer for a component or container. This peer is windowless and98* allows the Component and Container classes to be extended directly to99* create windowless components that are defined entirely in java.100*101* @param target The Component to be created102* @return the peer for the specified component103*/104default LightweightPeer createComponent(Component target) {105return LightweightPeerHolder.lightweightMarker;106}107108/**109* Creates this toolkit's implementation of the {@code Desktop} using the110* specified peer interface.111*112* @param target the desktop to be implemented113* @return this toolkit's implementation of the {@code Desktop}114* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns115* true116* @see java.awt.GraphicsEnvironment#isHeadless117* @see java.awt.Desktop118* @see java.awt.peer.DesktopPeer119* @since 1.6120*/121default DesktopPeer createDesktopPeer(Desktop target) {122throw new HeadlessException();123}124125/**126* Creates this toolkit's implementation of the {@code Taskbar} using the127* specified peer interface.128*129* @param target the taskbar to be implemented130* @return this toolkit's implementation of the {@code Taskbar}131* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns132* true133* @see java.awt.GraphicsEnvironment#isHeadless134* @see java.awt.Taskbar135* @see java.awt.peer.TaskbarPeer136* @since 9137*/138default TaskbarPeer createTaskbarPeer(Taskbar target) {139throw new HeadlessException();140}141142/**143* Creates this toolkit's implementation of {@code Button} using the144* specified peer interface.145*146* @param target the button to be implemented147* @return this toolkit's implementation of {@code Button}148* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns149* true150* @see java.awt.GraphicsEnvironment#isHeadless151* @see java.awt.Button152* @see java.awt.peer.ButtonPeer153*/154default ButtonPeer createButton(Button target) {155throw new HeadlessException();156}157158/**159* Creates this toolkit's implementation of {@code TextField} using the160* specified peer interface.161*162* @param target the text field to be implemented163* @return this toolkit's implementation of {@code TextField}164* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns165* true166* @see java.awt.GraphicsEnvironment#isHeadless167* @see java.awt.TextField168* @see java.awt.peer.TextFieldPeer169*/170default TextFieldPeer createTextField(TextField target) {171throw new HeadlessException();172}173174/**175* Creates this toolkit's implementation of {@code Label} using the176* specified peer interface.177*178* @param target the label to be implemented179* @return this toolkit's implementation of {@code Label}180* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns181* true182* @see java.awt.GraphicsEnvironment#isHeadless183* @see java.awt.Label184* @see java.awt.peer.LabelPeer185*/186default LabelPeer createLabel(Label target) {187throw new HeadlessException();188}189190/**191* Creates this toolkit's implementation of {@code List} using the specified192* peer interface.193*194* @param target the list to be implemented195* @return this toolkit's implementation of {@code List}196* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns197* true198* @see java.awt.GraphicsEnvironment#isHeadless199* @see java.awt.List200* @see java.awt.peer.ListPeer201*/202default ListPeer createList(java.awt.List target) {203throw new HeadlessException();204}205206/**207* Creates this toolkit's implementation of {@code Checkbox} using the208* specified peer interface.209*210* @param target the check box to be implemented211* @return this toolkit's implementation of {@code Checkbox}212* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns213* true214* @see java.awt.GraphicsEnvironment#isHeadless215* @see java.awt.Checkbox216* @see java.awt.peer.CheckboxPeer217*/218default CheckboxPeer createCheckbox(Checkbox target) {219throw new HeadlessException();220}221222/**223* Creates this toolkit's implementation of {@code Scrollbar} using the224* specified peer interface.225*226* @param target the scroll bar to be implemented227* @return this toolkit's implementation of {@code Scrollbar}228* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns229* true230* @see java.awt.GraphicsEnvironment#isHeadless231* @see java.awt.Scrollbar232* @see java.awt.peer.ScrollbarPeer233*/234default ScrollbarPeer createScrollbar(Scrollbar target) {235throw new HeadlessException();236}237238/**239* Creates this toolkit's implementation of {@code ScrollPane} using the240* specified peer interface.241*242* @param target the scroll pane to be implemented243* @return this toolkit's implementation of {@code ScrollPane}244* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns245* true246* @see java.awt.GraphicsEnvironment#isHeadless247* @see java.awt.ScrollPane248* @see java.awt.peer.ScrollPanePeer249* @since 1.1250*/251default ScrollPanePeer createScrollPane(ScrollPane target) {252throw new HeadlessException();253}254255/**256* Creates this toolkit's implementation of {@code TextArea} using the257* specified peer interface.258*259* @param target the text area to be implemented260* @return this toolkit's implementation of {@code TextArea}261* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns262* true263* @see java.awt.GraphicsEnvironment#isHeadless264* @see java.awt.TextArea265* @see java.awt.peer.TextAreaPeer266*/267default TextAreaPeer createTextArea(TextArea target) {268throw new HeadlessException();269}270271/**272* Creates this toolkit's implementation of {@code Choice} using the273* specified peer interface.274*275* @param target the choice to be implemented276* @return this toolkit's implementation of {@code Choice}277* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns278* true279* @see java.awt.GraphicsEnvironment#isHeadless280* @see java.awt.Choice281* @see java.awt.peer.ChoicePeer282*/283default ChoicePeer createChoice(Choice target) {284throw new HeadlessException();285}286287/**288* Creates this toolkit's implementation of {@code Frame} using the289* specified peer interface.290*291* @param target the frame to be implemented292* @return this toolkit's implementation of {@code Frame}293* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns294* true295* @see java.awt.GraphicsEnvironment#isHeadless296* @see java.awt.Frame297* @see java.awt.peer.FramePeer298*/299default FramePeer createFrame(Frame target) {300throw new HeadlessException();301}302303/**304* Creates this toolkit's implementation of {@code Canvas} using the305* specified peer interface.306*307* @param target the canvas to be implemented308* @return this toolkit's implementation of {@code Canvas}309* @see java.awt.Canvas310* @see java.awt.peer.CanvasPeer311*/312default CanvasPeer createCanvas(Canvas target) {313return (CanvasPeer) createComponent(target);314}315316/**317* Creates this toolkit's implementation of {@code Panel} using the318* specified peer interface.319*320* @param target the panel to be implemented321* @return this toolkit's implementation of {@code Panel}322* @see java.awt.Panel323* @see java.awt.peer.PanelPeer324*/325default PanelPeer createPanel(Panel target) {326return (PanelPeer) createComponent(target);327}328329/**330* Creates this toolkit's implementation of {@code Window} using the331* specified peer interface.332*333* @param target the window to be implemented334* @return this toolkit's implementation of {@code Window}335* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns336* true337* @see java.awt.GraphicsEnvironment#isHeadless338* @see java.awt.Window339* @see java.awt.peer.WindowPeer340*/341default WindowPeer createWindow(Window target) {342throw new HeadlessException();343}344345/**346* Creates this toolkit's implementation of {@code Dialog} using the347* specified peer interface.348*349* @param target the dialog to be implemented350* @return this toolkit's implementation of {@code Dialog}351* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns352* true353* @see java.awt.GraphicsEnvironment#isHeadless354* @see java.awt.Dialog355* @see java.awt.peer.DialogPeer356*/357default DialogPeer createDialog(Dialog target) {358throw new HeadlessException();359}360361/**362* Creates this toolkit's implementation of {@code MenuBar} using the363* specified peer interface.364*365* @param target the menu bar to be implemented366* @return this toolkit's implementation of {@code MenuBar}367* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns368* true369* @see java.awt.GraphicsEnvironment#isHeadless370* @see java.awt.MenuBar371* @see java.awt.peer.MenuBarPeer372*/373default MenuBarPeer createMenuBar(MenuBar target) {374throw new HeadlessException();375}376377/**378* Creates this toolkit's implementation of {@code Menu} using the specified379* peer interface.380*381* @param target the menu to be implemented382* @return this toolkit's implementation of {@code Menu}383* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns384* true385* @see java.awt.GraphicsEnvironment#isHeadless386* @see java.awt.Menu387* @see java.awt.peer.MenuPeer388*/389default MenuPeer createMenu(Menu target) {390throw new HeadlessException();391}392393/**394* Creates this toolkit's implementation of {@code PopupMenu} using the395* specified peer interface.396*397* @param target the popup menu to be implemented398* @return this toolkit's implementation of {@code PopupMenu}399* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns400* true401* @see java.awt.GraphicsEnvironment#isHeadless402* @see java.awt.PopupMenu403* @see java.awt.peer.PopupMenuPeer404* @since 1.1405*/406default PopupMenuPeer createPopupMenu(PopupMenu target) {407throw new HeadlessException();408}409410/**411* Creates this toolkit's implementation of {@code MenuItem} using the412* specified peer interface.413*414* @param target the menu item to be implemented415* @return this toolkit's implementation of {@code MenuItem}416* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns417* true418* @see java.awt.GraphicsEnvironment#isHeadless419* @see java.awt.MenuItem420* @see java.awt.peer.MenuItemPeer421*/422default MenuItemPeer createMenuItem(MenuItem target) {423throw new HeadlessException();424}425426/**427* Creates this toolkit's implementation of {@code FileDialog} using the428* specified peer interface.429*430* @param target the file dialog to be implemented431* @return this toolkit's implementation of {@code FileDialog}432* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns433* true434* @see java.awt.GraphicsEnvironment#isHeadless435* @see java.awt.FileDialog436* @see java.awt.peer.FileDialogPeer437*/438default FileDialogPeer createFileDialog(FileDialog target) {439throw new HeadlessException();440}441442/**443* Creates this toolkit's implementation of {@code CheckboxMenuItem} using444* the specified peer interface.445*446* @param target the checkbox menu item to be implemented447* @return this toolkit's implementation of {@code CheckboxMenuItem}448* @throws HeadlessException if GraphicsEnvironment.isHeadless() returns449* true450* @see java.awt.GraphicsEnvironment#isHeadless451* @see java.awt.CheckboxMenuItem452* @see java.awt.peer.CheckboxMenuItemPeer453*/454default CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {455throw new HeadlessException();456}457458/**459* Creates the peer for a DragSourceContext. Always throws460* InvalidDndOperationException if GraphicsEnvironment.isHeadless() returns461* true.462*463* @param dge the {@code DragGestureEvent}464* @return the peer created465* @see java.awt.GraphicsEnvironment#isHeadless466*/467default DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) {468throw new InvalidDnDOperationException("Headless environment");469}470471/**472* Creates this toolkit's implementation of {@code Font} using the specified473* peer interface.474*475* @param name the font to be implemented476* @param style the style of the font, such as {@code PLAIN}, {@code BOLD},477* {@code ITALIC}, or a combination478* @return this toolkit's implementation of {@code Font}479* @see java.awt.Font480* @see java.awt.peer.FontPeer481* @see java.awt.GraphicsEnvironment#getAllFonts482*/483default FontPeer getFontPeer(String name, int style) {484return null;485}486487/**488* Creates the peer for a Robot.489*490* @param screen the GraphicsDevice indicating the coordinate system the491* Robot will operate in492* @return the peer created493* @throws AWTException if the platform configuration does not allow494* low-level input control495*/496default RobotPeer createRobot(GraphicsDevice screen) throws AWTException {497throw new AWTException(String.format("Unsupported device: %s", screen));498}499500default DataTransferer getDataTransferer() {501return null;502}503504/**505* Obtains this toolkit's implementation of helper class for {@code506* MouseInfo} operations.507*508* @return this toolkit's implementation of helper for {@code MouseInfo}509* @throws UnsupportedOperationException if this operation is not510* implemented511* @see java.awt.peer.MouseInfoPeer512* @see java.awt.MouseInfo513* @since 1.5514*/515default MouseInfoPeer getMouseInfoPeer() {516throw new UnsupportedOperationException("Not implemented");517}518}519520521