更新插件系统UI

This commit is contained in:
许轲 2023-09-23 01:39:38 +08:00
parent 86819258fa
commit 24ecfafa80
9 changed files with 227 additions and 18 deletions

View File

@ -104,7 +104,7 @@ JNotepad使用Java语言编写并基于JavaFX框架开发具有良好的
- `设置 > 语言`:切换语言。
- `插件 > 增加插件`(管理插件系统,待完善)
- `插件 > 增加插件`:管理插件系统。
## 依赖项

View File

@ -41,7 +41,7 @@ public class AppConfig {
shortcutKeys.add(createShortcutKey("saveAsItem", CTRL_ALT_S));
shortcutKeys.add(createShortcutKey("lineFeedItem", ""));
shortcutKeys.add(createShortcutKey("openConfigItem", ALT_S));
shortcutKeys.add(createShortcutKey("addItem", ""));
shortcutKeys.add(createShortcutKey("pluginManager", ""));
shortcutKeys.add(createShortcutKey("countItem", ""));
myData.setShortcutKey(shortcutKeys);
return myData;

View File

@ -18,7 +18,7 @@ public class TextConstants {
public static final String SET = "SET";
public static final String WORD_WRAP = "WORD_WRAP";
public static final String PLUGIN = "PLUGIN";
public static final String ADD_PLUGIN = "ADD_PLUGIN";
public static final String MANAGER_PLUGIN = "MANAGER_PLUGIN";
public static final String STATISTICS = "STATISTICS";
public static final String OPEN_CONFIGURATION_FILE = "OPEN_CONFIGURATION_FILE";
public static final String TOP = "TOP";

View File

@ -0,0 +1,63 @@
package org.jcnc.jnotepad.ui.pluginstage;
import javafx.geometry.Orientation;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.HBox;
/**
* 自定义分割面板用于将两个组件以水平方向分割显示
*
* <p>该分割面板包含左侧和右侧两个区域可分别设置内容</p>
*
* @author luke
*/
public class CustomSplitPane extends SplitPane {
private final HBox leftBox;
private final HBox rightBox;
/**
* 创建一个自定义分割面板指定左侧和右侧的文本标签
*
* @param leftText 左侧区域的文本标签
* @param rightText 右侧区域的文本标签
*/
public CustomSplitPane(String leftText, String rightText) {
// 创建左侧和右侧的框
leftBox = createBox(leftText);
rightBox = createBox(rightText);
// 设置水平分割面板的属性
this.setOrientation(Orientation.HORIZONTAL);
this.setDividerPositions(0.5);
// 添加左侧和右侧的框到分割面板
this.getItems().addAll(leftBox, rightBox);
}
private HBox createBox(String text) {
HBox box = new HBox();
box.getChildren().add(new javafx.scene.control.Label(text));
return box;
}
/**
* 设置左侧区域的内容
*
* @param content 左侧区域的内容节点
*/
public void setLeftContent(javafx.scene.Node content) {
leftBox.getChildren().clear();
leftBox.getChildren().add(content);
}
/**
* 设置右侧区域的内容
*
* @param content 右侧区域的内容节点
*/
public void setRightContent(javafx.scene.Node content) {
rightBox.getChildren().clear();
rightBox.getChildren().add(content);
}
}

View File

@ -0,0 +1,141 @@
package org.jcnc.jnotepad.ui.pluginstage;
import atlantafx.base.controls.Tile;
import atlantafx.base.controls.ToggleSwitch;
import atlantafx.base.theme.PrimerLight;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import java.util.HashMap;
import java.util.Map;
/**
* 插件管理面板用于管理插件的市场已安装和设置功能
*
* <p>此面板包含一个自定义分割面板用于显示不同的插件管理选项卡内容</p>
*
* @author luke
*/
public class PluginManagementPane extends BorderPane {
private CustomSplitPane customSplitPane;
private final Map<Tile, Node> tileContentMap = new HashMap<>();
/**
* 创建一个插件管理面板的实例
*/
public PluginManagementPane() {
init();
}
/**
* 初始化插件管理面板
*/
private void init() {
// 设置用户代理样式表
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
// 创建选项卡面板
TabPane tabPane = new TabPane();
// 创建市场已安装和设置选项卡
Tab marketTab = new Tab("市场");
Tab installedTab = new Tab("已安装");
Tab myTab = new Tab("设置");
// 禁用选项卡关闭按钮
marketTab.setClosable(false);
installedTab.setClosable(false);
myTab.setClosable(false);
// 创建选项卡内容面板
BorderPane marketTabContent = new BorderPane();
BorderPane installedTabContent = new BorderPane();
BorderPane myTabContent = new BorderPane();
// 创建自定义分割面板
customSplitPane = new CustomSplitPane("", "");
marketTabContent.setCenter(customSplitPane);
// 获取插件列表
var box = getBox();
customSplitPane.setLeftContent(box);
// 创建示例按钮并添加到已安装和设置选项卡中
installedTabContent.setCenter(new Button("2"));
myTabContent.setCenter(new Button("3"));
// 将选项卡内容设置到选项卡中
marketTab.setContent(marketTabContent);
installedTab.setContent(installedTabContent);
myTab.setContent(myTabContent);
// 将选项卡添加到选项卡面板中
tabPane.getTabs().addAll(marketTab, installedTab, myTab);
// 将选项卡面板设置为插件管理面板的中心内容
this.setCenter(tabPane);
}
/**
* 创建包含插件列表的VBox
*
* @return 包含插件列表的VBox
*/
private VBox getBox() {
// 创建示例插件列表项
var tile1 = createTile("运行插件", "这是一个运行插件\t\t\t\t\t\t\t\t");
var tile2 = createTile("终端插件", "这是一个终端插件");
var tile3 = createTile("构建插件", "这是一个构建插件");
// 创建VBox并将插件列表项添加到其中
var box = new VBox(tile1, tile2, tile3);
return box;
}
/**
* 创建插件列表项Tile
*
* @param title 插件标题
* @param description 插件描述
* @return 创建的插件列表项Tile
*/
private Tile createTile(String title, String description) {
var tile = new Tile(title, description);
var tgl = new ToggleSwitch();
// 设置Tile的操作和操作处理程序
tile.setAction(tgl);
tile.setActionHandler(() -> {
customSplitPane.setRightContent(tileContentMap.get(tile));
System.out.println("点击了" + title);
});
// 创建专属的customSplitPane内容
var content = createCustomSplitPaneContent(title);
// 将内容与Tile关联起来
tileContentMap.put(tile, content);
return tile;
}
/**
* 创建专属于每个插件的CustomSplitPane内容
*
* @param title 插件标题
* @return 创建的CustomSplitPane内容
*/
private Node createCustomSplitPaneContent(String title) {
// TODO: 2023/9/23 未完成
return new Label("详情" + title);
}
}

View File

@ -2,6 +2,7 @@ package org.jcnc.jnotepad.views.root.top.menu;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;
@ -11,9 +12,8 @@ import org.jcnc.jnotepad.controller.event.handler.menubar.*;
import org.jcnc.jnotepad.controller.event.handler.util.SetBtn;
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
import org.jcnc.jnotepad.model.entity.ShortcutKey;
import org.jcnc.jnotepad.plugin.PluginManagerInterface;
import org.jcnc.jnotepad.ui.pluginstage.PluginManagementPane;
import org.jcnc.jnotepad.util.LogUtil;
import org.jcnc.jnotepad.util.UiUtil;
import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTabPane;
import org.jcnc.jnotepad.views.root.left.sidebar.tools.SidebarToolBar;
@ -90,7 +90,7 @@ public class TopMenuBar extends MenuBar {
/**
* 增加
*/
private MenuItem addItem;
private MenuItem pluginManagerItem;
/**
* 查看
*/
@ -268,21 +268,26 @@ public class TopMenuBar extends MenuBar {
pluginMenu = new Menu();
UiResourceBundle.bindStringProperty(pluginMenu.textProperty(), PLUGIN);
addItem = new MenuItem();
addItem.setOnAction(event -> {
PluginManagerInterface pluginManagerInterface = PluginManagerInterface.getInstance();
Stage stage = new Stage();
stage.getIcons().add(UiUtil.getAppIcon());
pluginManagerInterface.start(stage);
pluginManagerItem = new MenuItem();
pluginManagerItem.setOnAction(event -> {
Stage newStage = new Stage(); // 创建一个新的Stage对象
newStage.setTitle("插件管理");
PluginManagementPane pluginManagementPane = new PluginManagementPane();
Scene scene = new Scene(pluginManagementPane, 900, 500);
newStage.setScene(scene);
newStage.show();
});
UiResourceBundle.bindStringProperty(addItem.textProperty(), ADD_PLUGIN);
itemMap.put("addItem", addItem);
UiResourceBundle.bindStringProperty(pluginManagerItem.textProperty(), MANAGER_PLUGIN);
itemMap.put("pluginManager", pluginManagerItem);
countItem = new MenuItem();
UiResourceBundle.bindStringProperty(countItem.textProperty(), STATISTICS);
itemMap.put("countItem", countItem);
pluginMenu.getItems().addAll(addItem, countItem);
pluginMenu.getItems().addAll(pluginManagerItem, countItem);
}
/**

View File

@ -18,5 +18,5 @@ SAVE_AS=另存为
SAVE=保存
ROW=行数
FILE=文件
ADD_PLUGIN=增加插件
MANAGER_PLUGIN=管理插件
ENCODE=编码

View File

@ -18,5 +18,5 @@ SAVE_AS=Save As
SAVE=Save
ROW=Row
FILE=File
ADD_PLUGIN=Add Plugin
MANAGER_PLUGIN=Manager Plugin
ENCODE=Encoding

View File

@ -18,5 +18,5 @@ SAVE_AS=另存为
SAVE=保存
ROW=行数
FILE=文件
ADD_PLUGIN=增加插件
MANAGER_PLUGIN=插件管理
ENCODE=编码