swing-ui 0.1.25 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE +5 -4
  2. package/README.md +144 -7
  3. package/SwingUI.js +2611 -0
  4. package/classes/Arc.js +185 -0
  5. package/classes/Button.js +55 -0
  6. package/classes/CheckBox.js +33 -0
  7. package/classes/CheckBoxMenuItem.js +24 -0
  8. package/classes/ComboBox.js +329 -0
  9. package/classes/ComponentContainer.js +828 -0
  10. package/classes/ContextMenu.js +141 -0
  11. package/classes/DocumentEditor.js +168 -0
  12. package/classes/Ellipse.js +76 -0
  13. package/classes/InternalWindow.js +397 -0
  14. package/classes/InternalWindowContainer.js +93 -0
  15. package/classes/Label.js +52 -0
  16. package/classes/Line.js +105 -0
  17. package/classes/List.js +452 -0
  18. package/classes/MediaPlayer.js +504 -0
  19. package/classes/Menu.js +74 -0
  20. package/classes/MenuBar.js +56 -0
  21. package/classes/MenuItem.js +92 -0
  22. package/classes/Panel.js +50 -0
  23. package/classes/PasswordField.js +47 -0
  24. package/classes/Polygon.js +236 -0
  25. package/classes/Polyline.js +240 -0
  26. package/classes/ProgressBar.js +62 -0
  27. package/classes/RadioButton.js +110 -0
  28. package/classes/RadioButtonMenuItem.js +106 -0
  29. package/classes/Rectangle.js +199 -0
  30. package/classes/ScrollPane.js +53 -0
  31. package/classes/ScrollableComponent.js +141 -0
  32. package/classes/Separator.js +24 -0
  33. package/classes/Shape.js +584 -0
  34. package/classes/ShapeContainer.js +231 -0
  35. package/classes/Slider.js +172 -0
  36. package/classes/Spinner.js +172 -0
  37. package/classes/SplitView.js +82 -0
  38. package/classes/Stroke.js +115 -0
  39. package/classes/Table.js +982 -0
  40. package/classes/Tabs.js +228 -0
  41. package/classes/TextArea.js +125 -0
  42. package/classes/TextComponent.js +207 -0
  43. package/classes/TextField.js +128 -0
  44. package/classes/TextShape.js +123 -0
  45. package/classes/ToggleButton.js +147 -0
  46. package/classes/ToolBar.js +120 -0
  47. package/classes/TrayIcon.js +54 -0
  48. package/classes/Tree.js +569 -0
  49. package/classes/UIComponent.js +2113 -0
  50. package/classes/Window.js +609 -0
  51. package/enums.js +298 -0
  52. package/fonts.conf +32 -0
  53. package/functions.js +254 -0
  54. package/icon.png +0 -0
  55. package/index.js +109 -4
  56. package/jar/gui-11.jar +0 -0
  57. package/jar/lib/flatlaf.jar +0 -0
  58. package/jar/lib/jna.jar +0 -0
  59. package/package.json +58 -33
  60. package/typedefs.js +973 -0
  61. package/types/SwingUI.d.ts +727 -0
  62. package/types/classes/Arc.d.ts +111 -0
  63. package/types/classes/Button.d.ts +38 -0
  64. package/types/classes/CheckBox.d.ts +22 -0
  65. package/types/classes/CheckBoxMenuItem.d.ts +18 -0
  66. package/types/classes/ComboBox.d.ts +172 -0
  67. package/types/classes/ComponentContainer.d.ts +131 -0
  68. package/types/classes/ContextMenu.d.ts +74 -0
  69. package/types/classes/DocumentEditor.d.ts +95 -0
  70. package/types/classes/Ellipse.d.ts +34 -0
  71. package/types/classes/InternalWindow.d.ts +163 -0
  72. package/types/classes/InternalWindowContainer.d.ts +36 -0
  73. package/types/classes/Label.d.ts +33 -0
  74. package/types/classes/Line.d.ts +48 -0
  75. package/types/classes/List.d.ts +223 -0
  76. package/types/classes/MediaPlayer.d.ts +381 -0
  77. package/types/classes/Menu.d.ts +43 -0
  78. package/types/classes/MenuBar.d.ts +26 -0
  79. package/types/classes/MenuItem.d.ts +57 -0
  80. package/types/classes/Panel.d.ts +28 -0
  81. package/types/classes/PasswordField.d.ts +22 -0
  82. package/types/classes/Polygon.d.ts +93 -0
  83. package/types/classes/Polyline.d.ts +96 -0
  84. package/types/classes/ProgressBar.d.ts +36 -0
  85. package/types/classes/RadioButton.d.ts +70 -0
  86. package/types/classes/RadioButtonMenuItem.d.ts +71 -0
  87. package/types/classes/Rectangle.d.ts +82 -0
  88. package/types/classes/ScrollPane.d.ts +23 -0
  89. package/types/classes/ScrollableComponent.d.ts +81 -0
  90. package/types/classes/Separator.d.ts +14 -0
  91. package/types/classes/Shape.d.ts +223 -0
  92. package/types/classes/ShapeContainer.d.ts +92 -0
  93. package/types/classes/Slider.d.ts +107 -0
  94. package/types/classes/Spinner.d.ts +129 -0
  95. package/types/classes/SplitView.d.ts +47 -0
  96. package/types/classes/Stroke.d.ts +99 -0
  97. package/types/classes/Table.d.ts +652 -0
  98. package/types/classes/Tabs.d.ts +118 -0
  99. package/types/classes/TextArea.d.ts +45 -0
  100. package/types/classes/TextComponent.d.ts +136 -0
  101. package/types/classes/TextField.d.ts +94 -0
  102. package/types/classes/TextShape.d.ts +73 -0
  103. package/types/classes/ToggleButton.d.ts +84 -0
  104. package/types/classes/ToolBar.d.ts +82 -0
  105. package/types/classes/TrayIcon.d.ts +43 -0
  106. package/types/classes/Tree.d.ts +354 -0
  107. package/types/classes/UIComponent.d.ts +945 -0
  108. package/types/classes/Window.d.ts +334 -0
  109. package/types/enums.d.ts +437 -0
  110. package/types/functions.d.ts +109 -0
  111. package/types/index.d.ts +188 -0
  112. package/types/typedefs.d.ts +1626 -0
  113. package/ui-process-manager.js +317 -0
  114. package/video-devices-linux.sh +72 -0
  115. package/video-devices-mac.sh +33 -0
  116. package/CHANGES.md +0 -3
@@ -0,0 +1,727 @@
1
+ /**
2
+ * Main SwingUI class that handles all communication between JavaScript and GUI and provides many utility methods not related to specific GUI components.
3
+ * <b>NOTE:</b> Do not instantiate this class, but instead use global `ui` constant, which is an instance of this class.
4
+ *
5
+ * See usage example below.
6
+ *
7
+ * @class
8
+ * @global
9
+ * @see ui
10
+ * @example <h2>Usage examples:</h2>
11
+ * const data = ui.clipboard(); // getting clipboard data
12
+ * const _screens = ui.screens; // getting screens information array
13
+ * ui.openURL("http://swing-ui.com/");
14
+ */
15
+ export class SwingUI {
16
+ /**
17
+ * @internal
18
+ * @private
19
+ */
20
+ private static WorkerSignalIndex;
21
+ /**
22
+ * @internal
23
+ * @private
24
+ */
25
+ private static WorkerSignal;
26
+ /**
27
+ * <b>NOTE:</b> Do not instantiate this class. It's already instantiated and assigned to a global variable `ui`.
28
+ * @internal
29
+ * @private
30
+ */
31
+ private constructor();
32
+ /**
33
+ * @internal
34
+ * @private
35
+ */
36
+ private stats;
37
+ /**
38
+ * @internal
39
+ * @private
40
+ */
41
+ private gui_process_id;
42
+ /**
43
+ * @internal
44
+ * @private
45
+ */
46
+ private callback;
47
+ /**
48
+ * @internal
49
+ * @private
50
+ */
51
+ private _msg;
52
+ InitGUIProcess(): Promise<void>;
53
+ /**
54
+ * Send a messages to GUI process via STD out. Use internally for communication only.
55
+ * @param {Object} msg - JSON Object message to send to GUI.
56
+ * @param {function(any):any} [callback] - Only pass callback to block event loop and wait for response
57
+ * @return {any|void} Returns response from GUI or undefined.
58
+ * @internal
59
+ * @ignore
60
+ */
61
+ sendToGUI(msg: Object, callback?: (arg0: any) => any): any | void;
62
+ /**
63
+ * Immediately sends all queued messages to GUI without waiting for queue threshold or execution end. It's similar to flush() function in data streams.
64
+ * It can be used to force messages to be sent imedietly instead of waiting for message queue to be full, if it's important to update some UI component or content right away.
65
+ * It may improve performance to set `compress` to `false` to skip compression for already compressed data, such as UI component's background image or large icon.
66
+ *
67
+ * @param {boolean} [compress=true] - Whether to compress messages before sending.
68
+ * @return {this} Returns `this` instance for chaining.
69
+ * @example <h2>Sending queued messages before proceeding:</h2>
70
+ * ui.sendMessageQueue();
71
+ *
72
+ * @example <h2>Sending queued messages without compressing:</h2>
73
+ * ui.sendMessageQueue(false);
74
+ */
75
+ sendMessageQueue(compress?: boolean): this;
76
+ /**
77
+ * Returns a detected or specified application root directory.
78
+ *
79
+ * @readonly
80
+ * @type {string}
81
+ */
82
+ readonly get rootDirectory(): string;
83
+ /**
84
+ * Gets the JavaScript runtime name ("node", "bun", "deno", or "unknown"). Useful when building an application compatible with multiple JavaScript runtimes.
85
+ * @type {string}
86
+ * @readonly
87
+ * @example <h2>Getting current JavaScript runtime:</h2>
88
+ * console.log(ui.runtime);
89
+ * // prints "node", or what ever your runtime is.
90
+ */
91
+ readonly get runtime(): string;
92
+ /**
93
+ * Returns a short identifier of an operating system on current machine. Possible values: "windows", "linux", "darwin" (for MacOS), "freebsd", "openbsd", "sunos", and "android".
94
+ * @type {string}
95
+ * @readonly
96
+ * @example <h2>Getting a short identifier of an operating system:</h2>
97
+ * console.log(ui.os); // e.g., prints "windows"
98
+ */
99
+ readonly get os(): string;
100
+ /**
101
+ * Getter property that returns an array of available UI look and feel IDs on your system. For example Windows OS can have a Windows look and feel that linux doesn't have. Use them to set the desired look and feel using ui.ui(id) method.
102
+ *
103
+ * @readonly
104
+ * @see {@link SwingUI#ui|ui.ui(id)}
105
+ * @type {string[]}
106
+ */
107
+ readonly get list(): string[];
108
+ /**
109
+ * Returns an array of screen objects [{x,y,width,height}] that are configured on this computer. X and Y is the position of screens relative to one virtual screen. It's useful when you have multiple screens.
110
+ *
111
+ * @readonly
112
+ * @type {Object[]}
113
+ * @example <h2>Getting a list of screens:</h2>
114
+ * console.debug(ui.screens);
115
+ *
116
+ * // Example of returned array:
117
+ * [
118
+ * {
119
+ * default: true,
120
+ * id: '\\Display0',
121
+ * description: 'Win32GraphicsDevice[screen=0]',
122
+ * x: 0,
123
+ * y: 0,
124
+ * width: 2560,
125
+ * height: 1080,
126
+ * refresh_rate: 59,
127
+ * bit_depth: 32,
128
+ * type: 'screen'
129
+ * },
130
+ * {
131
+ * default: false,
132
+ * id: '\\Display1',
133
+ * description: 'Win32GraphicsDevice[screen=1]',
134
+ * x: -1280,
135
+ * y: 255,
136
+ * width: 1280,
137
+ * height: 1024,
138
+ * refresh_rate: 60,
139
+ * bit_depth: 32,
140
+ * type: 'screen'
141
+ * }
142
+ * ]
143
+ */
144
+ readonly get screens(): Object[];
145
+ /**
146
+ * Checks if current operating system supports system tray icons.
147
+ *
148
+ * @readonly
149
+ * @type {boolean}
150
+ */
151
+ readonly get systemTraySupported(): boolean;
152
+ /**
153
+ * Gets a GUI software license information stored in the package.json file of your project.
154
+ *
155
+ * @readonly
156
+ * @type {Object}
157
+ */
158
+ readonly get license(): Object;
159
+ /**
160
+ * Gets and returns a swing-ui module version from package.json file.
161
+ *
162
+ * @readonly
163
+ * @type {string}
164
+ */
165
+ readonly get version(): string;
166
+ /**
167
+ * Returns details of memory usage by GUI process.
168
+ *
169
+ * @readonly
170
+ * @type {Object}
171
+ * @example <h2>Getting RAM details about the GUI process:</h2>
172
+ * console.log(ui.memoryUsage);
173
+ *
174
+ * // Example output
175
+ * {
176
+ * total: 268435456,
177
+ * max: 4263510016,
178
+ * max_heap: 4263510016,
179
+ * used: 23540264,
180
+ * non_heap: 39226904,
181
+ * free: 244895192,
182
+ * heap: 21443112
183
+ * }
184
+ */
185
+ readonly get memoryUsage(): Object;
186
+ /**
187
+ * Returns an array of fonts installed on the system.
188
+ *
189
+ * @readonly
190
+ * @type {string[]}
191
+ * @example <h2>Getting a list of fonts installed on the system:</h2>
192
+ * console.log(ui.fonts);
193
+ *
194
+ * // example output:
195
+ * [
196
+ * 'Adobe Arabic',
197
+ * 'Adobe Caslon Pro',
198
+ * 'Adobe Caslon Pro Bold',
199
+ * ...
200
+ * ]
201
+ */
202
+ readonly get fonts(): string[];
203
+ /**
204
+ * A getter to get environment variables.
205
+ *
206
+ * @readonly
207
+ * @type {object}
208
+ */
209
+ readonly get env(): object;
210
+ /**
211
+ * Gets a current process ID
212
+ *
213
+ * @readonly
214
+ * @type {number}
215
+ */
216
+ readonly get pid(): number;
217
+ /**
218
+ * Performs garbage collection in JavaScript and GUI.
219
+ * @return {SwingUI} Returns an instance of SwingUI object for method chaining.
220
+ * @example <h2>Usage example:</h2>
221
+ * ui.gc();
222
+ */
223
+ gc(): SwingUI;
224
+ /**
225
+ * Increases and decreases default font size of all UI components.
226
+ *
227
+ * @param {number} by - By how many pixels to adjust font size (positive integer increases size, negative decreases)
228
+ * @return {this} Returns an instance of SwingUI object for method chaining.
229
+ */
230
+ adjustFontSize(by: number): this;
231
+ /**
232
+ * Increases and decreases default font size of all controls.
233
+ *
234
+ * @param {number} by - By how much to adjust font size (positive increases size, negative decreases)
235
+ * @return {this} Returns an instance of SwingUI object for method chaining.
236
+ */
237
+ adjustDefaultFontSize(by: number): this;
238
+ /**
239
+ * Sets default font to be used by all components. Any font property may be changed (name, size, bold, etc.)
240
+ *
241
+ * @param {Font} font - New font
242
+ * @returns {this} Returns an instance of SwingUI object for method chaining.
243
+ */
244
+ setDefaultFont(font: Font): this;
245
+ /**
246
+ * Sets or reads clipboard content data. Data types must be values of object (enum) DataType.
247
+ *
248
+ * @param {object} [data] - Object ob data to be stored in a clipboard {Type: data}. See example below.
249
+ * @returns {object|SwingUI} When setting arguments, `this` instance of SwingUI is returned, otherwise clipboard data object is returned.
250
+ * @see DataType
251
+ * @example <h2>Valid data types for the clipboard data object:</h2>
252
+ * // Sets all possible data types to clipboard
253
+ * ui.clipboard({
254
+ * Text: "text to copy",
255
+ * HTML: "<b>HTML Content</b>",
256
+ * JSON: object,
257
+ * Image: "base64 encoded image data",
258
+ * URIList: ["http://url_1.com", "http://url_2.com"],
259
+ * Files: ["C://my_file.txt", ...],
260
+ * URL: "http://url.com"
261
+ * });
262
+ * @example <h2>Setting some plain text and HTML data to clipboard:</h2>
263
+ * const data = {};
264
+ * data[DataType.Text] = "Plain text content";
265
+ * data[DataType.HTML] = "<b>HTML Content</b>";
266
+ * ui.clipboard(data);
267
+ */
268
+ clipboard(...args: any[]): object | SwingUI;
269
+ /**
270
+ * Sets or gets boolean whether the layout of containers is validated during resizing, or after resizing is complete.
271
+ *
272
+ * @param {boolean} [value] - Enables or disables dynamic layout
273
+ * @return {boolean|SwingUI} When setting arguments, `this` instance of SwingUI is returned, otherwise current value is returned.
274
+ */
275
+ dynamicLayout(...args: any[]): boolean | SwingUI;
276
+ /**
277
+ * Gets or sets Java's GUI look and feel ID. Obtain a list of supported UIs by the system using ui.list getter property.
278
+ *
279
+ * @param {string} [id] - Identifies of Java Swing's UI to be used.
280
+ * @param {object} [options] - Additional look-and-feel options. Options apply only to some look-and-feels, like FlatLaf. Example: {border-radius: 5}.
281
+ * @return {string|SwingUI} When setting arguments, `this` instance of SwingUI is returned, otherwise current value is returned.
282
+ * @throws Error When argument is invalid.
283
+ * @see SwingUI#list
284
+ * @example <h2>Setting FlatDarkLaf UI with all options</h2>
285
+ * ui.ui(
286
+ * "FlatDarkLaf",
287
+ * {
288
+ * borderRadius:8,
289
+ * showScrollbarButtons: true,
290
+ * scrollbarSize: 14,
291
+ * selectedTabColor: "#FFFFFF",
292
+ * scrollbarColor: "#FF7777",
293
+ * arrowType: "triangle" // "triangle" or "chevron" (default)
294
+ * }
295
+ * );
296
+ */
297
+ ui(...args: any[]): string | SwingUI;
298
+ /**
299
+ * Shows a message dialog window like alert() in web browser.
300
+ *
301
+ * @param {string} message
302
+ * @param {string} [title] - Message window title
303
+ * @param {MessageIcon} [icon] - Use: MessageIcon.[Info|Warning|Error]
304
+ * @param {Window} [ownerWindow] - If set, the message dialog window will attempts to be centered at specified window
305
+ * @return {void} Does not return a value.
306
+ */
307
+ showMessage(message: string, title?: string, icon?: MessageIcon, ownerWindow?: Window): void;
308
+ /**
309
+ * Sets a custom Error handler when error events come if from GUI. Event object has a "e.message" parameter, and
310
+ * may have "e.target" that references a component related to the error.
311
+ * e:{
312
+ * message (always)
313
+ * target: (when component is related to the error)
314
+ * }
315
+ * @param {function(Object):any} callback - Function to be called instead of default error handling.
316
+ * @return {SwingUI} Returns `this` instance of SwingUI class.
317
+ */
318
+ onError(callback: (arg0: Object) => any): SwingUI;
319
+ /**
320
+ * Gets or sets text rendering mode used in UI components.
321
+ *
322
+ * @param {string} [mode] - Specifies font antialiasing mode to use (on|lcd|gasp|off) (NOT IMPLEMENTED YET).
323
+ * @returns {string|null} Returns font antialiasing mode: `on`, `lcd`, `gasp`, `off`, or `null` object if font antialiasing could not be detected.
324
+ */
325
+ fontAntialiasing(...args: any[]): string | null;
326
+ /**
327
+ * Gets or sets the event throttle interval for high-frequency events, like mouse motion or resizing. Value is in milliseconds, so 100 means no more than 10 same type of events per component per second.
328
+ * Applies only to some high frequency events, such as resizing and moving.
329
+ *
330
+ * @param {number} [ms] - Minimum amount of time (in milliseconds) between same type of events per component.
331
+ * @return {SwingUI|number} When setting arguments, `this` instance of SwingUI is returned, otherwise current value is returned.
332
+ * @example <h2>Setting and getting examples:</h2>
333
+ * ui.eventThrottle(10); // Sets new value
334
+ * console.debug(ui.eventThrottle()); // prints current value
335
+ */
336
+ eventThrottle(...args: any[]): SwingUI | number;
337
+ /**
338
+ * Adjusts or retrieves the thread pool size and keep-alive time for image loading tasks.
339
+ * Each argument is optional. Setting `null` to any argument will not change it's value.
340
+ * Returns current configuration if no arguments are specified.
341
+ *
342
+ * @param {number} [min] - The minimum number of threads to keep alive (core pool size). Default is 1.
343
+ * @param {number} [max] - The maximum number of threads allowed (max pool size). Default is 5.
344
+ * @param {number} [keep_alive] - The idle time (in seconds) before excess threads are terminated when idle. Default is 5 seconds.
345
+ * @return {object|SwingUI} When setting arguments, `this` instance of SwingUI is returned, otherwise current value is returned.
346
+ */
347
+ iconLoadingThreads(...args: any[]): object | SwingUI;
348
+ /**
349
+ * Requests operating system to move top-most window of this application (or all windows) to foreground before other windows. Operating may refuse to do it.
350
+ * To forcefully bring a specific Window to the front you can set window.alwaysOnTop(true), and then window.alwaysOnTop(false), but it should not be abused in order to maintain a positive user experience.
351
+ *
352
+ * @param {boolean} [all_windows=false] - Move all windows of this application to foreground instead of just top-most window.
353
+ * @returns {SwingUI} returns `this` ui object for chaining.
354
+ */
355
+ requestForeground(all_windows?: boolean): SwingUI;
356
+ /**
357
+ * Sets or gets a default menu bar that should be used by macOS at the top of the screen. If the specified menu bar was added to any parent component, it will be removed from that component.
358
+ * This is supported only on macOS.
359
+ *
360
+ * @param {MenuBar|null} [menu_bar] - MenuBar component. Set to `null` to remove default menu bar.
361
+ * @return {MenuBar|boolean} If called without parameters, a default `Menubar` component is returned or `null` of it was never set; otherwise `boolean` is returned indicating if the operation was accepted by the operating system.
362
+ * @throws {Error} When passed argument is not a {@link MenuBar} object.
363
+ */
364
+ defaultMenuBar(...args: any[]): MenuBar | boolean;
365
+ /**
366
+ * Gracefully exits the application with specified exit code (status code) and optional exit signal. Emits onExit() event handlers, closes connection to GUI and notifies GUI to gracefully exit. This is a recommended way to exit the application.
367
+ *
368
+ * @param {number} [exitCode] - Exit code.
369
+ * @param {string} [signal] - One of received exit signals: `SIGINT`, `SIGUSR1`, `SIGUSR2`, `SIGTERM`, `SIGHUP`.
370
+ * @return {void} Does not return a value.
371
+ * @example <h2>Exiting the app gracefully:</h2>
372
+ * ui.exit();
373
+ * ui.exit(10); // existing with exit code 10
374
+ * @see SwingUI#onExit
375
+ */
376
+ exit(exitCode?: number, signal?: string): void;
377
+ /**
378
+ * Sets and gets locking keys state (Caps lock key, Num lock key, and Scroll lock key) to ON and OFF.
379
+ *
380
+ * @param {Object} [keys] - Keys object example {caps_lock: false, num_lock: true, scroll_lock: false}. Only set keys you want to change.
381
+ * @return {Object|SwingUI} When setting arguments, `this` instance of SwingUI is returned, otherwise current value is returned.
382
+ * @example <h2>Setting Caps Lock to ON</h2>
383
+ * ui.lockingKeys({caps_lock: true});
384
+ */
385
+ lockingKeys(...args: any[]): Object | SwingUI;
386
+ /**
387
+ * Gets or sets a position of a pointing device. If "screen" is specified,
388
+ * the {x,y} position will be relative to the specified screen, otherwise
389
+ * the position will be set relative to screen at index 0 (default screen).
390
+ * You can get a list of screens with ui.screens getter.
391
+ *
392
+ * @param {number} [x] - Use only to set pointer location
393
+ * @param {number} [y] - required if x is specified
394
+ * @param {number} [screen]
395
+ * @return {Object | SwingUI} When setting arguments, `this` instance of SwingUI is returned, otherwise current value is returned.
396
+ */
397
+ mouseLocation(...args: any[]): Object | SwingUI;
398
+ /**
399
+ * Performs mouse button action or mouse wheel scrolling action.
400
+ *
401
+ * @param {MouseAction} action - MouseAction.[Press, Release, Click, DoubleClick, VerticalScroll, HorizontalScroll]
402
+ * @param {MouseButton|number} button_or_scrolls - MouseButton.[Left, Right, Middle] OR integer for scroll amount if action is MouseAction.VerticalScroll or MouseAction.HorizontalScroll
403
+ * @return {SwingUI} Returns `this` instance of SwingUI class.
404
+ * @see MouseAction
405
+ */
406
+ mouseAction(action: MouseAction, button_or_scrolls: MouseButton | number): SwingUI;
407
+ /**
408
+ * Performs a key press, key release, or key type operation. For value use one character string when using "Press" or "Release" action, or a string of text to be typed when using "Type" action.
409
+ *
410
+ * @param {KeyAction} action - KeyAction.[Press|Release|Type]
411
+ * @param {number|number[]|string} key_code_or_string - Key code, array of key codes, or a string, which will be converted to an array of key codes.
412
+ * @return {SwingUI} Returns `this` instance of SwingUI class.
413
+ * @see KeyAction
414
+ * @example <h2>Performing a key type action:</h2>
415
+ * ui.keyboardAction(KeyAction.Type, "A");
416
+ */
417
+ keyboardAction(action: KeyAction, key_code_or_string: number | number[] | string, ...args: any[]): SwingUI;
418
+ /**
419
+ * Returns the index of the screen whose bounds contain the given coordinate, or -1 if the point does not fall within any configured screen.
420
+ *
421
+ * Accepts either:
422
+ * - Separate numeric coordinates (x, y), or
423
+ * - A point-like object with numeric `x` and `y` properties.
424
+ *
425
+ * @param {number|Object} xOrPoint - Either the X coordinate or a point object containing {x, y}.
426
+ * @param {number} [y] - The Y coordinate (required if xOrPoint is a number).
427
+ * @returns {number} The index of the matching screen, or -1 if none matched.
428
+ * @throws {Error} If the input is invalid (object is missing `x` or `y` properties) or coordinates are not finite numbers.
429
+ *
430
+ * @example <h2>Using separate x and y coordinates</h2>
431
+ * const screenIndex = ui.screenIndexAt(1920, 540);
432
+ * console.log(screenIndex); // e.g. 1, or -1 if not within any screen
433
+ *
434
+ * @example <h2>Using a point object</h2>
435
+ * const cursor = { x: 3440, y: 1080 };
436
+ * const screenIndex = ui.screenIndexAt(cursor);
437
+ * console.log(screenIndex); // e.g. 2, or -1 if not within any screen
438
+ */
439
+ screenIndexAt(xOrPoint: number | Object, y?: number): number;
440
+ /**
441
+ * Opens provided URL in a default web browser.
442
+ *
443
+ * @param {string} url - Website address to open.
444
+ * @return {this} Returns `this` instance of SwingUI class.
445
+ */
446
+ openURL(url: string): this;
447
+ /**
448
+ * Opens file or a folder with a default application associated the file type, or inside a file manager application (is specified).
449
+ *
450
+ * @param {string} path - Absolute path of a local file or directory.
451
+ * @param {boolean} [in_file_manager=false] - Indicates if the file should be open inside a default file manager application instead of a default application associated with that file type.
452
+ * @return {boolean} Returns `true` if the path exists and this operation is supported by the operating system; otherwise returns `false`.
453
+ */
454
+ openPath(path: string, in_file_manager?: boolean): boolean;
455
+ /**
456
+ * Tells operating system to print a file using default file printing dialog window.
457
+ *
458
+ * @param {String} path - Absolute path of a local file to print.
459
+ * @return {boolean} Returns `true` if the file exists and this operation is supported by the operating system; otherwise returns `false`.
460
+ */
461
+ printFile(path: string): boolean;
462
+ /**
463
+ * Opens the default mail client’s compose window with fields pre-filled according to a `mailto:` URI.
464
+ * The `mailto:` URI can include message fields such as `to`, `cc`, `subject`, `body`, etc.
465
+ * For details, see [RFC 2368](https://www.rfc-editor.org/rfc/rfc2368) (The mailto URL scheme).
466
+ * In some cases an error message may provide details as to why starting the application failed.
467
+ *
468
+ * @param {string} [mailto_uri=""] - A `mailto:` URI. Leave empty to simply open the compose window without any fields filled in.
469
+ * @returns {boolean} Returns `true` if this action is supported by the operating system and the default mail application compose window starts successfully; otherwise returns `false`.
470
+ */
471
+ mail(mailto_uri?: string): boolean;
472
+ /**
473
+ * Synchronously pauses main thread code execution for a specified amount of milliseconds.
474
+ *
475
+ * @param {number} ms - Amount of milliseconds to sleep.
476
+ * @returns {boolean} Returns `true` when code execution resumed because of specified timeout, `false` for any other reason.
477
+ */
478
+ sleep(ms: number): boolean;
479
+ /**
480
+ * Synchronously checks if the file or directory exist.
481
+ *
482
+ * @param {string|URL} file_path - File or directory path to check
483
+ * @returns {boolean} Returns `true` if the file or directory exist; otherwise returns `false`.
484
+ * @throws {Error} When the file path is invalid.
485
+ */
486
+ fileExists(file_path: string | URL): boolean;
487
+ /**
488
+ * Synchronously reads a local file and returns its data.
489
+ * NOTE: Memory limit set by JavaScript runtime and operating system limits the file size that can be read.
490
+ *
491
+ * @param {string} file_path
492
+ * @param {string} [data_type="string"] - Desired return data type: `string`, `Uint8Array`, `ArrayBuffer`, `Buffer`. NOTE: `Buffer` may not be supported in all JavaScript runtimes and exception may occur.
493
+ * @param {string} [encoding="utf-8"] - Text encoding to use. Only applies when `data_type` argument is "string".
494
+ * @returns {string|Uint8Array|ArrayBuffer|Buffer} Returns the data in specified data type.
495
+ * @throws {Error} When the file path is invalid.
496
+ * @throws {Error} When file doesn't exist.
497
+ * @throws {Error} When file cannot be read.
498
+ * @throws {Error} When `data_type` parameter is invalid.
499
+ */
500
+ readFile(file_path: string, data_type?: string, encoding?: string): string | Uint8Array | ArrayBuffer | Buffer;
501
+ /**
502
+ * Writes data to a file synchronously.
503
+ *
504
+ * @param {string|URL} file_path - Local destination file path.
505
+ * @param {string|ArrayBuffer|Uint8Array|Buffer} data - Data to write to a file.
506
+ * @param {string} [mode="write"] - "write" or "append"
507
+ * @param {boolean} [overwrite=true] - `true` to overwrite existing file with the same path. `false` to fail and return `false` if a file with the same path already exists.
508
+ * @param {boolean} [create_dir=false] - `true` to create directory if it doesn't exist. `false` is default. If `false` and directory doesn't exist, an Errow will be thrown.
509
+ * @returns {boolean} Returns `true` on success, or throws an Error on failure.
510
+ * @throws {Error} When the file path is invalid.
511
+ * @throws {Error} When the file exists and `overwrite` argument is not `true`.
512
+ * @throws {Error} When access to the file is denied.
513
+ * @throws {Error} When directory to the specified file failed to be automatically created.
514
+ * @throws {Error} When the directory of the file path doesn't exist and `create_dir` argument is not true.
515
+ * @throws {Error} When failed to write the file.
516
+ */
517
+ writeFile(file_path: string | URL, data: string | ArrayBuffer | Uint8Array | Buffer, mode?: string, overwrite?: boolean, create_dir?: boolean): boolean;
518
+ /**
519
+ * Gets information about a file or directory, like times, size, if it's a file or directory, etc.
520
+ *
521
+ * @param {string|URL} file_path - Local file or directory path.
522
+ * @param {boolean} [about_link=false] - `true` makes the method return information about the symbolic link itself instead of the path the link redirects to. Only applies to symbolic links.
523
+ * @returns {FileStat} Returns information about specified file or directory, or throws an Error if it doesn't exist, access is denied, or argument is invalid.
524
+ * @throws {Error} When the file path is invalid.
525
+ * @throws {Error} When the file is not found.
526
+ * @see FileStat
527
+ */
528
+ fileStat(file_path: string | URL, about_link?: boolean): FileStat;
529
+ /**
530
+ * Deletes a file or moves it to trash synchronously.
531
+ *
532
+ * @param {string} file_path - Path to the file to delete
533
+ * @param {boolean} [move_to_trash=false] - Move file to trash instead of completely deleting it.
534
+ * @returns {boolean} - Returns `true` on success or if the file didn't exist; otherwise returns `false` on failure
535
+ * @throws {Error} When the file path is invalid.
536
+ * @throws {Error} When the file path is a directory.
537
+ */
538
+ deleteFile(file_path: string, move_to_trash?: boolean): boolean;
539
+ /**
540
+ * Deletes a directory synchronously.
541
+ *
542
+ * @param {string} dir_path - Path to the directory to delete
543
+ * @param {boolean} [recursive=false] - Delete directory and its contents. (only has effect if `move_to_trash` parameter is false.
544
+ * @param {boolean} [move_to_trash=false] - Move file to trash instead of completely deleting it.
545
+ * @returns {boolean} - Returns true on success, or throws error on failure
546
+ * @throws {Error} When the directory path is invalid.
547
+ * @throws {Error} When the path is not a directory.
548
+ * @throws {Error} When the directory is not empty and `recursive=false`.
549
+ * @throws {Error} When failed to delete the directory.
550
+ */
551
+ deleteDirectory(dir_path: string, recursive?: boolean, move_to_trash?: boolean): boolean;
552
+ /**
553
+ * Deletes a file or directory synchronously.
554
+ *
555
+ * @param {string} path - Path to the directory to delete
556
+ * @param {boolean} [recursive=false] - Delete directory and its contents. (only has effect if `move_to_trash` parameter is false.
557
+ * @param {boolean} [move_to_trash=false] - Move file to trash instead of completely deleting it.
558
+ * @returns {boolean} - Returns true on success, or throws error on failure
559
+ * @throws {Error} When the file path is invalid.
560
+ * @throws {Error} When access is denied.
561
+ * @throws {Error} When failed to delete the file or directory.
562
+ */
563
+ deleteAny(path: string, recursive?: boolean, move_to_trash?: boolean): boolean;
564
+ /**
565
+ * Synchronously checks if a file can be read.
566
+ *
567
+ * @param {string|URL} file_path - Path to the file to check
568
+ * @returns {boolean} - Returns true if file can be read, false otherwise
569
+ * @throws {Error} When the file path is invalid.
570
+ */
571
+ canReadFile(file_path: string | URL): boolean;
572
+ /**
573
+ * Synchronously checks if a file can be written to.
574
+ *
575
+ * @param {string|URL} file_path - Path to the file to check
576
+ * @returns {boolean} - Returns true if file can be written to, false otherwise
577
+ * @throws {Error} When the file path is invalid.
578
+ */
579
+ canWriteFile(file_path: string | URL): boolean;
580
+ /**
581
+ * Creates a directory synchronously.
582
+ *
583
+ * @param {string} dir_path - Path to the directory to create
584
+ * @param {boolean} [recursive=false] - Create parent directories if they don't exist
585
+ * @returns {boolean} - Returns `true` on success or throws error on failure
586
+ * @throws {Error} When the directory path is invalid.
587
+ * @throws {Error} When the directory already exists.
588
+ * @throws {Error} When failed to create the directory.
589
+ */
590
+ makeDirectory(dir_path: string, recursive?: boolean): boolean;
591
+ /**
592
+ * Moves or copies a file synchronously. If the destination directory doesn't exist, the operation may fail.
593
+ *
594
+ * @param {string} from_file_path - Source file path
595
+ * @param {string} to_file_path - Destination file path
596
+ * @param {boolean} [copy=false] - Copy instead of move
597
+ * @returns {boolean} - Returns true on success, or throws an error on failure
598
+ * @throws {Error} On failure to move or copy the file.
599
+ */
600
+ moveFile(from_file_path: string, to_file_path: string, copy?: boolean): boolean;
601
+ /**
602
+ * Moves or copies a directory synchronously. If the destination parent directory doesn't exist, the operation may fail.
603
+ *
604
+ * @param {string} from_dir_path - Source directory path
605
+ * @param {string} to_dir_path - Destination directory path
606
+ * @param {boolean} [copy=false] - Copy instead of move
607
+ * @returns {boolean} - Returns true on success, or throws an error on failure
608
+ * @throws {Error} On failure to move or copy the file.
609
+ */
610
+ moveDirectory(from_dir_path: string, to_dir_path: string, copy?: boolean): boolean;
611
+ /**
612
+ * Reads the contents of a directory synchronously and returns an Array of files and directories.
613
+ *
614
+ * @param {string} dir_path - Path to the directory to read
615
+ * @returns {Array<string>} - Returns an Array of filenames/directory names in the directory.
616
+ * @throws {Error} When the directory path is invalid.
617
+ * @throws {Error} When the directory is not found.
618
+ * @throws {Error} When specified path is not a directory.
619
+ * @throws {Error} When access is denied.
620
+ * @throws {Error} When failed to read the directory.
621
+ */
622
+ listDirectory(dir_path: string): Array<string>;
623
+ /**
624
+ * Sets or gets a current working directory.
625
+ *
626
+ * @param {string} [dir=undefined] - New directory (omit when getting a directory).
627
+ * @returns {string} Returns current working directory. Throws error if the directory cannot be found or the user doesn't have permissions to access the specified directory when getting.
628
+ * @throws {Error} When setting working directory failed because it doesn't exist.
629
+ */
630
+ cwd(dir?: string): string;
631
+ /**
632
+ * Registers java-wide {@link MouseEvent} event handler that works in all Java apps (but not outside of Java applications).
633
+ *
634
+ * @param {function(MouseEvent):any} [callback=undefined] - Function to handle the event
635
+ * @param {boolean} [remove=false] - Remove the callback from this event
636
+ * @return {SwingUI|function[]} When called with arguments, returns `this` instance of SwingUI class, otherwise returns an array of current callbacks.
637
+ * @see MouseEvent
638
+ */
639
+ onMouseEvents(callback?: (arg0: MouseEvent) => any, remove?: boolean): SwingUI | Function[];
640
+ /**
641
+ * Registers java-wide {@link MouseMotionEvent} event handler that works in all Java apps (but not outside of Java applications).
642
+ *
643
+ * @param {function(MouseMotionEvent):any} [callback=undefined] - Function to handle the event
644
+ * @param {boolean} [remove=false] - Remove the callback from this event
645
+ * @return {SwingUI|function[]} When called with arguments, returns `this` instance of SwingUI class, otherwise returns an array of current callbacks.
646
+ * @see MouseMotionEvent
647
+ */
648
+ onMouseMotion(callback?: (arg0: MouseMotionEvent) => any, remove?: boolean): SwingUI | Function[];
649
+ /**
650
+ * Registers java-wide {@link MouseWheelEvent} handler that works in all Java apps (but not outside of Java applications).
651
+ *
652
+ * @param {function(Object):any} [callback=undefined] - Function to handle the {@link MouseWheelEvent}
653
+ * @param {boolean} [remove=false] - Remove the callback from this event
654
+ * @return {SwingUI|function[]} When called with arguments, returns `this` instance of SwingUI class, otherwise returns an array of current callbacks.
655
+ * @see MouseWheelEvent
656
+ * @see UIComponent#onMouseWheel
657
+ */
658
+ onMouseWheel(callback?: (arg0: Object) => any, remove?: boolean): SwingUI | Function[];
659
+ /**
660
+ * Registers java-wide {@link KeyEvent} keyboard key event handler. Handles keyboard keys actions made anywhere on the operating system.
661
+ *
662
+ * @param {function(KeyEvent):any} [callback=undefined] - Function to handle the event
663
+ * @param {boolean} [remove=false] - Remove the callback from this event
664
+ * @returns {SwingUI|function[]} When called with arguments, returns `this` instance of SwingUI class, otherwise returns an array of current callbacks.
665
+ * @see KeyEvent
666
+ */
667
+ onKey(callback?: (arg0: KeyEvent) => any, remove?: boolean): SwingUI | Function[];
668
+ /**
669
+ * Registers, gets, or unregisters event handler callbacks for application events on macOS.
670
+ *
671
+ * @param {function(AppEvent):any} [callback=undefined] - A callback function that receives an {@link AppEvent} object. Set to `null` to unregister all callbacks for this event. Omit to get an array of callbacks for this event.
672
+ * @param {boolean} [remove=false] - Remove the callback from this event.
673
+ * @returns {SwingUI|function[]} If called without parameters, an array of registered callbacks is returned; otherwise `this` instance of SwingUI class is returned.
674
+ * @see AppEvent
675
+ */
676
+ onAppEvents(callback?: (arg0: AppEvent) => any, remove?: boolean): SwingUI | Function[];
677
+ /**
678
+ * Registers, unregisters and retrieves event handler that receive STDIN data sent by command line interface (CLI).
679
+ *
680
+ * @param {function(Object):any|null|undefined} [callback] - Function to handle the event, `null` to remove all handlers, or omit to retrieve an array of handlers.
681
+ * @param {boolean} remove - Removed the callback from this event
682
+ * @return {SwingUI|function[]} If called without parameters, an array of registered callbacks is returned; otherwise `this` instance of SwingUI class is returned.
683
+ * @example <h2>Registering an event handler to receive CLI input:</h2>
684
+ * ui.onCLI(e => {console.log(`Received: ${e.data}`);});
685
+ */
686
+ onCLI(callback?: (arg0: Object) => any | null | undefined, remove?: boolean): SwingUI | Function[];
687
+ /**
688
+ * Registers, unregisters and retrieves event handler for an event emitted when UI look and feel is changed using ui.ui(id) method.
689
+ *
690
+ * @param {function(Object):any|null|undefined} [callback] - Function to handle the event, `null` to remove all handlers, or omit to retrieve an array of handlers.
691
+ * @param {boolean} remove - Removed the callback from this event
692
+ * @return {SwingUI|function[]} If called without parameters, an array of registered callbacks is returned; otherwise `this` instance of SwingUI class is returned.
693
+ * @example <h2>Receive UI look and feel change events:</h2>
694
+ * ui.onUIChange(e => {console.log(e);});
695
+ *
696
+ * // when UI changes, it prints the event like this:
697
+ * {
698
+ * newValue: {
699
+ * name: "Metal"
700
+ * dark: false
701
+ * id: "MetalLookAndFeel"
702
+ * }
703
+ * oldValue: {
704
+ * name: "FlatLaf Dark"
705
+ * dark: true
706
+ * id: "FlatDarkLaf"
707
+ * }
708
+ * event: "onUIChange"
709
+ * type: "change"
710
+ * }
711
+ * @see SwingUI#list
712
+ * @see SwingUI#ui
713
+ */
714
+ onUIChange(callback?: (arg0: Object) => any | null | undefined, remove?: boolean): SwingUI | Function[];
715
+ /**
716
+ * Registers, unregisters and retrieves event handler for exit event emitted by ui.exit() method.
717
+ *
718
+ * @param {function(Object):any|null|undefined} [callback] - Function to handle the event, `null` to remove all handlers, or omit to retrieve an array of handlers.
719
+ * @param {boolean} remove - Removed the callback from this event
720
+ * @return {SwingUI|function[]} If called without parameters, an array of registered callbacks is returned; otherwise `this` instance of SwingUI class is returned.
721
+ * @example <h2>Registering exit event handler:</h2>
722
+ * ui.onExit(e => {console.log(`Exiting with code: ${e.code}`);});
723
+ * @see SwingUI#exit
724
+ */
725
+ onExit(callback?: (arg0: Object) => any | null | undefined, remove?: boolean): SwingUI | Function[];
726
+ #private;
727
+ }