Skip to content

Commit 4e53757

Browse files
feat(core): Add PropertiesDialog (#2097)
* feat(core): Add PropertiesDialog Close #2071 Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com> * feat(core): Improve PropertiesDialog Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com> * feat(core): Improve PropertiesDialog Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com> --------- Signed-off-by: unknowIfGuestInDream <liang.tang.cx@gmail.com>
1 parent 34d8d0c commit 4e53757

File tree

13 files changed

+309
-4
lines changed

13 files changed

+309
-4
lines changed

core/src/main/java/com/tlcsdm/core/javafx/controlsfx/FxAction.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.tlcsdm.core.javafx.dialog.FxButtonType;
3636
import com.tlcsdm.core.javafx.dialog.FxDialog;
3737
import com.tlcsdm.core.javafx.dialog.PathWatchToolDialog;
38+
import com.tlcsdm.core.javafx.dialog.PropertiesDialog;
3839
import com.tlcsdm.core.javafx.dialog.SystemSettingDialog;
3940
import com.tlcsdm.core.javafx.dialog.WebBrowserDialog;
4041
import com.tlcsdm.core.javafx.helper.LayoutHelper;
@@ -403,6 +404,22 @@ public static Action openSysConfig(String text, Consumer<ActionEvent> eventHandl
403404
return create(text, eventHandler, "/com/tlcsdm/core/static/menubar/sysConfig.png");
404405
}
405406

407+
/**
408+
* 查看系统属性.
409+
*/
410+
public static Action openPropertiesDialog() {
411+
return openPropertiesDialog(I18nUtils.get("core.menubar.help.openPropDir"), actionEvent -> {
412+
PropertiesDialog.openPropertiesDialog();
413+
});
414+
}
415+
416+
/**
417+
* 查看系统属性.
418+
*/
419+
public static Action openPropertiesDialog(String text, Consumer<ActionEvent> eventHandler) {
420+
return create(text, eventHandler, "/com/tlcsdm/core/static/menubar/properties.png");
421+
}
422+
406423
/**
407424
* @see #openUserData(String, Consumer)
408425
*/
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright (c) 2019, 2023 unknowIfGuestInDream
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of unknowIfGuestInDream, any associated website, nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY
20+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package com.tlcsdm.core.javafx.dialog;
28+
29+
import com.tlcsdm.core.javafx.FxApp;
30+
import com.tlcsdm.core.javafx.richtext.InformationArea;
31+
import com.tlcsdm.core.javafx.richtext.PropertiesArea;
32+
import com.tlcsdm.core.util.I18nUtils;
33+
import javafx.scene.control.Tab;
34+
import javafx.scene.control.TabPane;
35+
import javafx.scene.layout.Priority;
36+
import javafx.scene.layout.VBox;
37+
import org.fxmisc.flowless.VirtualizedScrollPane;
38+
import org.fxmisc.richtext.InlineCssTextArea;
39+
import org.fxmisc.richtext.LineNumberFactory;
40+
41+
import java.lang.management.ManagementFactory;
42+
import java.lang.management.RuntimeMXBean;
43+
import java.nio.charset.Charset;
44+
import java.time.Duration;
45+
import java.time.Instant;
46+
import java.time.LocalDateTime;
47+
import java.time.ZoneId;
48+
import java.util.List;
49+
import java.util.Map;
50+
51+
/**
52+
* Property弹窗
53+
*
54+
* @author unknowIfGuestInDream
55+
*/
56+
public class PropertiesDialog {
57+
58+
private PropertiesDialog() {
59+
}
60+
61+
public static void openPropertiesDialog() {
62+
VBox vbox = new VBox();
63+
TabPane tabPane = new TabPane();
64+
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
65+
tabPane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING);
66+
67+
InformationArea overviewArea = new InformationArea();
68+
overviewArea.setEditable(false);
69+
overviewArea.setStyle("-fx-font-size: 14;-fx-padding: 5 0 0 5;");
70+
buildOverviewArea(overviewArea);
71+
VirtualizedScrollPane<InformationArea> overviewPane = new VirtualizedScrollPane<>(overviewArea);
72+
73+
InlineCssTextArea jvmArea = new InlineCssTextArea();
74+
jvmArea.setEditable(false);
75+
jvmArea.setStyle("-fx-font-size: 14;-fx-padding: 5 0 0 5;");
76+
jvmArea.setParagraphGraphicFactory(LineNumberFactory.get(jvmArea));
77+
buildJvmArea(jvmArea);
78+
VirtualizedScrollPane<InlineCssTextArea> jvmPane = new VirtualizedScrollPane<>(jvmArea);
79+
80+
PropertiesArea sysArea = new PropertiesArea();
81+
sysArea.setEditable(false);
82+
buildSysArea(sysArea);
83+
VirtualizedScrollPane<PropertiesArea> sysPane = new VirtualizedScrollPane<>(sysArea);
84+
85+
Tab overviewTab = new Tab("Overview");
86+
overviewTab.setContent(overviewPane);
87+
88+
Tab jvmTab = new Tab("JVM");
89+
jvmTab.setContent(jvmPane);
90+
91+
Tab sysTab = new Tab("System");
92+
sysTab.setContent(sysPane);
93+
94+
tabPane.getTabs().setAll(overviewTab, jvmTab, sysTab);
95+
96+
vbox.getChildren().addAll(tabPane);
97+
VBox.setVgrow(tabPane, Priority.ALWAYS);
98+
99+
FxDialog<VBox> dialog = new FxDialog<VBox>().setTitle(
100+
I18nUtils.get("core.menubar.setting.systemProperties")).setOwner(FxApp.primaryStage)
101+
.setPrefSize(680, 540).setResizable(true).setBody(vbox)
102+
.setButtonTypes(FxButtonType.CLOSE);
103+
dialog.setButtonHandler(FxButtonType.CLOSE, (e, s) -> s.close());
104+
dialog.show();
105+
}
106+
107+
private static void buildOverviewArea(InformationArea area) {
108+
// get name representing the running Java virtual machine.
109+
String name = ManagementFactory.getRuntimeMXBean().getName();
110+
// get pid
111+
String pid = name.split("@")[0];
112+
// 基本JVM信息
113+
String jvmName = ManagementFactory.getRuntimeMXBean().getVmName();
114+
String jvmVersion = System.getProperty("java.vm.version");
115+
String jvmVendor = System.getProperty("java.vm.vendor");
116+
String javaHome = System.getProperty("java.home");
117+
String fileEncoding = Charset.defaultCharset().displayName();
118+
String workingDir = System.getProperty("user.dir");
119+
// 运行时信息
120+
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
121+
// 获取JVM启动时间(毫秒)
122+
long startTime = runtimeMXBean.getStartTime();
123+
LocalDateTime startDateTime = LocalDateTime.ofInstant(
124+
Instant.ofEpochMilli(startTime), ZoneId.systemDefault());
125+
// 获取JVM运行时间(毫秒)
126+
long uptime = runtimeMXBean.getUptime();
127+
Duration duration = Duration.ofMillis(uptime);
128+
String runTime = "%d Day %d Hour %d Min %d s".formatted(duration.toDays(), duration.toHours() % 24,
129+
duration.toMinutes() % 60, duration.getSeconds() % 60);
130+
131+
area.appendText("PID: " + pid);
132+
area.appendText(System.lineSeparator());
133+
area.appendText("JVM: " + jvmName + " (" + System.getProperty("java.vm.info") + ")");
134+
area.appendText(System.lineSeparator());
135+
area.appendText("Java: " + jvmVendor + " " + jvmVersion);
136+
area.appendText(System.lineSeparator());
137+
area.appendText("Java Home: " + javaHome);
138+
area.appendText(System.lineSeparator());
139+
area.appendText("JVM StartUpTime: " + startDateTime);
140+
area.appendText(System.lineSeparator());
141+
area.appendText("JVM Run time: " + runTime);
142+
area.appendText(System.lineSeparator());
143+
area.appendText("Program Path: " + workingDir);
144+
area.appendText(System.lineSeparator());
145+
area.appendText("Encoding: " + fileEncoding);
146+
}
147+
148+
private static void buildJvmArea(InlineCssTextArea area) {
149+
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
150+
List<String> arguments = runtimeMxBean.getInputArguments();
151+
for (String arg : arguments) {
152+
area.appendText(arg);
153+
area.appendText(System.lineSeparator());
154+
}
155+
}
156+
157+
private static void buildSysArea(PropertiesArea area) {
158+
Map<String, String> env = System.getenv();
159+
env.forEach((key, value) -> {
160+
area.appendText(key + " = " + value);
161+
area.appendText(System.lineSeparator());
162+
});
163+
}
164+
165+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2023 unknowIfGuestInDream
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of unknowIfGuestInDream, any associated website, nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY
20+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
package com.tlcsdm.core.javafx.richtext;
29+
30+
import cn.hutool.core.text.CharSequenceUtil;
31+
import cn.hutool.core.util.StrUtil;
32+
import org.fxmisc.richtext.CodeArea;
33+
import org.fxmisc.richtext.model.StyleSpans;
34+
import org.fxmisc.richtext.model.StyleSpansBuilder;
35+
36+
import java.util.Collection;
37+
import java.util.Collections;
38+
import java.util.List;
39+
import java.util.Objects;
40+
41+
/**
42+
* Information TextArea.
43+
*
44+
* @author unknowIfGuestInDream
45+
*/
46+
public class InformationArea extends CodeArea {
47+
48+
public InformationArea() {
49+
super();
50+
getStyleClass().add("text-information-area");
51+
getStylesheets().add(Objects.requireNonNull(
52+
getClass().getResource("/com/tlcsdm/core/static/javafx/richtext/information.css")).toExternalForm());
53+
this.textProperty().addListener((obs, oldText, newText) -> this.setStyleSpans(0, computeHighlighting(newText)));
54+
}
55+
56+
private StyleSpans<Collection<String>> computeHighlighting(String text) {
57+
List<String> list = StrUtil.split(text, "\n");
58+
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
59+
for (String str : list) {
60+
List<String> l = CharSequenceUtil.split(str, ':', 2);
61+
if (l.size() != 2) {
62+
continue;
63+
}
64+
spansBuilder.add(Collections.singleton("infoKey"), l.get(0).length());
65+
spansBuilder.add(Collections.singleton("infoEqu"), 1);
66+
spansBuilder.add(Collections.emptyList(), l.get(1).length() + 1);
67+
}
68+
return spansBuilder.create();
69+
}
70+
71+
}

core/src/main/java/com/tlcsdm/core/javafx/richtext/PropertiesArea.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private StyleSpans<Collection<String>> computeHighlighting(String text) {
6060
List<String> list = StrUtil.split(text, "\n");
6161
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
6262
for (String str : list) {
63-
List<String> l = CharSequenceUtil.split(str, "=");
63+
List<String> l = CharSequenceUtil.split(str, '=', 2);
6464
if (l.size() != 2) {
6565
continue;
6666
}

core/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
requires java.net.http;
3737
requires java.sql;
3838
requires java.xml;
39+
requires java.management;
3940
requires static java.compiler;
4041
requires org.apache.commons.lang3;
4142
requires javafx.controls;

core/src/main/resources/com/tlcsdm/core/i18n/messages_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ core.menubar.file.exit=Exit
6666
core.menubar.setting=Setting
6767
core.menubar.setting.language=Language
6868
core.menubar.setting.systemSetting=System Setting
69+
core.menubar.setting.systemProperties=System Properties
6970
core.menubar.setting.colorPicker=Color Extractor
7071
core.menubar.setting.colorPicker.tips=Click to copy color
7172
core.menubar.setting.screenshot=Screenshot
@@ -99,6 +100,7 @@ core.menubar.help.submitFeedback=Submit feedback
99100
core.menubar.help.openLogDir=View Log
100101
core.menubar.help.openOutDir=Open output position
101102
core.menubar.help.openSysConfigDir=View System Config
103+
core.menubar.help.openPropDir=View system properties
102104
core.menubar.help.openUserData=View User Data
103105
core.menubar.help.release=Check for updates
104106
core.menubar.help.helpContent=Help Contents

core/src/main/resources/com/tlcsdm/core/i18n/messages_ja.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ core.menubar.file.exit=\u7D42\u4E86\u3059\u308B
6666
core.menubar.setting=\u8A2D\u5B9A
6767
core.menubar.setting.language=\u8A00\u8A9E
6868
core.menubar.setting.systemSetting=\u30B7\u30B9\u30C6\u30E0\u8A2D\u5B9A
69+
core.menubar.setting.systemProperties=\u30B7\u30B9\u30C6\u30E0\u30D7\u30ED\u30D1\u30C6\u30A3
6970
core.menubar.setting.colorPicker=\u30AB\u30E9\u30FC\u30A8\u30AF\u30B9\u30C8\u30E9\u30AF\u30BF
7071
core.menubar.setting.colorPicker.tips=\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u8272\u3092\u30B3\u30D4\u30FC
7172
core.menubar.setting.screenshot=\u30B9\u30AF\u30EA\u30FC\u30F3\u30B7\u30E7\u30C3\u30C8
@@ -99,6 +100,7 @@ core.menubar.help.submitFeedback=\u30D5\u30A3\u30FC\u30C9\u30D0\u30C3\u30AF\u309
99100
core.menubar.help.openLogDir=\u30D3\u30E5\u30FC\u30FB\u30ED\u30B0
100101
core.menubar.help.openOutDir=\u51FA\u529B\u4F4D\u7F6E\u3092\u958B\u304F
101102
core.menubar.help.openSysConfigDir=\u30B7\u30B9\u30C6\u30E0\u69CB\u6210\u306E\u8868\u793A
103+
core.menubar.help.openPropDir=\u30B7\u30B9\u30C6\u30E0\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u8868\u793A\u3059\u308B
102104
core.menubar.help.openUserData=\u30E6\u30FC\u30B6\u30FC\u30C7\u30FC\u30BF\u3092\u8868\u793A\u3059\u308B
103105
core.menubar.help.release=\u30A2\u30C3\u30D7\u30C7\u30FC\u30C8\u3092\u78BA\u8A8D
104106
core.menubar.help.helpContent=\u30D8\u30EB\u30D7\u30B3\u30F3\u30C6\u30F3\u30C4

core/src/main/resources/com/tlcsdm/core/i18n/messages_zh.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ core.menubar.file.exit=\u9000\u51FA
6666
core.menubar.setting=\u8BBE\u7F6E
6767
core.menubar.setting.language=\u8BED\u8A00
6868
core.menubar.setting.systemSetting=\u7CFB\u7EDF\u8BBE\u7F6E
69+
core.menubar.setting.systemProperties=\u7CFB\u7EDF\u5C5E\u6027
6970
core.menubar.setting.colorPicker=\u989C\u8272\u63D0\u53D6\u5668
7071
core.menubar.setting.colorPicker.tips=\u70B9\u51FB\u590D\u5236\u989C\u8272
7172
core.menubar.setting.screenshot=\u5C4F\u5E55\u622A\u56FE
@@ -99,6 +100,7 @@ core.menubar.help.submitFeedback=\u63D0\u4EA4\u53CD\u9988
99100
core.menubar.help.openLogDir=\u67E5\u770B\u65E5\u5FD7
100101
core.menubar.help.openOutDir=\u6253\u5F00\u8F93\u51FA\u4F4D\u7F6E
101102
core.menubar.help.openSysConfigDir=\u67E5\u770B\u7CFB\u7EDF\u914D\u7F6E
103+
core.menubar.help.openPropDir=\u67E5\u770B\u7CFB\u7EDF\u5C5E\u6027
102104
core.menubar.help.openUserData=\u67E5\u770B\u7528\u6237\u6570\u636E
103105
core.menubar.help.release=\u68C0\u67E5\u66F4\u65B0
104106
core.menubar.help.helpContent=\u5E2E\u52A9\u6587\u6863
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2023 unknowIfGuestInDream.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of unknowIfGuestInDream, any associated website, nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY
20+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
* {
29+
-fx-text-background-color: gray;
30+
}
31+
32+
.infoKey {
33+
-fx-fill: black;
34+
-fx-font-weight: bold;
35+
}
36+
37+
.infoEqu {
38+
-fx-fill: #323338;
39+
}

core/src/main/resources/com/tlcsdm/core/static/javafx/richtext/properties.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727

2828
* {
29-
-fx-text-background-color: white;
29+
-fx-text-background-color: gray;
3030
}
3131

3232
.propertyKey {

0 commit comments

Comments
 (0)