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,141 @@
1
+
2
+ import {ComponentContainer} from "./ComponentContainer.js";
3
+ import {UIComponent} from "./UIComponent.js";
4
+
5
+ /**
6
+ * ContextMenu UI component that extends ComponentContainer, which extends UIComponent class.
7
+ * ContextMenu is used to create menus that pop up when user right clicks on UI component or system tray icon.
8
+ * @class
9
+ * @global
10
+ * @see ComponentContainer
11
+ */
12
+ export class ContextMenu extends ComponentContainer
13
+ {
14
+ _parents = []; // multiple parents
15
+
16
+ /**
17
+ * ContextMenu constructor.
18
+ * @example
19
+ * // Usage example:
20
+ * const menu = new ContextMenu(); // creates new context menu
21
+ * new MenuItem("Item 1").addTo(menu); // adds menu item to context menu
22
+ * new MenuItem("Item 2").addTo(menu); // adds menu item to context menu
23
+ * textfield.contextMenu(menu); // set context menu for text field
24
+ */
25
+ constructor()
26
+ {
27
+ super("PopupMenu", (new.target === ContextMenu), ...arguments);
28
+ this.prop.invoker = null;
29
+ this.finalize(ContextMenu, ComponentContainer);
30
+ }
31
+
32
+ /**
33
+ * Registers, unregisters and gets a list of handler functions for the context menu popup events (when the the context menu becomes visible and hidden).
34
+ *
35
+ * @param {function(PopupEvent):any|null} [callback] - Event handler function that receives a {@link PopupEvent} as an argument. Pass `null` to unregister all registered callbacks.
36
+ * @param {boolean} [remove] - Set to `true` to unregister the handler function.
37
+ * @return {function[]|ComboBox} Returns an array of registered handler functions if arguments are omitted, otherwise returns `this` component instance.
38
+ * @see PopupEvent
39
+ * @example
40
+ * // event Object format:
41
+ * const e = {
42
+ * target: object, // The component that triggered the event.
43
+ * type: string, // `show`, `hide`, `cancel`.
44
+ * invoker: Object // UI Component that invoked the popup, or `null` if it was invoked programmatically.
45
+ * x: number, // X position relative to invoker. Only present when invoker is not `null`.
46
+ * y: number, // Y position relative to invoker. Only present when invoker is not `null`.
47
+ * screenX: number, // X position relative to default screen.
48
+ * screenY: number, // Y position relative to default screen.
49
+ * interactive: boolean, // Indicates if the popup was triggered by user's interaction (not programmatically).
50
+ * };
51
+ */
52
+ onPopupEvents(callback, ...args)
53
+ {
54
+ return this.event("onPopupEvents", callback, args[0] ?? false);
55
+ }
56
+
57
+ /**
58
+ * Adds a child component to this container component.
59
+ * Overrides addChild() method from UIComponent class to add component validation logic.
60
+ *
61
+ * @param {Object} component - UI Component that can be a child of this component.
62
+ * @param {...any} [data_or_index] - Argument to pass some extra data (such as Tab Name to add Panel to Tabs), or index at which to insert the child. By default component is added to the end.
63
+ * @returns {this}
64
+ */
65
+ addChild(component, ...data)
66
+ {
67
+ const allowedTypes = [Menu, MenuItem, RadioButtonMenuItem, CheckBoxMenuItem, Separator];
68
+
69
+ if(!allowedTypes.some(type => component instanceof type))
70
+ {
71
+ throw new Error(component.constructor.name + " cannot be added to ContextMenu");
72
+ }
73
+
74
+ super.addChild(component, ...data);
75
+ }
76
+
77
+ /**
78
+ * Open the menu with all its parent menus or context menu.
79
+ * @param {object} [position] - Example: {x: 100, y: 100}. Used to specify position where to open the ContextMenu. If invoker is specified, then position is relative to position of invoker component, otherwise it a screen position.
80
+ * @param {object} [invoker] - Used to set invoker if the context menu isn't assigned to any object and you want to be able to get invoker by using "invoker" getter.
81
+ * @return {ContextMenu} Returns `this` ContextMenu instance.
82
+ */
83
+ open(position = null, invoker = null)
84
+ {
85
+ const msg = {set: "open", control: this.id, data: {}};
86
+ if(position != null) msg.data.position = position;
87
+ if(invoker instanceof UIComponent) msg.data.invoker = invoker.id;
88
+
89
+ ui.sendToGUI(msg);
90
+ return this;
91
+ }
92
+
93
+ /**
94
+ * Returns last invoker Object that invoked the popup, or `null` if no invoker was involved.
95
+ * @readonly
96
+ * @type {Object|null}
97
+ */
98
+ get invoker()
99
+ {
100
+ return this.prop.invoker;
101
+ }
102
+
103
+ /**
104
+ * Adds this ContextMenu to a specified parent component.
105
+ *
106
+ * @param {object} parent - A valid component that accepts ContextMenu. `parent` must be derived from UIComponent.
107
+ * @return {ContextMenu} Returns an instance of `this` object.
108
+ */
109
+ addTo(parent, ...args)
110
+ {
111
+ if(typeof parent !== "object" || !(parent instanceof UIComponent)) throw Error(`'parent' must be derived from UIComponent of swing-ui module.`);
112
+ parent.verifyComponent();
113
+ parent.contextMenu(this);
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ * Removes this ContextMenu from all parent components or removes a specified child component from this ContextMenu.
119
+ *
120
+ * @param {Object} [child] - Child to be removed. When omitted, this context menu gets removed from all parent components.
121
+ * @param {boolean} [recursive] - Indicates whether to also remove all child's descendents.
122
+ * @return {ContextMenu} Returns an instance of `this` component.
123
+ * @example
124
+ * child.remove(); // Removes this context menu from it's parent components
125
+ * child.remove(true); // Removes this context menu from it's parent components and all its descendants recursively
126
+ * parent.remove(child); // removes child from parent container
127
+ * parent.remove(child, true); // Removes child from parent container and all of child's descendants recursively
128
+ */
129
+ remove(...args)
130
+ {
131
+ if(args.length === 0 || typeof args[0] !== "object") // removing this from parents
132
+ {
133
+ for(let parent of [...this._parents]) parent.contextMenu(null);
134
+ }
135
+
136
+ // when removing child component
137
+ if(args.length > 0) super.removeChild(...args);
138
+
139
+ return this;
140
+ }
141
+ }
@@ -0,0 +1,168 @@
1
+
2
+ import zlib from "zlib"; // https://nodejs.org/api/zlib.html#class-options
3
+ import {TextComponent} from "./TextComponent.js";
4
+ import {ScrollableComponent} from "./ScrollableComponent.js";
5
+
6
+ /**
7
+ * DocumentEditor UI component that extends TextComponent and ScrollableComponent, which extend UIComponent class.
8
+ * DocumentEditor is a text editor that can be switched to HTML mode to display or edit an HTML styled page. Only HTML 3.2 is supported. Modern tags like in HTML5 are not supported and may be ignored. HTML page can be styles with CSS but CSS support is also limited.
9
+ * Editing the HTML page is not great, but may be enough for basic purposes. CSS can be added to the document separately by setCSS() and addCSS() methods, or it can be embedded into the HTML content using `style` tags.
10
+ *
11
+ * For more methods for this component check UIComponent class.
12
+ * @class
13
+ * @global
14
+ * @see TextComponent
15
+ * @see ScrollableComponent
16
+ */
17
+ class DocumentEditor extends TextComponent
18
+ {
19
+ /**
20
+ * DocumentEditor constructor. Check usage examples below
21
+ *
22
+ * @param {string} [content] - Initial content.
23
+ * @example
24
+ * let content = "<html><body><h1>This is a header</h1><p>This is a new paragraph</p></body></html>";
25
+ * const editor1 = new DocumentEditor(content).html(true); // creates editor and sets content in constructor
26
+ * const editor2 = new DocumentEditor().html(true).text(content); // creates editor and then sets content
27
+ */
28
+ constructor()
29
+ {
30
+ super("DocumentEditor", (new.target === DocumentEditor), ...arguments);
31
+ this.finalize(DocumentEditor, TextComponent);
32
+ }
33
+
34
+ /**
35
+ * Sets or gets text or HTML content of the component (depending if HTML is enabled using html(boolean) method.
36
+ *
37
+ * @param {string} [text] - Can be plain text or HTML. HTML should be surrounded with HTML tags. Check example below.
38
+ * @param {TextAction} [action] - Specific action to perform with text. Replace, append, prepend, or insert. Do not use this argument for HTML content.
39
+ * @param {number} [insert_position] - Position where to insert text. Applies only if `action` argument is TextAction.Insert.
40
+ * @return {string|this} Returns text or HTML if no argument is set, otherwise returns `this` component.
41
+ * @example
42
+ * const txt = textfield.text(); // gets text value
43
+ * textfield.text("New Text"); // sets new text value
44
+ * textfield.html(true).text("<html>New Text Line 1<br />New Text Line 2</html>"); // changes editor's content type to HTML and sets HTML content
45
+ * textfield.text("Appended Text", TextAction.Append); // Appends new text to the end of current text
46
+ * textfield.text("Inserted Text", TextAction.Insert); // Inserts at current caret position
47
+ * textfield.text("Inserted Text", TextAction.Insert, textfield.caretPosition() - 50); // Inserts at specified position
48
+ */
49
+ text()
50
+ {
51
+ if(arguments.length > 0)
52
+ {
53
+ const msg = {control: this.id, set: "text", value: String(arguments[0]), data: {action: arguments.length > 1 ? arguments[1] : TextAction.Set}};
54
+ if(msg.data.action === TextAction.Insert && arguments.length > 2 && Number.isSafeInteger(arguments[2])) msg.data.index = arguments[2];
55
+ ui.sendToGUI(msg);
56
+ return this;
57
+ }
58
+ else
59
+ {
60
+ let r = this.property("text", []);
61
+
62
+ // base64 decode and Gunzip value before returning
63
+ return zlib.gunzipSync(Buffer.from(r, "base64"), {}).toString();
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Enables/Disables Word/Character line wrapping of long lines instead of scrolling horizontally.
69
+ *
70
+ * @param {LineWrap} [value] - LineWrap.Word, LineWrap.Character, or LineWrap.None
71
+ * @return {LineWrap|DocumentEditor} If argument is passed, `this` component instance is returned, otherwise line wrap value is returned.
72
+ * @see LineWrap
73
+ */
74
+ lineWrap(...args)
75
+ {
76
+ return this.property("lineWrap", args);
77
+ }
78
+
79
+ /**
80
+ * Sets or gets boolean value stating if content type of the document is HTML or not. True means HTML, false means plain text.
81
+ *
82
+ * @param {boolean} [value] - `true` to enable HTML content type, `false` to switch to plain text.
83
+ * @return {DocumentEditor|boolean} If argument is passed, `this` component instance is returned, otherwise `boolean` is returned.
84
+ */
85
+ html(...args)
86
+ {
87
+ if(args.length > 0) args[0] = (args[0] === true);
88
+ return this.property("html", args);
89
+ }
90
+
91
+ /**
92
+ * Adds CSS styles to be applied to the HTML document without adding this CSS to the HTML content. This method should be used only when DocumentEditor's HTML content type is enabled using html(true) method. Added CSS cannot be removed separately. To remove all added CSS use setCSS("") method.
93
+ *
94
+ * @param {string} css - CSS content (without `style` tags).
95
+ * @return {DocumentEditor}
96
+ */
97
+ addCSS(css)
98
+ {
99
+ this.property("addCSS", [String(css)]);
100
+ return this;
101
+ }
102
+
103
+ /**
104
+ * Sets new CSS styles to be applied to the HTML document without adding this CSS to the HTML content. It replaces previously added CSS. This method can be used to remove previously added CSS by calling setCSS(""). This method should be used only when DocumentEditor's HTML content type is enabled using html(true) method.
105
+ *
106
+ * @param {string} css - CSS content (without `style` tags).
107
+ * @return {DocumentEditor}
108
+ */
109
+ setCSS(css)
110
+ {
111
+ this.property("setCSS", [String(css)]);
112
+ return this;
113
+ }
114
+
115
+ /**
116
+ * Sets/gets a comma separated list of HTML tags to be excluded (stripped away) from HTML document (when content type is set to HTML using html(true).
117
+ *
118
+ * @param {string} [tags] - A list of tags separated by comma. e.g. editor.excludedTags("hr audio video div");
119
+ * @return {DocumentEditor|string}
120
+ */
121
+ excludedTags(...args)
122
+ {
123
+ return this.property("excludedTags", args);
124
+ }
125
+
126
+ /**
127
+ * Sets or gets the ability to click on HTML document's hypertext links made with `a` tag to open the link in a web browser. When enabled, user can click on a hyperlink to open the link's URL in a default web browser. For that HTML content type must be enabled with html(true) method and editing should be disabled with editable(false) method.
128
+ *
129
+ * @param {boolean} [enabled] - `true` to enable, `false` to disable.
130
+ * @return {DocumentEditor|boolean} If argument is omitted, `boolean` is returned, otherwise `this` DocumentEditor instance is returned.
131
+ */
132
+ linksEnabled(...args)
133
+ {
134
+ if(args.length > 0) args[0] = (args[0] === true);
135
+ return this.property("linksEnabled", args);
136
+ }
137
+
138
+ /**
139
+ * Registers, unregisters, and gets an Array of event handlers for the event when user clicks on a hyperlink. It gives the ability to create a custom action for hyperlink clicks. Check for event Object format in example below.
140
+ *
141
+ * @param {function(LinkEvent):any} [callback] - Handler function receiving {@link LinkEvent} object. Pass `null` to unregister all handler callbacks.
142
+ * @param {boolean} [remove] - Set to `true` to unregister the handler function.
143
+ * @return {function[]|ComboBox} Returns an array of registered handler functions if arguments are omitted, otherwise returns `this` component instance.
144
+ * @see LinkEvent
145
+ * @example
146
+ * // LinkEvent format example
147
+ * LinkEvent {
148
+ * target: DocumentEditor, // This component
149
+ * type: string, // `click`, `mouseenter`, or `mouseleave`
150
+ * url: string, // The href="" attribute of the `a` tag
151
+ * text: string, // Text of the hyperlink
152
+ * shift: boolean, // Indicates if Shift key was pressed when the event occurred
153
+ * ctrl: boolean, // Indicates if Ctrl key was pressed when the event occurred
154
+ * alt: boolean, // Indicates if Alt key was pressed when the event occurred
155
+ * modifiers: string // Keyboard modifiers mask
156
+ * modifiersText: string // Text representation of keyboard modifiers
157
+ * }
158
+ */
159
+ onLinkEvents(callback, ...args)
160
+ {
161
+ return this.event("onLinkEvents", callback, args[0] ?? false);
162
+ }
163
+ }
164
+
165
+ // Implement ScrollableComponent class methods
166
+ Object.getOwnPropertyNames(ScrollableComponent.prototype).forEach(m=>{if(m !== 'constructor') DocumentEditor.prototype[m] = ScrollableComponent.prototype[m];});
167
+
168
+ export { DocumentEditor };
@@ -0,0 +1,76 @@
1
+
2
+ import {Shape} from "./Shape.js";
3
+
4
+ /**
5
+ * `Ellipse` shape can draw an oval (when height and width are different) or a circle (when height and width are same).
6
+ *
7
+ * Ellipse extends the {@link Shape} class.
8
+ * @class
9
+ * @global
10
+ * @see Shape
11
+ */
12
+ export class Ellipse extends Shape
13
+ {
14
+ _size = {width: 100, height: 100};
15
+
16
+ /**
17
+ * Creates an instance of Arc shape.
18
+ *
19
+ * @param {Stroke} [stroke=undefined] - A border of the shape.
20
+ * @param {string} [background=undefined] - Color, gradient, or image background, similar to CSS. Use an empty string to remove the background.
21
+ * @param {number} [opacity=1] - Opacity of the shape (0 to 1).
22
+ * @param {number} [x=0] - Horizontal position from the left edge.
23
+ * @param {number} [y=0] - Vertical position from the top edge.
24
+ * @param {number} [width=100] - Width of the ellipse (horizontal diameter).
25
+ * @param {number} [height=undefined] - Height of the ellipse (vertical diameter). If omitted, height will be same as width.
26
+ */
27
+ constructor(stroke = undefined, background = undefined, opacity = 1, x = 0, y = 0, width = 100, height = undefined)
28
+ {
29
+ super(undefined, stroke, background, opacity, x, y);
30
+ this._type = "ellipse";
31
+ if(width == null) width = 100;
32
+ this._size = {width: width, height: height != null ? height : width};
33
+ }
34
+
35
+ /**
36
+ * Sets or gets the size of the `Ellipse` (horizontal and vertical diameter).
37
+ *
38
+ * @param {number|Size} width - Width of the ellipse (horizontal diameter), or a `Size` object (e.g., {width:300,height:300}).
39
+ * @param {number} [height] - Height of the ellipse (vertical diameter).
40
+ * @returns {Size|Ellipse} If called without parameters, current size is returned; otherwise this Ellipse object is returned.
41
+ * @see Size
42
+ */
43
+ size()
44
+ {
45
+ if(arguments.length > 0)
46
+ {
47
+ this._size = (arguments.length > 1) ? {width: arguments[0], height: arguments[1]} : arguments[0];
48
+
49
+ if(typeof this._size !== "object") this._size = {width: this._size, height: this._size};
50
+ this.update("size");
51
+ return this;
52
+ }
53
+ else
54
+ {
55
+ return {...this._size};
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Returns a JSON object that contains this shape properties. It may be converted back to this shape.
61
+ *
62
+ * @param {string} [include="all"] - Specified what to include. "all" is default. Valid values are: "all", "stroke", "background", "points", "basic".
63
+ * @return {object} Returns an object containing this shape's properties.
64
+ */
65
+ toObject(include = "all")
66
+ {
67
+ let shape = super.toObject(include);
68
+
69
+ if(this._type === "ellipse")
70
+ {
71
+ if(["all", "size"].includes(include)) shape.size = this._size;
72
+ }
73
+
74
+ return shape;
75
+ }
76
+ }