Skip to content

feat(core): Add PropertiesDialog #2097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.tlcsdm.core.javafx.dialog.FxButtonType;
import com.tlcsdm.core.javafx.dialog.FxDialog;
import com.tlcsdm.core.javafx.dialog.PathWatchToolDialog;
import com.tlcsdm.core.javafx.dialog.PropertiesDialog;
import com.tlcsdm.core.javafx.dialog.SystemSettingDialog;
import com.tlcsdm.core.javafx.dialog.WebBrowserDialog;
import com.tlcsdm.core.javafx.helper.LayoutHelper;
Expand Down Expand Up @@ -403,6 +404,22 @@ public static Action openSysConfig(String text, Consumer<ActionEvent> eventHandl
return create(text, eventHandler, "/com/tlcsdm/core/static/menubar/sysConfig.png");
}

/**
* 查看系统属性.
*/
public static Action openPropertiesDialog() {
return openPropertiesDialog(I18nUtils.get("core.menubar.help.openPropDir"), actionEvent -> {
PropertiesDialog.openPropertiesDialog();
});
}

/**
* 查看系统属性.
*/
public static Action openPropertiesDialog(String text, Consumer<ActionEvent> eventHandler) {
return create(text, eventHandler, "/com/tlcsdm/core/static/menubar/properties.png");
}

/**
* @see #openUserData(String, Consumer)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (c) 2019, 2023 unknowIfGuestInDream
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of unknowIfGuestInDream, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.tlcsdm.core.javafx.dialog;

import com.tlcsdm.core.javafx.FxApp;
import com.tlcsdm.core.javafx.richtext.InformationArea;
import com.tlcsdm.core.javafx.richtext.PropertiesArea;
import com.tlcsdm.core.util.I18nUtils;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;
import org.fxmisc.richtext.LineNumberFactory;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.charset.Charset;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;
import java.util.Map;

/**
* Property弹窗
*
* @author unknowIfGuestInDream
*/
public class PropertiesDialog {

private PropertiesDialog() {
}

public static void openPropertiesDialog() {
VBox vbox = new VBox();
TabPane tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
tabPane.getStyleClass().add(TabPane.STYLE_CLASS_FLOATING);

InformationArea overviewArea = new InformationArea();
overviewArea.setEditable(false);
overviewArea.setStyle("-fx-font-size: 14;-fx-padding: 5 0 0 5;");
buildOverviewArea(overviewArea);
VirtualizedScrollPane<InformationArea> overviewPane = new VirtualizedScrollPane<>(overviewArea);

InlineCssTextArea jvmArea = new InlineCssTextArea();
jvmArea.setEditable(false);
jvmArea.setStyle("-fx-font-size: 14;-fx-padding: 5 0 0 5;");
jvmArea.setParagraphGraphicFactory(LineNumberFactory.get(jvmArea));
buildJvmArea(jvmArea);
VirtualizedScrollPane<InlineCssTextArea> jvmPane = new VirtualizedScrollPane<>(jvmArea);

PropertiesArea sysArea = new PropertiesArea();
sysArea.setEditable(false);
buildSysArea(sysArea);
VirtualizedScrollPane<PropertiesArea> sysPane = new VirtualizedScrollPane<>(sysArea);

Tab overviewTab = new Tab("Overview");
overviewTab.setContent(overviewPane);

Tab jvmTab = new Tab("JVM");
jvmTab.setContent(jvmPane);

Tab sysTab = new Tab("System");
sysTab.setContent(sysPane);

tabPane.getTabs().setAll(overviewTab, jvmTab, sysTab);

vbox.getChildren().addAll(tabPane);
VBox.setVgrow(tabPane, Priority.ALWAYS);

FxDialog<VBox> dialog = new FxDialog<VBox>().setTitle(
I18nUtils.get("core.menubar.setting.systemProperties")).setOwner(FxApp.primaryStage)
.setPrefSize(680, 540).setResizable(true).setBody(vbox)
.setButtonTypes(FxButtonType.CLOSE);
dialog.setButtonHandler(FxButtonType.CLOSE, (e, s) -> s.close());
dialog.show();
}

private static void buildOverviewArea(InformationArea area) {
// get name representing the running Java virtual machine.
String name = ManagementFactory.getRuntimeMXBean().getName();
// get pid
String pid = name.split("@")[0];
// 基本JVM信息
String jvmName = ManagementFactory.getRuntimeMXBean().getVmName();
String jvmVersion = System.getProperty("java.vm.version");
String jvmVendor = System.getProperty("java.vm.vendor");
String javaHome = System.getProperty("java.home");
String fileEncoding = Charset.defaultCharset().displayName();
String workingDir = System.getProperty("user.dir");
// 运行时信息
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
// 获取JVM启动时间(毫秒)
long startTime = runtimeMXBean.getStartTime();
LocalDateTime startDateTime = LocalDateTime.ofInstant(
Instant.ofEpochMilli(startTime), ZoneId.systemDefault());
// 获取JVM运行时间(毫秒)
long uptime = runtimeMXBean.getUptime();
Duration duration = Duration.ofMillis(uptime);
String runTime = "%d Day %d Hour %d Min %d s".formatted(duration.toDays(), duration.toHours() % 24,
duration.toMinutes() % 60, duration.getSeconds() % 60);

area.appendText("PID: " + pid);
area.appendText(System.lineSeparator());
area.appendText("JVM: " + jvmName + " (" + System.getProperty("java.vm.info") + ")");
area.appendText(System.lineSeparator());
area.appendText("Java: " + jvmVendor + " " + jvmVersion);
area.appendText(System.lineSeparator());
area.appendText("Java Home: " + javaHome);
area.appendText(System.lineSeparator());
area.appendText("JVM StartUpTime: " + startDateTime);
area.appendText(System.lineSeparator());
area.appendText("JVM Run time: " + runTime);
area.appendText(System.lineSeparator());
area.appendText("Program Path: " + workingDir);
area.appendText(System.lineSeparator());
area.appendText("Encoding: " + fileEncoding);
}

private static void buildJvmArea(InlineCssTextArea area) {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
for (String arg : arguments) {
area.appendText(arg);
area.appendText(System.lineSeparator());
}
}

private static void buildSysArea(PropertiesArea area) {
Map<String, String> env = System.getenv();
env.forEach((key, value) -> {
area.appendText(key + " = " + value);
area.appendText(System.lineSeparator());
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2023 unknowIfGuestInDream
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of unknowIfGuestInDream, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.tlcsdm.core.javafx.richtext;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import org.fxmisc.richtext.CodeArea;
import org.fxmisc.richtext.model.StyleSpans;
import org.fxmisc.richtext.model.StyleSpansBuilder;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* Information TextArea.
*
* @author unknowIfGuestInDream
*/
public class InformationArea extends CodeArea {

public InformationArea() {
super();
getStyleClass().add("text-information-area");
getStylesheets().add(Objects.requireNonNull(
getClass().getResource("/com/tlcsdm/core/static/javafx/richtext/information.css")).toExternalForm());
this.textProperty().addListener((obs, oldText, newText) -> this.setStyleSpans(0, computeHighlighting(newText)));
}

private StyleSpans<Collection<String>> computeHighlighting(String text) {
List<String> list = StrUtil.split(text, "\n");
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
for (String str : list) {
List<String> l = CharSequenceUtil.split(str, ':', 2);
if (l.size() != 2) {
continue;
}
spansBuilder.add(Collections.singleton("infoKey"), l.get(0).length());
spansBuilder.add(Collections.singleton("infoEqu"), 1);
spansBuilder.add(Collections.emptyList(), l.get(1).length() + 1);
}
return spansBuilder.create();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private StyleSpans<Collection<String>> computeHighlighting(String text) {
List<String> list = StrUtil.split(text, "\n");
StyleSpansBuilder<Collection<String>> spansBuilder = new StyleSpansBuilder<>();
for (String str : list) {
List<String> l = CharSequenceUtil.split(str, "=");
List<String> l = CharSequenceUtil.split(str, '=', 2);
if (l.size() != 2) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
requires java.net.http;
requires java.sql;
requires java.xml;
requires java.management;
requires static java.compiler;
requires org.apache.commons.lang3;
requires javafx.controls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ core.menubar.file.exit=Exit
core.menubar.setting=Setting
core.menubar.setting.language=Language
core.menubar.setting.systemSetting=System Setting
core.menubar.setting.systemProperties=System Properties
core.menubar.setting.colorPicker=Color Extractor
core.menubar.setting.colorPicker.tips=Click to copy color
core.menubar.setting.screenshot=Screenshot
Expand Down Expand Up @@ -99,6 +100,7 @@ core.menubar.help.submitFeedback=Submit feedback
core.menubar.help.openLogDir=View Log
core.menubar.help.openOutDir=Open output position
core.menubar.help.openSysConfigDir=View System Config
core.menubar.help.openPropDir=View system properties
core.menubar.help.openUserData=View User Data
core.menubar.help.release=Check for updates
core.menubar.help.helpContent=Help Contents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ core.menubar.file.exit=\u7D42\u4E86\u3059\u308B
core.menubar.setting=\u8A2D\u5B9A
core.menubar.setting.language=\u8A00\u8A9E
core.menubar.setting.systemSetting=\u30B7\u30B9\u30C6\u30E0\u8A2D\u5B9A
core.menubar.setting.systemProperties=\u30B7\u30B9\u30C6\u30E0\u30D7\u30ED\u30D1\u30C6\u30A3
core.menubar.setting.colorPicker=\u30AB\u30E9\u30FC\u30A8\u30AF\u30B9\u30C8\u30E9\u30AF\u30BF
core.menubar.setting.colorPicker.tips=\u30AF\u30EA\u30C3\u30AF\u3057\u3066\u8272\u3092\u30B3\u30D4\u30FC
core.menubar.setting.screenshot=\u30B9\u30AF\u30EA\u30FC\u30F3\u30B7\u30E7\u30C3\u30C8
Expand Down Expand Up @@ -99,6 +100,7 @@ core.menubar.help.submitFeedback=\u30D5\u30A3\u30FC\u30C9\u30D0\u30C3\u30AF\u309
core.menubar.help.openLogDir=\u30D3\u30E5\u30FC\u30FB\u30ED\u30B0
core.menubar.help.openOutDir=\u51FA\u529B\u4F4D\u7F6E\u3092\u958B\u304F
core.menubar.help.openSysConfigDir=\u30B7\u30B9\u30C6\u30E0\u69CB\u6210\u306E\u8868\u793A
core.menubar.help.openPropDir=\u30B7\u30B9\u30C6\u30E0\u30D7\u30ED\u30D1\u30C6\u30A3\u3092\u8868\u793A\u3059\u308B
core.menubar.help.openUserData=\u30E6\u30FC\u30B6\u30FC\u30C7\u30FC\u30BF\u3092\u8868\u793A\u3059\u308B
core.menubar.help.release=\u30A2\u30C3\u30D7\u30C7\u30FC\u30C8\u3092\u78BA\u8A8D
core.menubar.help.helpContent=\u30D8\u30EB\u30D7\u30B3\u30F3\u30C6\u30F3\u30C4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ core.menubar.file.exit=\u9000\u51FA
core.menubar.setting=\u8BBE\u7F6E
core.menubar.setting.language=\u8BED\u8A00
core.menubar.setting.systemSetting=\u7CFB\u7EDF\u8BBE\u7F6E
core.menubar.setting.systemProperties=\u7CFB\u7EDF\u5C5E\u6027
core.menubar.setting.colorPicker=\u989C\u8272\u63D0\u53D6\u5668
core.menubar.setting.colorPicker.tips=\u70B9\u51FB\u590D\u5236\u989C\u8272
core.menubar.setting.screenshot=\u5C4F\u5E55\u622A\u56FE
Expand Down Expand Up @@ -99,6 +100,7 @@ core.menubar.help.submitFeedback=\u63D0\u4EA4\u53CD\u9988
core.menubar.help.openLogDir=\u67E5\u770B\u65E5\u5FD7
core.menubar.help.openOutDir=\u6253\u5F00\u8F93\u51FA\u4F4D\u7F6E
core.menubar.help.openSysConfigDir=\u67E5\u770B\u7CFB\u7EDF\u914D\u7F6E
core.menubar.help.openPropDir=\u67E5\u770B\u7CFB\u7EDF\u5C5E\u6027
core.menubar.help.openUserData=\u67E5\u770B\u7528\u6237\u6570\u636E
core.menubar.help.release=\u68C0\u67E5\u66F4\u65B0
core.menubar.help.helpContent=\u5E2E\u52A9\u6587\u6863
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 unknowIfGuestInDream.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of unknowIfGuestInDream, any associated website, nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

* {
-fx-text-background-color: gray;
}

.infoKey {
-fx-fill: black;
-fx-font-weight: bold;
}

.infoEqu {
-fx-fill: #323338;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/

* {
-fx-text-background-color: white;
-fx-text-background-color: gray;
}

.propertyKey {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading