!126 ♻️ 重构代码 解耦并重构顶部栏,侧边栏,关于子菜单项代码 修复第一次启动时找不到缓存报错的问题
Merge pull request !126 from 格物方能致知/refactor-I85A0L
This commit is contained in:
commit
a9f6f6936d
@ -7,6 +7,7 @@ import org.jcnc.jnotepad.controller.event.handler.menubar.OpenFile;
|
||||
import org.jcnc.jnotepad.model.entity.Cache;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -40,7 +41,12 @@ public class Controller implements ControllerAble {
|
||||
public void openAssociatedFileAndCreateTextArea(List<String> rawParameters) {
|
||||
// 获取上次打开的页面
|
||||
Cache cache = CACHE_MANAGER.getCache("tabs", "centerTabs");
|
||||
List<String> fileTab = (List<String>) cache.getCacheData();
|
||||
List<String> fileTab;
|
||||
if (cache == null) {
|
||||
fileTab = Collections.emptyList();
|
||||
} else {
|
||||
fileTab = (List<String>) cache.getCacheData();
|
||||
}
|
||||
fileTab.forEach(filePath -> new OpenFile().openFile(new File(filePath)));
|
||||
|
||||
if (!rawParameters.isEmpty()) {
|
||||
|
||||
@ -59,7 +59,7 @@ public class LineNumberTextArea extends CodeArea {
|
||||
// 用于整体文本处理(文本块)
|
||||
"//[^\n]*" + "|" + "/\\*(.|\\R)*?\\*/"
|
||||
// 用于可见段落处理(逐行)
|
||||
+ "|" + "/\\*[^\\v]*" + "|" + "^\\h*\\*([^\\v]*|/)";
|
||||
+ "|" + "/\\*[^\\v]*" + "|" + "^\\h*\\*([^\\v]*|/)";
|
||||
|
||||
|
||||
/**
|
||||
@ -149,18 +149,16 @@ public class LineNumberTextArea extends CodeArea {
|
||||
|
||||
static class VisibleParagraphStyler<PS, SEG, S> implements Consumer<ListModification<? extends Paragraph<PS, SEG, S>>> {
|
||||
private final GenericStyledArea<PS, SEG, S> area;
|
||||
private final Function<String,StyleSpans<S>> computeStyles;
|
||||
private final Function<String, StyleSpans<S>> computeStyles;
|
||||
private int prevParagraph, prevTextLength;
|
||||
|
||||
public VisibleParagraphStyler( GenericStyledArea<PS, SEG, S> area, Function<String,StyleSpans<S>> computeStyles )
|
||||
{
|
||||
public VisibleParagraphStyler(GenericStyledArea<PS, SEG, S> area, Function<String, StyleSpans<S>> computeStyles) {
|
||||
this.computeStyles = computeStyles;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept( ListModification<? extends Paragraph<PS, SEG, S>> lm )
|
||||
{
|
||||
public void accept(ListModification<? extends Paragraph<PS, SEG, S>> lm) {
|
||||
if (lm.getAddedSize() > 0) {
|
||||
Platform.runLater(() -> {
|
||||
int paragraph = Math.min(area.firstVisibleParToAllParIndex() + lm.getFrom(), area.getParagraphs().size() - 1);
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package org.jcnc.jnotepad.ui.setstage;
|
||||
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* 抽象窗格舞台
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public abstract class AbstractPaneStage extends BorderPane {
|
||||
private final Stage stage = new Stage();
|
||||
|
||||
/**
|
||||
* 获取舞台图标
|
||||
*
|
||||
* @return 舞台图标
|
||||
*/
|
||||
protected abstract Image getStageIcon();
|
||||
|
||||
/**
|
||||
* 获取舞台标题
|
||||
*
|
||||
* @return 舞台标题
|
||||
*/
|
||||
protected abstract String getStageTitle();
|
||||
|
||||
/**
|
||||
* 获取自定义舞台
|
||||
*
|
||||
* @return 舞台
|
||||
*/
|
||||
protected abstract Scene getCustomizationScene();
|
||||
|
||||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
protected abstract void initialize();
|
||||
|
||||
/**
|
||||
* 自定义启动方法
|
||||
*
|
||||
* @param stage 自定义舞台
|
||||
*/
|
||||
public abstract void run(Stage stage);
|
||||
|
||||
/**
|
||||
* 启动方法
|
||||
*/
|
||||
public void run() {
|
||||
stage.getIcons().add(getStageIcon());
|
||||
stage.setTitle(getStageTitle());
|
||||
stage.setScene(getCustomizationScene());
|
||||
stage.show();
|
||||
}
|
||||
}
|
||||
209
src/main/java/org/jcnc/jnotepad/ui/setstage/HelpPaneStage.java
Normal file
209
src/main/java/org/jcnc/jnotepad/ui/setstage/HelpPaneStage.java
Normal file
@ -0,0 +1,209 @@
|
||||
package org.jcnc.jnotepad.ui.setstage;
|
||||
|
||||
import atlantafx.base.controls.Notification;
|
||||
import atlantafx.base.theme.Styles;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Hyperlink;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.jcnc.jnotepad.util.LogUtil;
|
||||
import org.jcnc.jnotepad.util.UiUtil;
|
||||
import org.jcnc.jnotepad.views.manager.RootManager;
|
||||
|
||||
import static org.jcnc.jnotepad.common.constants.AppConstants.*;
|
||||
|
||||
/**
|
||||
* 帮助页面
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class HelpPaneStage extends AbstractPaneStage {
|
||||
public HelpPaneStage() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static Button getButton(String text, EventHandler<ActionEvent> eventEventHandler) {
|
||||
Button button = new Button(text);
|
||||
button.getStyleClass().addAll(Styles.SMALL);
|
||||
button.setOnAction(eventEventHandler);
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取舞台图标
|
||||
*
|
||||
* @return 舞台图标
|
||||
*/
|
||||
@Override
|
||||
protected Image getStageIcon() {
|
||||
return UiUtil.getAppIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取舞台标题
|
||||
*
|
||||
* @return 舞台标题
|
||||
*/
|
||||
@Override
|
||||
protected String getStageTitle() {
|
||||
return "关于 " + APP_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义舞台
|
||||
*
|
||||
* @return 舞台
|
||||
*/
|
||||
@Override
|
||||
protected Scene getCustomizationScene() {
|
||||
return new Scene(this, 450, 240);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化方法
|
||||
*/
|
||||
@Override
|
||||
protected void initialize() {
|
||||
initBottomBox();
|
||||
|
||||
initIconBox();
|
||||
|
||||
initTextBox();
|
||||
}
|
||||
|
||||
private void initTextBox() {
|
||||
VBox textBox = new VBox();
|
||||
textBox.setPadding(new Insets(10));
|
||||
HBox titleBox = new HBox(5);
|
||||
titleBox.setPadding(new Insets(10, 0, 0, 0));
|
||||
|
||||
Label titleLabel = new Label(APP_NAME);
|
||||
titleLabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
Label versionLabel = new Label(VERSION);
|
||||
versionLabel.setPadding(new Insets(0.5, 0, 0, 0));
|
||||
versionLabel.setStyle("-fx-font-size: 15px; -fx-font-weight: bold;");
|
||||
|
||||
titleBox.getChildren().addAll(titleLabel, versionLabel);
|
||||
|
||||
Label descriptionLabel = getLabel(APP_NAME + "是一款自由的集成开发环境。", new Insets(8, 0, 8, 0));
|
||||
|
||||
VBox linkBox = new VBox(7);
|
||||
Hyperlink repositoryLink = getHyperlink("仓库地址", "https://gitee.com/jcnc-org/JNotepad");
|
||||
Hyperlink feedBackLink = getHyperlink("提交反馈", "https://gitee.com/jcnc-org/JNotepad/issues/new/choose");
|
||||
Hyperlink qLink = getHyperlink("加入QQ群", "https://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=x3QF-jrJAKTiwu8kV5-giBk2ow66Kzyr&authKey=qNqrQauD7Ra4fXH%2Ftu4ylHXCyrf2EOYj9oMYOmFjlzYmrgDL8Yd0m2qhrQQEBL25&noverify=0&group_code=386279455");
|
||||
linkBox.getChildren().addAll(repositoryLink, feedBackLink, qLink);
|
||||
|
||||
Label authorLabel = getLabel("Copyleft © 2023 " + AUTHOR + ".", new Insets(8, 0, 8, 0));
|
||||
textBox.getChildren().addAll(titleBox, descriptionLabel, linkBox, authorLabel);
|
||||
this.setCenter(textBox);
|
||||
}
|
||||
|
||||
private void initIconBox() {
|
||||
VBox iconBox = new VBox();
|
||||
ImageView iconImageView = new ImageView(new Image("icon.png"));
|
||||
iconImageView.setFitWidth(50);
|
||||
iconImageView.setFitHeight(50);
|
||||
iconBox.setPadding(new Insets(20));
|
||||
iconBox.getChildren().addAll(iconImageView);
|
||||
this.setLeft(iconBox);
|
||||
}
|
||||
|
||||
private void initBottomBox() {
|
||||
HBox bottomBox = new HBox(10);
|
||||
bottomBox.setPadding(new Insets(7, 15, 7, 0));
|
||||
|
||||
bottomBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||
|
||||
Button leftBtn = getButton(" 复制并关闭 ", event -> {
|
||||
// 获取 RootManager 的实例
|
||||
RootManager rootManager = RootManager.getInstance();
|
||||
|
||||
// 创建一个新的 Notification
|
||||
Notification notification = new Notification();
|
||||
notification.setMessage("已成功复制软件信息!");
|
||||
|
||||
// 调用 RootManager 中的方法来显示 Notification
|
||||
rootManager.addNotificationToStackPane(rootManager.getRootStackPane(), notification);
|
||||
|
||||
Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
String info = "软件名字:" + APP_NAME + "\t" + "版本:" + VERSION;
|
||||
content.putString(info);
|
||||
LogUtil.getLogger(this.getClass()).info("软件信息已经复制到剪贴板:{}", info);
|
||||
clipboard.setContent(content);
|
||||
// 关闭当前的 Stage
|
||||
Stage currentStage = (Stage) ((Button) event.getSource()).getScene().getWindow();
|
||||
currentStage.close();
|
||||
|
||||
});
|
||||
Button rightBtn = getButton(" 关闭 ", event -> {
|
||||
// 关闭当前的 Stage
|
||||
Stage currentStage = (Stage) ((Button) event.getSource()).getScene().getWindow();
|
||||
currentStage.close();
|
||||
});
|
||||
bottomBox.getChildren().addAll(leftBtn, rightBtn);
|
||||
this.setBottom(bottomBox);
|
||||
}
|
||||
|
||||
private Label getLabel(String text, Insets insets) {
|
||||
Label label = new Label(text);
|
||||
label.setPadding(insets);
|
||||
label.setStyle("-fx-font-size: 14px;");
|
||||
return label;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取超链接
|
||||
*
|
||||
* @param text 链接文本
|
||||
* @param url 链接
|
||||
* @return 超链接
|
||||
*/
|
||||
private Hyperlink getHyperlink(String text, String url) {
|
||||
Hyperlink hyperlink = new Hyperlink();
|
||||
hyperlink.setText(text);
|
||||
hyperlink.setOnAction(event -> openWebsite(url));
|
||||
hyperlink.setVisited(true);
|
||||
hyperlink.setMnemonicParsing(true);
|
||||
hyperlink.setStyle("-color-link-fg-visited:-color-accent-fg;");
|
||||
return hyperlink;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义启动方法
|
||||
*
|
||||
* @param stage 舞台
|
||||
*/
|
||||
@Override
|
||||
public void run(Stage stage) {
|
||||
stage.getIcons().add(getStageIcon());
|
||||
stage.setTitle(getStageTitle());
|
||||
stage.setScene(getCustomizationScene());
|
||||
stage.setResizable(false);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开网页方法
|
||||
*/
|
||||
private void openWebsite(String url) {
|
||||
try {
|
||||
LogUtil.getLogger(this.getClass()).info("正在打开---{}", url);
|
||||
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
|
||||
} catch (java.io.IOException e) {
|
||||
LogUtil.getLogger(this.getClass()).info("打开失败---{}", url);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package org.jcnc.jnotepad.ui.pluginstage;
|
||||
package org.jcnc.jnotepad.ui.setstage.pluginstage;
|
||||
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.scene.control.SplitPane;
|
||||
@ -1,4 +1,4 @@
|
||||
package org.jcnc.jnotepad.ui.pluginstage;
|
||||
package org.jcnc.jnotepad.ui.setstage.pluginstage;
|
||||
|
||||
import atlantafx.base.controls.Tile;
|
||||
import atlantafx.base.controls.ToggleSwitch;
|
||||
@ -8,6 +8,7 @@ import javafx.beans.property.BooleanProperty;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.MenuItem;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
@ -27,8 +28,10 @@ import org.commonmark.renderer.html.HtmlRenderer;
|
||||
import org.jcnc.jnotepad.model.entity.PluginDescriptor;
|
||||
import org.jcnc.jnotepad.plugin.manager.PluginManager;
|
||||
import org.jcnc.jnotepad.ui.module.CustomSetButton;
|
||||
import org.jcnc.jnotepad.ui.setstage.AbstractPaneStage;
|
||||
import org.jcnc.jnotepad.util.LogUtil;
|
||||
import org.jcnc.jnotepad.util.PopUpUtil;
|
||||
import org.jcnc.jnotepad.util.UiUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
@ -49,7 +52,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author luke
|
||||
*/
|
||||
public class PluginManagementPane extends BorderPane {
|
||||
public class PluginManagementPane extends AbstractPaneStage {
|
||||
PluginManager pluginManager = PluginManager.getInstance();
|
||||
|
||||
/**
|
||||
@ -78,11 +81,11 @@ public class PluginManagementPane extends BorderPane {
|
||||
public PluginManagementPane() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化插件管理面板。
|
||||
*/
|
||||
private void initialize() {
|
||||
@Override
|
||||
protected void initialize() {
|
||||
// 初始化插件临时集合
|
||||
pluginManager.initializeTemporaryPluginDescriptors();
|
||||
// 创建选项卡面板
|
||||
@ -179,6 +182,17 @@ public class PluginManagementPane extends BorderPane {
|
||||
this.setBottom(bottomBox);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义启动方法
|
||||
*
|
||||
* @param stage 舞台
|
||||
*/
|
||||
@Override
|
||||
public void run(Stage stage) {
|
||||
// 在此添加自定义逻辑
|
||||
stage.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建包含插件列表的VBox,并将其包装在滚动面板中。
|
||||
*
|
||||
@ -420,4 +434,34 @@ public class PluginManagementPane extends BorderPane {
|
||||
});
|
||||
return authorLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取舞台图标
|
||||
*
|
||||
* @return 舞台图标
|
||||
*/
|
||||
@Override
|
||||
protected Image getStageIcon() {
|
||||
return UiUtil.getAppIcon();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取舞台标题
|
||||
*
|
||||
* @return 舞台标题
|
||||
*/
|
||||
@Override
|
||||
protected String getStageTitle() {
|
||||
return "插件管理";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取舞台
|
||||
*
|
||||
* @return 舞台
|
||||
*/
|
||||
@Override
|
||||
protected Scene getCustomizationScene() {
|
||||
return new Scene(this, 900, 600);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 抽象管理类
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public abstract class AbstractManager<T> {
|
||||
|
||||
/**
|
||||
* 获取节点列表
|
||||
*
|
||||
* @return 节点列表
|
||||
*/
|
||||
public abstract List<T> getNodeList();
|
||||
|
||||
public void registerNode(T node) {
|
||||
getNodeList().add(node);
|
||||
}
|
||||
}
|
||||
@ -76,7 +76,6 @@ public class RootManager {
|
||||
rootStackPane = new StackPane();
|
||||
|
||||
// 创建主界面布局
|
||||
BorderPane root = new BorderPane();
|
||||
root.setCenter(RootBorderPane.getInstance());
|
||||
|
||||
rootStackPane.getChildren().addAll(root);
|
||||
@ -110,4 +109,7 @@ public class RootManager {
|
||||
in.playFromStart();
|
||||
}
|
||||
|
||||
public StackPane getRootStackPane() {
|
||||
return rootStackPane;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import org.jcnc.jnotepad.controller.event.handler.setting.SetBtn;
|
||||
import org.jcnc.jnotepad.views.manager.builder.SideBarButtonBuilder;
|
||||
import org.jcnc.jnotepad.views.root.left.sidebar.tools.SidebarToolBar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -14,13 +15,13 @@ import java.util.List;
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class SidebarToolBarManager {
|
||||
public class SidebarToolBarManager extends AbstractManager<Node> {
|
||||
private static final SidebarToolBarManager INSTANCE = new SidebarToolBarManager();
|
||||
/**
|
||||
* 工具栏
|
||||
*/
|
||||
SidebarToolBar sidebarToolBar = SidebarToolBar.getInstance();
|
||||
List<Button> buttonList = new ArrayList<>();
|
||||
private final List<Node> nodeList = new ArrayList<>();
|
||||
|
||||
public static SidebarToolBarManager getInstance() {
|
||||
return INSTANCE;
|
||||
@ -28,24 +29,30 @@ public class SidebarToolBarManager {
|
||||
|
||||
public void initSidebarToolBar() {
|
||||
registerSidebarToolBar();
|
||||
initButtons();
|
||||
// 将节点添加到工具栏
|
||||
sidebarToolBar.getItems().addAll(nodeList);
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
// 将按钮添加到工具栏
|
||||
sidebarToolBar.getItems().addAll(buttonList);
|
||||
}
|
||||
|
||||
public void registerSidebarToolBar() {
|
||||
registerButton(sidebarToolBar.getSetButton(), new SetBtn());
|
||||
// 注册设置按钮
|
||||
registerNode(
|
||||
new SideBarButtonBuilder()
|
||||
.setButton(sidebarToolBar.getSetButton())
|
||||
.setImageView(new ImageView(new Image("tools.png")))
|
||||
.setImageViewEssentialAttribute(10D, 10D, true, 2.5D, 2.5D)
|
||||
.setButtonEssentialAttribute(20D, 20D)
|
||||
.setEventHandler(new SetBtn()).build());
|
||||
}
|
||||
|
||||
public void registerButton(Button button, EventHandler<ActionEvent> eventHandler) {
|
||||
buttonList.add(button);
|
||||
setButton(button, eventHandler);
|
||||
}
|
||||
|
||||
private void setButton(Button button, EventHandler<ActionEvent> eventHandler) {
|
||||
button.setOnAction(eventHandler);
|
||||
/**
|
||||
* 获取节点列表
|
||||
*
|
||||
* @return 节点列表
|
||||
*/
|
||||
@Override
|
||||
public List<Node> getNodeList() {
|
||||
return nodeList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,30 +1,20 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import atlantafx.base.controls.Notification;
|
||||
import atlantafx.base.theme.Styles;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import javafx.scene.input.KeyCombination;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||
import org.jcnc.jnotepad.controller.config.AppConfigController;
|
||||
import org.jcnc.jnotepad.controller.event.handler.menubar.*;
|
||||
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
||||
import org.jcnc.jnotepad.model.entity.ShortcutKey;
|
||||
import org.jcnc.jnotepad.ui.pluginstage.PluginManagementPane;
|
||||
import org.jcnc.jnotepad.ui.setstage.HelpPaneStage;
|
||||
import org.jcnc.jnotepad.ui.setstage.pluginstage.PluginManagementPane;
|
||||
import org.jcnc.jnotepad.util.LogUtil;
|
||||
import org.jcnc.jnotepad.util.UiUtil;
|
||||
import org.jcnc.jnotepad.views.root.top.menu.TopMenuBar;
|
||||
@ -32,7 +22,6 @@ import org.slf4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jcnc.jnotepad.common.constants.AppConstants.*;
|
||||
import static org.jcnc.jnotepad.common.constants.TextConstants.*;
|
||||
|
||||
/**
|
||||
@ -40,10 +29,10 @@ import static org.jcnc.jnotepad.common.constants.TextConstants.*;
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class TopMenuBarManager {
|
||||
public class TopMenuBarManager extends AbstractManager<Menu> {
|
||||
private static final TopMenuBarManager INSTANCE = new TopMenuBarManager();
|
||||
private final TopMenuBar topMenuBar = TopMenuBar.getInstance();
|
||||
private final List<Menu> topMenu = new ArrayList<>();
|
||||
private final List<Menu> nodeList = new ArrayList<>();
|
||||
private final Map<String, MenuItem> fileMenuItems = new HashMap<>();
|
||||
|
||||
private final Map<String, MenuItem> setMenuItems = new HashMap<>();
|
||||
@ -94,7 +83,6 @@ public class TopMenuBarManager {
|
||||
* 注册顶部菜单栏
|
||||
*/
|
||||
public void registerTopMenuBar() {
|
||||
|
||||
// 文件菜单
|
||||
registerFileMenuItem(topMenuBar.getNewItem(), NEW, "newItem", new NewFile());
|
||||
registerFileMenuItem(topMenuBar.getOpenItem(), OPEN, "openItem", new OpenFile());
|
||||
@ -128,160 +116,13 @@ public class TopMenuBarManager {
|
||||
});
|
||||
|
||||
//插件菜单
|
||||
registerPluginMenuItem(topMenuBar.getPluginManagerItem(), MANAGER_PLUGIN, "pluginManagerItem", event -> {
|
||||
Stage newStage = new Stage();
|
||||
newStage.getIcons().add(UiUtil.getAppIcon());
|
||||
newStage.setTitle("插件管理");
|
||||
|
||||
PluginManagementPane pluginManagementPane = new PluginManagementPane();
|
||||
|
||||
Scene scene = new Scene(pluginManagementPane, 900, 600);
|
||||
newStage.setScene(scene);
|
||||
newStage.show();
|
||||
});
|
||||
registerPluginMenuItem(topMenuBar.getPluginManagerItem(), MANAGER_PLUGIN, "pluginManagerItem", event -> new PluginManagementPane().run());
|
||||
registerPluginMenuItem(topMenuBar.getCountItem(), STATISTICS, "countItem", event -> {
|
||||
});
|
||||
|
||||
//帮助菜单
|
||||
registerHelpMenuItem(topMenuBar.getAboutItem(), ABOUT, "aboutItem", event -> {
|
||||
Stage aboutStage = new Stage();
|
||||
String leftBtnText = " 复制并关闭 ";
|
||||
|
||||
String rightBtnText = " 关闭 ";
|
||||
Button leftBtn = new Button();
|
||||
leftBtn.getStyleClass().addAll(Styles.SMALL);
|
||||
leftBtn.setText(leftBtnText);
|
||||
|
||||
Button rightBtn = new Button();
|
||||
rightBtn.getStyleClass().addAll(Styles.SMALL);
|
||||
rightBtn.setText(rightBtnText);
|
||||
aboutStage.getIcons().add(UiUtil.getAppIcon());
|
||||
aboutStage.setTitle("关于 " + APP_NAME);
|
||||
BorderPane root = new BorderPane();
|
||||
VBox textBox = new VBox();
|
||||
VBox iconBox = new VBox();
|
||||
ImageView iconImageView = new ImageView(new Image("icon.png"));
|
||||
iconImageView.setFitWidth(50);
|
||||
iconImageView.setFitHeight(50);
|
||||
iconBox.setPadding(new Insets(20));
|
||||
|
||||
iconBox.getChildren().addAll(iconImageView);
|
||||
|
||||
|
||||
textBox.setPadding(new Insets(10));
|
||||
|
||||
HBox titleBox = new HBox(5);
|
||||
titleBox.setPadding(new Insets(10, 0, 0, 0));
|
||||
|
||||
Label titleLabel = new Label(APP_NAME);
|
||||
titleLabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
Label versionLabel = new Label(VERSION);
|
||||
versionLabel.setPadding(new Insets(0.5, 0, 0, 0));
|
||||
versionLabel.setStyle("-fx-font-size: 15px; -fx-font-weight: bold;");
|
||||
|
||||
titleBox.getChildren().addAll(titleLabel, versionLabel);
|
||||
|
||||
Label descriptionLabel = new Label(APP_NAME + "是一款自由的集成开发环境。");
|
||||
descriptionLabel.setPadding(new Insets(8, 0, 8, 0));
|
||||
descriptionLabel.setStyle("-fx-font-size: 14px;");
|
||||
|
||||
VBox linkBox = new VBox(7);
|
||||
Hyperlink repositoryLink = new Hyperlink();
|
||||
repositoryLink.setText("仓库地址");
|
||||
repositoryLink.setOnAction(event1 -> {
|
||||
openWebsite("https://gitee.com/jcnc-org/JNotepad");
|
||||
});
|
||||
repositoryLink.setVisited(true);
|
||||
repositoryLink.setMnemonicParsing(true);
|
||||
repositoryLink.setStyle("-color-link-fg-visited:-color-accent-fg;");
|
||||
|
||||
Hyperlink feedBackLink = new Hyperlink();
|
||||
feedBackLink.setText("提交反馈");
|
||||
feedBackLink.setOnAction(event1 -> {
|
||||
openWebsite("https://gitee.com/jcnc-org/JNotepad/issues/new/choose");
|
||||
});
|
||||
feedBackLink.setVisited(true);
|
||||
feedBackLink.setMnemonicParsing(true);
|
||||
feedBackLink.setStyle("-color-link-fg-visited:-color-accent-fg;");
|
||||
|
||||
Hyperlink qLink = new Hyperlink();
|
||||
qLink.setText("加入QQ群");
|
||||
qLink.setOnAction(event1 -> {
|
||||
openWebsite("https://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=x3QF-jrJAKTiwu8kV5-giBk2ow66Kzyr&authKey=qNqrQauD7Ra4fXH%2Ftu4ylHXCyrf2EOYj9oMYOmFjlzYmrgDL8Yd0m2qhrQQEBL25&noverify=0&group_code=386279455");
|
||||
});
|
||||
qLink.setVisited(true);
|
||||
qLink.setMnemonicParsing(true);
|
||||
qLink.setStyle("-color-link-fg-visited:-color-accent-fg;");
|
||||
|
||||
linkBox.getChildren().addAll(repositoryLink, feedBackLink, qLink);
|
||||
|
||||
Label authorLabel = new Label("Copyleft © 2023 " + AUTHOR + ".");
|
||||
authorLabel.setPadding(new Insets(8, 0, 8, 0));
|
||||
authorLabel.setStyle("-fx-font-size: 14px;");
|
||||
|
||||
textBox.getChildren().addAll(titleBox, descriptionLabel, linkBox, authorLabel);
|
||||
|
||||
HBox bottomBox = new HBox(10);
|
||||
bottomBox.setPadding(new Insets(7, 15, 7, 0));
|
||||
|
||||
bottomBox.setAlignment(Pos.BOTTOM_RIGHT);
|
||||
|
||||
leftBtn.setOnAction(event1 -> {
|
||||
|
||||
// 获取 RootManager 的实例
|
||||
RootManager rootManager = RootManager.getInstance();
|
||||
|
||||
// 创建一个新的 Notification
|
||||
Notification notification = new Notification();
|
||||
notification.setMessage("已成功复制软件信息!");
|
||||
|
||||
// 调用 RootManager 中的方法来显示 Notification
|
||||
rootManager.addNotificationToStackPane(rootManager.rootStackPane, notification);
|
||||
|
||||
Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
String info = "软件名字:" + APP_NAME + "\t" + "版本:" + VERSION;
|
||||
content.putString(info);
|
||||
LogUtil.getLogger(this.getClass()).info("软件信息已经复制到剪贴板:" + info);
|
||||
clipboard.setContent(content);
|
||||
// 关闭当前的 Stage
|
||||
Stage currentStage = (Stage) leftBtn.getScene().getWindow();
|
||||
currentStage.close();
|
||||
|
||||
});
|
||||
|
||||
rightBtn.setOnAction(event1 -> {
|
||||
// 关闭当前的 Stage
|
||||
Stage currentStage = (Stage) rightBtn.getScene().getWindow();
|
||||
currentStage.close();
|
||||
});
|
||||
bottomBox.getChildren().addAll(leftBtn, rightBtn);
|
||||
|
||||
root.setLeft(iconBox);
|
||||
root.setCenter(textBox);
|
||||
|
||||
root.setBottom(bottomBox);
|
||||
|
||||
Scene scene = new Scene(root, 450, 240);
|
||||
aboutStage.setResizable(false);
|
||||
aboutStage.setScene(scene);
|
||||
aboutStage.show();
|
||||
|
||||
});
|
||||
registerHelpMenuItem(topMenuBar.getAboutItem(), ABOUT, "aboutItem", event -> new HelpPaneStage().run(new Stage()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开网页方法
|
||||
*/
|
||||
private void openWebsite(String url) {
|
||||
try {
|
||||
LogUtil.getLogger(this.getClass()).info("正在打开---" + url);
|
||||
java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
|
||||
} catch (java.io.IOException e) {
|
||||
LogUtil.getLogger(this.getClass()).info("打开失败---" + url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换语言
|
||||
@ -434,16 +275,15 @@ public class TopMenuBarManager {
|
||||
// 保证json的key必须和变量名一致
|
||||
MenuItem menuItem = topMenuBar.getItemMap().get(shortcutKey.getButtonName());
|
||||
String shortKeyValue = shortcutKey.getShortcutKeyValue();
|
||||
if (Objects.isNull(menuItem)) {
|
||||
continue;
|
||||
}
|
||||
if ("".equals(shortKeyValue)) {
|
||||
if ("".equals(shortKeyValue) && menuItem != null) {
|
||||
itemsToUnbind.add(menuItem);
|
||||
continue;
|
||||
}
|
||||
logger.info("功能名称:{}->快捷键:{}", menuItem.getText(), shortKeyValue);
|
||||
// 动态添加快捷键
|
||||
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
||||
if (menuItem != null) {
|
||||
logger.info("功能名称:{}->快捷键:{}", menuItem.getText(), shortKeyValue);
|
||||
// 动态添加快捷键
|
||||
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
||||
}
|
||||
}
|
||||
// 解绑需要解绑的快捷键
|
||||
itemsToUnbind.forEach(menuItem -> menuItem.setAccelerator(null));
|
||||
@ -455,7 +295,7 @@ public class TopMenuBarManager {
|
||||
private void refreshTopMenuBar() {
|
||||
ObservableList<Menu> menus = topMenuBar.getMenus();
|
||||
menus.clear();
|
||||
menus.addAll(topMenu);
|
||||
menus.addAll(nodeList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -535,6 +375,16 @@ public class TopMenuBarManager {
|
||||
itemMap.put((String) value.getUserData(), value);
|
||||
menu.getItems().add(value);
|
||||
});
|
||||
topMenu.add(menu);
|
||||
registerNode(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取节点列表
|
||||
*
|
||||
* @return 节点列表
|
||||
*/
|
||||
@Override
|
||||
public List<Menu> getNodeList() {
|
||||
return nodeList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
package org.jcnc.jnotepad.views.manager.builder;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.ImageView;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 侧边栏按钮建造者
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class SideBarButtonBuilder {
|
||||
private Button button;
|
||||
private ImageView imageView;
|
||||
private EventHandler<ActionEvent> eventHandler;
|
||||
|
||||
public Button build() {
|
||||
Optional<Button> container = Optional.of(new Button());
|
||||
button = container.get();
|
||||
button.setGraphic(imageView);
|
||||
button.setOnAction(eventHandler);
|
||||
return button;
|
||||
}
|
||||
|
||||
public SideBarButtonBuilder setImageView(ImageView imageView) {
|
||||
this.imageView = imageView;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SideBarButtonBuilder setButtonEssentialAttribute(Double relativelyPrefWidth, Double relativelyPrefHeight) {
|
||||
Optional<Double> container = Optional.of(relativelyPrefHeight);
|
||||
button.setPrefWidth(imageView.getFitWidth() + container.orElse(20D));
|
||||
container = Optional.of(relativelyPrefWidth);
|
||||
button.setPrefHeight(imageView.getFitHeight() + container.orElse(20D));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置ImageView属性
|
||||
*
|
||||
* @param fitWidth 适合宽度
|
||||
* @param fitHeight 适合高度
|
||||
* @param preserveRatio 保持比例
|
||||
* @param scaleX X轴比例
|
||||
* @param scaleY Y轴比例
|
||||
* @return 建造者对象
|
||||
*/
|
||||
public SideBarButtonBuilder setImageViewEssentialAttribute(Double fitWidth, Double fitHeight, boolean preserveRatio, Double scaleX, Double scaleY) {
|
||||
Optional<Double> container = Optional.of(fitWidth);
|
||||
imageView.setFitWidth(container.orElse(10D));
|
||||
container = Optional.of(fitHeight);
|
||||
imageView.setFitHeight(container.orElse(10D));
|
||||
imageView.setPreserveRatio(preserveRatio);
|
||||
container = Optional.of(scaleX);
|
||||
imageView.setScaleX(container.orElse(2.5));
|
||||
container = Optional.of(scaleY);
|
||||
imageView.setScaleY(container.orElse(2.5));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public SideBarButtonBuilder setEventHandler(EventHandler<ActionEvent> eventHandler) {
|
||||
this.eventHandler = eventHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SideBarButtonBuilder setButton(Button button) {
|
||||
this.button = button;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,6 @@
|
||||
package org.jcnc.jnotepad.views.root.left.sidebar.tools;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
|
||||
/**
|
||||
* SidebarToolBar 是 JNotepad 应用程序的工具栏类。
|
||||
@ -25,23 +23,6 @@ public class SidebarToolBar extends javafx.scene.control.ToolBar {
|
||||
Button setButton = new Button();
|
||||
|
||||
private SidebarToolBar() {
|
||||
// 创建工具栏上的按钮
|
||||
Image image = new Image("tools.png");
|
||||
ImageView imageView = new ImageView(image);
|
||||
imageView.setFitWidth(10);
|
||||
imageView.setFitHeight(10);
|
||||
|
||||
imageView.setPreserveRatio(true);
|
||||
|
||||
// 设置水平缩放比例
|
||||
imageView.setScaleX(2.5);
|
||||
// 设置垂直缩放比例
|
||||
imageView.setScaleY(2.5);
|
||||
|
||||
// 设置缩放比例
|
||||
setButton.setGraphic(imageView);
|
||||
setButton.setPrefWidth(imageView.getFitWidth() + 20);
|
||||
setButton.setPrefHeight(imageView.getFitHeight() + 20);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user