1 /*
   2  * Copyright (c) 2000, 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.dnd.DragGestureEvent;
  30 import java.awt.dnd.InvalidDnDOperationException;
  31 import java.awt.dnd.peer.DragSourceContextPeer;
  32 import java.awt.peer.*;
  33 
  34 import sun.awt.datatransfer.DataTransferer;
  35 
  36 final class LightweightPeerHolder {
  37     static final LightweightPeer lightweightMarker = new NullComponentPeer();
  38 
  39     private LightweightPeerHolder() {
  40     }
  41 }
  42 
  43 /**
  44  * Interface for component creation support in toolkits.
  45  */
  46 public interface ComponentFactory {
  47 
  48     /**
  49      * Creates a peer for a component or container. This peer is windowless and
  50      * allows the Component and Container classes to be extended directly to
  51      * create windowless components that are defined entirely in java.
  52      *
  53      * @param  target The Component to be created
  54      * @return the peer for the specified component
  55      */
  56     default LightweightPeer createComponent(Component target) {
  57         return LightweightPeerHolder.lightweightMarker;
  58     }
  59 
  60     /**
  61      * Creates this toolkit's implementation of the {@code Desktop} using the
  62      * specified peer interface.
  63      *
  64      * @param  target the desktop to be implemented
  65      * @return this toolkit's implementation of the {@code Desktop}
  66      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
  67      *         true
  68      * @see java.awt.GraphicsEnvironment#isHeadless
  69      * @see java.awt.Desktop
  70      * @see java.awt.peer.DesktopPeer
  71      * @since 1.6
  72      */
  73     default DesktopPeer createDesktopPeer(Desktop target) {
  74         throw new HeadlessException();
  75     }
  76     
  77     /**
  78      * Creates this toolkit's implementation of the {@code Taskbar} using the
  79      * specified peer interface.
  80      *
  81      * @param  target the taskbar to be implemented
  82      * @return this toolkit's implementation of the {@code Taskbar}
  83      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
  84      *         true
  85      * @see java.awt.GraphicsEnvironment#isHeadless
  86      * @see java.awt.Taskbar
  87      * @see java.awt.peer.TaskbarPeer
  88      * @since 1.9
  89      */
  90     default TaskbarPeer createTaskbarPeer(Taskbar target) {
  91         throw new HeadlessException();
  92     }
  93 
  94     /**
  95      * Creates this toolkit's implementation of {@code Button} using the
  96      * specified peer interface.
  97      *
  98      * @param  target the button to be implemented
  99      * @return this toolkit's implementation of {@code Button}
 100      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 101      *         true
 102      * @see java.awt.GraphicsEnvironment#isHeadless
 103      * @see java.awt.Button
 104      * @see java.awt.peer.ButtonPeer
 105      */
 106     default ButtonPeer createButton(Button target) {
 107         throw new HeadlessException();
 108     }
 109 
 110     /**
 111      * Creates this toolkit's implementation of {@code TextField} using the
 112      * specified peer interface.
 113      *
 114      * @param  target the text field to be implemented
 115      * @return this toolkit's implementation of {@code TextField}
 116      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 117      *         true
 118      * @see java.awt.GraphicsEnvironment#isHeadless
 119      * @see java.awt.TextField
 120      * @see java.awt.peer.TextFieldPeer
 121      */
 122     default TextFieldPeer createTextField(TextField target) {
 123         throw new HeadlessException();
 124     }
 125 
 126     /**
 127      * Creates this toolkit's implementation of {@code Label} using the
 128      * specified peer interface.
 129      *
 130      * @param  target the label to be implemented
 131      * @return this toolkit's implementation of {@code Label}
 132      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 133      *         true
 134      * @see java.awt.GraphicsEnvironment#isHeadless
 135      * @see java.awt.Label
 136      * @see java.awt.peer.LabelPeer
 137      */
 138     default LabelPeer createLabel(Label target) {
 139         throw new HeadlessException();
 140     }
 141 
 142     /**
 143      * Creates this toolkit's implementation of {@code List} using the specified
 144      * peer interface.
 145      *
 146      * @param  target the list to be implemented
 147      * @return this toolkit's implementation of {@code List}
 148      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 149      *         true
 150      * @see java.awt.GraphicsEnvironment#isHeadless
 151      * @see java.awt.List
 152      * @see java.awt.peer.ListPeer
 153      */
 154     default ListPeer createList(java.awt.List target) {
 155         throw new HeadlessException();
 156     }
 157 
 158     /**
 159      * Creates this toolkit's implementation of {@code Checkbox} using the
 160      * specified peer interface.
 161      *
 162      * @param  target the check box to be implemented
 163      * @return this toolkit's implementation of {@code Checkbox}
 164      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 165      *         true
 166      * @see java.awt.GraphicsEnvironment#isHeadless
 167      * @see java.awt.Checkbox
 168      * @see java.awt.peer.CheckboxPeer
 169      */
 170     default CheckboxPeer createCheckbox(Checkbox target) {
 171         throw new HeadlessException();
 172     }
 173 
 174     /**
 175      * Creates this toolkit's implementation of {@code Scrollbar} using the
 176      * specified peer interface.
 177      *
 178      * @param  target the scroll bar to be implemented
 179      * @return this toolkit's implementation of {@code Scrollbar}
 180      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 181      *         true
 182      * @see java.awt.GraphicsEnvironment#isHeadless
 183      * @see java.awt.Scrollbar
 184      * @see java.awt.peer.ScrollbarPeer
 185      */
 186     default ScrollbarPeer createScrollbar(Scrollbar target) {
 187         throw new HeadlessException();
 188     }
 189 
 190     /**
 191      * Creates this toolkit's implementation of {@code ScrollPane} using the
 192      * specified peer interface.
 193      *
 194      * @param  target the scroll pane to be implemented
 195      * @return this toolkit's implementation of {@code ScrollPane}
 196      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 197      *         true
 198      * @see java.awt.GraphicsEnvironment#isHeadless
 199      * @see java.awt.ScrollPane
 200      * @see java.awt.peer.ScrollPanePeer
 201      * @since 1.1
 202      */
 203     default ScrollPanePeer createScrollPane(ScrollPane target) {
 204         throw new HeadlessException();
 205     }
 206 
 207     /**
 208      * Creates this toolkit's implementation of {@code TextArea} using the
 209      * specified peer interface.
 210      *
 211      * @param  target the text area to be implemented
 212      * @return this toolkit's implementation of {@code TextArea}
 213      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 214      *         true
 215      * @see java.awt.GraphicsEnvironment#isHeadless
 216      * @see java.awt.TextArea
 217      * @see java.awt.peer.TextAreaPeer
 218      */
 219     default TextAreaPeer createTextArea(TextArea target) {
 220         throw new HeadlessException();
 221     }
 222 
 223     /**
 224      * Creates this toolkit's implementation of {@code Choice} using the
 225      * specified peer interface.
 226      *
 227      * @param  target the choice to be implemented
 228      * @return this toolkit's implementation of {@code Choice}
 229      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 230      *         true
 231      * @see java.awt.GraphicsEnvironment#isHeadless
 232      * @see java.awt.Choice
 233      * @see java.awt.peer.ChoicePeer
 234      */
 235     default ChoicePeer createChoice(Choice target) {
 236         throw new HeadlessException();
 237     }
 238 
 239     /**
 240      * Creates this toolkit's implementation of {@code Frame} using the
 241      * specified peer interface.
 242      *
 243      * @param  target the frame to be implemented
 244      * @return this toolkit's implementation of {@code Frame}
 245      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 246      *         true
 247      * @see java.awt.GraphicsEnvironment#isHeadless
 248      * @see java.awt.Frame
 249      * @see java.awt.peer.FramePeer
 250      */
 251     default FramePeer createFrame(Frame target) {
 252         throw new HeadlessException();
 253     }
 254 
 255     /**
 256      * Creates this toolkit's implementation of {@code Canvas} using the
 257      * specified peer interface.
 258      *
 259      * @param  target the canvas to be implemented
 260      * @return this toolkit's implementation of {@code Canvas}
 261      * @see java.awt.Canvas
 262      * @see java.awt.peer.CanvasPeer
 263      */
 264     default CanvasPeer createCanvas(Canvas target) {
 265         return (CanvasPeer) createComponent(target);
 266     }
 267 
 268     /**
 269      * Creates this toolkit's implementation of {@code Panel} using the
 270      * specified peer interface.
 271      *
 272      * @param  target the panel to be implemented
 273      * @return this toolkit's implementation of {@code Panel}
 274      * @see java.awt.Panel
 275      * @see java.awt.peer.PanelPeer
 276      */
 277     default PanelPeer createPanel(Panel target) {
 278         return (PanelPeer) createComponent(target);
 279     }
 280 
 281     /**
 282      * Creates this toolkit's implementation of {@code Window} using the
 283      * specified peer interface.
 284      *
 285      * @param  target the window to be implemented
 286      * @return this toolkit's implementation of {@code Window}
 287      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 288      *         true
 289      * @see java.awt.GraphicsEnvironment#isHeadless
 290      * @see java.awt.Window
 291      * @see java.awt.peer.WindowPeer
 292      */
 293     default WindowPeer createWindow(Window target) {
 294         throw new HeadlessException();
 295     }
 296 
 297     /**
 298      * Creates this toolkit's implementation of {@code Dialog} using the
 299      * specified peer interface.
 300      *
 301      * @param  target the dialog to be implemented
 302      * @return this toolkit's implementation of {@code Dialog}
 303      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 304      *         true
 305      * @see java.awt.GraphicsEnvironment#isHeadless
 306      * @see java.awt.Dialog
 307      * @see java.awt.peer.DialogPeer
 308      */
 309     default DialogPeer createDialog(Dialog target) {
 310         throw new HeadlessException();
 311     }
 312 
 313     /**
 314      * Creates this toolkit's implementation of {@code MenuBar} using the
 315      * specified peer interface.
 316      *
 317      * @param  target the menu bar to be implemented
 318      * @return this toolkit's implementation of {@code MenuBar}
 319      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 320      *         true
 321      * @see java.awt.GraphicsEnvironment#isHeadless
 322      * @see java.awt.MenuBar
 323      * @see java.awt.peer.MenuBarPeer
 324      */
 325     default MenuBarPeer createMenuBar(MenuBar target) {
 326         throw new HeadlessException();
 327     }
 328 
 329     /**
 330      * Creates this toolkit's implementation of {@code Menu} using the specified
 331      * peer interface.
 332      *
 333      * @param  target the menu to be implemented
 334      * @return this toolkit's implementation of {@code Menu}
 335      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 336      *         true
 337      * @see java.awt.GraphicsEnvironment#isHeadless
 338      * @see java.awt.Menu
 339      * @see java.awt.peer.MenuPeer
 340      */
 341     default MenuPeer createMenu(Menu target) {
 342         throw new HeadlessException();
 343     }
 344 
 345     /**
 346      * Creates this toolkit's implementation of {@code PopupMenu} using the
 347      * specified peer interface.
 348      *
 349      * @param  target the popup menu to be implemented
 350      * @return this toolkit's implementation of {@code PopupMenu}
 351      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 352      *         true
 353      * @see java.awt.GraphicsEnvironment#isHeadless
 354      * @see java.awt.PopupMenu
 355      * @see java.awt.peer.PopupMenuPeer
 356      * @since 1.1
 357      */
 358     default PopupMenuPeer createPopupMenu(PopupMenu target) {
 359         throw new HeadlessException();
 360     }
 361 
 362     /**
 363      * Creates this toolkit's implementation of {@code MenuItem} using the
 364      * specified peer interface.
 365      *
 366      * @param  target the menu item to be implemented
 367      * @return this toolkit's implementation of {@code MenuItem}
 368      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 369      *         true
 370      * @see java.awt.GraphicsEnvironment#isHeadless
 371      * @see java.awt.MenuItem
 372      * @see java.awt.peer.MenuItemPeer
 373      */
 374     default MenuItemPeer createMenuItem(MenuItem target) {
 375         throw new HeadlessException();
 376     }
 377 
 378     /**
 379      * Creates this toolkit's implementation of {@code FileDialog} using the
 380      * specified peer interface.
 381      *
 382      * @param  target the file dialog to be implemented
 383      * @return this toolkit's implementation of {@code FileDialog}
 384      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 385      *         true
 386      * @see java.awt.GraphicsEnvironment#isHeadless
 387      * @see java.awt.FileDialog
 388      * @see java.awt.peer.FileDialogPeer
 389      */
 390     default FileDialogPeer createFileDialog(FileDialog target) {
 391         throw new HeadlessException();
 392     }
 393 
 394     /**
 395      * Creates this toolkit's implementation of {@code CheckboxMenuItem} using
 396      * the specified peer interface.
 397      *
 398      * @param  target the checkbox menu item to be implemented
 399      * @return this toolkit's implementation of {@code CheckboxMenuItem}
 400      * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns
 401      *         true
 402      * @see java.awt.GraphicsEnvironment#isHeadless
 403      * @see java.awt.CheckboxMenuItem
 404      * @see java.awt.peer.CheckboxMenuItemPeer
 405      */
 406     default CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) {
 407         throw new HeadlessException();
 408     }
 409 
 410     /**
 411      * Creates the peer for a DragSourceContext. Always throws
 412      * InvalidDndOperationException if GraphicsEnvironment.isHeadless() returns
 413      * true.
 414      *
 415      * @param  dge the {@code DragGestureEvent}
 416      * @return the peer created
 417      * @see java.awt.GraphicsEnvironment#isHeadless
 418      */
 419     default DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) {
 420         throw new InvalidDnDOperationException("Headless environment");
 421     }
 422 
 423     /**
 424      * Creates this toolkit's implementation of {@code Font} using the specified
 425      * peer interface.
 426      *
 427      * @param name the font to be implemented
 428      * @param style the style of the font, such as {@code PLAIN}, {@code BOLD},
 429      *        {@code ITALIC}, or a combination
 430      * @return this toolkit's implementation of {@code Font}
 431      * @see java.awt.Font
 432      * @see java.awt.peer.FontPeer
 433      * @see java.awt.GraphicsEnvironment#getAllFonts
 434      */
 435     default FontPeer getFontPeer(String name, int style) {
 436         return null;
 437     }
 438 
 439     default RobotPeer createRobot(Robot target, GraphicsDevice screen)
 440             throws AWTException {
 441         throw new HeadlessException();
 442     }
 443 
 444     default DataTransferer getDataTransferer() {
 445         return null;
 446     }
 447 
 448     /**
 449      * Obtains this toolkit's implementation of helper class for {@code
 450      * MouseInfo} operations.
 451      *
 452      * @return this toolkit's implementation of helper for {@code MouseInfo}
 453      * @throws UnsupportedOperationException if this operation is not
 454      *         implemented
 455      * @see java.awt.peer.MouseInfoPeer
 456      * @see java.awt.MouseInfo
 457      * @since 1.5
 458      */
 459     default MouseInfoPeer getMouseInfoPeer() {
 460         throw new UnsupportedOperationException("Not implemented");
 461     }
 462 }