From 4692e4b43679dcb3e56e637e0556cc002f5e9fed Mon Sep 17 00:00:00 2001 From: octopus_yan Date: Sun, 8 Sep 2024 01:36:17 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0=E7=AA=97=E4=BD=93?= =?UTF-8?q?=E9=98=B4=E5=BD=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../octopusyan/alistgui/config/Context.java | 49 ++++++++----------- src/main/resources/css/root.scss | 10 ++-- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/main/java/cn/octopusyan/alistgui/config/Context.java b/src/main/java/cn/octopusyan/alistgui/config/Context.java index e906c74..cf14ca4 100644 --- a/src/main/java/cn/octopusyan/alistgui/config/Context.java +++ b/src/main/java/cn/octopusyan/alistgui/config/Context.java @@ -4,6 +4,7 @@ import cn.octopusyan.alistgui.base.BaseController; import cn.octopusyan.alistgui.controller.MainController; import cn.octopusyan.alistgui.controller.RootController; import cn.octopusyan.alistgui.controller.SetupController; +import cn.octopusyan.alistgui.manager.ConfigManager; import cn.octopusyan.alistgui.util.FxmlUtil; import javafx.application.Platform; import javafx.beans.binding.StringBinding; @@ -12,13 +13,11 @@ import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.fxml.FXMLLoader; -import javafx.geometry.Insets; -import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.effect.DropShadow; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.util.Callback; +import lombok.Getter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,9 +34,11 @@ public class Context { private static final Logger log = LoggerFactory.getLogger(Context.class); private static Scene scene; private static final IntegerProperty currentViewIndexProperty = new SimpleIntegerProperty(0); + // 获取控制器集合 /** * 控制器集合 */ + @Getter private static final Map> controllers = new HashMap<>(); /** * 默认语言文件 Base Name @@ -61,11 +62,6 @@ public class Context { throw new IllegalStateException("Utility class"); } - // 获取控制器集合 - public static Map> getControllers() { - return controllers; - } - // 获取控制工厂 public static Callback, Object> getControlFactory() { return type -> { @@ -171,39 +167,34 @@ public class Context { private static void loadScene() throws IOException { FXMLLoader loader = FxmlUtil.load("root-view"); loader.setControllerFactory(Context.getControlFactory()); - Parent root = loader.load();//底层面板 -// bindShadow((Pane) root); + //底层面板 + Pane root = loader.load(); Optional.ofNullable(scene).ifPresentOrElse( s -> s.setRoot(root), () -> { - scene = new Scene(root); - URL resource = Objects.requireNonNull(Context.class.getResource("/css/root.css")); + scene = new Scene(root, root.getPrefWidth() + 20, root.getPrefHeight() + 20, Color.TRANSPARENT); + URL resource = Objects.requireNonNull(Context.class.getResource("/css/root-view.css")); scene.getStylesheets().addAll(resource.toExternalForm()); scene.setFill(Color.TRANSPARENT); } ); } - // 设置当前展示的界面 - public static void setCurrentViewIndex(Number newValue) { - currentViewIndexProperty.setValue(newValue); + /** + * 设置当前展示的界面 + * + * @param index 界面Index + */ + public static void setCurrentViewIndex(Number index) { + currentViewIndexProperty.setValue(index); } - // 获取当前展示的界面Index + /** + * 获取当前展示的界面Index + * + * @return 界面Index + */ public static Integer getCurrentViewIndex() { return currentViewIndexProperty.get(); } - - private static void bindShadow(Pane pane) { - Pane root = new Pane(); - root.setPadding(new Insets(20, 20, 20, 20)); - DropShadow dropshadow = new DropShadow();// 阴影向外 - dropshadow.setRadius(10);// 颜色蔓延的距离 - dropshadow.setOffsetX(0);// 水平方向,0则向左右两侧,正则向右,负则向左 - dropshadow.setOffsetY(0);// 垂直方向,0则向上下两侧,正则向下,负则向上 - dropshadow.setSpread(0.1);// 颜色变淡的程度 - dropshadow.setColor(Color.BLACK);// 设置颜色 - root.setEffect(dropshadow);// 绑定指定窗口控件 - root.getChildren().addAll(pane); - } } \ No newline at end of file diff --git a/src/main/resources/css/root.scss b/src/main/resources/css/root.scss index d11c35a..bac8976 100644 --- a/src/main/resources/css/root.scss +++ b/src/main/resources/css/root.scss @@ -2,13 +2,17 @@ * Root **************************************************/ -.root { +.root-pane { -fx-font-size: 15; -fx-font-weight: normal; -} -.root-pane { -fx-background-radius: 15; -fx-border-radius: 15; + + // 窗口阴影 + -fx-background-color: rgba(255, 255, 255, 1); + -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.3), 15, 0, 0, 0); + -fx-background-insets: 20; + -fx-padding: 20; }