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