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,397 @@
1
+
2
+ import {ComponentContainer} from "./ComponentContainer.js";
3
+ import {UIComponent} from "./UIComponent.js";
4
+
5
+ /**
6
+ * InternalWindow UI component. Extends ComponentContainer, which extends UIComponent class.
7
+ * Internal window is a Window like component, but it can only be added to InternalWindowContainer for window-in-window experience.
8
+ * By default, InternalWindow is not visible. Use .visible(true) or .show() to make it visible.
9
+ *
10
+ * For more methods for this component check UIComponent class.
11
+ * @class
12
+ * @global
13
+ */
14
+ export class InternalWindow extends ComponentContainer
15
+ {
16
+ #prop = {
17
+ closeOperation: Window.CloseOperation.Dispose,
18
+ innerOffset: null
19
+ };
20
+
21
+ /**
22
+ * InternalWindow constructor.
23
+ *
24
+ * @param {string} [text] - Window title text
25
+ */
26
+ constructor()
27
+ {
28
+ if(arguments.length > 0)
29
+ {
30
+ super("InternalFrame", (new.target === InternalWindow), arguments[0]);
31
+ }
32
+ else
33
+ {
34
+ super("InternalFrame", (new.target === InternalWindow));
35
+ }
36
+
37
+ this.prop.innerOffset = null;
38
+
39
+ this.finalize(InternalWindow, ComponentContainer);
40
+
41
+ // callback to clear innerOffset cache
42
+ const clearOffset = e=>{this.prop.innerOffset = null;};
43
+ ui.onUIChange(clearOffset); // register callback
44
+ this.onDispose(e=>{ui.onUIChange(clearOffset, true);}); // unregister callback
45
+ }
46
+
47
+ /**
48
+ * Sets or gets the operation to perform when the InternalWindow's close button is clicked by a user or a close() method is called on this InternalWindow.
49
+ *
50
+ * Default value is `Window.CloseOperation.Dispose`.
51
+ *
52
+ * @param {Window.CloseOperation} [operation] - One of Window.CloseOperation enum values. (default is `Dispose`)
53
+ * @return {InternalWindow|Window.CloseOperation} Returns `this` component if argument is provided, otherwise returns value.
54
+ */
55
+ closeOperation(...args) // nothing, hide, dispose
56
+ {
57
+ if(args.length === 0) return this.#prop.closeOperation;
58
+
59
+ this.#prop.closeOperation = args[0];
60
+ return this.property("closeOperation", args);
61
+ }
62
+
63
+ /**
64
+ * Gets, registers or unregisters an event handler for when the state of the Window changes between normal, minimized, maximized.
65
+ *
66
+ * @param {function(Object): any} [callback] - The event handler function. Receives an event object.
67
+ * @param {boolean} [remove=false] - Set to `true` to unregister the event handler.
68
+ * @returns {this}
69
+ *
70
+ * @example
71
+ * // Example event object:
72
+ * const e = {
73
+ * target: InternalWindow, // The component that triggered the event.
74
+ * type: string, // `change`
75
+ * fromState: Window.State, // Previous state
76
+ * toState: Window.State, // New state
77
+ * interactive: boolean // Indicates if the state was changed by user's interaction with window
78
+ * };
79
+ */
80
+ onStateChange(callback, ...args)
81
+ {
82
+ return this.event("onStateChange", callback, args[0] ?? false);
83
+ }
84
+
85
+ /**
86
+ * Gets, registers or unregisters an event handler for window events, such as activate, deactivate, close, etc.
87
+ *
88
+ * @param {function(Object): any} [callback] - The event handler function. Receives an event object.
89
+ * @param {boolean} [remove=false] - Set to `true` to unregister the event handler.
90
+ * @returns {this}
91
+ *
92
+ * @example
93
+ * // Example event object:
94
+ * const e = {
95
+ * target: InternalWindow, // The component that triggered the event.
96
+ * type: string, // `activate`, `deactivate`, `minimize`, `restore`, `closing`, `close`, `show`
97
+ * interactive: boolean // Indicates if triggered by user's interaction with window
98
+ * };
99
+ */
100
+ onWindowEvents(callback, ...args)
101
+ {
102
+ return this.event("onWindowEvents", callback, args[0] ?? false);
103
+ }
104
+
105
+ /**
106
+ * Performs previously specified close operation on this InternalWindow.
107
+ * To specify what operation should be performed use closeOperation(Window.CloseOperation.[Nothing|Exit|Hide|Dispose])
108
+ *
109
+ * @return {InternalWindow} Returns this window component
110
+ */
111
+ close()
112
+ {
113
+ const msg = {control: this.id, set: "close"};
114
+
115
+ switch(this.#prop.closeOperation)
116
+ {
117
+ case Window.CloseOperation.Dispose:
118
+ {
119
+ this.emit("onWindowEvents", {type: "closing", interactive: false});
120
+ this.emit("onWindowEvents", {type: "close", interactive: false});
121
+
122
+ ui.sendToGUI(msg);
123
+
124
+ this.destroy();
125
+ break;
126
+ }
127
+ case Window.CloseOperation.Hide:
128
+ {
129
+ this.hide();
130
+ break;
131
+ }
132
+ case Window.CloseOperation.Exit:
133
+ {
134
+ this.emit("onWindowEvents", {type: "closing", interactive: false});
135
+ this.emit("onWindowEvents", {type: "close", interactive: false});
136
+ this.emit("onDispose", {type: "dispose"});
137
+ ui.sendToGUI(msg);
138
+ ui.exit(0);
139
+ break;
140
+ }
141
+ case Window.CloseOperation.Nothing:
142
+ {
143
+ ui.sendToGUI(msg);
144
+ break;
145
+ }
146
+ }
147
+
148
+ return this;
149
+ }
150
+
151
+ /**
152
+ * Sets or get a window state. Use one of these enum values: Window.State.[Normal|Minimized|Maximized]
153
+ *
154
+ * @param {Window.State} [state] - Setting new window state
155
+ * @returns {Window.State|Window} Returns `this` Window if argument is provided, otherwise returns current state.
156
+ * @example
157
+ * window.state(Window.State.Maximized);
158
+ * if(window.state() === Window.State.Maximized) console.log("It works!");
159
+ */
160
+ state()
161
+ {
162
+ if(arguments.length > 0) arguments[0] = parseInt(arguments[0]);
163
+ return this.property("state", arguments);
164
+ }
165
+
166
+ /**
167
+ * Sets or gets whether minimize button in window title bar should be visible.
168
+ * @param {boolean} [value] - `true` to show (default), `false` - to hide.
169
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
170
+ */
171
+ minimizable()
172
+ {
173
+ return this.property("canMinimize", arguments);
174
+ }
175
+
176
+ /**
177
+ * Sets or gets whether maximize button in window title bar should be visible.
178
+ * @param {boolean} [value] - `true` to show (default), `false` - to hide.
179
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
180
+ */
181
+ maximizable()
182
+ {
183
+ return this.property("canMaximize", arguments);
184
+ }
185
+
186
+ /**
187
+ * Sets or gets whether close button in window title bar should be visible.
188
+ * @param {boolean} [value] - `true` to show (default), `false` - to hide.
189
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
190
+ */
191
+ closable()
192
+ {
193
+ return this.property("canClose", arguments);
194
+ }
195
+
196
+ /**
197
+ * Sets or gets the ability to resize the window in GUI. Programmatically it can still be resized even when this is disabled.
198
+ * @param {boolean} [value] - `true` to enable (default), `false` - to disable.
199
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
200
+ */
201
+ resizable()
202
+ {
203
+ return this.property("canResize", arguments);
204
+ }
205
+
206
+ /**
207
+ * Sets or gets the ability to move the window in GUI by dragging title bar or resizing. Programmatically it can still be moved and resized even when this is disabled.
208
+ * This may not be supported in Linux and some other systems.
209
+ *
210
+ * @param {boolean} [value] - `true` to enable (default), `false` - to disable.
211
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
212
+ */
213
+ movable()
214
+ {
215
+ return this.property("canMove", arguments);
216
+ }
217
+
218
+ /**
219
+ * Sets or gets whether the InternalWindow should be above other internal windows in default layer. It puts the InternalWindow component in a higher layer. More than one InternalWindow can be in the top layer.
220
+ *
221
+ * @param {boolean} [value] - `true` to set enable, `false` to disable (default).
222
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
223
+ */
224
+ alwaysOnTop()
225
+ {
226
+ return this.property("alwaysOnTop", arguments);
227
+ }
228
+
229
+ /**
230
+ * Make this window be selected (activated) or not.
231
+ *
232
+ * @param {boolean} [selected] - `true` to activate, `false` to deactivate.
233
+ * @return {InternalWindow|boolean} Returns `this` component instance if argument is set, otherwise returns current value.
234
+ */
235
+ selected()
236
+ {
237
+ if(this.parent == null) throw Error(`Cannot call selected() on InternalWindow before this InternalWindow is added to InternalWindowContainer.`);
238
+
239
+ if(arguments.length === 0)
240
+ {
241
+ return (this.parent.selectedWindow() === this);
242
+ }
243
+ else
244
+ {
245
+ if(arguments[0] === true)
246
+ {
247
+ this.parent.selectedWindow(this);
248
+ }
249
+ else
250
+ {
251
+ this.parent.selectedWindow(null);
252
+ }
253
+
254
+ return this;
255
+ }
256
+ }
257
+
258
+ /**
259
+ * Sets or gets a size of content container of this Window (doesn't include the size of the window borders like size() function does).
260
+ *
261
+ * @param {number|Size} [width_or_size] - Width integer or a Size object as a sole parameter.
262
+ * @param {number} [height] - Integer height value (required if the first argument is a numeric width).
263
+ * @return {InternalWindow|Size} Returns `this` InternalWindow component if called with parameters, otherwise returns the inner size.
264
+ * @see Size
265
+ */
266
+ innerSize(...args)
267
+ {
268
+ if(args.length > 0)
269
+ {
270
+ const size = {width: 0, height: 0};
271
+
272
+ if(args.length === 1)
273
+ {
274
+ if(typeof args[0] === "object" && "width" in args[0] && "height" in args[0])
275
+ {
276
+ size.width = parseInt(args[0].width);
277
+ size.height = parseInt(args[0].height);
278
+ }
279
+ else
280
+ {
281
+ return this; // invalid input
282
+ }
283
+ }
284
+ else if(args.length > 1)
285
+ {
286
+ size.width = parseInt(args[0]);
287
+ size.height = parseInt(args[1]);
288
+ }
289
+
290
+ size.width += this.innerOffset.left + this.innerOffset.right;
291
+ size.height += this.innerOffset.top + this.innerOffset.bottom;
292
+
293
+ return this.size(size);
294
+ }
295
+ else
296
+ {
297
+ return {
298
+ width: this.size().width - (this.innerOffset.left + this.innerOffset.right),
299
+ height: this.size().height - (this.innerOffset.top + this.innerOffset.bottom)
300
+ };
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Indicates the minimum size the content container of the InternalWindow it can be resized to. It overrides previously set minSize() value.
306
+ *
307
+ * @param {number|Size} width_or_size - Width, or a Size formatted object as a sole parameter.
308
+ * @param {number} height - Height of the component.
309
+ * @returns {Size|InternalWindow|null} If called without parameters, current minimum inner Size is returned or `null` if it wasn't previously set; otherwise returns `this` component instance for chaining.
310
+ * @see InternalWindow#maxInnerSize
311
+ * @see UIComponent#minSize
312
+ * @see Size
313
+ */
314
+ minInnerSize(...args)
315
+ {
316
+ if(args.length > 0)
317
+ {
318
+ let s = (typeof args[0] === "object") ? {...args[0]} : {width: args[0], height: args[1]};
319
+
320
+ // add offset
321
+ const offset = this.innerOffset;
322
+ s.width += offset.left + offset.right;
323
+ s.height += offset.top + offset.bottom;
324
+
325
+ this.minSize(s);
326
+ }
327
+ else
328
+ {
329
+ let s = this.minSize();
330
+
331
+ if(s == null) return null;
332
+
333
+ // subtract offset
334
+ const offset = this.innerOffset;
335
+ s.width -= (offset.left + offset.right);
336
+ s.height -= (offset.top + offset.bottom);
337
+
338
+ return s;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Indicates the maximum size the content container of the InternalWindow it can be resized to. It overrides previously set maxSize() value.
344
+ *
345
+ * @param {number|Size} width_or_size - Width, or a Size formatted object as a sole parameter.
346
+ * @param {number} height - Height of the component.
347
+ * @returns {Size|InternalWindow|null} If called without parameters, current maximum inner Size is returned or `null` if it wasn't previously set; otherwise returns `this` component instance for chaining.
348
+ * @see InternalWindow#minInnerSize
349
+ * @see UIComponent#maxSize
350
+ * @see Size
351
+ */
352
+ maxInnerSize(...args)
353
+ {
354
+ if(args.length > 0)
355
+ {
356
+ let s = (typeof args[0] === "object") ? {...args[0]} : {width: args[0], height: args[1]};
357
+
358
+ // add offset
359
+ const offset = this.innerOffset;
360
+ s.width += offset.left + offset.right;
361
+ s.height += offset.top + offset.bottom;
362
+
363
+ this.maxSize(s);
364
+ }
365
+ else
366
+ {
367
+ let s = this.maxSize();
368
+
369
+ if(s == null) return null;
370
+
371
+ // subtract offset
372
+ const offset = this.innerOffset;
373
+ s.width -= (offset.left + offset.right);
374
+ s.height -= (offset.top + offset.bottom);
375
+
376
+ return s;
377
+ }
378
+ }
379
+
380
+ /**
381
+ * Gets the offset (in pixels) from each edge of the window to the content container.
382
+ * @type {Object}
383
+ * @example
384
+ * // Returned offset object format:
385
+ * {
386
+ * top: number,
387
+ * right: number,
388
+ * bottom: number,
389
+ * left: number
390
+ * }
391
+ */
392
+ get innerOffset()
393
+ {
394
+ if(this.prop.innerOffset == null) this.prop.innerOffset = this.property("innerOffset", []);
395
+ return this.prop.innerOffset;
396
+ }
397
+ }
@@ -0,0 +1,93 @@
1
+
2
+ import {UIComponent} from "./UIComponent.js";
3
+ import {ComponentContainer} from "./ComponentContainer.js";
4
+ import {InternalWindow} from "./InternalWindow.js";
5
+ import {ScrollableComponent} from "./ScrollableComponent.js";
6
+
7
+ /**
8
+ * InternalWindowContainer UI component, extends ScrollableComponent class.
9
+ * Internal window container is a component designed to contain InternalWindow components.
10
+ *
11
+ * For more methods for this component check {@link ComponentContainer}, {@link ScrollableComponent} and {@link UIComponent} classes.
12
+ * @class
13
+ * @global
14
+ */
15
+ class InternalWindowContainer extends ComponentContainer
16
+ {
17
+ /**
18
+ * InternalWindowContainer constructor.
19
+ * @example
20
+ * const container = new InternalWindowContainer().size(600, 500).addTo(window);
21
+ * const win1 = new InternalWindow("New Window Title").addTo(container);
22
+ */
23
+ constructor()
24
+ {
25
+ if(arguments.length > 0)
26
+ {
27
+ super("DesktopPane", (new.target === InternalWindowContainer), arguments[0]);
28
+ }
29
+ else
30
+ {
31
+ super("DesktopPane", (new.target === InternalWindowContainer));
32
+ }
33
+
34
+ this.finalize(InternalWindowContainer, ComponentContainer);
35
+ }
36
+
37
+ /**
38
+ * Sets or gets currently selected InternalWindow component.
39
+ *
40
+ * @window [InternalWindow] [window] - InternalWindow component that should become selected.
41
+ * @return {InternalWindowContainer|InternalWindow|null} - If setting, returns `this` component instance. If getting, returns selected InternalWindow or `null` (if there are no windows added yet).
42
+ */
43
+ selectedWindow(...args)
44
+ {
45
+ if(args.length > 0)
46
+ {
47
+ if(!(args[0] instanceof InternalWindow)) return this;
48
+
49
+ args[0] = args[0].id;
50
+
51
+ return this.property("selected", args);
52
+ }
53
+
54
+ let id = this.property("selected", args);
55
+
56
+ return id > -1 ? UIComponent.get(id) : null;
57
+ }
58
+
59
+ /**
60
+ * Sets or gets an index of a selected InternalWindow component.
61
+ *
62
+ * @param {number} [index] - Index of an item to select.
63
+ * @returns {number|InternalWindowContainer} If index is specified, then `this` component instance is returned, otherwise currently selected InternalWindow index is returned.
64
+ * @see InternalWindow
65
+ * @see InternalWindowContainer#selectedWindow
66
+ */
67
+ selectedIndex(...args)
68
+ {
69
+ if(args.length > 0)
70
+ {
71
+ if(!Number.isSafeInteger(args[0])) return this;
72
+ return this.selectedWindow(this.child(args[0]))
73
+ }
74
+
75
+ return this.childIndex(this.selectedWindow());
76
+ }
77
+
78
+ /**
79
+ * Prevents internal windows from being moved outside of visible area of window container. Otherwise windows can be move beyond the boundaries and scroll bars would appear to scroll to those windows.
80
+ * This may not work on some systems yet.
81
+ *
82
+ * @param {boolean} [enforce] - To enable border enforcement set `true`, to disable set `false.
83
+ * @return {InternalWindowContainer|boolean} If setting, returns `this` component instance, otherwise returns `boolean` value.
84
+ */
85
+ enforceBoundaries()
86
+ {
87
+ return this.property("enforceBoundaries", arguments);
88
+ }
89
+ }
90
+
91
+ ComponentContainer.implementClass(InternalWindowContainer, ScrollableComponent);
92
+
93
+ export {InternalWindowContainer};
@@ -0,0 +1,52 @@
1
+
2
+ import {UIComponent} from "./UIComponent.js";
3
+
4
+ /**
5
+ * Label UI component, extends UIComponent class.
6
+ * Label can be used to display plain text, HTML content, and image as an icon.
7
+ *
8
+ * For more methods for this component check UIComponent class.
9
+ * @class
10
+ * @global
11
+ */
12
+ export class Label extends UIComponent
13
+ {
14
+ /**
15
+ * Label constructor.
16
+ * @param {string} [text] - Initial text to display in the label.
17
+ * @example <h2>Few ways to create and use Label:</h2>
18
+ * // Setting text in constructor
19
+ * const label1 = new Label("New label text");
20
+ *
21
+ * // Setting text after instantiation
22
+ * const label2 = new Label().text("Second label text");
23
+ *
24
+ * // setting an image icon
25
+ * const label2 = new Label().icon("images/icon.png");
26
+ *
27
+ * // setting HTML content to be rendered in the label component
28
+ * const label2 = new Label("<html><body><h1>Label Header</h1><p>New paragraph</p></body></html>");
29
+ */
30
+ constructor()
31
+ {
32
+ if(arguments.length > 0)
33
+ {
34
+ super("Label", (new.target === Label), arguments[0]);
35
+ }
36
+ else
37
+ {
38
+ super("Label", (new.target === Label));
39
+ }
40
+
41
+ this.finalize(Label);
42
+ }
43
+
44
+ /**
45
+ * Returns current size of an icon, or `undefined` when no icon has been set or icon failed to load.
46
+ * @type {Object|undefined}
47
+ */
48
+ get iconSize()
49
+ {
50
+ return this.property("iconSize", []);
51
+ }
52
+ }
@@ -0,0 +1,105 @@
1
+
2
+ import {Shape} from "./Shape.js";
3
+
4
+ /**
5
+ * A `Line` shape that extends the {@link Shape} class.
6
+ *
7
+ * Line is a geometric line that doesn't have an area to be filled. For the line to be visible you specify the stroke size to be more that 0.
8
+ *
9
+ * Line points are relative to the position of the `Line` shape. If you daw multiple lines that are related to each other, make sure to set same position for each of the lines.
10
+ * @class
11
+ * @global
12
+ * @see Shape
13
+ */
14
+ export class Line extends Shape
15
+ {
16
+ _points = new Array(4);
17
+
18
+ /**
19
+ * Creates an instance of a Line shape.
20
+ *
21
+ * @param {Stroke} stroke - A border of the shape.
22
+ * @param {number} opacity - Opacity of the shape (0 to 1).
23
+ * @param {number} [x] - Horizontal position from the left edge.
24
+ * @param {number} [y] - Vertical position from the top edge.
25
+ * @param {number} [point1] - An object with X and Y coordinates {x: number, y: number}.
26
+ * @param {number} [point2] - An object with X and Y coordinates {x: number, y: number}.
27
+ */
28
+ constructor(stroke, opacity = 1, x = 0, y = 0, point1 = {x: 0, y: 0}, point2 = {x: 100, y: 100})
29
+ {
30
+ super(undefined, stroke, null, opacity, x, y);
31
+ this._type = "line";
32
+
33
+ this._points = [point1.x, point1.y, point2.x, point2.y];
34
+ }
35
+
36
+ /**
37
+ * Sets or gets the first point of the line.
38
+ *
39
+ * @param {number|{x:number, y:number}} x - X coordinate of the point, or an object with X and Y coordinates {x: number, y: number}.
40
+ * @param {number} [y] - Y coordinate of the point (required only if `x` parameter is a number).
41
+ * @returns {Line|Point} If called without parameters, returns current point; otherwise returns this Line shape for chaining.
42
+ */
43
+ point1()
44
+ {
45
+ if(arguments.length > 0)
46
+ {
47
+ if(typeof arguments[0] === "object")
48
+ {
49
+ arguments[1] = arguments[0].y;
50
+ arguments[0] = arguments[0].x;
51
+ }
52
+
53
+ this._points[0] = arguments[0];
54
+ this._points[1] = arguments[1];
55
+ this.update("points");
56
+ return this;
57
+ }
58
+
59
+ return {x: this._points[0], y: this._points[1]};
60
+ }
61
+
62
+ /**
63
+ * Sets or gets the second point of the line.
64
+ *
65
+ * @param {number|{x:number, y:number}} x - X coordinate of the point, or an object with X and Y coordinates {x: number, y: number}.
66
+ * @param {number} [y] - Y coordinate of the point (required only if `x` parameter is a number).
67
+ * @return {Line|Point} If called without parameters, returns current point; otherwise returns this Line shape for chaining.
68
+ */
69
+ point2()
70
+ {
71
+ if(arguments.length > 0)
72
+ {
73
+ if(typeof arguments[0] === "object")
74
+ {
75
+ arguments[1] = arguments[0].y;
76
+ arguments[0] = arguments[0].x;
77
+ }
78
+
79
+ this._points[2] = arguments[0];
80
+ this._points[3] = arguments[1];
81
+ this.update("points");
82
+ return this;
83
+ }
84
+
85
+ return {x: this._points[2], y: this._points[3]};
86
+ }
87
+
88
+ /**
89
+ * Returns a JSON object that contains this shape properties. It may be converted back to this shape.
90
+ *
91
+ * @param {string} [include="all"] - Specified what to include. "all" is default. Valid values are: "all", "stroke", "background", "points", "basic".
92
+ * @return {object} Returns an object containing this shape's properties.
93
+ */
94
+ toObject(include = "all")
95
+ {
96
+ let shape = super.toObject(include);
97
+
98
+ if(this._type === "line")
99
+ {
100
+ if(include === "all" || include === "points") shape.points = this._points;
101
+ }
102
+
103
+ return shape;
104
+ }
105
+ }