swing-ui 0.1.25 → 1.0.3
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.
- package/LICENSE +5 -4
- package/README.md +144 -7
- package/SwingUI.js +2611 -0
- package/classes/Arc.js +185 -0
- package/classes/Button.js +55 -0
- package/classes/CheckBox.js +33 -0
- package/classes/CheckBoxMenuItem.js +24 -0
- package/classes/ComboBox.js +329 -0
- package/classes/ComponentContainer.js +828 -0
- package/classes/ContextMenu.js +141 -0
- package/classes/DocumentEditor.js +168 -0
- package/classes/Ellipse.js +76 -0
- package/classes/InternalWindow.js +397 -0
- package/classes/InternalWindowContainer.js +93 -0
- package/classes/Label.js +52 -0
- package/classes/Line.js +105 -0
- package/classes/List.js +452 -0
- package/classes/MediaPlayer.js +504 -0
- package/classes/Menu.js +74 -0
- package/classes/MenuBar.js +56 -0
- package/classes/MenuItem.js +92 -0
- package/classes/Panel.js +50 -0
- package/classes/PasswordField.js +47 -0
- package/classes/Polygon.js +236 -0
- package/classes/Polyline.js +240 -0
- package/classes/ProgressBar.js +62 -0
- package/classes/RadioButton.js +110 -0
- package/classes/RadioButtonMenuItem.js +106 -0
- package/classes/Rectangle.js +199 -0
- package/classes/ScrollPane.js +53 -0
- package/classes/ScrollableComponent.js +141 -0
- package/classes/Separator.js +24 -0
- package/classes/Shape.js +584 -0
- package/classes/ShapeContainer.js +231 -0
- package/classes/Slider.js +172 -0
- package/classes/Spinner.js +172 -0
- package/classes/SplitView.js +82 -0
- package/classes/Stroke.js +115 -0
- package/classes/Table.js +982 -0
- package/classes/Tabs.js +228 -0
- package/classes/TextArea.js +125 -0
- package/classes/TextComponent.js +207 -0
- package/classes/TextField.js +128 -0
- package/classes/TextShape.js +123 -0
- package/classes/ToggleButton.js +147 -0
- package/classes/ToolBar.js +120 -0
- package/classes/TrayIcon.js +54 -0
- package/classes/Tree.js +569 -0
- package/classes/UIComponent.js +2154 -0
- package/classes/Window.js +609 -0
- package/enums.js +298 -0
- package/fonts.conf +32 -0
- package/functions.js +254 -0
- package/icon.png +0 -0
- package/index.js +109 -4
- package/jar/gui-11.jar +0 -0
- package/jar/lib/flatlaf.jar +0 -0
- package/jar/lib/jna.jar +0 -0
- package/package.json +58 -33
- package/typedefs.js +973 -0
- package/types/SwingUI.d.ts +727 -0
- package/types/classes/Arc.d.ts +111 -0
- package/types/classes/Button.d.ts +38 -0
- package/types/classes/CheckBox.d.ts +22 -0
- package/types/classes/CheckBoxMenuItem.d.ts +18 -0
- package/types/classes/ComboBox.d.ts +172 -0
- package/types/classes/ComponentContainer.d.ts +131 -0
- package/types/classes/ContextMenu.d.ts +74 -0
- package/types/classes/DocumentEditor.d.ts +95 -0
- package/types/classes/Ellipse.d.ts +34 -0
- package/types/classes/InternalWindow.d.ts +163 -0
- package/types/classes/InternalWindowContainer.d.ts +36 -0
- package/types/classes/Label.d.ts +33 -0
- package/types/classes/Line.d.ts +48 -0
- package/types/classes/List.d.ts +223 -0
- package/types/classes/MediaPlayer.d.ts +381 -0
- package/types/classes/Menu.d.ts +43 -0
- package/types/classes/MenuBar.d.ts +26 -0
- package/types/classes/MenuItem.d.ts +57 -0
- package/types/classes/Panel.d.ts +28 -0
- package/types/classes/PasswordField.d.ts +22 -0
- package/types/classes/Polygon.d.ts +93 -0
- package/types/classes/Polyline.d.ts +96 -0
- package/types/classes/ProgressBar.d.ts +36 -0
- package/types/classes/RadioButton.d.ts +70 -0
- package/types/classes/RadioButtonMenuItem.d.ts +71 -0
- package/types/classes/Rectangle.d.ts +82 -0
- package/types/classes/ScrollPane.d.ts +23 -0
- package/types/classes/ScrollableComponent.d.ts +81 -0
- package/types/classes/Separator.d.ts +14 -0
- package/types/classes/Shape.d.ts +223 -0
- package/types/classes/ShapeContainer.d.ts +92 -0
- package/types/classes/Slider.d.ts +107 -0
- package/types/classes/Spinner.d.ts +129 -0
- package/types/classes/SplitView.d.ts +47 -0
- package/types/classes/Stroke.d.ts +99 -0
- package/types/classes/Table.d.ts +652 -0
- package/types/classes/Tabs.d.ts +118 -0
- package/types/classes/TextArea.d.ts +45 -0
- package/types/classes/TextComponent.d.ts +136 -0
- package/types/classes/TextField.d.ts +94 -0
- package/types/classes/TextShape.d.ts +73 -0
- package/types/classes/ToggleButton.d.ts +84 -0
- package/types/classes/ToolBar.d.ts +82 -0
- package/types/classes/TrayIcon.d.ts +43 -0
- package/types/classes/Tree.d.ts +354 -0
- package/types/classes/UIComponent.d.ts +966 -0
- package/types/classes/Window.d.ts +334 -0
- package/types/enums.d.ts +437 -0
- package/types/functions.d.ts +109 -0
- package/types/index.d.ts +188 -0
- package/types/typedefs.d.ts +1626 -0
- package/ui-process-manager.js +317 -0
- package/video-devices-linux.sh +72 -0
- package/video-devices-mac.sh +33 -0
- package/CHANGES.md +0 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
|
|
2
|
+
import {Shape} from "./Shape.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TextShape is used to draw text as a shape. It can also have a {@link Stroke}, background, and everything like other shapes have.
|
|
6
|
+
*
|
|
7
|
+
* In Text shape you can also specify font parameters, like name, size, underlines, italic, bold, strikethrough and more. Check out {@link FontFamily} enum for generic font family names that can be used for cross-platform compatibility.
|
|
8
|
+
*
|
|
9
|
+
* @class
|
|
10
|
+
* @global
|
|
11
|
+
* @see Shape
|
|
12
|
+
*/
|
|
13
|
+
export class TextShape extends Shape
|
|
14
|
+
{
|
|
15
|
+
_text = "";
|
|
16
|
+
_font = {size: 13, name: FontFamily.SansSerif};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Constructor of Text shape. Color, Gradient, or background image are specified in "background" argument, because it's a Shape.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} text - Text to be drawn as shape
|
|
22
|
+
* @param {Font} [font=undefined] - Font object, such as {size: 13, name: "sans-serif", ...}.
|
|
23
|
+
* @param {Stroke} [stroke=null] - Stroke object.
|
|
24
|
+
* @param {string} [background="#000000"] - Background string, CSS style. See {@link Shape#background} for details.
|
|
25
|
+
* @param {number} [opacity=1] - Opacity of the shape. Valid value is a decimal between 0 - 1.
|
|
26
|
+
* @param {number} [x=0] - X position of top-left corner of text
|
|
27
|
+
* @param {number} [y=0] - Y position of top-left corner of text
|
|
28
|
+
* @see Font
|
|
29
|
+
* //@param {number} [width] - Width of the text bounding box. null means all in one line. No wrapping.
|
|
30
|
+
* //@param {number} [height] - Height of the text bounding box. null means auto-detect, without limit.
|
|
31
|
+
*/
|
|
32
|
+
constructor(text, font = undefined, stroke = null, background = "#000000", opacity = 1, x = 0, y = 0)
|
|
33
|
+
{
|
|
34
|
+
super(undefined, stroke, background, opacity, x, y);
|
|
35
|
+
this._type = "text";
|
|
36
|
+
this._text = text;
|
|
37
|
+
if(!(typeof font === "object")) font = {size: 13, name: "sans-serif"}; // set default font
|
|
38
|
+
if(font !== null) this._font = font;
|
|
39
|
+
this.background(background);
|
|
40
|
+
this.opacity(opacity);
|
|
41
|
+
this.position(x, y);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Sets new text to the shape. this will recreate the graphics of the shape for the new text.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} text - New text for the shape.
|
|
48
|
+
* @return {string|TextShape} If called without parameters, current text value is returned; otherwise this `Text` shape object is returned.
|
|
49
|
+
*/
|
|
50
|
+
text()
|
|
51
|
+
{
|
|
52
|
+
if(arguments.length > 0)
|
|
53
|
+
{
|
|
54
|
+
const new_text = String(arguments[0]);
|
|
55
|
+
if(new_text !== this._text) // update if different
|
|
56
|
+
{
|
|
57
|
+
this._text = new_text;
|
|
58
|
+
this.update("text");
|
|
59
|
+
}
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return this._text;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Gets or sets the font used for the `Text` shape. See the example for font object format.
|
|
68
|
+
*
|
|
69
|
+
* @param {Font} [font] - Font object.
|
|
70
|
+
* @return {TextShape|Font}
|
|
71
|
+
* @see Font
|
|
72
|
+
* @example
|
|
73
|
+
* textShape.font({name: "sans-serif", size: 14, italic: true}); // Sets new font.
|
|
74
|
+
* const font = textShape.font(); // gets component's font
|
|
75
|
+
*
|
|
76
|
+
* // Full list of supported font properties:
|
|
77
|
+
* const font = {
|
|
78
|
+
* name: string, // Font name or family name from {@link FontFamily} (e.g., "sans-serif")
|
|
79
|
+
* size: number, // Font size in pixels
|
|
80
|
+
* bold: boolean, // Whether the text is bold
|
|
81
|
+
* italic: boolean, // Whether the text is italic
|
|
82
|
+
* underlined: boolean, // Whether the text is underlined
|
|
83
|
+
* strikethrough: boolean, // Whether the text has a strikethrough
|
|
84
|
+
* direction: string, // Text direction: "ltr" or "rtl"
|
|
85
|
+
* kerning: boolean, // Enable or disable kerning
|
|
86
|
+
* ligatures: boolean, // Enable or disable font ligatures
|
|
87
|
+
* tracking: number // Letter spacing adjustment: -1, 0 (default), or 1
|
|
88
|
+
* };
|
|
89
|
+
* @see Font
|
|
90
|
+
* @see FontFamily
|
|
91
|
+
*/
|
|
92
|
+
font()
|
|
93
|
+
{
|
|
94
|
+
if(arguments.length > 0)
|
|
95
|
+
{
|
|
96
|
+
if(typeof arguments[0] !== "object") return this;
|
|
97
|
+
this._font = arguments[0];
|
|
98
|
+
this.update("font");
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return this._font;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Returns a JSON object that contains this shape properties. It may be converted back to this shape.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} [include="all"] - Specified what to include. "all" is default. Valid values are: "all", "stroke", "background", "points", "basic".
|
|
109
|
+
* @return {object} Returns an object containing this shape's properties.
|
|
110
|
+
*/
|
|
111
|
+
toObject(what = "all")
|
|
112
|
+
{
|
|
113
|
+
let shape = super.toObject(what);
|
|
114
|
+
|
|
115
|
+
if(this._type === "text")
|
|
116
|
+
{
|
|
117
|
+
if(["all", "text"].includes(what)) shape.text = this._text;
|
|
118
|
+
if(["all", "font"].includes(what)) shape.font = this._font;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return shape;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
|
|
2
|
+
import {UIComponent} from "./UIComponent.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ToggleButton UI component that is similar to a `Button` component, but can be selected.
|
|
6
|
+
* @class
|
|
7
|
+
* @global
|
|
8
|
+
*/
|
|
9
|
+
export class ToggleButton extends UIComponent
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* ToggleButton constructor.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} [text] - Button text
|
|
15
|
+
* @example
|
|
16
|
+
* this.button1 = new ToggleButton().text("Click Me");
|
|
17
|
+
* this.button2 = new ToggleButton("Click Me");
|
|
18
|
+
*/
|
|
19
|
+
constructor()
|
|
20
|
+
{
|
|
21
|
+
if(arguments.length > 0)
|
|
22
|
+
{
|
|
23
|
+
super("ToggleButton", (new.target === ToggleButton), arguments[0]);
|
|
24
|
+
}
|
|
25
|
+
else
|
|
26
|
+
{
|
|
27
|
+
super("ToggleButton", (new.target === ToggleButton));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
this.finalize(ToggleButton);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sets/Gets selection state of the toggle button.
|
|
35
|
+
*
|
|
36
|
+
* @param {boolean} [selected] - `true` to select, `false` to deselect the toggle button.
|
|
37
|
+
* @return {boolean|ToggleButton} If called without arguments, returns `boolean` value, otherwise returns `this` ToggleButton instance.
|
|
38
|
+
*/
|
|
39
|
+
selected()
|
|
40
|
+
{
|
|
41
|
+
return this.property("selected", arguments.length > 0 ? [arguments[0] === true] : []);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Sets/Gets whether the toggle button can be selected by the user.
|
|
46
|
+
*
|
|
47
|
+
* @param {boolean} [selectable] - `true` to allow selection, `false` to prevent the toggle button from being selected.
|
|
48
|
+
* @return {boolean|ToggleButton} If called without arguments, returns `boolean` value, otherwise returns `this` ToggleButton instance.
|
|
49
|
+
* @see ToggleButton#selected
|
|
50
|
+
*/
|
|
51
|
+
selectable()
|
|
52
|
+
{
|
|
53
|
+
const args = arguments;
|
|
54
|
+
if(args.length > 0) args[0] = (args[0] === true); // ensure boolean type
|
|
55
|
+
return this.property("selectable", args);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Sets or gets a value of this component.
|
|
60
|
+
* @param {*} [value] - Value to be held by this component
|
|
61
|
+
* @return {ToggleButton|*} If setting a value, then an instance of `this` component is returned, otherwise current value is returned.
|
|
62
|
+
*/
|
|
63
|
+
value()
|
|
64
|
+
{
|
|
65
|
+
return this.property("value", arguments);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Gets or sets the selected value within this ToggleButton group.
|
|
70
|
+
*
|
|
71
|
+
* If a value is provided, selects a ToggleButton within the group that matches the given value (including this one).
|
|
72
|
+
*
|
|
73
|
+
* @param {number|string} [value] - Value to select within the group.
|
|
74
|
+
* @return {ToggleButton|number|string|null} If value is provided, an instance of `this` object is returned. If no argument is provided, a value of the currently selected radio button in the group is returned, or `null`, if no button is selected or selected button doesn't have a value.
|
|
75
|
+
*/
|
|
76
|
+
selectedValue()
|
|
77
|
+
{
|
|
78
|
+
return this.property("selectedValue", arguments);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Adds this ToggleButton to the group of another ToggleButton while abandoning current group, or removes it from its current group and creates its own when you pass `null`.
|
|
83
|
+
*
|
|
84
|
+
* - Call without parameters to get an Array of all components in its group.
|
|
85
|
+
* - Pass another ToggleButton to join its group.
|
|
86
|
+
* - Pass `null` to leave the current group (if any) and create its own group.
|
|
87
|
+
*
|
|
88
|
+
* @param {ToggleButton|null} [component] - A ToggleButton to join, or `null` to leave the current group. Omit to get the grouped ToggleButton components.
|
|
89
|
+
* @returns {ToggleButton|ToggleButton[]} This ToggleButton, for chaining when called with parameter, otherwise an Array of all ToggleButton components in its group.
|
|
90
|
+
*/
|
|
91
|
+
group(...args)
|
|
92
|
+
{
|
|
93
|
+
if(args.length > 0)
|
|
94
|
+
{
|
|
95
|
+
if(args[0] !== null && !(args[0] instanceof this.constructor)) throw new Error(`Invalid value passed to ${this.constructor.name}.group(). ${this.constructor.name} component or NULL is expected.`);
|
|
96
|
+
return this.property("group", [args[0] !== null ? args[0].id : null]);
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
{
|
|
100
|
+
let _items = this.property("group", []);
|
|
101
|
+
|
|
102
|
+
for(let i in _items) _items[i] = UIComponent.get(_items[i]);
|
|
103
|
+
|
|
104
|
+
return _items;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Deselect all RadioButton elements grouped with this element.
|
|
110
|
+
*
|
|
111
|
+
* @return {RadioButton} Returns `this` component.
|
|
112
|
+
*/
|
|
113
|
+
clearSelection()
|
|
114
|
+
{
|
|
115
|
+
ui.sendToGUI({control: this.id, set: "clearSelection"});
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Sets or gets an action command. This command is specified in event object for onAction(e => {alert(e.command);}) event handler.
|
|
121
|
+
* Default value of action command for a Button is it's initial text.
|
|
122
|
+
*
|
|
123
|
+
* @param {string} [command] (Optional)
|
|
124
|
+
* @return {string|Button} If called without arguments, returns `number` value, otherwise returns `this` Button instance.
|
|
125
|
+
* @example
|
|
126
|
+
* const button = new Button("Activate").addTo(window).center();
|
|
127
|
+
* button.command("Activate Motor 1");
|
|
128
|
+
* button.onAction(e => {
|
|
129
|
+
* alert(e.command); // shows a dialog window with a message "Activate Motor 1" when button is clicked.
|
|
130
|
+
* });
|
|
131
|
+
*/
|
|
132
|
+
command(...args)
|
|
133
|
+
{
|
|
134
|
+
if(args.length > 0 && typeof args[0] !== "string") args[0] = String(args[0]); // enforce string type
|
|
135
|
+
return this.property("actionCommand", args);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns current size of an icon, or `null` when no icon has been set or icon failed to load.
|
|
140
|
+
* @readonly
|
|
141
|
+
* @type {Size|null}
|
|
142
|
+
*/
|
|
143
|
+
get iconSize()
|
|
144
|
+
{
|
|
145
|
+
return this.property("iconSize", []);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
import {ComponentContainer} from "./ComponentContainer.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A toolbar component that is usually used at the top of window and can hold {@link Label}, {@link Button}, {@link TextField}, {@link ComboBox}, and a {@link Separator} to display useful tools for a user.
|
|
6
|
+
*
|
|
7
|
+
* Toolbar can be draggable and can be detached and displayed in a separate dedicated window. It can also be in horizontal (default) and vertical orientation.
|
|
8
|
+
*
|
|
9
|
+
* ToolBar extends ComponentContainer, which extends UIComponent.
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @global
|
|
13
|
+
*/
|
|
14
|
+
export class ToolBar extends ComponentContainer
|
|
15
|
+
{
|
|
16
|
+
/**
|
|
17
|
+
* Create an instance of ToolBar component object.
|
|
18
|
+
*/
|
|
19
|
+
constructor()
|
|
20
|
+
{
|
|
21
|
+
super("ToolBar", (new.target === ToolBar));
|
|
22
|
+
|
|
23
|
+
this.finalize(ToolBar, ComponentContainer);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sets of gets whether the ToolBar can be detached from the Window it was added to.
|
|
28
|
+
*
|
|
29
|
+
* @param {boolean} [detachable] - `true` to enable detaching, `false` to disable.
|
|
30
|
+
* @return {boolean|ToolBar} If no parameters were passed, current value is returned, otherwise `this` Toolbar component is returned for method chaining.
|
|
31
|
+
*/
|
|
32
|
+
detachable()
|
|
33
|
+
{
|
|
34
|
+
return this.property("detachable", arguments);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Sets or gets boolean whether the toolbar is attached to main Window. Has no affect if not attached to a Window yet.
|
|
39
|
+
*
|
|
40
|
+
* @param {boolean} [attached] - `true` to attach, `false` to detach from Window component the ToolBar is added to.
|
|
41
|
+
* @param {{x:number, y:number}} [floating_position] - Position on screen where toolbar should float {x:number, y:number}.
|
|
42
|
+
* @return {boolean|ToolBar} If no parameters were passed, current state is returned; otherwise `this` Toolbar component is returned for method chaining.
|
|
43
|
+
*/
|
|
44
|
+
attached(...args)
|
|
45
|
+
{
|
|
46
|
+
return this.property("attached", args.length === 0 ? [] : [{value: (args[0] !== false), location: args.length > 1 ? {x: args[1].x ?? 0, y: args[1].y ?? 0} : undefined}]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Sets or gets vertical or horizontal orientation of the ToolBar.
|
|
51
|
+
*
|
|
52
|
+
* @param {Orientation} [orientation] - One of these values: Orientation.Horizontal (default) or Orientation.Vertical
|
|
53
|
+
* @return {Orientation|ToolBar} If no parameters were passed, current orientation is returned; otherwise `this` Toolbar component is returned for method chaining.
|
|
54
|
+
* @see Orientation
|
|
55
|
+
*/
|
|
56
|
+
orientation(...args)
|
|
57
|
+
{
|
|
58
|
+
return this.property("orientation", args);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sets or gets a padding size between edge of the component and items inside it, and spacing between items.
|
|
63
|
+
*
|
|
64
|
+
* @param {number} padding - Padding size in pixels.
|
|
65
|
+
* @return {number|ToolBar} If no parameters were passed, current padding is returned; otherwise `this` Toolbar component is returned for method chaining.
|
|
66
|
+
*/
|
|
67
|
+
padding(...args)
|
|
68
|
+
{
|
|
69
|
+
if(args.length > 0) args[0] = parseInt(args[0]);
|
|
70
|
+
return this.property("padding", args);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Set or get alignment of components within toolbar.
|
|
75
|
+
*
|
|
76
|
+
* @param {string} [alignment] - "leading|trailing|left|center|right"
|
|
77
|
+
* @return {string|ToolBar} If no parameters were passed, current alignment is returned; otherwise `this` Toolbar component is returned for method chaining.
|
|
78
|
+
*/
|
|
79
|
+
alignment(...args)
|
|
80
|
+
{
|
|
81
|
+
if(args.length > 0 && typeof args[0] !== "string") throw new TypeError(`Invalid alignment argument type. String expected, but received '${typeof args[0]}'.`);
|
|
82
|
+
return this.property("alignment", args);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Add an invisible spacer of specified width and height.
|
|
87
|
+
*
|
|
88
|
+
* @param {number} width - Width of the spacer block
|
|
89
|
+
* @param {number} height - Height of the spacer block
|
|
90
|
+
* @return {ToolBar} Returns `this` ToolBar component for method chaining.
|
|
91
|
+
*/
|
|
92
|
+
addSpacer(width, height)
|
|
93
|
+
{
|
|
94
|
+
return this.property("addSpacer", [{width: width, height: height}]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Gets, registers or unregisters a docking event handler function. This event handler is called when the ToolBar gets attached/detached.
|
|
99
|
+
*
|
|
100
|
+
* @param {function(Object): any} [callback] - The event handler function. Receives an event object.
|
|
101
|
+
* @param {boolean} [remove=false] - Set to `true` to unregister the event handler.
|
|
102
|
+
* @returns {ToolBar|function[]} An array of handler functions if no arguments are passed, otherwise `this` component for method chaining.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Event object format:
|
|
106
|
+
* const e = {
|
|
107
|
+
* target: object, // The ToolBar component that triggered the event.
|
|
108
|
+
* type: string, // "attached", "detached".
|
|
109
|
+
* interactive: boolean // Only when type is "update". `true` when update was made by the user interacting with the GUI. `false` when update was made programmatically.
|
|
110
|
+
* orientation: Orientation // current orientation
|
|
111
|
+
* location: string // "top", "bottom", "left", "right". Only when `e.interactive` is `true`.
|
|
112
|
+
* mouseX: number // Mouse X position relative to Window's content area. Only when `e.interactive` is `true`.
|
|
113
|
+
* mouseY: number // Mouse Y position relative to Window's content area. Only when `e.interactive` is `true`.
|
|
114
|
+
* };
|
|
115
|
+
*/
|
|
116
|
+
onDockEvents(callback, ...args)
|
|
117
|
+
{
|
|
118
|
+
return this.event("onDockEvents", callback, args[0] ?? false);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
import {UIComponent} from "./UIComponent.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TrayIcon is a system icon usually displayed in a tray of icons for applications running or capable of running in the background.
|
|
6
|
+
*
|
|
7
|
+
* TrayIcon component is able to show system notification messages, have context menu and show tooltip text on mouse hover.
|
|
8
|
+
*
|
|
9
|
+
* @class
|
|
10
|
+
* @global
|
|
11
|
+
* @example <h2>Create new TrayIcon:</h2>
|
|
12
|
+
* const icon = new TrayIcon("/path/to/icon.png").tooltip("New App Icon").contextMenu(existing_context_menu).show();
|
|
13
|
+
*
|
|
14
|
+
* @example <h2>Set an event handler:</h2>
|
|
15
|
+
* icon.onMouseEvents(e => {
|
|
16
|
+
* console.log(`${e.clicks} ${e.type}`);
|
|
17
|
+
* })
|
|
18
|
+
* .onAction(e => {
|
|
19
|
+
* console.log("System tray icon action was performed.");
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* @example <h2>Show system message:</h2>
|
|
23
|
+
* icon.showNotification(`Warning Sample`, `This is a sample message`, MessageIcon.Warning);
|
|
24
|
+
*
|
|
25
|
+
* @example <h2>hide and show the icon:</h2>
|
|
26
|
+
* icon.hide(); // or icon.visible(false);
|
|
27
|
+
*
|
|
28
|
+
* icons.show(); // or icon.visible(true);
|
|
29
|
+
*/
|
|
30
|
+
export class TrayIcon extends UIComponent
|
|
31
|
+
{
|
|
32
|
+
/**
|
|
33
|
+
* Slider TrayIcon. Creates an instance of TrayIcon UI component.
|
|
34
|
+
* @param {string} icon - Icon image (relative/absolute path or base64 encoded image string).
|
|
35
|
+
*/
|
|
36
|
+
constructor(icon)
|
|
37
|
+
{
|
|
38
|
+
super("SystemTrayIcon", (new.target === TrayIcon), icon);
|
|
39
|
+
this.finalize(TrayIcon);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Displays system notification.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} title - Title of the notification message
|
|
46
|
+
* @param {string} message - The message body
|
|
47
|
+
* @param {MessageIcon} [icon=MessageIcon.Info] - One of the values: MessageIcon.Info, MessageIcon.Warning, MessageIcon.Info, or `null` to not show any icon.
|
|
48
|
+
* @return {TrayIcon} Returns `this` TrayIcon component for method chaining.
|
|
49
|
+
*/
|
|
50
|
+
showNotification(title, message, icon = MessageIcon.Info)
|
|
51
|
+
{
|
|
52
|
+
return this.property("showNotification", [{title: String(title), message: String(message), icon: parseInt(icon)}]);
|
|
53
|
+
}
|
|
54
|
+
}
|