♻️ 重构代码 重构应用对话框类

This commit is contained in:
gewuyou 2023-09-11 23:11:20 +08:00
parent df7140ff34
commit 967ad9343c
12 changed files with 218 additions and 48 deletions

View File

@ -73,12 +73,6 @@
<scope>system</scope>
<systemPath>${project.basedir}/libs/icu4j-73.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>

View File

@ -15,7 +15,6 @@ module org.jcnc.jnotepad {
requires org.kordamp.ikonli.core;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.antdesignicons;
requires lombok;
exports org.jcnc.jnotepad;
exports org.jcnc.jnotepad.model.enums;
exports org.jcnc.jnotepad.app.config;

View File

@ -1,7 +1,6 @@
package org.jcnc.jnotepad.app.config;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.jcnc.jnotepad.model.entity.ShortcutKey;
import java.util.ArrayList;
@ -14,7 +13,6 @@ import static org.jcnc.jnotepad.common.constants.TextConstants.CHINESE;
*
* @author 许轲
*/
@Data
public class AppConfig {
private static final String CTRL_N = "ctrl+n";
private static final String CTRL_O = "ctrl+o";
@ -63,4 +61,28 @@ public class AppConfig {
shortcutKey.setShortcutKeyValue(shortcutKeyValue);
return shortcutKey;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public List<ShortcutKey> getShortcutKey() {
return shortcutKey;
}
public void setShortcutKey(List<ShortcutKey> shortcutKey) {
this.shortcutKey = shortcutKey;
}
public boolean isTextWrap() {
return textWrap;
}
public void setTextWrap(boolean textWrap) {
this.textWrap = textWrap;
}
}

View File

@ -1,6 +1,5 @@
package org.jcnc.jnotepad.controller.config;
import lombok.Data;
import org.jcnc.jnotepad.app.config.AppConfig;
import org.jcnc.jnotepad.exception.AppException;
import org.jcnc.jnotepad.model.entity.ShortcutKey;
@ -24,7 +23,6 @@ import java.util.List;
*
* @author songdragon
*/
@Data
public class AppConfigController {
/**
@ -165,4 +163,21 @@ public class AppConfigController {
public List<ShortcutKey> getShortcutKey() {
return this.appConfig.getShortcutKey();
}
/**
* 获取当前配置文件所在目录
*
* @return 所在目录
*/
public String getDir() {
return dir;
}
public void setDir(String dir) {
this.dir = dir;
}
private AppConfig getAppConfig() {
return appConfig;
}
}

View File

@ -0,0 +1,45 @@
package org.jcnc.jnotepad.model.entity;
/**
* 插件信息
*
* @author gewuyou
*/
public class PluginInfo {
/**
* 插件名称
*/
private String pluginName;
/**
* 插件版本
*/
private String version;
/**
* 启用状态
*/
private boolean enabled;
public String getPluginName() {
return pluginName;
}
public void setPluginName(String pluginName) {
this.pluginName = pluginName;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@ -1,28 +0,0 @@
package org.jcnc.jnotepad.model.entity;
import lombok.Data;
/**
* 插件类
*
* @author gewuyou
*/
@Data
public class Plugins {
/**
* 插件名称
*/
private String pluginName;
/**
* 插件版本
*/
private String version;
/**
* 作者
*/
private String author;
/**
* 插件描述
*/
private String description;
}

View File

@ -1,13 +1,11 @@
package org.jcnc.jnotepad.model.entity;
import lombok.Data;
/**
* 快捷键信息类
*
* @author gewuyou
*/
@Data
public class ShortcutKey {
/**
* 按钮名称
@ -17,4 +15,20 @@ public class ShortcutKey {
* 快捷键值
*/
private String shortcutKeyValue;
public String getButtonName() {
return buttonName;
}
public void setButtonName(String buttonName) {
this.buttonName = buttonName;
}
public String getShortcutKeyValue() {
return shortcutKeyValue;
}
public void setShortcutKeyValue(String shortcutKeyValue) {
this.shortcutKeyValue = shortcutKeyValue;
}
}

View File

@ -3,6 +3,8 @@ package org.jcnc.jnotepad.plugin;
import org.jcnc.jnotepad.plugin.interfaces.Plugin;
import org.jcnc.jnotepad.util.LogUtil;
import java.util.Map;
/**
* 新按钮插件
*
@ -33,4 +35,24 @@ public class ButtonPlugin implements Plugin {
// 在这里实现新按钮插件的逻辑
LogUtil.getLogger(this.getClass()).info("新按钮插件执行了!");
}
/**
* 获取插件的配置参数
*
* @return 插件的配置参数
*/
@Override
public Map<String, Object> getConfig() {
return null;
}
/**
* 设置插件的配置参数
*
* @param config 插件的配置参数
*/
@Override
public void setConfig(Map<String, Object> config) {
}
}

View File

@ -74,7 +74,7 @@ public class PluginManager {
String displayName = plugin.getDisplayName();
categories.computeIfAbsent(categoryName, k -> new ArrayList<>()).add(displayName);
} else {
LogUtil.getLogger(this.getClass()).info("Plugins file not found: {}", pluginFilePath);
LogUtil.getLogger(this.getClass()).info("PluginInfo file not found: {}", pluginFilePath);
}
}

View File

@ -1,5 +1,8 @@
package org.jcnc.jnotepad.plugin.interfaces;
import java.util.Map;
/**
* 插件接口
* <p>
@ -16,6 +19,7 @@ public interface Plugin extends PluginCategory {
*/
String getDisplayName();
/**
* 初始化插件
*/
@ -25,4 +29,19 @@ public interface Plugin extends PluginCategory {
* 执行插件的逻辑
*/
void execute();
/**
* 获取插件的配置参数
*
* @return 插件的配置参数
*/
Map<String, Object> getConfig();
/**
* 设置插件的配置参数
*
* @param config 插件的配置参数
*/
void setConfig(Map<String, Object> config);
}

View File

@ -58,7 +58,7 @@ public class AppDialog extends Stage {
HBox hBox = new HBox(builder.getHBoxSpacing(), confirmButton, cancelButton);
hBox.setAlignment(builder.getHboxPos());
hBox.setPadding(builder.getHBoxPaddingInsets());
hBox.setPadding(builder.gethBoxPaddingInsets());
vbox.getChildren().addAll(label, customTextLabel, hBox);
borderPane.setLeft(iconBox);

View File

@ -4,7 +4,6 @@ import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.image.Image;
import javafx.stage.Modality;
import lombok.Data;
import org.jcnc.jnotepad.model.enums.DialogType;
import org.jcnc.jnotepad.ui.dialog.interfaces.DialogButtonAction;
import org.jcnc.jnotepad.util.UiUtil;
@ -15,7 +14,6 @@ import org.kordamp.ikonli.javafx.FontIcon;
*
* @author gewuyou
*/
@Data
public class AppDialogBuilder {
private AppDialog appDialog;
private Image appIcon = UiUtil.getAppIcon();
@ -96,6 +94,10 @@ public class AppDialogBuilder {
return this;
}
public AppDialog build() {
appDialog = new AppDialog(this);
return appDialog;
}
/**
* 设置对话框标题
@ -238,9 +240,75 @@ public class AppDialogBuilder {
return this;
}
public Image getAppIcon() {
return appIcon;
}
public AppDialog build() {
appDialog = new AppDialog(this);
return appDialog;
public String getTitle() {
return title;
}
public String getHeaderText() {
return headerText;
}
public String getCustomText() {
return customText;
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
public FontIcon getIcon() {
return icon;
}
public DialogButtonAction getLeftBtnAction() {
return leftBtnAction;
}
public DialogButtonAction getRightBtnAction() {
return rightBtnAction;
}
public String getLeftBtnText() {
return leftBtnText;
}
public String getRightBtnText() {
return rightBtnText;
}
public Insets getIconCoxPaddingInsets() {
return iconCoxPaddingInsets;
}
public Insets gethBoxPaddingInsets() {
return hBoxPaddingInsets;
}
public boolean isResizable() {
return isResizable;
}
public double getHBoxSpacing() {
return hBoxSpacing;
}
public Pos getVboxPos() {
return vboxPos;
}
public Pos getHboxPos() {
return hboxPos;
}
public Modality getModality() {
return modality;
}
}