diff --git a/src/main/java/org/jcnc/jnotepad/LunchApp.java b/src/main/java/org/jcnc/jnotepad/LunchApp.java index 1a917b1..aa6a15c 100644 --- a/src/main/java/org/jcnc/jnotepad/LunchApp.java +++ b/src/main/java/org/jcnc/jnotepad/LunchApp.java @@ -11,6 +11,7 @@ import org.jcnc.jnotepad.constants.AppConstants; import org.jcnc.jnotepad.constants.TextConstants; import org.jcnc.jnotepad.controller.i18n.LocalizationController; import org.jcnc.jnotepad.manager.ThreadPoolManager; +import org.jcnc.jnotepad.tool.PopUpUtil; import org.jcnc.jnotepad.tool.SingletonUtil; import org.jcnc.jnotepad.tool.UiUtil; import org.jcnc.jnotepad.view.manager.ViewManager; @@ -72,6 +73,8 @@ public class LunchApp extends Application { primaryStage.setWidth(SCENE.getWidth()); primaryStage.setHeight(SCENE.getHeight()); primaryStage.getIcons().add(UiUtil.getAppIcon()); + PopUpUtil.errorAlert("错误", "读写错误", "配置文件读写错误!", null, null); + primaryStage.show(); } diff --git a/src/main/java/org/jcnc/jnotepad/ui/module/CustomSetButton.java b/src/main/java/org/jcnc/jnotepad/ui/module/CustomSetButton.java new file mode 100644 index 0000000..3304417 --- /dev/null +++ b/src/main/java/org/jcnc/jnotepad/ui/module/CustomSetButton.java @@ -0,0 +1,13 @@ +package org.jcnc.jnotepad.ui.module; + +import javafx.scene.control.Button; + +/** + * @author luke + */ +public class CustomSetButton extends Button { + public CustomSetButton(String text) { + // 设置按钮文本 + setText(text); + } +} diff --git a/src/main/java/org/jcnc/jnotepad/ui/module/SettingsComponent.java b/src/main/java/org/jcnc/jnotepad/ui/module/SettingsComponent.java new file mode 100644 index 0000000..6d82278 --- /dev/null +++ b/src/main/java/org/jcnc/jnotepad/ui/module/SettingsComponent.java @@ -0,0 +1,78 @@ +package org.jcnc.jnotepad.ui.module; + +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.control.Label; +import javafx.scene.control.Button; +import javafx.scene.layout.VBox; + +/** + * 设置组件类,用于创建一个包含标签和按钮的垂直布局。 + * + *

+ * 此组件可用于用户界面,提供了设置标签文本、按钮文本和按钮点击事件处理程序的方法。 + *

+ * + *

+ * 示例用法: + *

{@code
+ * SettingsComponent settings = new SettingsComponent("标签文本", "按钮文本");
+ * settings.setButtonAction(event -> {
+ *     // 处理按钮点击事件的逻辑
+ * });
+ * }
+ *

+ * + * @author luke + * @since 1.0.0 + */ +public class SettingsComponent extends VBox { + private final Label label; + private final Button button; + + /** + * 创建一个设置组件实例。 + * + * @param labelText 标签文本 + * @param buttonText 按钮文本 + */ + public SettingsComponent(String labelText, String buttonText) { + setSpacing(10); + + // 初始化标签 + label = new Label(labelText); + + // 创建按钮 + button = new Button(buttonText); + + // 将标签和按钮添加到垂直布局 + getChildren().addAll(label, button); + } + + /** + * 设置标签的文本。 + * + * @param text 新的标签文本 + */ + public void setLabelText(String text) { + label.setText(text); + } + + /** + * 设置按钮的文本。 + * + * @param text 新的按钮文本 + */ + public void setButtonText(String text) { + button.setText(text); + } + + /** + * 设置按钮的点击事件处理程序。 + * + * @param eventHandler 按钮点击事件处理程序 + */ + public void setButtonAction(EventHandler eventHandler) { + button.setOnAction(eventHandler); + } +} diff --git a/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java b/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java new file mode 100644 index 0000000..3280ca1 --- /dev/null +++ b/src/main/java/org/jcnc/jnotepad/ui/setstage/DeveloperDebugStage.java @@ -0,0 +1,60 @@ +package org.jcnc.jnotepad.ui.setstage; + +import javafx.application.Application; +import javafx.geometry.Insets; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.layout.VBox; +import javafx.stage.Stage; +import org.jcnc.jnotepad.tool.PopUpUtil; + +/** + * @author luke + */ +public class DeveloperDebugStage extends Stage { + + public void start(Stage primaryStage) { + // 创建主舞台 + primaryStage.setTitle("开发者调试页面"); + + // 创建一个垂直布局 + VBox root = new VBox(); + root.setPadding(new Insets(20)); + root.setSpacing(10); + + // 添加一些调试功能按钮和标签 + Label titleLabel = new Label("开发者调试页面"); + Button debugButton1 = new Button("错误提示框"); + Button debugButton2 = new Button("调试功能2"); + Button debugButton3 = new Button("调试功能3"); + + // 按钮点击事件处理 + debugButton1.setOnAction(e -> { + // 在这里执行调试功能1的代码 + System.out.println("开发者调试: " + debugButton1.getText() + " 启动!"); + PopUpUtil.errorAlert("错误", "读写错误", "配置文件读写错误!", null, null); + + }); + + debugButton2.setOnAction(e -> { + // 在这里执行调试功能2的代码 + }); + + debugButton3.setOnAction(e -> { + // 在这里执行调试功能3的代码 + }); + + // 将组件添加到布局中 + root.getChildren().addAll(titleLabel, debugButton1, debugButton2, debugButton3); + + // 创建场景 + Scene scene = new Scene(root, 400, 300); + + // 将场景添加到舞台 + primaryStage.setScene(scene); + + // 显示舞台 + primaryStage.show(); + } +} diff --git a/src/main/java/org/jcnc/jnotepad/ui/setstage/SetStage.java b/src/main/java/org/jcnc/jnotepad/ui/setstage/SetStage.java index 3524a01..a0aa1f5 100644 --- a/src/main/java/org/jcnc/jnotepad/ui/setstage/SetStage.java +++ b/src/main/java/org/jcnc/jnotepad/ui/setstage/SetStage.java @@ -1,5 +1,6 @@ package org.jcnc.jnotepad.ui.setstage; +import atlantafx.base.theme.Styles; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; @@ -9,14 +10,29 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; import javafx.stage.Stage; +import org.jcnc.jnotepad.tool.UiUtil; +import org.jcnc.jnotepad.ui.module.CustomSetButton; +import org.jcnc.jnotepad.ui.module.SettingsComponent; + +import static org.jcnc.jnotepad.constants.AppConstants.SCREEN_LENGTH; +import static org.jcnc.jnotepad.constants.AppConstants.SCREEN_WIDTH; /** * SetStage类表示设置窗口的单例对象。此窗口用于显示不同的设置选项和其对应的布局。 * 通过调用getInstance方法获取SetStage的实例,并使用openSetStage方法打开设置窗口。 + * + * @author luke */ public class SetStage extends Stage { + public static final String GENERAL_SETTING_1 = "常规设置项1"; + public static final String GENERAL_SETTING_2 = "常规设置项2"; + public static final String APPEARANCE_SETTING_1 = "外观设置项1"; + public static final String APPEARANCE_SETTING_2 = "外观设置项2"; + public static final String SECURITY_SETTING_1 = "安全设置项1"; + public static final String SECURITY_SETTING_2 = "安全设置项2"; private static SetStage instance; private StackPane contentDisplay; @@ -46,7 +62,6 @@ public class SetStage extends Stage { primaryStage.setTitle("设置窗口"); - contentDisplay = new StackPane(); TreeView treeView = createTreeView(); @@ -54,21 +69,34 @@ public class SetStage extends Stage { SplitPane splitPane = new SplitPane(treeView, contentDisplay); splitPane.setDividerPositions(0.3); - HBox bottomBox= new HBox(10); + HBox bottomBox = new HBox(10); bottomBox.setAlignment(Pos.CENTER_RIGHT); bottomBox.setStyle("-fx-background-color: rgba(43,43,43,0.12);"); - bottomBox.setPadding(new Insets(10,10,10,10)); - Button confirmButton=new Button(" 确认 "); - Button cancelButton =new Button(" 取消 "); - Button applicationButton =new Button(" 应用 "); - bottomBox.getChildren().addAll(confirmButton,cancelButton,applicationButton); + bottomBox.setPadding(new Insets(5, 15, 5, 0)); + Button confirmButton = new Button(" 确认 "); + confirmButton.setTextFill(Color.WHITE); + + confirmButton.getStyleClass().addAll(Styles.SMALL); + confirmButton.setStyle("-fx-background-color: rgb(54,88,128);"); + CustomSetButton cancelButton = new CustomSetButton(" 取消 "); + cancelButton.setOnAction(event -> { + Stage stage = (Stage) cancelButton.getScene().getWindow(); + stage.close(); + + }); + cancelButton.getStyleClass().addAll(Styles.SMALL); + Button applicationButton = new Button(" 应用 "); + applicationButton.getStyleClass().addAll(Styles.SMALL); + bottomBox.getChildren().addAll(confirmButton, cancelButton, applicationButton); BorderPane root = new BorderPane(); root.setCenter(splitPane); root.setBottom(bottomBox); - Scene scene = new Scene(root, 800, 600); + Scene scene = new Scene(root, SCREEN_WIDTH - 100, SCREEN_LENGTH - 80); + + primaryStage.getIcons().add(UiUtil.getAppIcon()); primaryStage.setScene(scene); primaryStage.show(); @@ -124,14 +152,15 @@ public class SetStage extends Stage { return treeView; } + private Node createLayoutForSelectedItem(String selectedItem) { return switch (selectedItem) { - case "常规设置项1" -> createGeneralSettingsLayout1(); - case "常规设置项2" -> createGeneralSettingsLayout2(); - case "外观设置项1" -> createAppearanceSettingsLayout1(); - case "外观设置项2" -> createAppearanceSettingsLayout2(); - case "安全设置项1" -> createSecuritySettingsLayout1(); - case "安全设置项2" -> createSecuritySettingsLayout2(); + case GENERAL_SETTING_1 -> createGeneralSettingsLayout1(); + case GENERAL_SETTING_2 -> createGeneralSettingsLayout2(); + case APPEARANCE_SETTING_1 -> createAppearanceSettingsLayout1(); + case APPEARANCE_SETTING_2 -> createAppearanceSettingsLayout2(); + case SECURITY_SETTING_1 -> createSecuritySettingsLayout1(); + case SECURITY_SETTING_2 -> createSecuritySettingsLayout2(); default -> null; }; } @@ -142,23 +171,18 @@ public class SetStage extends Stage { * @return 常规设置项1的布局节点 */ private Node createGeneralSettingsLayout1() { - VBox generalLayout = new VBox(); + VBox generalLayout = new VBox(10); + generalLayout.setPadding(new Insets(25)); - // 添加一个Label作为设置项的标题 - Label titleLabel = new Label("常规设置项1"); + SettingsComponent devBox = new SettingsComponent("打开开发者调试页面","开发者调试页面"); + devBox.setButtonAction(event -> { + // 创建并启动DeveloperDebugPage + DeveloperDebugStage debugPage = new DeveloperDebugStage(); + debugPage.start(new Stage()); + }); - // 添加一个TextField用于输入 - TextField textField = new TextField(); - textField.setPromptText("输入设置项1的值"); - // 添加一个CheckBox用于开关 - CheckBox checkBox = new CheckBox("启用设置项1"); - - // 添加一个Button用于保存设置 - Button saveButton = new Button("保存设置"); - - // 将所有节点添加到VBox布局中 - generalLayout.getChildren().addAll(titleLabel, textField, checkBox, saveButton); + generalLayout.getChildren().addAll(devBox); return generalLayout; }