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
package/index.js CHANGED
@@ -1,12 +1,117 @@
1
1
  /**
2
- * @version 2024-09-24
2
+ * Swing-UI GUI for JavaScript Runtime, such as Node.js, Bun, Deno 2.
3
3
  */
4
4
 
5
+ import fs from "fs";
6
+ import path from "path";
5
7
 
6
- // Export the main GUI class
7
- global.ui = new class
8
+ import JBridge from "java-bridge";
9
+
10
+ // show if debugger options were set
11
+ if(process.execArgv.some(arg => arg.startsWith("--inspect"))) console.log("JavaScript Debugger option is set.");
12
+
13
+ // show runtime version
14
+ if(process.argv.indexOf("--v") > -1) console.log(`JavaScript Runtime Version: ${process.version.replace("v", "")}`);
15
+
16
+ const __dirname = import.meta.dirname ?? import.meta.dir ?? path.dirname((await import("url")).fileURLToPath(import.meta.url));
17
+
18
+ // Dynamically assign each function to globalThis
19
+ import * as functions from "./functions.js"; // Import all functions from functions.js
20
+ if(typeof structuredClone !== "function") // add structuredClone() function in case it doesn't exist (node <17)
21
+ {
22
+ const v8 = await import("v8");
23
+ functions.structuredClone = ((obj) => {return v8.deserialize(v8.serialize(obj));});
24
+ }
25
+ Object.entries(functions).forEach(([name, func]) => {Object.defineProperty(globalThis, name, {writable: false, configurable: false, value: func});});
26
+
27
+ // Dynamically assign each enum to globalThis
28
+ import * as enums from "./enums.js"; // Import all functions from functions.js
29
+ Object.entries(enums).forEach(([name, enum_obj]) => {Object.defineProperty(globalThis, name, {writable: false, configurable: false, value: enum_obj});});
30
+
31
+ /**
32
+ * Catch and show uncaught exceptions
33
+ *
34
+ * @param ex Error
35
+ */
36
+ process.on("uncaughtException", function(ex){
37
+ try
38
+ {
39
+ //process.exitCode = 1;
40
+ let output = "Oops!\nUncaught JavaScript Exception Occurred:\n\n";
41
+
42
+ if(typeof ex === "string")
43
+ {
44
+ output += ex;
45
+ }
46
+ else if(typeof ex === "object")
47
+ {
48
+ output += ex.name + ": " + ex.message + "\n";
49
+
50
+ for(let [i, line] of (ex.stack !== undefined) ? ex.stack.split("\n").entries() : [].entries())
51
+ {
52
+ line = line.trim().replace(/\(eval at <anonymous> /ig, "").replace("))", ")");
53
+ if(line.length > 0) output += "\n" + i + ": " + line;
54
+ if(i++ > 6) break;
55
+ }
56
+ }
57
+
58
+ if(ex.name !== "SyntaxError") output += "\n\nUse try{}catch(ex){} to make sure it doesn't happen again.";
59
+ output += "\n\nThe app will terminate from this exception in 30 seconds.";
60
+
61
+ output += "\n\n" + (new Date()).toLocaleString();
62
+
63
+ error(output, false);
64
+
65
+ setTimeout(() => {ui.exit(1); process.exit();}, 30000);
66
+ }catch(ex)
67
+ {error("Oops: " + ex, true);}
68
+ });
69
+
70
+ /**
71
+ * Catch and show uncaught exceptions inside a promise
72
+ *
73
+ * @param ex Error
74
+ * @param promise Promise
75
+ */
76
+ process.on("unhandledRejection", (ex, promise) => {
77
+ error("===== UNCAUGHT EXCEPTION INSIDE OF PROMISE =====\n\n" + (ex.stack !== undefined ? ex.stack : ex), false);
78
+ });
79
+
80
+ // LOAD UI classes
81
+ const classesDir = path.join(__dirname, "classes");
82
+
83
+ // load all UI components
84
+ for(const file of fs.readdirSync(classesDir))
8
85
  {
86
+ if(!file.endsWith(".js")) continue; // skip non-.js files
87
+
88
+ const component = await import(new URL("file://" + path.join(classesDir, file)));
89
+ const className = Object.keys(component)[0];
90
+
91
+ Object.defineProperty(globalThis, className, {writable: false, configurable: false, value: component[className]});
92
+ }
9
93
 
10
- };
94
+ try
95
+ {
96
+ let ui = new (await import("./SwingUI.js")).SwingUI(__dirname, JBridge);
97
+ await ui.InitGUIProcess();
98
+ Object.defineProperty(globalThis, "ui", {writable: false, configurable: false, value: ui});
99
+ }catch(ex)
100
+ {
101
+ error(`Failed to initialize 'swing-ui' GUI!\n\n${ex.stack || ex}`, false);
102
+ process.exit(1);
103
+ }
11
104
 
105
+ /**
106
+ * This is a global instance of the main SwingUI class. Use this variable to call functions of {@link SwingUI} class.
107
+ *
108
+ * @type {SwingUI}
109
+ * @global
110
+ * @readonly
111
+ * @see SwingUI
112
+ * @example
113
+ * let _screens = ui.screens; // lists screens in an Array
114
+ * const data = ui.clipboard(); // retrieves data copied to clipboard
115
+ */
116
+ globalThis.ui;
12
117
 
package/jar/gui-11.jar ADDED
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,35 +1,60 @@
1
1
  {
2
- "name": "swing-ui",
3
- "version": "0.1.25",
4
- "description": "Coming soon",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "keywords": [
10
- "gui",
11
- "ui",
12
- "\"user",
13
- "interface\"",
14
- "java",
15
- "swing",
16
- "forms",
17
- "components",
18
- "graphic",
19
- "graphical"
20
- ],
21
- "author": "Dmitriy Kulikovskiy",
22
- "license": "SEE LICENCE IN A LICENCE FILE",
23
- "homepage": "https://swing-ui.com",
24
- "bugs": "https://swing-ui.com/contact-me",
25
- "repository": {
26
- "type": "git",
27
- "url": ""
28
- },
29
- "files": [
30
- "index.js",
31
- "README.md",
32
- "CHANGES.md",
33
- "LICENCE"
34
- ]
2
+ "name": "swing-ui",
3
+ "version": "1.0.1",
4
+ "description": "Graphic User Interface for JavaScript",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "docs": "jsdoc -c docs-files/jsdoc.json",
8
+ "docs-to-json": "jsdoc -c docs-files/jsdoc.json --explain > docs-files/static/data.json",
9
+ "convert-json-docs": "node docs-files/convert-json-docs.js",
10
+ "apply-inherited-methods": "node docs-files/apply-inherited-methods.js"
11
+ },
12
+ "types": "./types/index.d.ts",
13
+ "type": "module",
14
+ "keywords": [
15
+ "gui",
16
+ "ui",
17
+ "java",
18
+ "swing",
19
+ "graphic",
20
+ "graphical",
21
+ "interface",
22
+ "swing-ui"
23
+ ],
24
+ "author": "swing-ui.com",
25
+ "license": "SEE LICENCE IN A LICENCE FILE",
26
+ "homepage": "https://swing-ui.com",
27
+ "bugs": "https://swing-ui.com/report-bug/",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": ""
31
+ },
32
+ "files": [
33
+ "classes/",
34
+ "jar/gui-11.jar",
35
+ "jar/lib/flatlaf.jar",
36
+ "jar/lib/jna.jar",
37
+ "types/",
38
+ "enums.js",
39
+ "fonts.conf",
40
+ "functions.js",
41
+ "icon.png",
42
+ "index.js",
43
+ "LICENSE",
44
+ "package.json",
45
+ "README.md",
46
+ "SwingUI.js",
47
+ "typedefs.js",
48
+ "ui-process-manager.js",
49
+ "video-devices-linux.sh",
50
+ "video-devices-mac.sh"
51
+ ],
52
+ "engines": {
53
+ "node": ">= 18",
54
+ "bun": ">= 1.1.0",
55
+ "deno": ">= 2.6.0"
56
+ },
57
+ "dependencies": {
58
+ "java-bridge": "^2.8.1"
59
+ }
35
60
  }