From 38712c33479eab3e788524cafb1dff9fa9c7f69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 7 Oct 2023 16:14:13 +0800 Subject: [PATCH 01/18] =?UTF-8?q?#I806RZ=20state=20to=20=E5=B7=B2=E5=AE=8C?= =?UTF-8?q?=E6=88=90=20=E8=B7=9F=E9=9A=8F=E7=AA=97=E4=BD=93=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BC=B8=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/layout/MenuPane.java | 39 +++++++++++++++++-- src/main/java/com/light/util/FxDataUtil.java | 19 +++++++++ src/main/java/com/light/util/FxUtil.java | 25 ++++++++++++ src/main/java/com/light/view/ManagerView.java | 13 +++++++ 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/light/util/FxDataUtil.java create mode 100644 src/main/java/com/light/view/ManagerView.java diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index f2cd33c..8af7a6d 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -1,12 +1,19 @@ package com.light.layout; +import atlantafx.base.theme.Styles; +import com.light.util.FxDataUtil; +import com.light.util.FxUtil; +import com.light.view.HomeView; import javafx.geometry.Orientation; +import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.Separator; +import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +import javafx.scene.text.Text; import org.kordamp.ikonli.antdesignicons.AntDesignIconsFilled; import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; @@ -16,7 +23,7 @@ import java.util.Optional; public class MenuPane extends StackPane { - private static final String STYLE_SHEET = MenuPane.class.getResource("/css/menu.css").toExternalForm(); + private static final String STYLE_SHEET = FxUtil.getResource("/css/menu.css"); // 顶部导航栏 private final NavItem setting = new NavItem(new FontIcon(AntDesignIconsFilled.SETTING), "设置", null); @@ -28,10 +35,14 @@ public class MenuPane extends StackPane { // 底部导航栏 private final Label downloadLabel = new Label("正在下载", new FontIcon(BootstrapIcons.ARROW_DOWN)); + private final Text downloadLabelText = new Text(FxDataUtil.DOWNLOAD_PROPERTY.getValue().toString()); + private final HBox downloadBox = new HBox(10, downloadLabel, downloadLabelText); private final Label updateLabel = new Label("正在更新", new FontIcon(BootstrapIcons.ARROW_DOWN)); - private final VBox bottomMenu = new VBox(downloadLabel, updateLabel); + private final Text updateLabelText = new Text(FxDataUtil.UPDATE_PROPERTY.getValue().toString()); + private final HBox updateBox = new HBox(10, updateLabel, updateLabelText); + private final VBox bottomMenu = new VBox(downloadBox, updateBox); - private VBox asideContainer = new VBox(topMenu, new Separator(Orientation.HORIZONTAL), dynamicMenu, new Separator(Orientation.HORIZONTAL), bottomMenu); + private final VBox asideContainer = new VBox(topMenu, new Separator(Orientation.HORIZONTAL), dynamicMenu, new Separator(Orientation.HORIZONTAL), bottomMenu); private final ContentPane contentPane; @@ -41,7 +52,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( - new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", null), + new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new HomeView()), new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", null), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); @@ -63,11 +74,31 @@ public class MenuPane extends StackPane { this.downloadLabel.getStyleClass().add("download-label"); this.updateLabel.getStyleClass().add("update-label"); + // 直接设置样式 + downloadBox.setAlignment(Pos.CENTER_LEFT); + downloadLabelText.getStyleClass().addAll(Styles.TEXT, Styles.SUCCESS); + updateBox.setAlignment(Pos.CENTER_LEFT); + updateLabelText.getStyleClass().addAll(Styles.TEXT, Styles.WARNING); + + initEvent(); + } + + /** + * 初始化监听事件 + */ + private void initEvent() { // 加上监听 dynamicMenu.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { Optional.ofNullable(newValue).ifPresent(menuItem -> { contentPane.setContent(menuItem.getContent());//设置内容 }); }); + + FxDataUtil.DOWNLOAD_PROPERTY.addListener((observable, oldValue, newValue) -> { + downloadLabelText.setText(newValue.toString()); + }); + FxDataUtil.UPDATE_PROPERTY.addListener((observable, oldValue, newValue) -> { + updateLabelText.setText(newValue.toString()); + }); } } diff --git a/src/main/java/com/light/util/FxDataUtil.java b/src/main/java/com/light/util/FxDataUtil.java new file mode 100644 index 0000000..de69f7b --- /dev/null +++ b/src/main/java/com/light/util/FxDataUtil.java @@ -0,0 +1,19 @@ +package com.light.util; + +import javafx.beans.property.SimpleIntegerProperty; + +/** + * 全局数据工具类 + */ +public final class FxDataUtil { + + /** + * 正在下载数量 + */ + public static final SimpleIntegerProperty DOWNLOAD_PROPERTY = new SimpleIntegerProperty(0); + /** + * 正在更新数量 + */ + public static final SimpleIntegerProperty UPDATE_PROPERTY = new SimpleIntegerProperty(0); + +} diff --git a/src/main/java/com/light/util/FxUtil.java b/src/main/java/com/light/util/FxUtil.java index c8bb440..853701b 100644 --- a/src/main/java/com/light/util/FxUtil.java +++ b/src/main/java/com/light/util/FxUtil.java @@ -20,18 +20,43 @@ import java.util.concurrent.Callable; */ public class FxUtil { + /** + * 获取资源文件 + * @param resources + * @return + */ public static String getResource(String resources) { return FxUtil.class.getResource(resources).toExternalForm(); } + /** + * 获取图片 + * @param resources + * @return + */ public static Image getImage(String resources) { return new Image(getResource(resources)); } + /** + * 获取图片组件 + * + * @param resources + * @param size + * @return + */ public static ImageView getImageView(String resources, double size) { return getImageView(resources, size, size); } + /** + * 获取图片组件 + * + * @param resources + * @param height + * @param width + * @return + */ public static ImageView getImageView(String resources, double height, double width) { ImageView imageView = new ImageView(getResource(resources)); imageView.setFitHeight(height); diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java new file mode 100644 index 0000000..0ebd552 --- /dev/null +++ b/src/main/java/com/light/view/ManagerView.java @@ -0,0 +1,13 @@ +package com.light.view; + +import javafx.scene.layout.StackPane; + +public class ManagerView extends StackPane { + + public ManagerView() { + } + + public void initialize() { + + } +} -- Gitee From 64546438d959a8159c1dcfaef64d276e1b12cc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 7 Oct 2023 17:59:39 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 3 +- src/main/java/com/light/layout/MenuPane.java | 3 +- src/main/java/com/light/util/FxDataUtil.java | 6 ++ src/main/java/com/light/view/ManagerView.java | 102 ++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index 9ca0696..8683acb 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -1,5 +1,6 @@ package com.light; +import atlantafx.base.theme.Dracula; import atlantafx.base.theme.PrimerLight; import com.light.layout.ContentPane; import com.light.layout.MenuPane; @@ -23,7 +24,7 @@ public class GitManagerApp extends Application { @Override public void start(Stage stage) throws Exception { // 主题 - Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet()); + Application.setUserAgentStylesheet(new Dracula().getUserAgentStylesheet()); // 根节点 StackPane root = new StackPane(); diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 8af7a6d..799cc93 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -4,6 +4,7 @@ import atlantafx.base.theme.Styles; import com.light.util.FxDataUtil; import com.light.util.FxUtil; import com.light.view.HomeView; +import com.light.view.ManagerView; import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.control.Label; @@ -53,7 +54,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new HomeView()), - new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", null), + new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", new ManagerView()), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); dynamicMenu.getSelectionModel().selectFirst(); diff --git a/src/main/java/com/light/util/FxDataUtil.java b/src/main/java/com/light/util/FxDataUtil.java index de69f7b..2514a4b 100644 --- a/src/main/java/com/light/util/FxDataUtil.java +++ b/src/main/java/com/light/util/FxDataUtil.java @@ -1,6 +1,10 @@ package com.light.util; +import com.light.view.ManagerView; import javafx.beans.property.SimpleIntegerProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.control.TableColumn; /** * 全局数据工具类 @@ -16,4 +20,6 @@ public final class FxDataUtil { */ public static final SimpleIntegerProperty UPDATE_PROPERTY = new SimpleIntegerProperty(0); + public static final ObservableList GIT_PROJECT_OBSERVABLE_LIST = FXCollections.observableArrayList(); + } diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 0ebd552..cc399cc 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -1,13 +1,115 @@ package com.light.view; +import atlantafx.base.controls.CustomTextField; +import com.light.util.FxDataUtil; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.scene.control.CheckBox; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableView; +import javafx.scene.control.cell.CheckBoxTableCell; +import javafx.scene.control.cell.ChoiceBoxTableCell; +import javafx.scene.control.cell.TextFieldTableCell; +import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; +import org.kordamp.ikonli.javafx.FontIcon; public class ManagerView extends StackPane { + private CustomTextField searchField; + + private TableView tableView; + + private final VBox vBox = new VBox(10); + public ManagerView() { + initialize(); } public void initialize() { + searchField = new CustomTextField(); + searchField.setLeft(new FontIcon(BootstrapIcons.SEARCH)); + + initTable(); + VBox.setVgrow(tableView, Priority.ALWAYS); + + vBox.getChildren().addAll(searchField, tableView); + this.getChildren().add(vBox); + + initData(); + initEvent(); + } + + public void initTable() { + var selectAll = new CheckBox(); + + var col0 = new TableColumn(); + col0.setGraphic(selectAll); + col0.setSortable(false); + col0.setCellFactory(CheckBoxTableCell.forTableColumn(col0)); + col0.setCellValueFactory(param -> param.getValue().status()); + col0.setEditable(true); + + var col1 = new TableColumn("仓库"); + col1.setCellFactory(TextFieldTableCell.forTableColumn()); + col1.setCellValueFactory( + c -> new SimpleStringProperty(c.getValue().name()) + ); + + var col2 = new TableColumn("作者"); + col2.setCellFactory(TextFieldTableCell.forTableColumn()); + col2.setCellValueFactory( + c -> new SimpleStringProperty(c.getValue().author()) + ); + + var col3 = new TableColumn("分支"); + col3.setCellFactory(ChoiceBoxTableCell.forTableColumn( + "master", "develop" + )); + col3.setCellValueFactory( + c -> new SimpleStringProperty(c.getValue().branch()) + ); + + var col4 = new TableColumn("更新时间"); + col4.setCellFactory(TextFieldTableCell.forTableColumn()); + col4.setCellValueFactory( + c -> new SimpleStringProperty(c.getValue().updateTime()) + ); + + tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); + tableView.getColumns().setAll(col0, col1, col2, col3, col4); + tableView.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY); + tableView.getSelectionModel().selectFirst(); + selectAll.setOnAction(evt -> { + tableView.getItems().forEach( + item -> item.status().set(selectAll.isSelected()) + ); + evt.consume(); + }); + + tableView.setMaxWidth(Double.MAX_VALUE); + tableView.setMinHeight(300); + tableView.setEditable(true); + } + + public void initData() { + FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.add( + new GitProject("git", "project", "develop", "2023-09-30", + new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); + } + + public void initEvent() { + + } + public record GitProject(String name, + String author, + String branch, + String updateTime, + SimpleDoubleProperty downloadRate, + SimpleBooleanProperty status) { } } -- Gitee From 58d6480640361a33c786572b176ce0638714a4b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 7 Oct 2023 22:16:54 +0800 Subject: [PATCH 03/18] =?UTF-8?q?+=20=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 2 +- src/main/java/com/light/layout/MenuPane.java | 3 +-- src/main/java/com/light/view/ManagerView.java | 5 ++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index 8683acb..8d34273 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -24,7 +24,7 @@ public class GitManagerApp extends Application { @Override public void start(Stage stage) throws Exception { // 主题 - Application.setUserAgentStylesheet(new Dracula().getUserAgentStylesheet()); + Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet()); // 根节点 StackPane root = new StackPane(); diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 799cc93..9806793 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -3,7 +3,6 @@ package com.light.layout; import atlantafx.base.theme.Styles; import com.light.util.FxDataUtil; import com.light.util.FxUtil; -import com.light.view.HomeView; import com.light.view.ManagerView; import javafx.geometry.Orientation; import javafx.geometry.Pos; @@ -53,7 +52,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( - new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new HomeView()), + new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", null), new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", new ManagerView()), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index cc399cc..00ebea9 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -5,7 +5,9 @@ import com.light.util.FxDataUtil; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ObservableValue; import javafx.scene.control.CheckBox; +import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.CheckBoxTableCell; @@ -14,6 +16,7 @@ import javafx.scene.control.cell.TextFieldTableCell; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +import javafx.util.Callback; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; @@ -81,7 +84,7 @@ public class ManagerView extends StackPane { tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); tableView.getColumns().setAll(col0, col1, col2, col3, col4); - tableView.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY); + tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tableView.getSelectionModel().selectFirst(); selectAll.setOnAction(evt -> { tableView.getItems().forEach( -- Gitee From c5965bd6ac2fea838ceedb4320ec16032f3b7ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sat, 7 Oct 2023 22:55:37 +0800 Subject: [PATCH 04/18] =?UTF-8?q?+=20=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 92 +++++++++---------- 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 00ebea9..6c5f895 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -1,31 +1,37 @@ package com.light.view; import atlantafx.base.controls.CustomTextField; +import atlantafx.base.theme.Styles; +import atlantafx.base.theme.Tweaks; import com.light.util.FxDataUtil; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleStringProperty; -import javafx.beans.value.ObservableValue; +import javafx.scene.control.Button; import javafx.scene.control.CheckBox; -import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.ChoiceBoxTableCell; -import javafx.scene.control.cell.TextFieldTableCell; +import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import javafx.util.Callback; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; public class ManagerView extends StackPane { + // 上半部分:搜索、更新 private CustomTextField searchField; + private final Button updateButton = new Button("更新"); + private final HBox hBox = new HBox(5); + // 表格 + private final CheckBox selectAll = new CheckBox(); private TableView tableView; + // 整体 private final VBox vBox = new VBox(10); public ManagerView() { @@ -35,11 +41,16 @@ public class ManagerView extends StackPane { public void initialize() { searchField = new CustomTextField(); searchField.setLeft(new FontIcon(BootstrapIcons.SEARCH)); + updateButton.setMnemonicParsing(true); + hBox.getChildren().addAll(searchField, updateButton); + HBox.setHgrow(searchField, Priority.ALWAYS); + // 初始化表格 initTable(); + + vBox.getChildren().addAll(hBox, tableView); VBox.setVgrow(tableView, Priority.ALWAYS); - vBox.getChildren().addAll(searchField, tableView); this.getChildren().add(vBox); initData(); @@ -47,52 +58,31 @@ public class ManagerView extends StackPane { } public void initTable() { - var selectAll = new CheckBox(); - - var col0 = new TableColumn(); - col0.setGraphic(selectAll); - col0.setSortable(false); - col0.setCellFactory(CheckBoxTableCell.forTableColumn(col0)); - col0.setCellValueFactory(param -> param.getValue().status()); - col0.setEditable(true); - - var col1 = new TableColumn("仓库"); - col1.setCellFactory(TextFieldTableCell.forTableColumn()); - col1.setCellValueFactory( - c -> new SimpleStringProperty(c.getValue().name()) - ); - - var col2 = new TableColumn("作者"); - col2.setCellFactory(TextFieldTableCell.forTableColumn()); - col2.setCellValueFactory( - c -> new SimpleStringProperty(c.getValue().author()) - ); - - var col3 = new TableColumn("分支"); - col3.setCellFactory(ChoiceBoxTableCell.forTableColumn( - "master", "develop" - )); - col3.setCellValueFactory( - c -> new SimpleStringProperty(c.getValue().branch()) - ); - - var col4 = new TableColumn("更新时间"); - col4.setCellFactory(TextFieldTableCell.forTableColumn()); - col4.setCellValueFactory( - c -> new SimpleStringProperty(c.getValue().updateTime()) - ); + var select = new TableColumn(); + select.setGraphic(selectAll); + select.setSortable(false); + select.setCellFactory(CheckBoxTableCell.forTableColumn(select)); + select.setCellValueFactory(param -> param.getValue().status()); + select.setEditable(true); + + var warehouse = new TableColumn("仓库"); + warehouse.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().name())); + + var author = new TableColumn("作者"); + author.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().author())); + + var branch = new TableColumn("分支"); + branch.setCellFactory(ChoiceBoxTableCell.forTableColumn("master", "develop")); + branch.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().branch())); + + var updateTime = new TableColumn("更新时间"); + updateTime.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().updateTime())); tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); - tableView.getColumns().setAll(col0, col1, col2, col3, col4); + tableView.getColumns().setAll(select, warehouse, author, branch, updateTime); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); + tableView.getStyleClass().addAll(Tweaks.EDGE_TO_EDGE, Styles.BORDERED); tableView.getSelectionModel().selectFirst(); - selectAll.setOnAction(evt -> { - tableView.getItems().forEach( - item -> item.status().set(selectAll.isSelected()) - ); - evt.consume(); - }); - tableView.setMaxWidth(Double.MAX_VALUE); tableView.setMinHeight(300); tableView.setEditable(true); @@ -105,7 +95,13 @@ public class ManagerView extends StackPane { } public void initEvent() { - + // 全选按钮事件 + selectAll.setOnAction(event -> { + tableView.getItems().forEach( + item -> item.status().set(selectAll.isSelected()) + ); + event.consume(); + }); } public record GitProject(String name, -- Gitee From 03c65a7cec002ebdbc45889d3690cc17fc843cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 8 Oct 2023 09:16:46 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 6c5f895..d2592fd 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -7,6 +7,7 @@ import com.light.util.FxDataUtil; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleStringProperty; +import javafx.geometry.Insets; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.TableColumn; @@ -25,6 +26,7 @@ public class ManagerView extends StackPane { // 上半部分:搜索、更新 private CustomTextField searchField; private final Button updateButton = new Button("更新"); + private final Button addLocalButton = new Button("添加本地项目"); private final HBox hBox = new HBox(5); // 表格 @@ -41,14 +43,17 @@ public class ManagerView extends StackPane { public void initialize() { searchField = new CustomTextField(); searchField.setLeft(new FontIcon(BootstrapIcons.SEARCH)); + addLocalButton.setMnemonicParsing(true); updateButton.setMnemonicParsing(true); - hBox.getChildren().addAll(searchField, updateButton); + hBox.getChildren().addAll(searchField, addLocalButton, updateButton); + hBox.setPadding(new Insets(5, 0, 0, 0)); HBox.setHgrow(searchField, Priority.ALWAYS); // 初始化表格 initTable(); vBox.getChildren().addAll(hBox, tableView); + vBox.setPadding(new Insets(0, 1, 0, 1)); VBox.setVgrow(tableView, Priority.ALWAYS); this.getChildren().add(vBox); @@ -62,7 +67,7 @@ public class ManagerView extends StackPane { select.setGraphic(selectAll); select.setSortable(false); select.setCellFactory(CheckBoxTableCell.forTableColumn(select)); - select.setCellValueFactory(param -> param.getValue().status()); + select.setCellValueFactory(param -> param.getValue().selected()); select.setEditable(true); var warehouse = new TableColumn("仓库"); @@ -91,14 +96,14 @@ public class ManagerView extends StackPane { public void initData() { FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.add( new GitProject("git", "project", "develop", "2023-09-30", - new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); + "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); } public void initEvent() { // 全选按钮事件 selectAll.setOnAction(event -> { tableView.getItems().forEach( - item -> item.status().set(selectAll.isSelected()) + item -> item.selected().set(selectAll.isSelected()) ); event.consume(); }); @@ -107,8 +112,14 @@ public class ManagerView extends StackPane { public record GitProject(String name, String author, String branch, + String createTime, String updateTime, + String remote, + String local, + String description, + String remark, + int level, SimpleDoubleProperty downloadRate, - SimpleBooleanProperty status) { + SimpleBooleanProperty selected) { } } -- Gitee From 1c2e1e541fe07c7e7bf643b29da390ef3003782c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 8 Oct 2023 10:11:51 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/model/GitProject.java | 19 ++++++++++ src/main/java/com/light/util/FxDataUtil.java | 5 +-- src/main/java/com/light/view/HomeView.java | 21 ++++++++++ src/main/java/com/light/view/ManagerView.java | 38 +++++++++---------- 4 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/light/model/GitProject.java create mode 100644 src/main/java/com/light/view/HomeView.java diff --git a/src/main/java/com/light/model/GitProject.java b/src/main/java/com/light/model/GitProject.java new file mode 100644 index 0000000..1d84f6c --- /dev/null +++ b/src/main/java/com/light/model/GitProject.java @@ -0,0 +1,19 @@ +package com.light.model; + +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; + +public record GitProject(String id, + String name, + String author, + String branch, + String createTime, + String updateTime, + String remote, + String local, + String description, + String remark, + int level, + SimpleDoubleProperty downloadRate, + SimpleBooleanProperty selected) { +} diff --git a/src/main/java/com/light/util/FxDataUtil.java b/src/main/java/com/light/util/FxDataUtil.java index 2514a4b..f7c7f76 100644 --- a/src/main/java/com/light/util/FxDataUtil.java +++ b/src/main/java/com/light/util/FxDataUtil.java @@ -1,10 +1,9 @@ package com.light.util; -import com.light.view.ManagerView; +import com.light.model.GitProject; import javafx.beans.property.SimpleIntegerProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.scene.control.TableColumn; /** * 全局数据工具类 @@ -20,6 +19,6 @@ public final class FxDataUtil { */ public static final SimpleIntegerProperty UPDATE_PROPERTY = new SimpleIntegerProperty(0); - public static final ObservableList GIT_PROJECT_OBSERVABLE_LIST = FXCollections.observableArrayList(); + public static final ObservableList GIT_PROJECT_OBSERVABLE_LIST = FXCollections.observableArrayList(); } diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java new file mode 100644 index 0000000..77626dd --- /dev/null +++ b/src/main/java/com/light/view/HomeView.java @@ -0,0 +1,21 @@ +package com.light.view; + +import com.light.util.FxDataUtil; +import javafx.scene.control.TextField; +import javafx.scene.input.KeyCode; +import javafx.scene.layout.StackPane; + +public class HomeView extends StackPane { + public HomeView() { + var tf = new TextField(); + tf.setPromptText("Prompt text"); + tf.setPrefWidth(200); + this.getChildren().add(tf); + + tf.setOnKeyPressed(event -> { + if (event.getCode() == KeyCode.ENTER) { + FxDataUtil.DOWNLOAD_PROPERTY.set(Integer.parseInt(tf.getText())); + } + }); + } +} diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index d2592fd..e5476e0 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -3,9 +3,11 @@ package com.light.view; import atlantafx.base.controls.CustomTextField; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; +import com.light.model.GitProject; import com.light.util.FxDataUtil; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.geometry.Insets; import javafx.scene.control.Button; @@ -69,6 +71,8 @@ public class ManagerView extends StackPane { select.setCellFactory(CheckBoxTableCell.forTableColumn(select)); select.setCellValueFactory(param -> param.getValue().selected()); select.setEditable(true); + var id = new TableColumn("序号"); + id.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().id())); var warehouse = new TableColumn("仓库"); warehouse.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().name())); @@ -80,11 +84,18 @@ public class ManagerView extends StackPane { branch.setCellFactory(ChoiceBoxTableCell.forTableColumn("master", "develop")); branch.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().branch())); - var updateTime = new TableColumn("更新时间"); - updateTime.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().updateTime())); + var level = new TableColumn("学习等级"); + level.setCellValueFactory(c -> new SimpleIntegerProperty(c.getValue().level()).asObject()); + + var process = new TableColumn("进度"); + process.setCellValueFactory(c -> c.getValue().downloadRate().asObject()); + + var operation = new TableColumn("操作"); +// operation.setCellFactory(); + operation.setCellValueFactory(c -> new SimpleStringProperty("")); tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); - tableView.getColumns().setAll(select, warehouse, author, branch, updateTime); + tableView.getColumns().setAll(select, id, warehouse, author, branch, level, process, operation); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tableView.getStyleClass().addAll(Tweaks.EDGE_TO_EDGE, Styles.BORDERED); tableView.getSelectionModel().selectFirst(); @@ -94,8 +105,11 @@ public class ManagerView extends StackPane { } public void initData() { - FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.add( - new GitProject("git", "project", "develop", "2023-09-30", + // TODO 查H2数据库获取数据 + FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.addAll( + new GitProject("1", "git", "project", "develop", "2023-09-30", + "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true)), + new GitProject("2", "git", "project", "develop", "2023-09-30", "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); } @@ -108,18 +122,4 @@ public class ManagerView extends StackPane { event.consume(); }); } - - public record GitProject(String name, - String author, - String branch, - String createTime, - String updateTime, - String remote, - String local, - String description, - String remark, - int level, - SimpleDoubleProperty downloadRate, - SimpleBooleanProperty selected) { - } } -- Gitee From 3fe854b0ffaafa93b11b6630d76c19722c5d0c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Sun, 8 Oct 2023 14:36:32 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/layout/MenuPane.java | 3 +- src/main/java/com/light/view/Home.java | 77 ++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/light/view/Home.java diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 9806793..569eebb 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -3,6 +3,7 @@ package com.light.layout; import atlantafx.base.theme.Styles; import com.light.util.FxDataUtil; import com.light.util.FxUtil; +import com.light.view.Home; import com.light.view.ManagerView; import javafx.geometry.Orientation; import javafx.geometry.Pos; @@ -52,7 +53,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( - new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", null), + new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new Home()), new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", new ManagerView()), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); diff --git a/src/main/java/com/light/view/Home.java b/src/main/java/com/light/view/Home.java new file mode 100644 index 0000000..de85ddf --- /dev/null +++ b/src/main/java/com/light/view/Home.java @@ -0,0 +1,77 @@ +package com.light.view; + +import atlantafx.base.controls.Message; +import atlantafx.base.controls.Notification; +import atlantafx.base.theme.Styles; +import atlantafx.base.util.Animations; +import javafx.animation.FadeTransition; +import javafx.animation.Timeline; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.StackPane; +import javafx.util.Duration; +import org.apache.commons.lang3.StringUtils; +import org.kordamp.ikonli.javafx.FontIcon; + +import java.io.File; + +public class Home extends BorderPane { + + //首页是一个输入框 让用户键入代码存放路径 + public Home(){ + //输入框横向布局 + HBox hBox1 = new HBox(10); + hBox1.setAlignment(Pos.CENTER); + //错误提示横向布局 + HBox hBox2 = new HBox(10); + hBox2.setAlignment(Pos.CENTER); + //错误提示 + var danger = new Message("Danger", null); + danger.getStyleClass().add(Styles.DANGER); + + //输入框 + var textField = new TextField(); + textField.setPromptText("请输入代码存放路径"); + textField.setMinWidth(500); + //加载按钮 + Button load = new Button("加载"); + load.setOnAction(btn -> { + System.out.println("用户输入路径:" + textField.getText()); + try{ + File file = new File(textField.getText()); + if(file.exists()){ + //todo 输入正确,读取文件夹中内容 + + }else{ + danger.setDescription("该路径不存在或路径下无内容"); + } + }catch (Exception e){ + danger.setDescription("路径不正确"); + } + + if(StringUtils.isNotEmpty(danger.getDescription())){ + hBox2.getChildren().add(danger); + FadeTransition ft = new FadeTransition(); + ft.setDuration(Duration.seconds(4)); + ft.setNode(danger); + ft.setFromValue(1.0); + ft.setToValue(0.0); + ft.play(); + ft.setOnFinished(event -> { + danger.setDescription(null); + hBox2.getChildren().remove(danger); + }); + } + }); + hBox1.getChildren().addAll(textField,load); + + this.setTop(hBox2); + this.setCenter(hBox1); + } + +} -- Gitee From 3ca0e4a565276b6d373a0cb47a3926f52435784e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 8 Oct 2023 14:42:07 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/HomeView.java | 21 ----- src/main/java/com/light/view/ManagerView.java | 90 ++++++++++++++++--- 2 files changed, 79 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/com/light/view/HomeView.java diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java deleted file mode 100644 index 77626dd..0000000 --- a/src/main/java/com/light/view/HomeView.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.light.view; - -import com.light.util.FxDataUtil; -import javafx.scene.control.TextField; -import javafx.scene.input.KeyCode; -import javafx.scene.layout.StackPane; - -public class HomeView extends StackPane { - public HomeView() { - var tf = new TextField(); - tf.setPromptText("Prompt text"); - tf.setPrefWidth(200); - this.getChildren().add(tf); - - tf.setOnKeyPressed(event -> { - if (event.getCode() == KeyCode.ENTER) { - FxDataUtil.DOWNLOAD_PROPERTY.set(Integer.parseInt(tf.getText())); - } - }); - } -} diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index e5476e0..45d8f72 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -9,20 +9,22 @@ import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; +import javafx.collections.FXCollections; import javafx.geometry.Insets; -import javafx.scene.control.Button; -import javafx.scene.control.CheckBox; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; +import javafx.scene.control.*; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.ChoiceBoxTableCell; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +import javafx.util.Callback; +import org.apache.commons.lang3.StringUtils; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; +import java.util.List; + public class ManagerView extends StackPane { // 上半部分:搜索、更新 @@ -45,6 +47,7 @@ public class ManagerView extends StackPane { public void initialize() { searchField = new CustomTextField(); searchField.setLeft(new FontIcon(BootstrapIcons.SEARCH)); + searchField.setPromptText("请输入仓库名称或者作者名称进行搜索..."); addLocalButton.setMnemonicParsing(true); updateButton.setMnemonicParsing(true); hBox.getChildren().addAll(searchField, addLocalButton, updateButton); @@ -71,8 +74,15 @@ public class ManagerView extends StackPane { select.setCellFactory(CheckBoxTableCell.forTableColumn(select)); select.setCellValueFactory(param -> param.getValue().selected()); select.setEditable(true); + select.setPrefWidth(40d); + select.setMaxWidth(40d); + select.setMinWidth(40d); + var id = new TableColumn("序号"); id.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().id())); + id.setPrefWidth(50d); + id.setMaxWidth(50d); + id.setMinWidth(50d); var warehouse = new TableColumn("仓库"); warehouse.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().name())); @@ -91,8 +101,11 @@ public class ManagerView extends StackPane { process.setCellValueFactory(c -> c.getValue().downloadRate().asObject()); var operation = new TableColumn("操作"); -// operation.setCellFactory(); - operation.setCellValueFactory(c -> new SimpleStringProperty("")); + operation.setCellFactory(param -> new OperationTableCell()); + operation.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().id())); + operation.setPrefWidth(120d); + operation.setMaxWidth(120d); + operation.setMinWidth(120d); tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); tableView.getColumns().setAll(select, id, warehouse, author, branch, level, process, operation); @@ -102,15 +115,30 @@ public class ManagerView extends StackPane { tableView.setMaxWidth(Double.MAX_VALUE); tableView.setMinHeight(300); tableView.setEditable(true); + + tableView.setRowFactory(new Callback, TableRow>() { + @Override + public TableRow call(TableView param) { + return new TableRow() { + @Override + protected void updateItem(GitProject item, boolean empty) { + super.updateItem(item, empty); + if (!empty) { + setTooltip(new Tooltip(item.author())); + } + } + }; + } + }); } public void initData() { // TODO 查H2数据库获取数据 - FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.addAll( - new GitProject("1", "git", "project", "develop", "2023-09-30", - "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true)), - new GitProject("2", "git", "project", "develop", "2023-09-30", - "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); + for (int i = 0; i < 10000000; i++) { + FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.addAll( + new GitProject(i + "", "g" + i + "it", "project", "develop", "2023-09-30", + "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); + } } public void initEvent() { @@ -121,5 +149,45 @@ public class ManagerView extends StackPane { ); event.consume(); }); + + searchField.setOnKeyReleased(event -> { + String text = searchField.getText(); + if (StringUtils.isNotBlank(text)) { + List list; + if (FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.size() > 10000) { + list = FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST. + parallelStream().filter(param -> param.name().contains(text) || param.author().contains(text)).toList(); + } else { + list = FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST. + stream().filter(param -> param.name().contains(text) || param.author().contains(text)).toList(); + } + tableView.setItems(FXCollections.observableList(list)); + } else { + tableView.setItems(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); + } + }); + } + + private class OperationTableCell extends TableCell { + Button updateButton = new Button("更新"); + Button detailButton = new Button("详情"); + HBox operationBOx = new HBox(updateButton, detailButton); + + public OperationTableCell() { + updateButton.getStyleClass().addAll(Styles.FLAT, Styles.ACCENT); + updateButton.setMnemonicParsing(true); + detailButton.getStyleClass().addAll(Styles.FLAT, Styles.SUCCESS); + detailButton.setMnemonicParsing(true); + } + + @Override + protected void updateItem(String item, boolean empty) { + super.updateItem(item, empty); + if (empty) { + setGraphic(null); + } else { + setGraphic(operationBOx); + } + } } } -- Gitee From f8463c58472191df61514a59451e9450005b65f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Sun, 8 Oct 2023 15:32:23 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8F=90=E7=A4=BA=EF=BC=8C=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=A1=86=E6=97=A0=E8=BE=B9=E6=A1=86=E5=92=8C?= =?UTF-8?q?=E9=98=B4=E5=BD=B1=EF=BC=8C=E5=B7=AE=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/enums/Level.java | 36 ++++++ src/main/java/com/light/layout/MenuPane.java | 4 +- .../java/com/light/util/AnimationUtils.java | 106 ++++++++++++++++++ src/main/java/com/light/util/NoticeUtils.java | 80 +++++++++++++ .../light/view/{Home.java => HomeView.java} | 66 ++++------- 5 files changed, 244 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/light/enums/Level.java create mode 100644 src/main/java/com/light/util/AnimationUtils.java create mode 100644 src/main/java/com/light/util/NoticeUtils.java rename src/main/java/com/light/view/{Home.java => HomeView.java} (33%) diff --git a/src/main/java/com/light/enums/Level.java b/src/main/java/com/light/enums/Level.java new file mode 100644 index 0000000..cb3ecad --- /dev/null +++ b/src/main/java/com/light/enums/Level.java @@ -0,0 +1,36 @@ +package com.light.enums; + +import javafx.scene.Node; +import org.kordamp.ikonli.Ikon; +import org.kordamp.ikonli.antdesignicons.AntDesignIconsFilled; + +import java.util.Arrays; +import java.util.List; + +public enum Level { + PRIMARY(AntDesignIconsFilled.MESSAGE), + SUCCESS(AntDesignIconsFilled.CHECK_CIRCLE), + INFO(AntDesignIconsFilled.INFO_CIRCLE), + WARN(AntDesignIconsFilled.EXCLAMATION_CIRCLE), + DANGER(AntDesignIconsFilled.CLOSE_CIRCLE); + + Level(Ikon ikon) { + this.ikon = ikon; + } + + private Ikon ikon; + + public Ikon getIkon() { + return ikon; + } + + public String getStyleClass() { + return name().toLowerCase(); + } + + public void resetStyleClass(Node node) { + List strings = Arrays.stream(values()).map(Level::getStyleClass).toList(); + node.getStyleClass().removeAll(strings);// 删除之前的StyleClass + node.getStyleClass().add(getStyleClass()); // 添加新的StyleClass + } +} diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 569eebb..799cc93 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -3,7 +3,7 @@ package com.light.layout; import atlantafx.base.theme.Styles; import com.light.util.FxDataUtil; import com.light.util.FxUtil; -import com.light.view.Home; +import com.light.view.HomeView; import com.light.view.ManagerView; import javafx.geometry.Orientation; import javafx.geometry.Pos; @@ -53,7 +53,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( - new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new Home()), + new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new HomeView()), new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", new ManagerView()), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); diff --git a/src/main/java/com/light/util/AnimationUtils.java b/src/main/java/com/light/util/AnimationUtils.java new file mode 100644 index 0000000..d065ea1 --- /dev/null +++ b/src/main/java/com/light/util/AnimationUtils.java @@ -0,0 +1,106 @@ +package com.light.util; + +import javafx.animation.Interpolator; +import javafx.animation.KeyFrame; +import javafx.animation.KeyValue; +import javafx.animation.Timeline; +import javafx.beans.value.WritableValue; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.util.Duration; + +import java.util.ArrayList; +import java.util.List; + +/** + * 简单动画工具类 + */ +public class AnimationUtils { + + /** + * 并行动画 + *
+ * 注意:target,startValue,endValue 长度必须一致 + * + * @param duration 执行时间,默认从0开始 + * @param targets + * @param startValue 开始值 + * @param endValue 结束值 + * @param finishedHandler 动画结束事件 + * @param + * @return + */ + public static Timeline parallel(Duration duration, + WritableValue[] targets, + T[] startValue, + T[] endValue, + EventHandler finishedHandler) { + return parallel(duration, targets, startValue, endValue, finishedHandler, false, Duration.ZERO); + } + + /** + * 并行动画 + *
+ * 注意:target,startValue,endValue 长度必须一致 + * + * @param duration 执行时间,默认从0开始 + * @param targets + * @param startValue 开始值 + * @param endValue 结束值 + * @param finishedHandler 动画结束事件 + * @param autoReverse 自动倒带 + * @param + * @return + */ + public static Timeline parallel(Duration duration, + WritableValue[] targets, + T[] startValue, + T[] endValue, + EventHandler finishedHandler, + boolean autoReverse) { + return parallel(duration, targets, startValue, endValue, finishedHandler, autoReverse, Duration.ZERO); + } + + /** + * 并行动画 + *
+ * 注意:target,startValue,endValue 长度必须一致 + * + * @param duration 执行时间,默认从0开始 + * @param targets + * @param startValue 开始值 + * @param endValue 结束值 + * @param finishedHandler 动画结束事件 + * @param autoReverse 自动倒带 + * @param pause 动画完成之前的暂停时间*2 + * @param + * @return + */ + public static Timeline parallel(Duration duration, + WritableValue[] targets, + T[] startValue, + T[] endValue, + EventHandler finishedHandler, + boolean autoReverse, + Duration pause) { + final Timeline timeline = new Timeline(); + List startKeyValues = new ArrayList<>(); + List endKeyValues = new ArrayList<>(); + for (int i = 0; i < targets.length; i++) { + WritableValue writableValue = targets[i]; + startKeyValues.add(new KeyValue(writableValue, startValue[i], Interpolator.LINEAR)); + endKeyValues.add(new KeyValue(writableValue, endValue[i], Interpolator.LINEAR)); + } + KeyFrame startKeyFrame = new KeyFrame(Duration.ZERO, startKeyValues.toArray(new KeyValue[0])); + KeyFrame endKeyFrame = new KeyFrame(duration, endKeyValues.toArray(new KeyValue[0])); + timeline.getKeyFrames().setAll(startKeyFrame, endKeyFrame); + if (pause.toMillis() != 0) { + timeline.getKeyFrames().add(new KeyFrame(duration.add(pause))); // 暂停动画 + } + timeline.setCycleCount(autoReverse ? 2 : 1); + timeline.setAutoReverse(autoReverse); + timeline.setOnFinished(finishedHandler); + return timeline; + } + +} diff --git a/src/main/java/com/light/util/NoticeUtils.java b/src/main/java/com/light/util/NoticeUtils.java new file mode 100644 index 0000000..994f0c1 --- /dev/null +++ b/src/main/java/com/light/util/NoticeUtils.java @@ -0,0 +1,80 @@ +package com.light.util; + +import com.light.enums.Level; +import javafx.animation.Timeline; +import javafx.beans.value.WritableValue; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.layout.StackPane; +import javafx.stage.Window; +import javafx.util.Duration; +import org.kordamp.ikonli.javafx.FontIcon; + +import java.util.Optional; + +/** + * 消息提示工具类 + */ +public class NoticeUtils { + + public static void show(Window window, String message, Level level) { + if (window == null) { + window = FxUtil.getFocusedWindow(); + } + Optional.ofNullable(window) + .map(Window::getScene) + .map(Scene::getRoot) + .filter(root -> { + Class nodeClass = root.getClass(); + return StackPane.class == nodeClass; + }) + .map(root -> (StackPane) root) + .ifPresentOrElse( + root -> addMessageNode(root, message, level), + () -> System.err.println("未获取到: Scene | Root | StackPane")); + } + + private static void addMessageNode(StackPane root, String message, Level level) { + Label messageNode = new Label(message); + messageNode.setGraphic(FontIcon.of(level.getIkon())); + messageNode.getStyleClass().addAll("cf-message", level.getStyleClass()); + messageNode.setOpacity(0); + StackPane.setAlignment(messageNode, Pos.TOP_CENTER); + StackPane.setMargin(messageNode, new Insets(30)); + root.getChildren().add(messageNode); + //启动动画 + play(messageNode); + } + + /** + * 开始动画 + * + * @param node + */ + private static void play(Node node) { + Timeline parallel = AnimationUtils.parallel(Duration.millis(250), + new WritableValue[]{node.opacityProperty(), node.translateYProperty()}, + new Object[]{0.0, -20}, + new Object[]{1.0, 0}, + event -> { + // 动画完成,移除该节点。 + node.setDisable(true); // 解决有残影问题 + StackPane parent = (StackPane) node.getParent(); + parent.getChildren().remove(node); + }, true, Duration.seconds(1.5)); + parallel.play(); + // 鼠标移入暂停动画 + node.hoverProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + parallel.pause(); + } else { + parallel.play(); + } + }); + } + +} diff --git a/src/main/java/com/light/view/Home.java b/src/main/java/com/light/view/HomeView.java similarity index 33% rename from src/main/java/com/light/view/Home.java rename to src/main/java/com/light/view/HomeView.java index de85ddf..4272290 100644 --- a/src/main/java/com/light/view/Home.java +++ b/src/main/java/com/light/view/HomeView.java @@ -1,38 +1,26 @@ package com.light.view; -import atlantafx.base.controls.Message; -import atlantafx.base.controls.Notification; -import atlantafx.base.theme.Styles; -import atlantafx.base.util.Animations; -import javafx.animation.FadeTransition; -import javafx.animation.Timeline; +import com.light.enums.Level; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.TextField; -import javafx.scene.image.Image; -import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; -import javafx.scene.layout.StackPane; -import javafx.util.Duration; -import org.apache.commons.lang3.StringUtils; -import org.kordamp.ikonli.javafx.FontIcon; import java.io.File; -public class Home extends BorderPane { +import static com.light.util.NoticeUtils.show; + +public class HomeView extends BorderPane { //首页是一个输入框 让用户键入代码存放路径 - public Home(){ + public HomeView() { //输入框横向布局 - HBox hBox1 = new HBox(10); - hBox1.setAlignment(Pos.CENTER); + HBox inputHBox = new HBox(10); + inputHBox.setAlignment(Pos.CENTER); //错误提示横向布局 - HBox hBox2 = new HBox(10); - hBox2.setAlignment(Pos.CENTER); - //错误提示 - var danger = new Message("Danger", null); - danger.getStyleClass().add(Styles.DANGER); + HBox noticeHBox = new HBox(10); + noticeHBox.setAlignment(Pos.CENTER); //输入框 var textField = new TextField(); @@ -42,36 +30,22 @@ public class Home extends BorderPane { Button load = new Button("加载"); load.setOnAction(btn -> { System.out.println("用户输入路径:" + textField.getText()); - try{ + //错误提示 + try { File file = new File(textField.getText()); - if(file.exists()){ + if (file.exists()) { //todo 输入正确,读取文件夹中内容 - }else{ - danger.setDescription("该路径不存在或路径下无内容"); + } else { + show(null, "该路径不存在或路径下无内容", Level.DANGER); } - }catch (Exception e){ - danger.setDescription("路径不正确"); - } - - if(StringUtils.isNotEmpty(danger.getDescription())){ - hBox2.getChildren().add(danger); - FadeTransition ft = new FadeTransition(); - ft.setDuration(Duration.seconds(4)); - ft.setNode(danger); - ft.setFromValue(1.0); - ft.setToValue(0.0); - ft.play(); - ft.setOnFinished(event -> { - danger.setDescription(null); - hBox2.getChildren().remove(danger); - }); + } catch (Exception e) { + show(null, "路径不正确", Level.DANGER); } }); - hBox1.getChildren().addAll(textField,load); - - this.setTop(hBox2); - this.setCenter(hBox1); + inputHBox.getChildren().addAll(textField, load); + this.setTop(noticeHBox); + this.setCenter(inputHBox); } -} +} \ No newline at end of file -- Gitee From 83d0ae49594f6fd9378f775d3a1788a5984a991c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Sun, 8 Oct 2023 15:34:12 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/module-info.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index f359b55..7463f14 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -11,4 +11,5 @@ open module com.leo { requires org.jetbrains.annotations; requires org.kordamp.ikonli.antdesignicons; requires org.kordamp.ikonli.bootstrapicons; + requires org.kordamp.ikonli.core; } -- Gitee From d30af52bfb5c5c872b964ec6f282f0181a114efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 8 Oct 2023 15:59:19 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E5=A2=9E=E5=8A=A0root=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 6 +- src/main/java/com/light/view/ManagerView.java | 84 +++++++++++++++---- src/main/resources/css/menu.css | 23 ++++- src/main/resources/css/root.css | 22 +++++ 4 files changed, 115 insertions(+), 20 deletions(-) create mode 100644 src/main/resources/css/root.css diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index 8d34273..18e33ff 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -1,15 +1,14 @@ package com.light; -import atlantafx.base.theme.Dracula; import atlantafx.base.theme.PrimerLight; import com.light.layout.ContentPane; import com.light.layout.MenuPane; +import com.light.util.FxUtil; import com.light.util.NodeUtils; import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.image.Image; -import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; @@ -21,6 +20,8 @@ public class GitManagerApp extends Application { public static final Logger LOGGER = LoggerFactory.getLogger(GitManagerApp.class); + private static final String STYLE_SHEET = FxUtil.getResource("/css/root.css"); + @Override public void start(Stage stage) throws Exception { // 主题 @@ -50,6 +51,7 @@ public class GitManagerApp extends Application { stage.setScene(scene); stage.show(); + scene.getStylesheets().add(STYLE_SHEET); LOGGER.info("项目启动完成。。。"); } diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 45d8f72..3626826 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -1,6 +1,8 @@ package com.light.view; +import atlantafx.base.controls.Card; import atlantafx.base.controls.CustomTextField; +import atlantafx.base.controls.Tile; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; import com.light.model.GitProject; @@ -11,6 +13,7 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.geometry.Insets; +import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.ChoiceBoxTableCell; @@ -18,7 +21,8 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import javafx.util.Callback; +import javafx.scene.paint.Color; +import javafx.scene.shape.Circle; import org.apache.commons.lang3.StringUtils; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; @@ -116,25 +120,12 @@ public class ManagerView extends StackPane { tableView.setMinHeight(300); tableView.setEditable(true); - tableView.setRowFactory(new Callback, TableRow>() { - @Override - public TableRow call(TableView param) { - return new TableRow() { - @Override - protected void updateItem(GitProject item, boolean empty) { - super.updateItem(item, empty); - if (!empty) { - setTooltip(new Tooltip(item.author())); - } - } - }; - } - }); + tableView.setRowFactory(param -> new OperationTableRow()); } public void initData() { // TODO 查H2数据库获取数据 - for (int i = 0; i < 10000000; i++) { + for (int i = 0; i < 100; i++) { FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.addAll( new GitProject(i + "", "g" + i + "it", "project", "develop", "2023-09-30", "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); @@ -150,6 +141,7 @@ public class ManagerView extends StackPane { event.consume(); }); + // 搜索框执行逻辑 searchField.setOnKeyReleased(event -> { String text = searchField.getText(); if (StringUtils.isNotBlank(text)) { @@ -168,7 +160,10 @@ public class ManagerView extends StackPane { }); } - private class OperationTableCell extends TableCell { + /** + * 自定义表格 - button + */ + private static class OperationTableCell extends TableCell { Button updateButton = new Button("更新"); Button detailButton = new Button("详情"); HBox operationBOx = new HBox(updateButton, detailButton); @@ -190,4 +185,59 @@ public class ManagerView extends StackPane { } } } + + /** + * 自定义行 - 提示框 + */ + private static class OperationTableRow extends TableRow { + + private Card toolTipCard = new Card(); + private Tooltip tooltip = new Tooltip(); + + public OperationTableRow() { + tooltip.setGraphic(toolTipCard); + tooltip.getStyleClass().removeAll("tooltip"); + initialize(); + } + + @Override + protected void updateItem(GitProject item, boolean empty) { + super.updateItem(item, empty); + if (!empty) { + setTooltip(tooltip); + } + } + + public void initialize() { + + toolTipCard.getStyleClass().add(Styles.ELEVATED_1); + toolTipCard.setMinWidth(300); + toolTipCard.setMaxWidth(300); + + var header2 = new Tile( + "Reviewers", + "Request up to 10 reviewers" + ); + toolTipCard.setHeader(header2); + + var tf2 = new CustomTextField(); + tf2.setPromptText("Search people"); + tf2.setLeft(new FontIcon(BootstrapIcons.SEARCH)); + toolTipCard.setSubHeader(tf2); + + var body2 = new VBox(10); + toolTipCard.setBody(body2); + for (int i = 0; i < 5; i++) { + var cb = new CheckBox(); + var lbl = new Label("123"); + var circle = new Circle( + 8, Color.GRAY + ); + + var row = new HBox(10, circle, cb, lbl); + row.setAlignment(Pos.CENTER_LEFT); + body2.getChildren().add(row); + } + } + } } diff --git a/src/main/resources/css/menu.css b/src/main/resources/css/menu.css index e11cca9..f22296c 100644 --- a/src/main/resources/css/menu.css +++ b/src/main/resources/css/menu.css @@ -107,4 +107,25 @@ .update-label > .ikonli-font-icon { -fx-icon-size: 14px; -fx-icon-color: -cf-success-color; -} \ No newline at end of file +} + +.cf-message{ + -fx-alignment: center-left; + -fx-min-height: 40px; + -fx-graphic-text-gap: 8px; + -fx-padding: 0 10px; + -fx-background-color: rgb(168, 70, 70); + -fx-background-radius:3px; + -fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.2), 10.0, 0, 0, 0); + -fx-text-fill: -cf-text-color; + -fx-font-size: 14px; + -fx-wrap-text: true; +} +.cf-message > .ikonli-font-icon{ + -fx-icon-color: -cf-primary-color; + -fx-icon-size: 18px; +} +.cf-message.success > .ikonli-font-icon{-fx-icon-color: -cf-success-color;} +.cf-message.info > .ikonli-font-icon{-fx-icon-color: -cf-info-color;} +.cf-message.warn > .ikonli-font-icon{-fx-icon-color: -cf-warn-color;} +.cf-message.danger > .ikonli-font-icon{-fx-icon-color: -cf-danger-color;} \ No newline at end of file diff --git a/src/main/resources/css/root.css b/src/main/resources/css/root.css new file mode 100644 index 0000000..6d09662 --- /dev/null +++ b/src/main/resources/css/root.css @@ -0,0 +1,22 @@ +@import "colors.css"; + +.cf-message{ + -fx-alignment: center-left; + -fx-min-height: 40px; + -fx-graphic-text-gap: 8px; + -fx-padding: 0 10px; + -fx-background-color: rgb(255,255,255); + -fx-background-radius:3px; + -fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.2), 10.0, 0, 0, 0); + -fx-text-fill: -cf-text-color; + -fx-font-size: 14px; + -fx-wrap-text: true; +} +.cf-message > .ikonli-font-icon{ + -fx-icon-color: -cf-primary-color; + -fx-icon-size: 18px; +} +.cf-message.success > .ikonli-font-icon{-fx-icon-color: -cf-success-color;} +.cf-message.info > .ikonli-font-icon{-fx-icon-color: -cf-info-color;} +.cf-message.warn > .ikonli-font-icon{-fx-icon-color: -cf-warn-color;} +.cf-message.danger > .ikonli-font-icon{-fx-icon-color: -cf-danger-color;} \ No newline at end of file -- Gitee From af3a467b6f67304f0e1cf080c0875da97ed0464b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Sun, 8 Oct 2023 17:35:05 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AE=A1=E7=90=86=E9=A1=B5=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9C=AC=E6=AC=A1=E9=A1=B9=E7=9B=AE=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/layout/MenuPane.java | 2 +- src/main/java/com/light/view/HomeView.java | 70 +++++++++++-------- src/main/java/com/light/view/ManagerView.java | 69 ++++++++++++++++++ 3 files changed, 112 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 799cc93..3f9395a 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -53,7 +53,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( - new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "首页", new HomeView()), + new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "下载新项目", new HomeView()), new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", new ManagerView()), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); diff --git a/src/main/java/com/light/view/HomeView.java b/src/main/java/com/light/view/HomeView.java index 4272290..c57ba3a 100644 --- a/src/main/java/com/light/view/HomeView.java +++ b/src/main/java/com/light/view/HomeView.java @@ -1,51 +1,65 @@ package com.light.view; import com.light.enums.Level; +import javafx.collections.FXCollections; import javafx.geometry.Pos; import javafx.scene.control.Button; +import javafx.scene.control.ChoiceBox; import javafx.scene.control.TextField; import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; - -import java.io.File; +import javafx.scene.layout.VBox; +import org.apache.commons.lang3.StringUtils; import static com.light.util.NoticeUtils.show; public class HomeView extends BorderPane { - //首页是一个输入框 让用户键入代码存放路径 + //下载新项目 两个输入框 克隆/下载地址 下载到哪里 一个分支复选框 一个下载按钮 + //添加本地项目 展示一个输入框 让用户键入代码存放路径 public HomeView() { - //输入框横向布局 - HBox inputHBox = new HBox(10); - inputHBox.setAlignment(Pos.CENTER); - //错误提示横向布局 - HBox noticeHBox = new HBox(10); - noticeHBox.setAlignment(Pos.CENTER); - - //输入框 - var textField = new TextField(); - textField.setPromptText("请输入代码存放路径"); - textField.setMinWidth(500); - //加载按钮 - Button load = new Button("加载"); - load.setOnAction(btn -> { - System.out.println("用户输入路径:" + textField.getText()); + /** + * 下载新项目 + * 输入框 下载地址 + * 输入框 目的地 + * 复选框 分支 + * 按钮 下载 + */ + //纵向布局 + VBox downloadVBox = new VBox(10); + downloadVBox.setAlignment(Pos.CENTER); + //下载框 + var downloadPath = new TextField(); + downloadPath.setPromptText("请输入下载地址"); + downloadPath.setMaxWidth(600); + //目的地框 + var targetPath = new TextField(); + targetPath.setPromptText("请输入目的地"); + targetPath.setMaxWidth(600); + //分支复选框 + ChoiceBox choiceBox = new ChoiceBox<>(FXCollections.observableArrayList("master", "dev", "A", "B", "C")); + choiceBox.setMaxWidth(600); + choiceBox.setValue("master"); + choiceBox.setOnAction(e -> { + System.out.println(choiceBox.getSelectionModel().getSelectedItem()); + }); + //下载按钮 + Button downloadButton = new Button("下载"); + downloadButton.setOnAction(btn -> { + System.out.println("用户下载路径:" + downloadPath.getText()); + System.out.println("用户目标路径:" + targetPath.getText()); //错误提示 try { - File file = new File(textField.getText()); - if (file.exists()) { - //todo 输入正确,读取文件夹中内容 - + if (StringUtils.isEmpty(downloadPath.getText()) || StringUtils.isEmpty(targetPath.getText())) { + show(null, "请输入路径", Level.WARN); } else { - show(null, "该路径不存在或路径下无内容", Level.DANGER); + //todo 输入正确,读取文件夹中内容 } } catch (Exception e) { - show(null, "路径不正确", Level.DANGER); + show(null, "下载失败,请稍后重试", Level.DANGER); } }); - inputHBox.getChildren().addAll(textField, load); - this.setTop(noticeHBox); - this.setCenter(inputHBox); + downloadVBox.getChildren().addAll(downloadPath, targetPath, choiceBox, downloadButton); + this.setCenter(downloadVBox); } } \ No newline at end of file diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 3626826..59a53fa 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -5,8 +5,10 @@ import atlantafx.base.controls.CustomTextField; import atlantafx.base.controls.Tile; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; +import com.light.enums.Level; import com.light.model.GitProject; import com.light.util.FxDataUtil; +import com.light.util.NoticeUtils; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; @@ -27,8 +29,11 @@ import org.apache.commons.lang3.StringUtils; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; +import java.io.File; import java.util.List; +import static com.light.util.NoticeUtils.show; + public class ManagerView extends StackPane { // 上半部分:搜索、更新 @@ -141,6 +146,56 @@ public class ManagerView extends StackPane { event.consume(); }); + //添加本地项目按钮事件 + addLocalButton.setOnAction(btn -> { + /** + * 添加本地项目 + * 输入框 让用户键入代码存放路径 + * 按钮 加载 + */ + //输入框横向布局 + HBox inputHBox = new HBox(10); + inputHBox.setAlignment(Pos.CENTER); + //错误提示横向布局 + HBox noticeHBox = new HBox(10); + noticeHBox.setAlignment(Pos.CENTER); + + //输入框 + var textField = new TextField(); + textField.setPromptText("请输入代码存放路径"); + textField.setMinWidth(500); + //加载按钮 + Button load = new Button("加载"); + load.setOnAction(loadBtn -> { + System.out.println("用户输入路径:" + textField.getText()); + //错误提示 + try { + if(StringUtils.isEmpty(textField.getText())){ + NoticeUtils.show(null, "请输入路径", Level.WARN); + }else{ + File file = new File(textField.getText()); + if (file.exists()) { + //todo 输入正确,读取文件夹中内容 + + } else { + NoticeUtils.show(null, "该路径不存在或路径下无内容", Level.DANGER); + } + } + } catch (Exception e) { + NoticeUtils.show(null, "路径不正确", Level.DANGER); + } + }); + inputHBox.getChildren().addAll(textField, load); + + var alert = new Alert(Alert.AlertType.INFORMATION); + alert.setTitle("添加本地项目路径"); + alert.setHeaderText(null); + alert.setGraphic(inputHBox); + alert.initOwner(getScene().getWindow()); + this.show(alert); + }); + + // 搜索框执行逻辑 searchField.setOnKeyReleased(event -> { String text = searchField.getText(); @@ -160,6 +215,20 @@ public class ManagerView extends StackPane { }); } + //添加本地项目弹框 + private void show(Dialog alert) { + // copy customized styles, like changed accent color etc + try { + for (var pc : getScene().getRoot().getPseudoClassStates()) { + alert.getDialogPane().pseudoClassStateChanged(pc, true); + } + alert.getDialogPane().getStylesheets().addAll(getScene().getRoot().getStylesheets()); + } catch (Exception ignored) { + // yes, ignored + } + alert.showAndWait(); + } + /** * 自定义表格 - button */ -- Gitee From 169259e09e56b712aa6ea8a5520aeb6d72fbaab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Sun, 8 Oct 2023 20:43:27 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 123 ++++++++++++------ 1 file changed, 86 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 59a53fa..463c0de 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -2,6 +2,7 @@ package com.light.view; import atlantafx.base.controls.Card; import atlantafx.base.controls.CustomTextField; +import atlantafx.base.controls.RingProgressIndicator; import atlantafx.base.controls.Tile; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; @@ -15,6 +16,8 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.geometry.Insets; +import javafx.geometry.NodeOrientation; +import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.control.cell.CheckBoxTableCell; @@ -23,17 +26,15 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import javafx.scene.paint.Color; -import javafx.scene.shape.Circle; +import javafx.scene.text.Text; import org.apache.commons.lang3.StringUtils; +import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; import java.io.File; import java.util.List; -import static com.light.util.NoticeUtils.show; - public class ManagerView extends StackPane { // 上半部分:搜索、更新 @@ -104,9 +105,11 @@ public class ManagerView extends StackPane { branch.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().branch())); var level = new TableColumn("学习等级"); + level.setCellFactory(param -> new LevelTableCell()); level.setCellValueFactory(c -> new SimpleIntegerProperty(c.getValue().level()).asObject()); var process = new TableColumn("进度"); + process.setCellFactory(param -> new ProcessTableCell()); process.setCellValueFactory(c -> c.getValue().downloadRate().asObject()); var operation = new TableColumn("操作"); @@ -133,7 +136,7 @@ public class ManagerView extends StackPane { for (int i = 0; i < 100; i++) { FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.addAll( new GitProject(i + "", "g" + i + "it", "project", "develop", "2023-09-30", - "2023-09-30", "", "", "", "", 1, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); + "2023-09-30", "https://gitee.com/code-poison/git-manager-client-fx.git", "D:\\workspace\\workspace-dev\\git-manager-client-fx", "测试一下效果", "", i % 5, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); } } @@ -170,9 +173,9 @@ public class ManagerView extends StackPane { System.out.println("用户输入路径:" + textField.getText()); //错误提示 try { - if(StringUtils.isEmpty(textField.getText())){ + if (StringUtils.isEmpty(textField.getText())) { NoticeUtils.show(null, "请输入路径", Level.WARN); - }else{ + } else { File file = new File(textField.getText()); if (file.exists()) { //todo 输入正确,读取文件夹中内容 @@ -235,13 +238,14 @@ public class ManagerView extends StackPane { private static class OperationTableCell extends TableCell { Button updateButton = new Button("更新"); Button detailButton = new Button("详情"); - HBox operationBOx = new HBox(updateButton, detailButton); + HBox operationBox = new HBox(updateButton, detailButton); public OperationTableCell() { updateButton.getStyleClass().addAll(Styles.FLAT, Styles.ACCENT); updateButton.setMnemonicParsing(true); detailButton.getStyleClass().addAll(Styles.FLAT, Styles.SUCCESS); detailButton.setMnemonicParsing(true); + operationBox.setAlignment(Pos.CENTER_LEFT); } @Override @@ -250,7 +254,44 @@ public class ManagerView extends StackPane { if (empty) { setGraphic(null); } else { - setGraphic(operationBOx); + setGraphic(operationBox); + } + } + } + + private static class LevelTableCell extends TableCell { + + public LevelTableCell() { + } + + @Override + protected void updateItem(Integer item, boolean empty) { + super.updateItem(item, empty); + if (!empty) { + var hBox = new HBox(); + hBox.setAlignment(Pos.CENTER_LEFT); + for (int i = 0; i < item; i++) { + hBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); + } + setGraphic(hBox); + } else { + setGraphic(null); + } + } + } + + private static class ProcessTableCell extends TableCell { + public ProcessTableCell() { + } + + @Override + protected void updateItem(Double item, boolean empty) { + super.updateItem(item, empty); + if (!empty) { + var basicInd = new RingProgressIndicator(0, false); + setGraphic(basicInd); + } else { + setGraphic(null); } } } @@ -260,12 +301,18 @@ public class ManagerView extends StackPane { */ private static class OperationTableRow extends TableRow { - private Card toolTipCard = new Card(); - private Tooltip tooltip = new Tooltip(); + private final Card toolTipCard = new Card(); + private final Tooltip tooltip = new Tooltip(); + + private final Tile name = new Tile(); + private final Text author = new Text(); + + private final Label remoteAddr = new Label(); + private final Label localAddr = new Label(); + private final Label level = new Label(); + private final Label remark = new Label(); public OperationTableRow() { - tooltip.setGraphic(toolTipCard); - tooltip.getStyleClass().removeAll("tooltip"); initialize(); } @@ -273,40 +320,42 @@ public class ManagerView extends StackPane { protected void updateItem(GitProject item, boolean empty) { super.updateItem(item, empty); if (!empty) { + refreshData(item); setTooltip(tooltip); } } public void initialize() { - + tooltip.setGraphic(toolTipCard); + tooltip.getStyleClass().removeAll("tooltip"); toolTipCard.getStyleClass().add(Styles.ELEVATED_1); toolTipCard.setMinWidth(300); toolTipCard.setMaxWidth(300); + toolTipCard.setHeader(name); + level.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); - var header2 = new Tile( - "Reviewers", - "Request up to 10 reviewers" - ); - toolTipCard.setHeader(header2); - - var tf2 = new CustomTextField(); - tf2.setPromptText("Search people"); - tf2.setLeft(new FontIcon(BootstrapIcons.SEARCH)); - toolTipCard.setSubHeader(tf2); - - var body2 = new VBox(10); - toolTipCard.setBody(body2); - for (int i = 0; i < 5; i++) { - var cb = new CheckBox(); - var lbl = new Label("123"); - var circle = new Circle( - 8, Color.GRAY - ); - - var row = new HBox(10, circle, cb, lbl); - row.setAlignment(Pos.CENTER_LEFT); - body2.getChildren().add(row); + // 分割线 + Separator separator = new Separator(Orientation.HORIZONTAL); + + VBox bodyVbox = new VBox(5); + toolTipCard.setBody(bodyVbox); + bodyVbox.getChildren().addAll(separator, author, remoteAddr, localAddr, level, remark); + } + + private void refreshData(GitProject item) { + // 项目名称 + name.setTitle(item.name()); + name.setDescription(item.description()); + author.setText("仓库 作者: " + item.author()); + remoteAddr.setText("仓库 地址: " + item.remote()); + localAddr.setText("本地 地址: " + item.local()); + level.setText("学习 等级: "); + HBox levelBox = new HBox(); + level.setGraphic(levelBox); + for (int i = 0; i < item.level(); i++) { + levelBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); } + remark.setText("仓库 备注: " + item.remark()); } } } -- Gitee From 35333f060cade3d96aab14bcd9f1e0823be441d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Mon, 9 Oct 2023 10:49:36 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=A1=B5-=E6=B7=BB=E5=8A=A0=E6=9C=AC=E6=AC=A1=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E8=B7=AF=E5=BE=84-=E5=8A=A0=E8=BD=BD=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=8F=90=E7=A4=BA=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 463c0de..fc61bed 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -149,13 +149,12 @@ public class ManagerView extends StackPane { event.consume(); }); - //添加本地项目按钮事件 + /** + * 添加本地项目按钮事件 + * 输入框 让用户键入代码存放路径 + * 按钮 加载 + */ addLocalButton.setOnAction(btn -> { - /** - * 添加本地项目 - * 输入框 让用户键入代码存放路径 - * 按钮 加载 - */ //输入框横向布局 HBox inputHBox = new HBox(10); inputHBox.setAlignment(Pos.CENTER); @@ -174,18 +173,18 @@ public class ManagerView extends StackPane { //错误提示 try { if (StringUtils.isEmpty(textField.getText())) { - NoticeUtils.show(null, "请输入路径", Level.WARN); + NoticeUtils.show(getScene().getWindow(), "请输入路径", Level.WARN); } else { File file = new File(textField.getText()); if (file.exists()) { //todo 输入正确,读取文件夹中内容 } else { - NoticeUtils.show(null, "该路径不存在或路径下无内容", Level.DANGER); + NoticeUtils.show(getScene().getWindow(), "该路径不存在或路径下无内容", Level.DANGER); } } } catch (Exception e) { - NoticeUtils.show(null, "路径不正确", Level.DANGER); + NoticeUtils.show(getScene().getWindow(), "路径不正确", Level.DANGER); } }); inputHBox.getChildren().addAll(textField, load); @@ -198,7 +197,6 @@ public class ManagerView extends StackPane { this.show(alert); }); - // 搜索框执行逻辑 searchField.setOnKeyReleased(event -> { String text = searchField.getText(); -- Gitee From 8749fb8907105ad7c61e307a7c22b4e7ff8a152c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Mon, 9 Oct 2023 10:53:09 +0800 Subject: [PATCH 15/18] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 113 ++++++++++-------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 463c0de..d34f11a 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -2,7 +2,6 @@ package com.light.view; import atlantafx.base.controls.Card; import atlantafx.base.controls.CustomTextField; -import atlantafx.base.controls.RingProgressIndicator; import atlantafx.base.controls.Tile; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; @@ -16,17 +15,18 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.geometry.Insets; -import javafx.geometry.NodeOrientation; import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.ChoiceBoxTableCell; +import javafx.scene.control.cell.ProgressBarTableCell; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.Text; +import javafx.util.Callback; import org.apache.commons.lang3.StringUtils; import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; @@ -105,15 +105,15 @@ public class ManagerView extends StackPane { branch.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().branch())); var level = new TableColumn("学习等级"); - level.setCellFactory(param -> new LevelTableCell()); + level.setCellFactory(LevelTableCell.forTableColumn()); level.setCellValueFactory(c -> new SimpleIntegerProperty(c.getValue().level()).asObject()); - var process = new TableColumn("进度"); - process.setCellFactory(param -> new ProcessTableCell()); + var process = new TableColumn("更新进度"); + process.setCellFactory(ProgressBarTableCell.forTableColumn()); process.setCellValueFactory(c -> c.getValue().downloadRate().asObject()); var operation = new TableColumn("操作"); - operation.setCellFactory(param -> new OperationTableCell()); + operation.setCellFactory(OperationTableCell.forTableColumn()); operation.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().id())); operation.setPrefWidth(120d); operation.setMaxWidth(120d); @@ -121,14 +121,13 @@ public class ManagerView extends StackPane { tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); tableView.getColumns().setAll(select, id, warehouse, author, branch, level, process, operation); + tableView.setRowFactory(OperationTableRow.forTableRow()); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tableView.getStyleClass().addAll(Tweaks.EDGE_TO_EDGE, Styles.BORDERED); tableView.getSelectionModel().selectFirst(); tableView.setMaxWidth(Double.MAX_VALUE); tableView.setMinHeight(300); tableView.setEditable(true); - - tableView.setRowFactory(param -> new OperationTableRow()); } public void initData() { @@ -233,12 +232,17 @@ public class ManagerView extends StackPane { } /** - * 自定义表格 - button + * 操作列 - 按钮 */ private static class OperationTableCell extends TableCell { Button updateButton = new Button("更新"); Button detailButton = new Button("详情"); HBox operationBox = new HBox(updateButton, detailButton); + private SimpleDoubleProperty rate; + + public static Callback, TableCell> forTableColumn() { + return param -> new OperationTableCell(); + } public OperationTableCell() { updateButton.getStyleClass().addAll(Styles.FLAT, Styles.ACCENT); @@ -246,52 +250,63 @@ public class ManagerView extends StackPane { detailButton.getStyleClass().addAll(Styles.FLAT, Styles.SUCCESS); detailButton.setMnemonicParsing(true); operationBox.setAlignment(Pos.CENTER_LEFT); + initEvent(); } @Override protected void updateItem(String item, boolean empty) { super.updateItem(item, empty); - if (empty) { + if (empty || getTableRow() == null || StringUtils.isBlank(item)) { setGraphic(null); } else { + rate = null; + GitProject project = getTableRow().getItem(); + if (null != project) { + rate = project.downloadRate(); + } setGraphic(operationBox); } } + + private void initEvent() { + // TODO Auto-generated method stub + updateButton.setOnMouseClicked(event -> { + rate.set(0.0); + for (int i = 0; i < 100; i++) { + double dRate = (double) i / 100; + System.out.println(dRate); + rate.set(dRate); + } + }); + } } + /** + * 学习等级列 - 星级 + */ private static class LevelTableCell extends TableCell { + private final HBox hBox = new HBox(); + + public static Callback, TableCell> forTableColumn() { + return param -> new LevelTableCell(); + } + public LevelTableCell() { + hBox.setAlignment(Pos.CENTER_LEFT); } @Override protected void updateItem(Integer item, boolean empty) { super.updateItem(item, empty); - if (!empty) { - var hBox = new HBox(); - hBox.setAlignment(Pos.CENTER_LEFT); + if (empty || item == null || getTableRow() == null) { + setGraphic(null); + } else { + hBox.getChildren().clear(); for (int i = 0; i < item; i++) { hBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); } setGraphic(hBox); - } else { - setGraphic(null); - } - } - } - - private static class ProcessTableCell extends TableCell { - public ProcessTableCell() { - } - - @Override - protected void updateItem(Double item, boolean empty) { - super.updateItem(item, empty); - if (!empty) { - var basicInd = new RingProgressIndicator(0, false); - setGraphic(basicInd); - } else { - setGraphic(null); } } } @@ -301,7 +316,6 @@ public class ManagerView extends StackPane { */ private static class OperationTableRow extends TableRow { - private final Card toolTipCard = new Card(); private final Tooltip tooltip = new Tooltip(); private final Tile name = new Tile(); @@ -311,38 +325,42 @@ public class ManagerView extends StackPane { private final Label localAddr = new Label(); private final Label level = new Label(); private final Label remark = new Label(); + private final HBox levelBox = new HBox(); - public OperationTableRow() { - initialize(); + public static Callback, TableRow> forTableRow() { + return param -> new OperationTableRow(); } - @Override - protected void updateItem(GitProject item, boolean empty) { - super.updateItem(item, empty); - if (!empty) { - refreshData(item); - setTooltip(tooltip); - } - } - - public void initialize() { + public OperationTableRow() { + Card toolTipCard = new Card(); tooltip.setGraphic(toolTipCard); tooltip.getStyleClass().removeAll("tooltip"); toolTipCard.getStyleClass().add(Styles.ELEVATED_1); toolTipCard.setMinWidth(300); toolTipCard.setMaxWidth(300); toolTipCard.setHeader(name); - level.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); // 分割线 Separator separator = new Separator(Orientation.HORIZONTAL); VBox bodyVbox = new VBox(5); toolTipCard.setBody(bodyVbox); - bodyVbox.getChildren().addAll(separator, author, remoteAddr, localAddr, level, remark); + bodyVbox.getChildren().addAll(separator, author, remoteAddr, localAddr, levelBox, remark); + } + + @Override + protected void updateItem(GitProject item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setTooltip(null); + } else { + refreshData(item); + setTooltip(tooltip); + } } private void refreshData(GitProject item) { + levelBox.getChildren().clear(); // 项目名称 name.setTitle(item.name()); name.setDescription(item.description()); @@ -350,8 +368,7 @@ public class ManagerView extends StackPane { remoteAddr.setText("仓库 地址: " + item.remote()); localAddr.setText("本地 地址: " + item.local()); level.setText("学习 等级: "); - HBox levelBox = new HBox(); - level.setGraphic(levelBox); + levelBox.getChildren().add(level); for (int i = 0; i < item.level(); i++) { levelBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); } -- Gitee From 51aa4593627c84ae881e4cc438373dc56edbea09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B8=A3?= <18600824670@163.com> Date: Mon, 9 Oct 2023 17:07:28 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E7=AE=A1=E7=90=86=E9=A1=B5-=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9C=AC=E5=9C=B0=E9=A1=B9=E7=9B=AE=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=BC=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/view/ManagerView.java | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 37ed217..79b9da8 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -17,15 +17,20 @@ import javafx.collections.FXCollections; import javafx.geometry.Insets; import javafx.geometry.Orientation; import javafx.geometry.Pos; +import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.ChoiceBoxTableCell; import javafx.scene.control.cell.ProgressBarTableCell; +import javafx.scene.image.Image; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.Text; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; import javafx.util.Callback; import org.apache.commons.lang3.StringUtils; import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; @@ -162,11 +167,24 @@ public class ManagerView extends StackPane { noticeHBox.setAlignment(Pos.CENTER); //输入框 - var textField = new TextField(); + TextField textField = new TextField(); textField.setPromptText("请输入代码存放路径"); - textField.setMinWidth(500); + textField.setMinWidth(550); + //设置打开窗口时焦点不在输入框中 + textField.setFocusTraversable(false); //加载按钮 Button load = new Button("加载"); + inputHBox.getChildren().addAll(textField, load); + Scene scene = new Scene(inputHBox,700,100); + Stage projectPathStage = new Stage(); + projectPathStage.initOwner(getScene().getWindow()); + //设置此窗口在优先级最高 屏蔽其他窗口 + projectPathStage.initModality(Modality.WINDOW_MODAL); + projectPathStage.getIcons().add(new Image("/icons/git.png")); + projectPathStage.setTitle("添加本地项目"); + projectPathStage.setScene(scene); + projectPathStage.show(); + load.setOnAction(loadBtn -> { System.out.println("用户输入路径:" + textField.getText()); //错误提示 @@ -186,14 +204,6 @@ public class ManagerView extends StackPane { NoticeUtils.show(getScene().getWindow(), "路径不正确", Level.DANGER); } }); - inputHBox.getChildren().addAll(textField, load); - - var alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("添加本地项目路径"); - alert.setHeaderText(null); - alert.setGraphic(inputHBox); - alert.initOwner(getScene().getWindow()); - this.show(alert); }); // 搜索框执行逻辑 @@ -215,20 +225,6 @@ public class ManagerView extends StackPane { }); } - //添加本地项目弹框 - private void show(Dialog alert) { - // copy customized styles, like changed accent color etc - try { - for (var pc : getScene().getRoot().getPseudoClassStates()) { - alert.getDialogPane().pseudoClassStateChanged(pc, true); - } - alert.getDialogPane().getStylesheets().addAll(getScene().getRoot().getStylesheets()); - } catch (Exception ignored) { - // yes, ignored - } - alert.showAndWait(); - } - /** * 操作列 - 按钮 */ -- Gitee From 0670990d36328e1109863de24ad06ecf838ee117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Mon, 9 Oct 2023 17:30:37 +0800 Subject: [PATCH 17/18] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/GitManagerApp.java | 2 + .../com/light/component/LevelTableCell.java | 40 ++++ .../light/component/OperationTableCell.java | 63 ++++++ .../com/light/component/TooltipTableRow.java | 79 ++++++++ src/main/java/com/light/model/GitProject.java | 10 + src/main/java/com/light/util/FxDataUtil.java | 8 +- src/main/java/com/light/view/ManagerView.java | 184 +++--------------- src/main/resources/css/menu.css | 1 - 8 files changed, 226 insertions(+), 161 deletions(-) create mode 100644 src/main/java/com/light/component/LevelTableCell.java create mode 100644 src/main/java/com/light/component/OperationTableCell.java create mode 100644 src/main/java/com/light/component/TooltipTableRow.java diff --git a/src/main/java/com/light/GitManagerApp.java b/src/main/java/com/light/GitManagerApp.java index 18e33ff..76f09a7 100644 --- a/src/main/java/com/light/GitManagerApp.java +++ b/src/main/java/com/light/GitManagerApp.java @@ -1,5 +1,6 @@ package com.light; +import atlantafx.base.theme.Dracula; import atlantafx.base.theme.PrimerLight; import com.light.layout.ContentPane; import com.light.layout.MenuPane; @@ -26,6 +27,7 @@ public class GitManagerApp extends Application { public void start(Stage stage) throws Exception { // 主题 Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet()); +// Application.setUserAgentStylesheet(new Dracula().getUserAgentStylesheet()); // 根节点 StackPane root = new StackPane(); diff --git a/src/main/java/com/light/component/LevelTableCell.java b/src/main/java/com/light/component/LevelTableCell.java new file mode 100644 index 0000000..cfe17da --- /dev/null +++ b/src/main/java/com/light/component/LevelTableCell.java @@ -0,0 +1,40 @@ +package com.light.component; + +import com.light.model.GitProject; +import javafx.geometry.Pos; +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.scene.layout.HBox; +import javafx.util.Callback; +import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; +import org.kordamp.ikonli.javafx.FontIcon; + +/** + * 学习等级列 - 星级 + */ +public class LevelTableCell extends TableCell { + + private final HBox hBox = new HBox(); + + public static Callback, TableCell> forTableColumn() { + return param -> new LevelTableCell(); + } + + public LevelTableCell() { + hBox.setAlignment(Pos.CENTER_LEFT); + } + + @Override + protected void updateItem(Integer item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null || getTableRow() == null) { + setGraphic(null); + } else { + hBox.getChildren().clear(); + for (int i = 0; i < item; i++) { + hBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); + } + setGraphic(hBox); + } + } +} diff --git a/src/main/java/com/light/component/OperationTableCell.java b/src/main/java/com/light/component/OperationTableCell.java new file mode 100644 index 0000000..2db4141 --- /dev/null +++ b/src/main/java/com/light/component/OperationTableCell.java @@ -0,0 +1,63 @@ +package com.light.component; + +import atlantafx.base.theme.Styles; +import com.light.model.GitProject; +import com.light.util.FxDataUtil; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.control.TableCell; +import javafx.scene.control.TableColumn; +import javafx.scene.layout.HBox; +import javafx.util.Callback; +import org.apache.commons.lang3.StringUtils; + +/** + * 操作列 - 按钮 + */ +public class OperationTableCell extends TableCell { + Button updateButton = new Button("更新"); + Button detailButton = new Button("详情"); + HBox operationBox = new HBox(updateButton, detailButton); + private SimpleDoubleProperty rate; + + public static Callback, TableCell> forTableColumn() { + return param -> new OperationTableCell(); + } + + public OperationTableCell() { + updateButton.getStyleClass().addAll(Styles.FLAT, Styles.ACCENT); + updateButton.setMnemonicParsing(true); + detailButton.getStyleClass().addAll(Styles.FLAT, Styles.SUCCESS); + detailButton.setMnemonicParsing(true); + operationBox.setAlignment(Pos.CENTER_LEFT); + initEvent(); + } + + @Override + protected void updateItem(String item, boolean empty) { + super.updateItem(item, empty); + if (empty || getTableRow() == null || StringUtils.isBlank(item)) { + setGraphic(null); + } else { + rate = null; + GitProject project = getTableRow().getItem(); + if (null != project) { + rate = project.downloadRate(); + } + setGraphic(operationBox); + } + } + + private void initEvent() { + // TODO Auto-generated method stub + updateButton.setOnMouseClicked(event -> { + rate.set(0.0); + FxDataUtil.UPDATE_PROPERTY.set(FxDataUtil.UPDATE_NUMBER.incrementAndGet()); + for (int i = 0; i <= 100; i++) { + double dRate = (double) i / 100; + rate.set(dRate); + } + }); + } +} diff --git a/src/main/java/com/light/component/TooltipTableRow.java b/src/main/java/com/light/component/TooltipTableRow.java new file mode 100644 index 0000000..ec59b3c --- /dev/null +++ b/src/main/java/com/light/component/TooltipTableRow.java @@ -0,0 +1,79 @@ +package com.light.component; + +import atlantafx.base.controls.Card; +import atlantafx.base.controls.Tile; +import atlantafx.base.theme.Styles; +import com.light.model.GitProject; +import javafx.geometry.Orientation; +import javafx.scene.control.*; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; +import javafx.util.Callback; +import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; +import org.kordamp.ikonli.javafx.FontIcon; + +/** + * 自定义行 - 提示框 + */ +public class TooltipTableRow extends TableRow { + + private final Tooltip tooltip = new Tooltip(); + + private final Tile name = new Tile(); + private final Text author = new Text(); + + private final Label remoteAddr = new Label(); + private final Label localAddr = new Label(); + private final Label level = new Label(); + private final Label remark = new Label(); + private final HBox levelBox = new HBox(); + + public static Callback, TableRow> forTableRow() { + return param -> new TooltipTableRow(); + } + + public TooltipTableRow() { + Card toolTipCard = new Card(); + tooltip.setGraphic(toolTipCard); + tooltip.getStyleClass().removeAll("tooltip"); + toolTipCard.getStyleClass().add(Styles.ELEVATED_1); + toolTipCard.setMinWidth(300); + toolTipCard.setMaxWidth(300); + toolTipCard.setHeader(name); + + // 分割线 + Separator separator = new Separator(Orientation.HORIZONTAL); + + VBox bodyVbox = new VBox(5); + toolTipCard.setBody(bodyVbox); + bodyVbox.getChildren().addAll(separator, author, remoteAddr, localAddr, levelBox, remark); + } + + @Override + protected void updateItem(GitProject item, boolean empty) { + super.updateItem(item, empty); + if (empty || item == null) { + setTooltip(null); + } else { + refreshData(item); + setTooltip(tooltip); + } + } + + private void refreshData(GitProject item) { + levelBox.getChildren().clear(); + // 项目名称 + name.setTitle(item.name()); + name.setDescription(item.description()); + author.setText("仓库 作者: " + item.author()); + remoteAddr.setText("仓库 地址: " + item.remote()); + localAddr.setText("本地 地址: " + item.local()); + level.setText("学习 等级: "); + levelBox.getChildren().add(level); + for (int i = 0; i < item.level(); i++) { + levelBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); + } + remark.setText("仓库 备注: " + item.remark()); + } +} diff --git a/src/main/java/com/light/model/GitProject.java b/src/main/java/com/light/model/GitProject.java index 1d84f6c..8faa3e9 100644 --- a/src/main/java/com/light/model/GitProject.java +++ b/src/main/java/com/light/model/GitProject.java @@ -1,5 +1,6 @@ package com.light.model; +import com.light.util.FxDataUtil; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; @@ -16,4 +17,13 @@ public record GitProject(String id, int level, SimpleDoubleProperty downloadRate, SimpleBooleanProperty selected) { + + public void addSelectedListener() { + downloadRate.addListener((observable, oldValue, newValue) -> { + if (newValue != null && newValue.doubleValue() >= 1.0) { + selected.set(false); + FxDataUtil.UPDATE_PROPERTY.set(FxDataUtil.UPDATE_NUMBER.decrementAndGet()); + } + }); + } } diff --git a/src/main/java/com/light/util/FxDataUtil.java b/src/main/java/com/light/util/FxDataUtil.java index f7c7f76..1cbf64f 100644 --- a/src/main/java/com/light/util/FxDataUtil.java +++ b/src/main/java/com/light/util/FxDataUtil.java @@ -5,6 +5,8 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import java.util.concurrent.atomic.AtomicInteger; + /** * 全局数据工具类 */ @@ -13,11 +15,13 @@ public final class FxDataUtil { /** * 正在下载数量 */ - public static final SimpleIntegerProperty DOWNLOAD_PROPERTY = new SimpleIntegerProperty(0); + public static final AtomicInteger DOWNLOAD_NUMBER = new AtomicInteger(0); + public static final SimpleIntegerProperty DOWNLOAD_PROPERTY = new SimpleIntegerProperty(DOWNLOAD_NUMBER.intValue()); /** * 正在更新数量 */ - public static final SimpleIntegerProperty UPDATE_PROPERTY = new SimpleIntegerProperty(0); + public static final AtomicInteger UPDATE_NUMBER = new AtomicInteger(0); + public static final SimpleIntegerProperty UPDATE_PROPERTY = new SimpleIntegerProperty(UPDATE_NUMBER.intValue()); public static final ObservableList GIT_PROJECT_OBSERVABLE_LIST = FXCollections.observableArrayList(); diff --git a/src/main/java/com/light/view/ManagerView.java b/src/main/java/com/light/view/ManagerView.java index 79b9da8..c509130 100644 --- a/src/main/java/com/light/view/ManagerView.java +++ b/src/main/java/com/light/view/ManagerView.java @@ -1,10 +1,11 @@ package com.light.view; -import atlantafx.base.controls.Card; import atlantafx.base.controls.CustomTextField; -import atlantafx.base.controls.Tile; import atlantafx.base.theme.Styles; import atlantafx.base.theme.Tweaks; +import com.light.component.LevelTableCell; +import com.light.component.OperationTableCell; +import com.light.component.TooltipTableRow; import com.light.enums.Level; import com.light.model.GitProject; import com.light.util.FxDataUtil; @@ -15,7 +16,6 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.collections.FXCollections; import javafx.geometry.Insets; -import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; @@ -27,13 +27,9 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import javafx.scene.text.Text; import javafx.stage.Modality; import javafx.stage.Stage; -import javafx.stage.StageStyle; -import javafx.util.Callback; import org.apache.commons.lang3.StringUtils; -import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined; import org.kordamp.ikonli.bootstrapicons.BootstrapIcons; import org.kordamp.ikonli.javafx.FontIcon; @@ -56,7 +52,10 @@ public class ManagerView extends StackPane { private final VBox vBox = new VBox(10); public ManagerView() { + this.getChildren().add(vBox); initialize(); + initData(); + initEvent(); } public void initialize() { @@ -75,11 +74,6 @@ public class ManagerView extends StackPane { vBox.getChildren().addAll(hBox, tableView); vBox.setPadding(new Insets(0, 1, 0, 1)); VBox.setVgrow(tableView, Priority.ALWAYS); - - this.getChildren().add(vBox); - - initData(); - initEvent(); } public void initTable() { @@ -88,7 +82,6 @@ public class ManagerView extends StackPane { select.setSortable(false); select.setCellFactory(CheckBoxTableCell.forTableColumn(select)); select.setCellValueFactory(param -> param.getValue().selected()); - select.setEditable(true); select.setPrefWidth(40d); select.setMaxWidth(40d); select.setMinWidth(40d); @@ -106,6 +99,7 @@ public class ManagerView extends StackPane { author.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().author())); var branch = new TableColumn("分支"); + branch.setSortable(false); branch.setCellFactory(ChoiceBoxTableCell.forTableColumn("master", "develop")); branch.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().branch())); @@ -114,10 +108,12 @@ public class ManagerView extends StackPane { level.setCellValueFactory(c -> new SimpleIntegerProperty(c.getValue().level()).asObject()); var process = new TableColumn("更新进度"); + process.setSortable(false); process.setCellFactory(ProgressBarTableCell.forTableColumn()); process.setCellValueFactory(c -> c.getValue().downloadRate().asObject()); var operation = new TableColumn("操作"); + operation.setSortable(false); operation.setCellFactory(OperationTableCell.forTableColumn()); operation.setCellValueFactory(c -> new SimpleStringProperty(c.getValue().id())); operation.setPrefWidth(120d); @@ -126,7 +122,7 @@ public class ManagerView extends StackPane { tableView = new TableView<>(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); tableView.getColumns().setAll(select, id, warehouse, author, branch, level, process, operation); - tableView.setRowFactory(OperationTableRow.forTableRow()); + tableView.setRowFactory(TooltipTableRow.forTableRow()); tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); tableView.getStyleClass().addAll(Tweaks.EDGE_TO_EDGE, Styles.BORDERED); tableView.getSelectionModel().selectFirst(); @@ -138,9 +134,10 @@ public class ManagerView extends StackPane { public void initData() { // TODO 查H2数据库获取数据 for (int i = 0; i < 100; i++) { - FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.addAll( - new GitProject(i + "", "g" + i + "it", "project", "develop", "2023-09-30", - "2023-09-30", "https://gitee.com/code-poison/git-manager-client-fx.git", "D:\\workspace\\workspace-dev\\git-manager-client-fx", "测试一下效果", "", i % 5, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(true))); + GitProject gitProject = new GitProject(i + "", "g" + i + "it", "project", "develop", "2023-09-30", + "2023-09-30", "https://gitee.com/code-poison/git-manager-client-fx.git", "D:\\workspace\\workspace-dev\\git-manager-client-fx", "测试一下效果", "", i % 5, new SimpleDoubleProperty(0.0), new SimpleBooleanProperty(false)); + gitProject.addSelectedListener(); + FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST.add(gitProject); } } @@ -175,7 +172,7 @@ public class ManagerView extends StackPane { //加载按钮 Button load = new Button("加载"); inputHBox.getChildren().addAll(textField, load); - Scene scene = new Scene(inputHBox,700,100); + Scene scene = new Scene(inputHBox, 700, 100); Stage projectPathStage = new Stage(); projectPathStage.initOwner(getScene().getWindow()); //设置此窗口在优先级最高 屏蔽其他窗口 @@ -223,150 +220,21 @@ public class ManagerView extends StackPane { tableView.setItems(FxDataUtil.GIT_PROJECT_OBSERVABLE_LIST); } }); - } - - /** - * 操作列 - 按钮 - */ - private static class OperationTableCell extends TableCell { - Button updateButton = new Button("更新"); - Button detailButton = new Button("详情"); - HBox operationBox = new HBox(updateButton, detailButton); - private SimpleDoubleProperty rate; - public static Callback, TableCell> forTableColumn() { - return param -> new OperationTableCell(); - } - - public OperationTableCell() { - updateButton.getStyleClass().addAll(Styles.FLAT, Styles.ACCENT); - updateButton.setMnemonicParsing(true); - detailButton.getStyleClass().addAll(Styles.FLAT, Styles.SUCCESS); - detailButton.setMnemonicParsing(true); - operationBox.setAlignment(Pos.CENTER_LEFT); - initEvent(); - } - - @Override - protected void updateItem(String item, boolean empty) { - super.updateItem(item, empty); - if (empty || getTableRow() == null || StringUtils.isBlank(item)) { - setGraphic(null); - } else { - rate = null; - GitProject project = getTableRow().getItem(); - if (null != project) { - rate = project.downloadRate(); - } - setGraphic(operationBox); + // 全部更新按钮 + updateButton.setOnMouseClicked(event -> { + List list = tableView.getItems().stream().filter(param -> param.selected().get()).toList(); + if (!list.isEmpty()) { + updateButton.setDisable(true); + FxDataUtil.UPDATE_PROPERTY.set(FxDataUtil.UPDATE_NUMBER.addAndGet(list.size())); } - } - - private void initEvent() { - // TODO Auto-generated method stub - updateButton.setOnMouseClicked(event -> { - rate.set(0.0); - for (int i = 0; i < 100; i++) { + list.forEach(param -> { + param.downloadRate().set(0.0); + for (int i = 0; i <= 100; i++) { double dRate = (double) i / 100; - System.out.println(dRate); - rate.set(dRate); + param.downloadRate().set(dRate); } }); - } - } - - /** - * 学习等级列 - 星级 - */ - private static class LevelTableCell extends TableCell { - - private final HBox hBox = new HBox(); - - public static Callback, TableCell> forTableColumn() { - return param -> new LevelTableCell(); - } - - public LevelTableCell() { - hBox.setAlignment(Pos.CENTER_LEFT); - } - - @Override - protected void updateItem(Integer item, boolean empty) { - super.updateItem(item, empty); - if (empty || item == null || getTableRow() == null) { - setGraphic(null); - } else { - hBox.getChildren().clear(); - for (int i = 0; i < item; i++) { - hBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); - } - setGraphic(hBox); - } - } - } - - /** - * 自定义行 - 提示框 - */ - private static class OperationTableRow extends TableRow { - - private final Tooltip tooltip = new Tooltip(); - - private final Tile name = new Tile(); - private final Text author = new Text(); - - private final Label remoteAddr = new Label(); - private final Label localAddr = new Label(); - private final Label level = new Label(); - private final Label remark = new Label(); - private final HBox levelBox = new HBox(); - - public static Callback, TableRow> forTableRow() { - return param -> new OperationTableRow(); - } - - public OperationTableRow() { - Card toolTipCard = new Card(); - tooltip.setGraphic(toolTipCard); - tooltip.getStyleClass().removeAll("tooltip"); - toolTipCard.getStyleClass().add(Styles.ELEVATED_1); - toolTipCard.setMinWidth(300); - toolTipCard.setMaxWidth(300); - toolTipCard.setHeader(name); - - // 分割线 - Separator separator = new Separator(Orientation.HORIZONTAL); - - VBox bodyVbox = new VBox(5); - toolTipCard.setBody(bodyVbox); - bodyVbox.getChildren().addAll(separator, author, remoteAddr, localAddr, levelBox, remark); - } - - @Override - protected void updateItem(GitProject item, boolean empty) { - super.updateItem(item, empty); - if (empty || item == null) { - setTooltip(null); - } else { - refreshData(item); - setTooltip(tooltip); - } - } - - private void refreshData(GitProject item) { - levelBox.getChildren().clear(); - // 项目名称 - name.setTitle(item.name()); - name.setDescription(item.description()); - author.setText("仓库 作者: " + item.author()); - remoteAddr.setText("仓库 地址: " + item.remote()); - localAddr.setText("本地 地址: " + item.local()); - level.setText("学习 等级: "); - levelBox.getChildren().add(level); - for (int i = 0; i < item.level(); i++) { - levelBox.getChildren().add(new FontIcon(AntDesignIconsOutlined.STAR)); - } - remark.setText("仓库 备注: " + item.remark()); - } + }); } } diff --git a/src/main/resources/css/menu.css b/src/main/resources/css/menu.css index f22296c..3abb496 100644 --- a/src/main/resources/css/menu.css +++ b/src/main/resources/css/menu.css @@ -96,7 +96,6 @@ .download-label, .update-label { -fx-font-size: 14px; - -fx-text-fill: -cf-text-color; } .download-label > .ikonli-font-icon { -- Gitee From b069852822b5cb9cff8578d5bdfa0eb9575581ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E7=99=BD=E4=B8=8E=E5=AD=9F=E6=B5=A9=E7=84=B6?= <1063889643@qq.com> Date: Mon, 9 Oct 2023 17:40:10 +0800 Subject: [PATCH 18/18] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/light/layout/MenuPane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/light/layout/MenuPane.java b/src/main/java/com/light/layout/MenuPane.java index 3f9395a..9ad67ff 100644 --- a/src/main/java/com/light/layout/MenuPane.java +++ b/src/main/java/com/light/layout/MenuPane.java @@ -53,7 +53,7 @@ public class MenuPane extends StackPane { // 菜单栏标题 dynamicMenu.getItems().addAll( - new NavItem(new FontIcon(AntDesignIconsOutlined.HOME), "下载新项目", new HomeView()), + new NavItem(new FontIcon(AntDesignIconsOutlined.DOWNLOAD), "下载", new HomeView()), new NavItem(new FontIcon(AntDesignIconsOutlined.PARTITION), "管理", new ManagerView()), new NavItem(new FontIcon(AntDesignIconsOutlined.EDIT), "笔记", null) ); -- Gitee