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.
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 +2154 -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 +966 -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,231 @@
1
+ import {Shape} from "./Shape.js";
2
+ import {ComponentContainer} from "./ComponentContainer.js";
3
+
4
+ /**
5
+ * ShapeContainer is not a standalone component. ShapeContainer extends UIComponent and serves a purpose to implement Shape related methods and properties. ShapeContainer is extended by {@link Panel} and {@link Window} components.
6
+ * @class
7
+ * @global
8
+ * @see ComponentContainer
9
+ */
10
+ export class ShapeContainer extends ComponentContainer
11
+ {
12
+ /**
13
+ * ShapeContainer constructor.
14
+ * @internal
15
+ * @ignore
16
+ */
17
+ constructor(...args)
18
+ {
19
+ super(...args);
20
+ }
21
+
22
+ /**
23
+ * Returns amount of shapes added to this Window.
24
+ *
25
+ * @readonly
26
+ * @type {number}
27
+ */
28
+ get shapeCount()
29
+ {
30
+ return this._shapes.length;
31
+ }
32
+
33
+ /**
34
+ * Gets an array of shapes currently added to the component, or sets an array of new shapes while replacing existing ones.
35
+ *
36
+ * @param {Array<Shape>} [shapes] - An array of Shape objects, such as Rectangle, Line, Ellipse, etc.
37
+ * @returns Array<Shape> If called without arguments, an array of shapes is returned, otherwise `this` component instance is returned for chaining.
38
+ * @throws {TypeError} When one of passed array elements is not of Shape type.
39
+ * @see Shape
40
+ */
41
+ shapes(...args)
42
+ {
43
+ if(args.length === 0)
44
+ {
45
+ return [...this._shapes];
46
+ }
47
+ else if(Array.isArray(args[0]))
48
+ {
49
+ // validate new shapes
50
+ args[0].forEach((shape, i) =>
51
+ {
52
+ if(!(args[0][i] instanceof Shape)) throw new TypeError(`Invalid "shape" at index ${i} in the array argument passed to Panel.shapes(shapes).`);
53
+ });
54
+
55
+ const update = this.prop.update !== false;
56
+ if(update) this.update(false);
57
+
58
+ // remove existing shapes
59
+ for(let i = this._shapes.length - 1; i >= 0; i--) this._shapes[i].remove();
60
+
61
+ args[0].forEach(shape => shape.addTo(this));
62
+
63
+ if(update) this.update(true);
64
+ }
65
+
66
+ return this;
67
+ }
68
+
69
+ /**
70
+ * Gets a Shape at a specified index.
71
+ *
72
+ * @param {number} i - Index of the shape you want to get
73
+ * @returns {Shape} Returns a `Shape` at a specified `index`, or `undefined`, if `index` is out of bounds or invalid.
74
+ */
75
+ shape(i)
76
+ {
77
+ return this._shapes[i];
78
+ }
79
+
80
+ /**
81
+ * Gets an index of a specified Shape object or sets a new index making the Shape change its layer index position.
82
+ *
83
+ * @param {Shape} shape - Shape object in question
84
+ * @param {number} [new_index] - The new index to assign to the `Shape`. Moves the `Shape` in z-order.
85
+ * @return {number} Returns an index of the Shape or -1 if only first argument is passed, or `this` component index if `new_index` is passed.
86
+ * @throws {TypeError} When invalid argument type is passed as a `shape` argument.
87
+ * @throws {Error} When the shape is not added to this component while attempting to change its index to `new_index`.
88
+ */
89
+ shapeIndex(shape, new_index = undefined)
90
+ {
91
+ if(!(shape instanceof Shape)) throw new TypeError(`Invalid argument type. An instance of 'Shape' is expected.`);
92
+
93
+ const i = this._shapes.indexOf(shape);
94
+
95
+ if(new_index == null) return i;
96
+
97
+ if(i === -1) throw new Error(`The Shape is not added to this component.`);
98
+ else if(new_index >= this._shapes.length) new_index = this._shapes.length - 1;
99
+ else if(i === new_index) return new_index;
100
+
101
+ this._shapes.splice(i, 1);
102
+ this._shapes.splice(new_index, 0, shape);
103
+
104
+ return this.property("shape_index", [{old: i, new: new_index}])
105
+
106
+ }
107
+
108
+ /**
109
+ * Adds a Shape to be drawn on the panel.
110
+ *
111
+ * @param {Shape} shape - Shape object to draw on this panel
112
+ * @param {number} [index] - Set only if you want to insert the Shape at a specific index
113
+ * @returns {ShapeContainer} Returns `this` instance of the Panel.
114
+ * @see Shape#addTo
115
+ */
116
+ addShape(shape, index = -1)
117
+ {
118
+ if(!(shape instanceof Shape)) throw new Error(`Invalid "shape" argument passed to Panel.addShape(shape, ...).`);
119
+ if(index > this._shapes.length) throw new Error("Index is out of bounds");
120
+
121
+ // if already a child at same index, then skip it
122
+ if(index > -1 && this._shapes[index] === shape) return this;
123
+
124
+ if(shape.parent === this) // if parent was already set by shape.addTo() then finish adding
125
+ {
126
+ const action = index > -1 ? "insert_shape" : "add_shape";
127
+ if(index < 0) index = this._shapes.length;
128
+ this._shapes.splice(index, 0, shape);
129
+
130
+ const shapeObject = shape.toObject();
131
+ shapeObject.index = index;
132
+
133
+ ui.sendToGUI({control: this.id, set: action, value: shapeObject});
134
+ }
135
+ else // first set new parent to the Shape, then come back to finish
136
+ {
137
+ shape.addTo(this, index);
138
+ }
139
+
140
+ return this;
141
+ }
142
+
143
+ /**
144
+ * Removes a specified Shape, then the removed Shape is returned.
145
+ *
146
+ * @param {number|Shape} index_or_shape - Shape or index of the Shape to be removed.
147
+ * @return {Shape|boolean} Returns removed Shape, or `false` in case when index is invalid or out of bounds.
148
+ * @see Shape#remove
149
+ */
150
+ removeShape(index)
151
+ {
152
+ let shape = null;
153
+
154
+ // If index is the Shape object to be removed, find its index
155
+ if(index instanceof Shape)
156
+ {
157
+ shape = index;
158
+ index = this._shapes.indexOf(index);
159
+ if(index < 0) return false;
160
+ }
161
+ else
162
+ {
163
+ shape = this._shapes[index];
164
+ if(shape === undefined) return false;
165
+ }
166
+
167
+ if(shape.parent === this) // remove shape parent first, then come back
168
+ {
169
+ shape.remove();
170
+ }
171
+ else
172
+ {
173
+ // remove the shape
174
+ this._shapes.splice(index, 1);
175
+ ui.sendToGUI({control: this.id, set: "remove_shape", value: index});
176
+ }
177
+
178
+ return shape;
179
+ }
180
+
181
+ /**
182
+ * @internal
183
+ * @ignore
184
+ */
185
+ verifyToken(token)
186
+ {
187
+ return (this.temp_token != null && this.temp_token === token);
188
+ }
189
+
190
+ /**
191
+ * Registers, unregisters and gets a list of handler functions for Shape events (such as when mouse enters, leaves, mouse button clicks, etc.).
192
+ *
193
+ * @param {function(ShapeEvent):any} [callback] - Event handler function that receives {@link ShapeEvent} object as an argument. Check example below for event Object format.
194
+ * @param {boolean} [remove] - Set to `true` to unregister the handler function.
195
+ * @return {function[]|ComboBox} Returns an array of registered handler functions if arguments are omitted, otherwise returns `this` component instance.
196
+ * @see ShapeEvent
197
+ * @example
198
+ * let handler = function(e){console.log(e);}
199
+ * mainForm.panel_1 = new Panel().addTo(mainForm).onPopupEvents(handler);
200
+ *
201
+ * // event Object format:
202
+ * const e = {
203
+ * target: object, // The Panel component that triggered the event.
204
+ * type: string, // Possible values: `add`, `remove`, `click`, `mousedown`, `mouseup`, `mouseenter`, `mouseleave`, `mousemove`.
205
+ * x: number, // X position relative to target.
206
+ * y: number, // Y position relative to target.
207
+ * shapeIndex: number, // Index of the shape that triggered the event.
208
+ * dragging: boolean, // `true` if mouse is down while moving, otherwise false.
209
+ * alt: boolean, // `true` if Alt key was pressed on keyboard when event was emitted.
210
+ * shift: boolean, // `true` if Shift key was pressed on keyboard when event was emitted.
211
+ * ctrl: boolean, // `true` if Control key was pressed on keyboard when event was emitted.
212
+ * modifiers: string, // Modifiers used when the event was emitted
213
+ * modifiersText: string // Description of used modifiers
214
+ * };
215
+ */
216
+ onShapeEvents(callback, ...args)
217
+ {
218
+ let c = callback;
219
+
220
+ if(typeof c === "function")
221
+ {
222
+ c = e =>
223
+ {
224
+ e.shape = this._shapes[e.shapeIndex];
225
+ callback(e);
226
+ };
227
+ }
228
+
229
+ return this.event("onShapeEvents", c, args[0] ?? false);
230
+ }
231
+ }
@@ -0,0 +1,172 @@
1
+
2
+ import {UIComponent} from "./UIComponent.js";
3
+
4
+ /**
5
+ * Slider UI component is used to set value by sliding a thumb (handle) horizontally or vertically. Slider works only with integer numbers, so decimal places will not work.
6
+ *
7
+ * @class
8
+ * @global
9
+ */
10
+ export class Slider extends UIComponent
11
+ {
12
+ /**
13
+ * Slider constructor. Creates an instance of Slider UI component.
14
+ * @param {string} [text] - Text of the component.
15
+ */
16
+ constructor(...args)
17
+ {
18
+ if(args.length > 0) super("Slider", (new.target === Slider), args[0]); else super("Slider", (new.target === Slider));
19
+
20
+ this.finalize(Slider);
21
+ }
22
+
23
+ /**
24
+ * Sets or gets the spacing between minor tick marks (smaller markings) in the Slider.
25
+ *
26
+ * @param {number} [spacing] - The interval at which minor tick marks are drawn.
27
+ * @return {Slider|number} When setting a value, returns this component for chaining; otherwise returns the current value.
28
+ */
29
+ minorTickSpacing(...args)
30
+ {
31
+ if(args.length > 0) args[0] = parseInt(args[0]);
32
+ return this.property("minorTickSpacing", args);
33
+ }
34
+
35
+ /**
36
+ * Sets or gets the spacing between major tick marks (larger markings) in the Slider.
37
+ *
38
+ * @param {number} [spacing] - The interval at which major tick marks are drawn.
39
+ * @return {Slider|number} When setting a value, returns this component for chaining; otherwise returns the current value.
40
+ */
41
+ majorTickSpacing(...args)
42
+ {
43
+ if(args.length > 0) args[0] = parseInt(args[0]);
44
+ return this.property("majorTickSpacing", args);
45
+ }
46
+
47
+ /**
48
+ * Enables or disables snapping the slider's knob to the nearest tick mark.
49
+ *
50
+ * @param {boolean} [snap] - If true, the knob will snap to the nearest tick; if false, it moves freely.
51
+ * @return {Slider|boolean} When setting a value, returns this component for chaining; otherwise returns the current value.
52
+ */
53
+ snapToTicks(...args)
54
+ {
55
+ return this.property("snapToTicks", args);
56
+ }
57
+
58
+ /**
59
+ * Shows or hides tick marks on the Slider.
60
+ *
61
+ * @param {boolean} [visible] - If true, tick marks will be displayed; if false, they will be hidden.
62
+ * @return {Slider|boolean} When setting a value, returns this component for chaining; otherwise returns the current value.
63
+ */
64
+ showTicks(...args)
65
+ {
66
+ return this.property("showTicks", args);
67
+ }
68
+
69
+ /**
70
+ * Shows or hides numeric labels on the Slider.
71
+ *
72
+ * @param {boolean} [visible] - If true, labels will be displayed; if false, they will be hidden.
73
+ * @return {Slider|boolean} When setting a value, returns this component for chaining; otherwise returns the current value.
74
+ */
75
+ showLabels(...args)
76
+ {
77
+ return this.property("showLabels", args);
78
+ }
79
+
80
+ /**
81
+ * Shows or hides the track (line) behind the slider knob.
82
+ *
83
+ * @param {boolean} [visible] - If true, the track will be displayed; if false, it will be hidden.
84
+ * @return {Slider|boolean} When setting a value, returns this component for chaining; otherwise returns the current value.
85
+ */
86
+ showTrack(...args)
87
+ {
88
+ return this.property("showTrack", args);
89
+ }
90
+
91
+ /**
92
+ * Sets or gets whether the Slider is inverted (maximum value on the left/top).
93
+ *
94
+ * @param {boolean} [inverted] - If true, the maximum value is on the left/top; if false, it is on the right/bottom.
95
+ * @return {Slider|boolean} When setting a value, returns this component for chaining; otherwise returns the current value.
96
+ */
97
+ inverted(...args)
98
+ {
99
+ return this.property("inverted", args);
100
+ }
101
+
102
+ /**
103
+ * Sets or gets the minimum value of the Slider.
104
+ *
105
+ * @param {number} [minValue] - The minimum allowed value.
106
+ * @return {Slider|number} When setting a value, returns this component for chaining; otherwise returns the current value.
107
+ */
108
+ min(...args)
109
+ {
110
+ if(args.length > 0) args[0] = parseInt(args[0]);
111
+ return this.property("min", args);
112
+ }
113
+
114
+ /**
115
+ * Sets or gets the maximum value of the Slider.
116
+ *
117
+ * @param {number} [maxValue] - The maximum allowed value.
118
+ * @return {Slider|number} When setting a value, returns this component for chaining; otherwise returns the current value.
119
+ */
120
+ max(...args)
121
+ {
122
+ if(args.length > 0) args[0] = parseInt(args[0]);
123
+ return this.property("max", args);
124
+ }
125
+
126
+ /**
127
+ * Sets or get integer value of the slider.
128
+ *
129
+ * @param {number} [value] - Value to display by the slider's handle. Must be between min and max allowed values.
130
+ * @return {Slider|number} When setting a value, returns this component for chaining; otherwise returns the current value.
131
+ */
132
+ value(...args)
133
+ {
134
+ if(args.length > 0) args[0] = parseInt(args[0]);
135
+ return this.property("value", args);
136
+ }
137
+
138
+ /**
139
+ * Sets or gets the orientation of the Slider.
140
+ *
141
+ * @param {Orientation} [orientation] - The slider's orientation: `Orientation.Horizontal` or `Orientation.Vertical`.
142
+ * @return {Slider|Orientation} When setting a value, returns this component for chaining; otherwise returns the current value.
143
+ */
144
+ orientation(...args)
145
+ {
146
+ return this.property("orientation", args);
147
+ }
148
+
149
+ /**
150
+ *
151
+ * Enables or disables onChange event to be continuously emitted while user is moving the handle and value is changing.
152
+ * If disabled, the onChange event will only be invoked after user stopped sliding the knob and releases mouse button.
153
+ *
154
+ * @param {boolean} [enabled] - If true, change events are emitted during sliding; if false, only when handle is released.
155
+ * @return {Slider|boolean} When setting a value, returns this component for chaining; otherwise returns the current value.
156
+ */
157
+ emitWhileSliding(...args)
158
+ {
159
+ return this.property("changeWhileSliding", args);
160
+ }
161
+
162
+ /**
163
+ * Indicates if the slider handle is being moved at that moment and not released yet.
164
+ *
165
+ * @readonly
166
+ * @type {boolean}
167
+ */
168
+ get isAdjusting()
169
+ {
170
+ return this.property("isAdjusting", []);
171
+ }
172
+ }
@@ -0,0 +1,172 @@
1
+
2
+ import {TextComponent} from "./TextComponent.js";
3
+
4
+ /**
5
+ * Component that can hold a number, list items, date/time, and IP addresses. Iterate through numbers or list items with up and down buttons or up and down keys (when Spinner has focus).
6
+ *
7
+ * @class
8
+ * @global
9
+ */
10
+ export class Spinner extends TextComponent
11
+ {
12
+ /**
13
+ * Defines the available spinner data types.
14
+ * Determines what type of values the spinner can represent and iterate through.
15
+ *
16
+ * @readonly
17
+ * @enum {number}
18
+ * @property {number} Number Spinner holds and iterates through numeric values.
19
+ * @property {number} List Spinner iterates through values from a predefined list.
20
+ * @property {number} DateTime Spinner holds and iterates through date and/or time values.
21
+ * @property {number} IPv4 Spinner holds and iterates through IPv4 address values.
22
+ * @property {number} IPv6 Spinner holds and iterates through IPv6 address values.
23
+ * @see Spinner#constructor
24
+ */
25
+ static Type = Object.freeze({Number: 0, List: 1, DateTime: 2, IPv4: 3, IPv6: 4});
26
+
27
+ /**
28
+ * Defines the available step units for {@link Spinner.Type.DateTime} spinners.
29
+ * Each unit represents the part of the date or time that changes when incremented or decremented.
30
+ *
31
+ * @readonly
32
+ * @enum {number}
33
+ * @property {number} Era Represents the era (e.g., BC/AD).
34
+ * @property {number} Year Represents the year.
35
+ * @property {number} Month Represents the month.
36
+ * @property {number} WeekOfYear Represents the week of the year.
37
+ * @property {number} WeekOfMonth Represents the week within the month.
38
+ * @property {number} DayOfMonth Represents the day of the month.
39
+ * @property {number} DayOfYear Represents the day of the year.
40
+ * @property {number} DayOfWeek Represents the day of the week.
41
+ * @property {number} DayOfWeekInMonth Represents the nth day of the week within a month.
42
+ * @property {number} AM_PM Represents AM or PM in a 12-hour clock.
43
+ * @property {number} Hour Represents the hour in a 12-hour clock.
44
+ * @property {number} HourOfDay Represents the hour in a 24-hour clock.
45
+ * @property {number} Minute Represents the minute.
46
+ * @property {number} Second Represents the second.
47
+ * @property {number} Millisecond Represents the millisecond.
48
+ * @see Spinner#step
49
+ */
50
+ static Step = Object.freeze({Era: 0, Year: 1, Month: 2, WeekOfYear: 3, WeekOfMonth: 4, DayOfMonth: 5, DayOfYear: 6, DayOfWeek: 7, DayOfWeekInMonth: 8, AM_PM: 9, Hour: 10, HourOfDay: 11, Minute: 12, Second: 13, Millisecond: 14});
51
+
52
+ /**
53
+ * Creates a new Spinner component for selecting numbers, list items, dates/times, or IP addresses.
54
+ *
55
+ * @param {Spinner.Type} type - Spinner value type. Valid values are Spinner.Type.[Number (default)|List|DateTime|IPv4|IPv6]
56
+ * @param {string|Array<*>} [list_or_format] - Format of how the value should be displayed (for numbers), or Array of list items (when type is Spinner.DataType.List).
57
+ * @param {number} [min] - The minimum allowed value (numeric or date)
58
+ * @param {number} [max] - The maximum allowed value (numeric or date).
59
+ * @param {number|Spinner.Step} [step] - Step increment used when increasing/decreasing values. Pass `number` for Number type of spinner and `Spinner.Step` for DateTime type.
60
+ * @example
61
+ * // Number Type: new Spinner(type, format, min, max, step_size);
62
+ * new Spinner(Spinner.Type.Number, "0.00", 0, 100, 5);
63
+ * @example
64
+ * // List Type: new Spinner(new Array());
65
+ * new Spinner(Spinner.Type.List, ["Monday","Tuesday","Wednesday","Thursday","Friday"]);
66
+ * @example
67
+ * // DateTime type:
68
+ * new Spinner(Spinner.Type.DateTime, new Date(2000, 0, 1), new Date(2030, 11, 31), "yyyy-MM-dd", Spinner.Step.DayOfMonth);
69
+ */
70
+ constructor(type)
71
+ {
72
+ let args = {type: parseInt(type)};
73
+
74
+ switch(type)
75
+ {
76
+ case Spinner.Type.Number:
77
+ {
78
+ args.format = arguments.length > 1 ? String(arguments[1]) : "0.00";
79
+ args.min = arguments.length > 2 ? arguments[2] : 0;
80
+ args.max = arguments.length > 3 ? arguments[3] : 100;
81
+ args.step = arguments.length > 4 ? arguments[4] : 0.05;
82
+ break;
83
+ }
84
+ case Spinner.Type.List:
85
+ {
86
+ args.list = arguments[1];
87
+ break;
88
+ }
89
+ case Spinner.Type.DateTime:
90
+ {
91
+ args.format = arguments.length > 1 ? String(arguments[1]) : null;
92
+ args.min = arguments.length > 2 ? arguments[2] : null;
93
+ args.max = arguments.length > 3 ? arguments[3] : null;
94
+ args.step = arguments.length > 4 ? parseInt(arguments[4]) : Spinner.Step.Second;
95
+ break;
96
+ }
97
+ case Spinner.Type.IPv4:
98
+ {
99
+ break;
100
+ }
101
+ case Spinner.Type.IPv6:
102
+ {
103
+ break;
104
+ }
105
+ default:
106
+ {
107
+ args.type = Spinner.Type.Number; //Spinner.Type.Number;
108
+ }
109
+ }
110
+
111
+ super("Spinner", (new.target === Spinner), args);
112
+
113
+ this.finalize(Spinner);
114
+ }
115
+
116
+ /**
117
+ * Gets or sets the minimum allowed numeric value for the spinner.
118
+ * Applicable only if the spinner was initialized with {Spinner.Type.Number}, {Spinner.Type.DateTime} or {Spinner.Type.IPv4}.
119
+ * Returns `null` if spinner type is {Spinner.Type.List}.
120
+ *
121
+ * @param {number} [value] - The minimum value to set.
122
+ * @returns {number | null | Spinner} The current minimum value, `null` if not applicable, or the Spinner instance when setting.
123
+ */
124
+ min()
125
+ {
126
+ return this.property("min", arguments);
127
+ }
128
+
129
+ /**
130
+ * Gets or sets the maximum allowed numeric value for the spinner.
131
+ * Applicable only if the spinner was initialized with {Spinner.Type.Number}, {Spinner.Type.DateTime} or {Spinner.Type.IPv4}.
132
+ * Returns `null` if spinner type is {Spinner.Type.List}.
133
+ *
134
+ * @param {number} [value] - The maximum value to set.
135
+ * @returns {number | null | Spinner} The current maximum value, `null` if not applicable, or the Spinner instance when setting.
136
+ */
137
+ max()
138
+ {
139
+ return this.property("max", arguments);
140
+ }
141
+
142
+ /**
143
+ * Gets or sets the step increment/decrement for the spinner when changing values via arrows or keyboard.
144
+ * Applicable only if the spinner was initialized with {Spinner.Type.Number}, {Spinner.Type.DateTime}, or {Spinner.Type.IPv4}.
145
+ * Returns `null` if spinner type is {Spinner.Type.List}.
146
+ *
147
+ * @param {number} [value] - The step size to set.
148
+ * @returns {number | null | Spinner} The current step size, `null` if not applicable, or the Spinner instance when setting.
149
+ */
150
+ step()
151
+ {
152
+ return this.property("step", arguments);
153
+ }
154
+
155
+ /**
156
+ * Sets or gets a value displayed in the Spinner component. This method returns number, Date and string types for value depending on the type of the Spinner. To set and get only string value you should use .text() method.
157
+ *
158
+ * @param {number|string|Date} value - New value to set. For date/time accepted value types are `Date` object or a string in the format `yyyy-MM-dd HH:mm:ss`, `yyyy-MM-dd`, `HH:mm:ss` or Date.toISOString() string.
159
+ * @returns {Spinner|number|Date|string} If called without arguments, a current value is returned, otherwise `this` component instance is returned for chaining.
160
+ * @see Spinner#text
161
+ */
162
+ value(...args)
163
+ {
164
+ if(typeof args[0] === "object" && args[0] instanceof Date) args[0] = {type:"date",value:args[0].getTime()};
165
+
166
+ let r = this.property("value", args.length > 0 ? [args[0]] : []);
167
+
168
+ if(args.length === 0 && typeof r === "object" && r.type === "date") r = new Date(r.value);
169
+
170
+ return r;
171
+ }
172
+ }
@@ -0,0 +1,82 @@
1
+
2
+ import {ComponentContainer} from "./ComponentContainer.js";
3
+ import {UIComponent} from "./UIComponent.js";
4
+
5
+ /**
6
+ * A SplitView is a container component that holds two child components separated by a movable divider. The divider can be dragged to resize the space allocated to each component dynamically.
7
+ *
8
+ * Extends {@link ComponentContainer}, which extends {@link UIComponent}.
9
+ *
10
+ * NOTE: Set .dividerPosition(value) and add both child components before populating them with child components to make sure descendents' anchor settings yields expected result.
11
+ *
12
+ * @class
13
+ * @global
14
+ * @see ComponentContainer
15
+ */
16
+ export class SplitView extends ComponentContainer
17
+ {
18
+ /**
19
+ * Creates an instance of SplitView component.
20
+ *
21
+ * @param {string} [text} - Optional text property for the component. When adding this component to Tabs this text would be used as a Tab text.
22
+ */
23
+ constructor()
24
+ {
25
+ if(arguments.length > 0)
26
+ {
27
+ super("SplitView", (new.target === SplitView), arguments[0]);
28
+ }
29
+ else
30
+ {
31
+ super("SplitView", (new.target === SplitView));
32
+ }
33
+
34
+ this.finalize(SplitView, ComponentContainer);
35
+ }
36
+
37
+ /**
38
+ * Sets of gets the position of the divider (from top or left depends on orientation).
39
+ *
40
+ * @param {number} [position] - Position of the divider.
41
+ * @return {number|SplitView} If called without parameters, returns current value; otherwise returns this SplitView component for chaining.
42
+ * @see SplitView#orientation
43
+ */
44
+ dividerPosition()
45
+ {
46
+ return this.property("dividerLocation", arguments);
47
+ }
48
+
49
+ /**
50
+ * Sets of gets the thickness of the divider.
51
+ *
52
+ * @param {number} [size] - Thickness of the divider in pixels.
53
+ * @return {number|SplitView} If called without parameters, returns current value; otherwise returns this SplitView component for chaining.
54
+ */
55
+ dividerSize()
56
+ {
57
+ return this.property("dividerSize", arguments);
58
+ }
59
+
60
+ /**
61
+ * Returns an array of current sizes of both child components as an array of objects {width:number, height:number}.
62
+ *
63
+ * @type {Array<{width:number, height:number}>}
64
+ * @readonly
65
+ */
66
+ get panelSizes()
67
+ {
68
+ return this.property("panelSizes", arguments);
69
+ }
70
+
71
+ /**
72
+ * Sets or gets an orientation of two sides in relation to each other.
73
+ *
74
+ * @param {Orientation} [orientation] - One of the value: Orientation.Horizontal, Orientation.Vertical
75
+ * @return {number|SplitView} If called without parameters, returns current value; otherwise returns this SplitView component for chaining.
76
+ * @see Orientation
77
+ */
78
+ orientation(...args)
79
+ {
80
+ return this.property("orientation", args);
81
+ }
82
+ }