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