️ 优化代码逻辑

This commit is contained in:
gewuyou 2023-08-30 13:38:04 +08:00
parent 4db5107d81
commit 3a8b939cbe
28 changed files with 334 additions and 276 deletions

View File

@ -12,20 +12,24 @@ module org.jcnc.jnotepad {
requires ch.qos.logback.core; requires ch.qos.logback.core;
requires ch.qos.logback.classic; requires ch.qos.logback.classic;
requires com.ibm.icu; requires com.ibm.icu;
exports org.jcnc.jnotepad.app.config;
exports org.jcnc.jnotepad; exports org.jcnc.jnotepad;
exports org.jcnc.jnotepad.app.config;
exports org.jcnc.jnotepad.app.i18n;
exports org.jcnc.jnotepad.constants;
exports org.jcnc.jnotepad.controller.config;
exports org.jcnc.jnotepad.controller.manager;
exports org.jcnc.jnotepad.controller.i18n;
exports org.jcnc.jnotepad.controller.event.handler.tool;
exports org.jcnc.jnotepad.controller.event.handler.menuBar;
exports org.jcnc.jnotepad.tool; exports org.jcnc.jnotepad.tool;
exports org.jcnc.jnotepad.Interface; exports org.jcnc.jnotepad.Interface;
exports org.jcnc.jnotepad.controller.manager;
exports org.jcnc.jnotepad.view.manager;
exports org.jcnc.jnotepad.constants;
exports org.jcnc.jnotepad.controller.i18n;
exports org.jcnc.jnotepad.ui.root.center.tab; exports org.jcnc.jnotepad.ui.root.center.tab;
exports org.jcnc.jnotepad.ui.root.bottom.status; exports org.jcnc.jnotepad.ui.root.bottom.status;
exports org.jcnc.jnotepad.ui.root.top.menu; exports org.jcnc.jnotepad.ui.root.top.menu;
opens org.jcnc.jnotepad.app.config;
exports org.jcnc.jnotepad.ui.module; exports org.jcnc.jnotepad.ui.module;
exports org.jcnc.jnotepad.ui.setStage;
exports org.jcnc.jnotepad.ui.root.top.tools; exports org.jcnc.jnotepad.ui.root.top.tools;
exports org.jcnc.jnotepad.controller.event.handler.tool; exports org.jcnc.jnotepad.view.manager;
exports org.jcnc.jnotepad.controller.event.handler.menuBar; opens org.jcnc.jnotepad.app.config;
} }

View File

@ -8,5 +8,6 @@ public interface HBoxAble {
void addChild(Node node); void addChild(Node node);
void addChild(Node... nodes); void addChild(Node... nodes);
HBox getHBox(); HBox getHBox();
} }

View File

@ -6,12 +6,12 @@ import javafx.application.Application;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.jcnc.jnotepad.app.i18n.UIResourceBundle; import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
import org.jcnc.jnotepad.constants.AppConstants; import org.jcnc.jnotepad.constants.AppConstants;
import org.jcnc.jnotepad.constants.TextConstants; import org.jcnc.jnotepad.constants.TextConstants;
import org.jcnc.jnotepad.controller.i18n.LocalizationController; import org.jcnc.jnotepad.controller.i18n.LocalizationController;
import org.jcnc.jnotepad.controller.manager.Controller;
import org.jcnc.jnotepad.manager.ThreadPoolManager; import org.jcnc.jnotepad.manager.ThreadPoolManager;
import org.jcnc.jnotepad.tool.SingletonUtil;
import org.jcnc.jnotepad.tool.UiUtil; import org.jcnc.jnotepad.tool.UiUtil;
import org.jcnc.jnotepad.view.manager.ViewManager; import org.jcnc.jnotepad.view.manager.ViewManager;
@ -30,9 +30,12 @@ public class LunchApp extends Application {
* 线程池 * 线程池
*/ */
private final ExecutorService threadPool = ThreadPoolManager.getThreadPool(); private final ExecutorService threadPool = ThreadPoolManager.getThreadPool();
Controller controller = Controller.getInstance();
Scene scene; Scene scene;
public static void main(String[] args) {
launch(args);
}
@Override @Override
public void start(Stage primaryStage) { public void start(Stage primaryStage) {
Pane root = new Pane(); Pane root = new Pane();
@ -42,7 +45,7 @@ public class LunchApp extends Application {
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet()); Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm()); scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm());
initUiComponents(); initUiComponents();
UIResourceBundle.bindStringProperty(primaryStage.titleProperty(), TextConstants.TITLE); UiResourceBundle.bindStringProperty(primaryStage.titleProperty(), TextConstants.TITLE);
primaryStage.setWidth(width); primaryStage.setWidth(width);
primaryStage.setHeight(length); primaryStage.setHeight(length);
primaryStage.setScene(scene); primaryStage.setScene(scene);
@ -61,7 +64,7 @@ public class LunchApp extends Application {
// 使用线程池加载关联文件并创建文本区域 // 使用线程池加载关联文件并创建文本区域
List<String> rawParameters = getParameters().getRaw(); List<String> rawParameters = getParameters().getRaw();
controller.openAssociatedFileAndCreateTextArea(rawParameters); SingletonUtil.getController().openAssociatedFileAndCreateTextArea(rawParameters);
} }
@Override @Override
@ -70,8 +73,4 @@ public class LunchApp extends Application {
threadPool.shutdownNow(); threadPool.shutdownNow();
} }
public static void main(String[] args) {
launch(args);
}
} }

View File

@ -5,64 +5,23 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.jcnc.jnotepad.constants.TextConstants.CHINESE;
/** /**
* 数据模型类用于表示 MyData 对象的数据结构 * 数据模型类用于表示 MyData 对象的数据结构
* *
* @author 许轲 * @author 许轲
*/ */
public class AppConfig { public class AppConfig {
private String language;
@JsonIgnore
private boolean textWrap;
private List<ShortcutKey> shortcutKey;
/**
* ShortcutKey 用于表示快捷键信息
*/
public static class ShortcutKey {
private String buttonName;
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;
}
}
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;
}
private static final String CTRL_N = "ctrl+n"; private static final String CTRL_N = "ctrl+n";
private static final String CTRL_O = "ctrl+o"; private static final String CTRL_O = "ctrl+o";
private static final String CTRL_S = "ctrl+s"; private static final String CTRL_S = "ctrl+s";
private static final String CTRL_ALT_S = "ctrl+alt+s"; private static final String CTRL_ALT_S = "ctrl+alt+s";
private static final String ALT_S = "alt+s"; private static final String ALT_S = "alt+s";
private String language;
@JsonIgnore
private boolean textWrap;
private List<ShortcutKey> shortcutKey;
/** /**
* 生成默认应用配置对象 * 生成默认应用配置对象
@ -71,7 +30,7 @@ public class AppConfig {
*/ */
public static AppConfig generateDefaultAppConfig() { public static AppConfig generateDefaultAppConfig() {
AppConfig myData = new AppConfig(); AppConfig myData = new AppConfig();
myData.setLanguage("chinese"); myData.setLanguage(CHINESE);
myData.setTextWrap(false); myData.setTextWrap(false);
List<AppConfig.ShortcutKey> shortcutKeys = new ArrayList<>(); List<AppConfig.ShortcutKey> shortcutKeys = new ArrayList<>();
@ -102,6 +61,22 @@ public class AppConfig {
return shortcutKey; 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() { public boolean isTextWrap() {
return textWrap; return textWrap;
} }
@ -109,4 +84,28 @@ public class AppConfig {
public void setTextWrap(boolean textWrap) { public void setTextWrap(boolean textWrap) {
this.textWrap = textWrap; this.textWrap = textWrap;
} }
/**
* ShortcutKey 用于表示快捷键信息
*/
public static class ShortcutKey {
private String buttonName;
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

@ -15,31 +15,52 @@ import java.util.ResourceBundle;
* *
* @author songdragon * @author songdragon
*/ */
public class UIResourceBundle { public class UiResourceBundle {
private static final UIResourceBundle INSTANCE = new UIResourceBundle(); private static final UiResourceBundle INSTANCE = new UiResourceBundle();
/** /**
* resource目录下的i18n/i18nXXX.properties * resource目录下的i18n/i18nXXX.properties
*/ */
private static final String BASENAME = "i18n/i18n"; private static final String BASENAME = "i18n/i18n";
/**
* 资源文件的观察者绑定
*/
private final ObjectProperty<ResourceBundle> resources = new SimpleObjectProperty<>();
/** /**
* 当前语言 * 当前语言
*/ */
private Locale currentLocale; private Locale currentLocale;
public static UIResourceBundle getInstance() { private UiResourceBundle() {
}
public static UiResourceBundle getInstance() {
return INSTANCE; return INSTANCE;
} }
private UIResourceBundle() { /**
* 工具方法绑定StringProperty和Key对应的内容
*
* @param stringProperty 字符串属性
* @param key 键值
*/
public static void bindStringProperty(StringProperty stringProperty, String key) {
if (stringProperty == null) {
return;
}
stringProperty.bind(getInstance().getStringBinding(key));
} }
/** /**
* 资源文件的观察者绑定 * 获取当前资源中的key值
*
* @param key 资源所对应键
* @return 当前键所对应的值
*/ */
private final ObjectProperty<ResourceBundle> resources = new SimpleObjectProperty<>(); public static String getContent(String key) {
return INSTANCE.getResources().getString(key);
}
/** /**
* 获取当前资源文件 * 获取当前资源文件
@ -81,29 +102,6 @@ public class UIResourceBundle {
return Bindings.createStringBinding(() -> getResources().getString(key), resourcesProperty()); return Bindings.createStringBinding(() -> getResources().getString(key), resourcesProperty());
} }
/**
* 工具方法绑定StringProperty和Key对应的内容
*
* @param stringProperty 字符串属性
* @param key 键值
*/
public static void bindStringProperty(StringProperty stringProperty, String key) {
if (stringProperty == null) {
return;
}
stringProperty.bind(getInstance().getStringBinding(key));
}
/**
* 获取当前资源中的key值
*
* @param key 资源所对应键
* @return 当前键所对应的值
*/
public static String getContent(String key) {
return INSTANCE.getResources().getString(key);
}
/** /**
* 注册资源变更监听器 * 注册资源变更监听器
* *

View File

@ -7,9 +7,6 @@ package org.jcnc.jnotepad.constants;
*/ */
public class AppConstants { public class AppConstants {
private AppConstants() {
}
/** /**
* 初始宽度 * 初始宽度
*/ */
@ -23,4 +20,7 @@ public class AppConstants {
*/ */
public static final String APP_ICON = "/img/icon.png"; public static final String APP_ICON = "/img/icon.png";
private AppConstants() {
}
} }

View File

@ -8,19 +8,15 @@ package org.jcnc.jnotepad.constants;
*/ */
public class TextConstants { public class TextConstants {
private TextConstants() { public static final String TITLE = "title";
}
/// GlobalConfig文本常量 /// GlobalConfig文本常量
public static final String TITLE = "title";
public static final String SAVE = "SAVE"; public static final String SAVE = "SAVE";
public static final String FILE = "FILE"; public static final String FILE = "FILE";
public static final String NEW = "NEW"; public static final String NEW = "NEW";
public static final String OPEN = "OPEN"; public static final String OPEN = "OPEN";
public static final String SAVE_AS = "SAVE_AS"; public static final String SAVE_AS = "SAVE_AS";
public static final String RENAME = "RENAME"; public static final String RENAME = "RENAME";
public static final String SET = "SET"; public static final String SET = "SET";
public static final String WORD_WRAP = "WORD_WRAP"; public static final String WORD_WRAP = "WORD_WRAP";
@ -37,16 +33,18 @@ public class TextConstants {
public static final String COLUMN = "COLUMN"; public static final String COLUMN = "COLUMN";
public static final String WORD_COUNT = "WORD_COUNT"; public static final String WORD_COUNT = "WORD_COUNT";
public static final String ENCODE = "ENCODE"; public static final String ENCODE = "ENCODE";
/// Config 文本常量
/** /**
* 英文小写 * 英文小写
*/ */
public static final String ENGLISH = "english"; public static final String ENGLISH = "english";
/// Config 文本常量
/** /**
* 中文小写 * 中文小写
*/ */
public static final String CHINESE = "chinese"; public static final String CHINESE = "chinese";
private TextConstants() {
}
} }

View File

@ -22,27 +22,23 @@ import java.util.List;
*/ */
public class AppConfigController { public class AppConfigController {
private static final Logger logger = LogUtil.getLogger(AppConfigController.class);
private static final AppConfigController INSTANCE = new AppConfigController();
public static AppConfigController getInstance() {
return INSTANCE;
}
/** /**
* 配置文件名 * 配置文件名
*/ */
public static final String CONFIG_NAME = "jnotepadConfig.json"; public static final String CONFIG_NAME = "jnotepadConfig.json";
private static final Logger logger = LogUtil.getLogger(AppConfigController.class);
private static final AppConfigController INSTANCE = new AppConfigController();
private AppConfig appConfig; private AppConfig appConfig;
private String dir; private String dir;
private AppConfigController() { private AppConfigController() {
setDir(Paths.get(System.getProperty("user.home"), ".jnotepad").toString()); setDir(Paths.get(System.getProperty("user.home"), ".jnotepad").toString());
loadConfig(); loadConfig();
} }
public static AppConfigController getInstance() {
return INSTANCE;
}
/** /**
* 加载配置文件内容 * 加载配置文件内容
*/ */

View File

@ -2,7 +2,7 @@ package org.jcnc.jnotepad.controller.event.handler.menuBar;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import org.jcnc.jnotepad.app.i18n.UIResourceBundle; import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
import org.jcnc.jnotepad.constants.TextConstants; import org.jcnc.jnotepad.constants.TextConstants;
import org.jcnc.jnotepad.tool.UiUtil; import org.jcnc.jnotepad.tool.UiUtil;
import org.jcnc.jnotepad.ui.module.LineNumberTextArea; import org.jcnc.jnotepad.ui.module.LineNumberTextArea;
@ -36,7 +36,7 @@ public class NewFile implements EventHandler<ActionEvent> {
ViewManager viewManager = UiUtil.getViewManager(); ViewManager viewManager = UiUtil.getViewManager();
// 创建标签页 // 创建标签页
JNotepadTab jNotepadTab = new JNotepadTab( JNotepadTab jNotepadTab = new JNotepadTab(
UIResourceBundle.getContent(TextConstants.NEW_FILE) UiResourceBundle.getContent(TextConstants.NEW_FILE)
+ viewManager.selfIncreaseAndGetTabIndex(), + viewManager.selfIncreaseAndGetTabIndex(),
textArea); textArea);
// 设置当前标签页与本地文件无关联 // 设置当前标签页与本地文件无关联

View File

@ -1,8 +1,8 @@
package org.jcnc.jnotepad.controller.event.handler.menuBar; package org.jcnc.jnotepad.controller.event.handler.menuBar;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.tool.LogUtil; import org.jcnc.jnotepad.tool.LogUtil;
import org.jcnc.jnotepad.tool.SingletonUtil;
import java.io.File; import java.io.File;
@ -16,7 +16,7 @@ public class OpenConfig extends OpenFile {
@Override @Override
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
// 显示文件选择对话框并获取配置文件 // 显示文件选择对话框并获取配置文件
File file = AppConfigController.getInstance().getConfigPath().toFile(); File file = SingletonUtil.getAppConfigController().getConfigPath().toFile();
LogUtil.getLogger(this.getClass()).info("已调用打开配置文件功能,{}", file); LogUtil.getLogger(this.getClass()).info("已调用打开配置文件功能,{}", file);
// 创建打开文件的任务并启动线程执行任务 // 创建打开文件的任务并启动线程执行任务
openFile(file); openFile(file);

View File

@ -3,9 +3,9 @@ package org.jcnc.jnotepad.controller.event.handler.menuBar;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.controller.i18n.LocalizationController; import org.jcnc.jnotepad.controller.i18n.LocalizationController;
import org.jcnc.jnotepad.tool.LogUtil; import org.jcnc.jnotepad.tool.LogUtil;
import org.jcnc.jnotepad.tool.SingletonUtil;
import org.jcnc.jnotepad.tool.UiUtil; import org.jcnc.jnotepad.tool.UiUtil;
import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab; import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -46,7 +46,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
// 如果该文件是配置文件则刷新快捷键 // 如果该文件是配置文件则刷新快捷键
if (CONFIG_NAME.equals(selectedTab.getText())) { if (CONFIG_NAME.equals(selectedTab.getText())) {
// 重新加载语言包和快捷键 // 重新加载语言包和快捷键
AppConfigController.getInstance().loadConfig(); SingletonUtil.getAppConfigController().loadConfig();
UiUtil.getMenuBar().initShortcutKeys(); UiUtil.getMenuBar().initShortcutKeys();
LocalizationController.initLocal(); LocalizationController.initLocal();
logger.info("已刷新语言包!"); logger.info("已刷新语言包!");

View File

@ -2,7 +2,7 @@ package org.jcnc.jnotepad.controller.event.handler.tool;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import org.jcnc.jnotepad.ui.setStage.SetStage; import org.jcnc.jnotepad.tool.UiUtil;
/** /**
@ -21,7 +21,7 @@ public class SetBtn implements EventHandler<ActionEvent> {
*/ */
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
SetStage.getInstance().openSetStage(); UiUtil.getSetStage().openSetStage();
} }

View File

@ -1,8 +1,8 @@
package org.jcnc.jnotepad.controller.i18n; package org.jcnc.jnotepad.controller.i18n;
import org.jcnc.jnotepad.LunchApp; import org.jcnc.jnotepad.LunchApp;
import org.jcnc.jnotepad.app.i18n.UIResourceBundle;
import org.jcnc.jnotepad.controller.config.AppConfigController; import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.tool.SingletonUtil;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -36,15 +36,14 @@ public class LocalizationController {
SUPPORT_LANGUAGES.put(Locale.ENGLISH, ENGLISH); SUPPORT_LANGUAGES.put(Locale.ENGLISH, ENGLISH);
} }
public static Locale getCurrentLocal() { private final AppConfigController appConfigController;
return Locale.getDefault();
private LocalizationController() {
this.appConfigController = SingletonUtil.getAppConfigController();
} }
/** public static Locale getCurrentLocal() {
* 初始化语言配置 return Locale.getDefault();
*/
public static void initLocal() {
setCurrentLocal(null);
} }
/** /**
@ -65,19 +64,15 @@ public class LocalizationController {
} }
Locale.setDefault(locale); Locale.setDefault(locale);
UIResourceBundle.getInstance().resetLocal(getCurrentLocal()); SingletonUtil.getUiResourceBundle().resetLocal(getCurrentLocal());
LOCALIZATION_CONFIG.setLanguage(SUPPORT_LANGUAGES.get(locale)); LOCALIZATION_CONFIG.setLanguage(SUPPORT_LANGUAGES.get(locale));
} }
private LocalizationController() { /**
this.appConfigController = AppConfigController.getInstance(); * 初始化语言配置
} */
public static void initLocal() {
private final AppConfigController appConfigController; setCurrentLocal(null);
private void setLanguage(String language) {
appConfigController.updateLanguage(language);
} }
/** /**
@ -88,4 +83,8 @@ public class LocalizationController {
public String getLanguage() { public String getLanguage() {
return appConfigController.getLanguage(); return appConfigController.getLanguage();
} }
private void setLanguage(String language) {
appConfigController.updateLanguage(language);
}
} }

View File

@ -13,9 +13,6 @@ import java.util.concurrent.atomic.AtomicInteger;
* @author gewuyou * @author gewuyou
*/ */
public class ThreadPoolManager { public class ThreadPoolManager {
private ThreadPoolManager() {
}
private static final Logger logger = LogUtil.getLogger(ThreadPoolManager.class); private static final Logger logger = LogUtil.getLogger(ThreadPoolManager.class);
/** /**
* 核心线程数 * 核心线程数
@ -45,18 +42,6 @@ public class ThreadPoolManager {
* 当前运行线程数 * 当前运行线程数
*/ */
private static final AtomicInteger THREAD_COUNT = new AtomicInteger(1); private static final AtomicInteger THREAD_COUNT = new AtomicInteger(1);
/**
* 当前运行线程数自减
*
* @apiNote 当你创建任务时务必在最后执行一次该方法
* @see ThreadPoolManager
* @since 2023/8/26 22:00
*/
public static void threadContSelfSubtracting() {
THREAD_COUNT.decrementAndGet();
}
/** /**
* 线程工厂 * 线程工厂
*/ */
@ -78,6 +63,20 @@ public class ThreadPoolManager {
private static final ThreadPoolExecutor THREAD_POOL = new ThreadPoolExecutor( private static final ThreadPoolExecutor THREAD_POOL = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, TIME_UNIT, BLOCKING_QUEUE, THREAD_FACTORY, HANDLER); CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_TIME, TIME_UNIT, BLOCKING_QUEUE, THREAD_FACTORY, HANDLER);
private ThreadPoolManager() {
}
/**
* 当前运行线程数自减
*
* @apiNote 当你创建任务时务必在最后执行一次该方法
* @see ThreadPoolManager
* @since 2023/8/26 22:00
*/
public static void threadContSelfSubtracting() {
THREAD_COUNT.decrementAndGet();
}
public static ExecutorService getThreadPool() { public static ExecutorService getThreadPool() {
return THREAD_POOL; return THREAD_POOL;
} }

View File

@ -17,11 +17,11 @@ import java.nio.charset.Charset;
* @author 许轲 * @author 许轲
*/ */
public class EncodingDetector { public class EncodingDetector {
private static final Logger LOG = LogUtil.getLogger(EncodingDetector.class);
/** /**
* 编码侦测概率阈值50% * 编码侦测概率阈值50%
*/ */
public static final int THRESHOLD_CONFIDENCE = 50; public static final int THRESHOLD_CONFIDENCE = 50;
private static final Logger LOG = LogUtil.getLogger(EncodingDetector.class);
private EncodingDetector() { private EncodingDetector() {

View File

@ -15,9 +15,6 @@ import static com.fasterxml.jackson.core.util.DefaultIndenter.SYS_LF;
* @author songdragon * @author songdragon
*/ */
public class JsonUtil { public class JsonUtil {
private JsonUtil() {
}
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
static { static {
@ -29,6 +26,9 @@ public class JsonUtil {
OBJECT_MAPPER.setDefaultPrettyPrinter(prettyPrinter); OBJECT_MAPPER.setDefaultPrettyPrinter(prettyPrinter);
} }
private JsonUtil() {
}
public static String toJsonString(Object o) { public static String toJsonString(Object o) {
try { try {
return OBJECT_MAPPER.writeValueAsString(o); return OBJECT_MAPPER.writeValueAsString(o);

View File

@ -0,0 +1,63 @@
package org.jcnc.jnotepad.tool;
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.controller.manager.Controller;
/**
* 单例工具<br>
* 封装了除UI组件外项目中所有需要的单例组件以减少单例带来的代码的复杂性
*
* @author gewuyou
*/
public class SingletonUtil {
/**
* 控制器类
*/
private static final Controller CONTROLLER = Controller.getInstance();
/**
* 应用程序配置控制器
*/
private static final AppConfigController APP_CONFIG_CONTROLLER = AppConfigController.getInstance();
/**
* UI资源绑定组件
*/
private static final UiResourceBundle UI_RESOURCE_BUNDLE = UiResourceBundle.getInstance();
private SingletonUtil() {
}
/**
* 获取控制器类
*
* @return org.jcnc.jnotepad.controller.manager.Controller
* @since 2023/8/30 13:25
*/
public static Controller getController() {
return CONTROLLER;
}
/**
* 获取应用程序配置控制器
*
* @return org.jcnc.jnotepad.controller.config.AppConfigController
* @since 2023/8/30 12:48
*/
public static AppConfigController getAppConfigController() {
return APP_CONFIG_CONTROLLER;
}
/**
* 获取UI资源绑定组件I
*
* @return org.jcnc.jnotepad.app.i18n.UiResourceBundle
* @since 2023/8/30 12:45
*/
public static UiResourceBundle getUiResourceBundle() {
return UI_RESOURCE_BUNDLE;
}
}

View File

@ -7,6 +7,7 @@ import org.jcnc.jnotepad.ui.root.bottom.status.JNotepadStatusBox;
import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab; import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab;
import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTabPane;
import org.jcnc.jnotepad.ui.root.top.menu.JNotepadMenuBar; import org.jcnc.jnotepad.ui.root.top.menu.JNotepadMenuBar;
import org.jcnc.jnotepad.ui.setStage.SetStage;
import org.jcnc.jnotepad.view.manager.ViewManager; import org.jcnc.jnotepad.view.manager.ViewManager;
import java.util.Objects; import java.util.Objects;
@ -18,9 +19,6 @@ import java.util.Objects;
* @author gewuyou * @author gewuyou
*/ */
public class UiUtil { public class UiUtil {
private UiUtil() {
}
/** /**
* 标签页布局组件 * 标签页布局组件
*/ */
@ -41,6 +39,23 @@ public class UiUtil {
* 应用程序图标 * 应用程序图标
*/ */
private static final Image ICON = new Image(Objects.requireNonNull(UiUtil.class.getResource(AppConstants.APP_ICON)).toString()); private static final Image ICON = new Image(Objects.requireNonNull(UiUtil.class.getResource(AppConstants.APP_ICON)).toString());
/**
* 设置窗口
*/
private static final SetStage SET_STAGE = SetStage.getInstance();
private UiUtil() {
}
/**
* 获取设置窗口
*
* @return org.jcnc.jnotepad.ui.setStage.SetStage
* @since 2023/8/30 12:39
*/
public static SetStage getSetStage() {
return SET_STAGE;
}
/** /**
* 获取应用程序图标 * 获取应用程序图标

View File

@ -3,11 +3,10 @@ package org.jcnc.jnotepad.ui.module;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.tool.LogUtil; import org.jcnc.jnotepad.tool.LogUtil;
import org.jcnc.jnotepad.ui.root.bottom.status.JNotepadStatusBox; import org.jcnc.jnotepad.tool.SingletonUtil;
import org.jcnc.jnotepad.tool.UiUtil;
import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab; import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab;
import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTabPane;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -18,16 +17,15 @@ import java.io.IOException;
* @author 许轲 * @author 许轲
*/ */
public class LineNumberTextArea extends BorderPane { public class LineNumberTextArea extends BorderPane {
private final TextArea mainTextArea;
private final TextArea lineNumberArea;
static final int[] SIZE_TABLE = {9, 99, 999, 9999, 99999, 999999, 9999999, static final int[] SIZE_TABLE = {9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Integer.MAX_VALUE}; 99999999, 999999999, Integer.MAX_VALUE};
private static final int MIN_LINE_NUMBER_WIDTH = 30; private static final int MIN_LINE_NUMBER_WIDTH = 30;
private final TextArea mainTextArea;
private final TextArea lineNumberArea;
public LineNumberTextArea() { public LineNumberTextArea() {
mainTextArea = new TextArea(); mainTextArea = new TextArea();
mainTextArea.setWrapText(AppConfigController.getInstance().getAutoLineConfig()); mainTextArea.setWrapText(SingletonUtil.getAppConfigController().getAutoLineConfig());
lineNumberArea = new TextArea(); lineNumberArea = new TextArea();
lineNumberArea.setEditable(false); lineNumberArea.setEditable(false);
@ -58,12 +56,12 @@ public class LineNumberTextArea extends BorderPane {
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth()); lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> JNotepadStatusBox.getInstance().updateWordCountStatusLabel()); this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> UiUtil.getStatusBox().updateWordCountStatusLabel());
this.textProperty().addListener((observable, oldValue, newValue) -> { this.textProperty().addListener((observable, oldValue, newValue) -> {
// 更新行号 // 更新行号
updateLineNumberArea(); updateLineNumberArea();
// 更新状态栏 // 更新状态栏
JNotepadStatusBox.getInstance().updateWordCountStatusLabel(); UiUtil.getStatusBox().updateWordCountStatusLabel();
// 自动保存 // 自动保存
save(); save();
}); });
@ -73,7 +71,7 @@ public class LineNumberTextArea extends BorderPane {
* 以原文件编码格式写回文件 * 以原文件编码格式写回文件
*/ */
public void save() { public void save() {
JNotepadTab tab = JNotepadTabPane.getInstance().getSelected(); JNotepadTab tab = UiUtil.getJnotepadtab();
if (tab != null) { if (tab != null) {
File file = (File) tab.getUserData(); File file = (File) tab.getUserData();
String newValue = this.mainTextArea.getText(); String newValue = this.mainTextArea.getText();
@ -87,6 +85,7 @@ public class LineNumberTextArea extends BorderPane {
} }
} }
} }
private void updateLineNumberWidth() { private void updateLineNumberWidth() {
int numOfLines = mainTextArea.getParagraphs().size(); int numOfLines = mainTextArea.getParagraphs().size();
int count = 1; int count = 1;

View File

@ -3,7 +3,7 @@ package org.jcnc.jnotepad.ui.root.bottom.status;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
import org.jcnc.jnotepad.app.i18n.UIResourceBundle; import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
import org.jcnc.jnotepad.constants.TextConstants; import org.jcnc.jnotepad.constants.TextConstants;
import org.jcnc.jnotepad.ui.module.AbstractHBox; import org.jcnc.jnotepad.ui.module.AbstractHBox;
import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab; import org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab;
@ -21,13 +21,11 @@ import java.nio.charset.Charset;
public class JNotepadStatusBox extends AbstractHBox { public class JNotepadStatusBox extends AbstractHBox {
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox(); private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
private static final String STATUS_LABEL_FORMAT = "%s : %d \t%s: %d \t%s: %d \t";
/** /**
* 字数统计及光标 * 字数统计及光标
*/ */
private Label statusLabel; private Label statusLabel;
private static final String STATUS_LABEL_FORMAT = "%s : %d \t%s: %d \t%s: %d \t";
/** /**
* 显示文本编码 * 显示文本编码
*/ */
@ -38,6 +36,10 @@ public class JNotepadStatusBox extends AbstractHBox {
initStatusBox(); initStatusBox();
} }
public static JNotepadStatusBox getInstance() {
return STATUS_BOX;
}
/** /**
* 初始化状态栏组件 * 初始化状态栏组件
* *
@ -56,14 +58,10 @@ public class JNotepadStatusBox extends AbstractHBox {
this.getChildren().add(encodingLabel); this.getChildren().add(encodingLabel);
this.getProperties().put("borderpane-margin", new Insets(5, 10, 5, 10)); this.getProperties().put("borderpane-margin", new Insets(5, 10, 5, 10));
UIResourceBundle.getInstance().addListener((observable, oldValue, newValue) -> updateWhenTabSelected()); UiResourceBundle.getInstance().addListener((observable, oldValue, newValue) -> updateWhenTabSelected());
} }
public static JNotepadStatusBox getInstance() {
return STATUS_BOX;
}
public void updateEncodingLabel() { public void updateEncodingLabel() {
updateEncodingLabel(null); updateEncodingLabel(null);
} }
@ -143,9 +141,9 @@ public class JNotepadStatusBox extends AbstractHBox {
} }
protected String getStatusBarFormattedText(int row, int column, int wordCount) { protected String getStatusBarFormattedText(int row, int column, int wordCount) {
String rowText = UIResourceBundle.getContent(TextConstants.ROW); String rowText = UiResourceBundle.getContent(TextConstants.ROW);
String columnText = UIResourceBundle.getContent(TextConstants.COLUMN); String columnText = UiResourceBundle.getContent(TextConstants.COLUMN);
String wordCountText = UIResourceBundle.getContent(TextConstants.WORD_COUNT); String wordCountText = UiResourceBundle.getContent(TextConstants.WORD_COUNT);
return String.format(STATUS_LABEL_FORMAT, return String.format(STATUS_LABEL_FORMAT,
rowText, rowText,
row, row,
@ -158,6 +156,6 @@ public class JNotepadStatusBox extends AbstractHBox {
protected String getEncodingFormattedText(String encoding) { protected String getEncodingFormattedText(String encoding) {
String encodingLabelFormat = "\t%s : %s"; String encodingLabelFormat = "\t%s : %s";
return String.format(encodingLabelFormat, UIResourceBundle.getContent(TextConstants.ENCODE), encoding); return String.format(encodingLabelFormat, UiResourceBundle.getContent(TextConstants.ENCODE), encoding);
} }
} }

View File

@ -14,6 +14,7 @@ import java.nio.charset.Charset;
*/ */
public class JNotepadTab extends Tab { public class JNotepadTab extends Tab {
private final LineNumberTextArea lineNumberTextArea;
/** /**
* 默认关闭自动换行 * 默认关闭自动换行
*/ */
@ -22,18 +23,8 @@ public class JNotepadTab extends Tab {
* 是否与本地文件关联 * 是否与本地文件关联
*/ */
private boolean isRelevance = false; private boolean isRelevance = false;
private final LineNumberTextArea lineNumberTextArea;
private Charset charset = Charset.defaultCharset(); private Charset charset = Charset.defaultCharset();
public boolean isRelevance() {
return isRelevance;
}
public void setRelevance(boolean relevance) {
isRelevance = relevance;
}
public JNotepadTab(String tabTitle) { public JNotepadTab(String tabTitle) {
this(tabTitle, new LineNumberTextArea()); this(tabTitle, new LineNumberTextArea());
} }
@ -50,6 +41,14 @@ public class JNotepadTab extends Tab {
this.charset = charset; this.charset = charset;
} }
public boolean isRelevance() {
return isRelevance;
}
public void setRelevance(boolean relevance) {
isRelevance = relevance;
}
public boolean isAutoLine() { public boolean isAutoLine() {
return autoLine; return autoLine;
} }

View File

@ -17,6 +17,10 @@ public class JNotepadTabPane extends TabPane {
initListeners(); initListeners();
} }
public static JNotepadTabPane getInstance() {
return TAB_PANE;
}
/** /**
* 初始化监听器 * 初始化监听器
*/ */
@ -34,10 +38,6 @@ public class JNotepadTabPane extends TabPane {
); );
} }
public static JNotepadTabPane getInstance() {
return TAB_PANE;
}
/** /**
* 添加新tab并设置为选中状态 * 添加新tab并设置为选中状态
* *

View File

@ -5,7 +5,7 @@ import javafx.scene.control.*;
import javafx.scene.input.KeyCombination; import javafx.scene.input.KeyCombination;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.jcnc.jnotepad.app.config.AppConfig; import org.jcnc.jnotepad.app.config.AppConfig;
import org.jcnc.jnotepad.app.i18n.UIResourceBundle; import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
import org.jcnc.jnotepad.controller.config.AppConfigController; import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.controller.event.handler.menuBar.*; import org.jcnc.jnotepad.controller.event.handler.menuBar.*;
import org.jcnc.jnotepad.controller.event.handler.tool.SetBtn; import org.jcnc.jnotepad.controller.event.handler.tool.SetBtn;
@ -27,20 +27,20 @@ import static org.jcnc.jnotepad.constants.TextConstants.*;
*/ */
public class JNotepadMenuBar extends MenuBar { public class JNotepadMenuBar extends MenuBar {
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
private final Map<String, MenuItem> itemMap = new HashMap<>();
/** /**
* 标签页布局组件封装 * 标签页布局组件封装
*/ */
JNotepadTabPane jNotepadTabPane = JNotepadTabPane.getInstance(); JNotepadTabPane jNotepadTabPane = JNotepadTabPane.getInstance();
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
AppConfigController appConfigController = AppConfigController.getInstance(); AppConfigController appConfigController = AppConfigController.getInstance();
Logger logger = LogUtil.getLogger(this.getClass()); Logger logger = LogUtil.getLogger(this.getClass());
/**
private JNotepadMenuBar() { * 工具栏
initMenuBar(); */
} JNotepadToolBar toolBar = JNotepadToolBar.getInstance();
// 获取工具栏中的setButton
Button setButton = toolBar.getSetButton();
/** /**
* 文件菜单 * 文件菜单
*/ */
@ -49,18 +49,16 @@ public class JNotepadMenuBar extends MenuBar {
* 设置菜单 * 设置菜单
*/ */
private Menu setMenu; private Menu setMenu;
/// 菜单按钮
/** /**
* 插件菜单 * 插件菜单
*/ */
private Menu pluginMenu; private Menu pluginMenu;
/** /**
* 语言菜单 * 语言菜单
*/ */
private Menu languageMenu; private Menu languageMenu;
/// 菜单按钮
/** /**
* 新建 * 新建
*/ */
@ -101,7 +99,6 @@ public class JNotepadMenuBar extends MenuBar {
* 置顶按钮 * 置顶按钮
*/ */
private CheckMenuItem topItem; private CheckMenuItem topItem;
/** /**
* 中文选项 * 中文选项
*/ */
@ -110,15 +107,14 @@ public class JNotepadMenuBar extends MenuBar {
* 英文选项 * 英文选项
*/ */
private RadioMenuItem englishItem; private RadioMenuItem englishItem;
private final Map<String, MenuItem> itemMap = new HashMap<>();
/** private JNotepadMenuBar() {
* 工具栏 initMenuBar();
*/ }
JNotepadToolBar toolBar = JNotepadToolBar.getInstance();
// 获取工具栏中的setButton public static JNotepadMenuBar getInstance() {
Button setButton = toolBar.getSetButton(); return MENU_BAR;
}
/** /**
* 设置当前语言选中状态 * 设置当前语言选中状态
@ -176,17 +172,17 @@ public class JNotepadMenuBar extends MenuBar {
logger.info("初始化语言菜单!"); logger.info("初始化语言菜单!");
// 语言菜单 // 语言菜单
languageMenu = new Menu(); languageMenu = new Menu();
UIResourceBundle.bindStringProperty(languageMenu.textProperty(), LANGUAGE); UiResourceBundle.bindStringProperty(languageMenu.textProperty(), LANGUAGE);
ToggleGroup languageToggleGroup = new ToggleGroup(); ToggleGroup languageToggleGroup = new ToggleGroup();
chineseItem = new RadioMenuItem(); chineseItem = new RadioMenuItem();
UIResourceBundle.bindStringProperty(chineseItem.textProperty(), UPPER_CHINESE); UiResourceBundle.bindStringProperty(chineseItem.textProperty(), UPPER_CHINESE);
chineseItem.setUserData(Locale.CHINESE); chineseItem.setUserData(Locale.CHINESE);
itemMap.put("chineseItem", chineseItem); itemMap.put("chineseItem", chineseItem);
languageToggleGroup.getToggles().add(chineseItem); languageToggleGroup.getToggles().add(chineseItem);
englishItem = new RadioMenuItem(); englishItem = new RadioMenuItem();
UIResourceBundle.bindStringProperty(englishItem.textProperty(), UPPER_ENGLISH); UiResourceBundle.bindStringProperty(englishItem.textProperty(), UPPER_ENGLISH);
englishItem.setUserData(Locale.ENGLISH); englishItem.setUserData(Locale.ENGLISH);
itemMap.put("englishItem", englishItem); itemMap.put("englishItem", englishItem);
languageToggleGroup.getToggles().add(englishItem); languageToggleGroup.getToggles().add(englishItem);
@ -202,27 +198,27 @@ public class JNotepadMenuBar extends MenuBar {
logger.info("初始化文件菜单!"); logger.info("初始化文件菜单!");
// 文件菜单 // 文件菜单
fileMenu = new Menu(); fileMenu = new Menu();
UIResourceBundle.bindStringProperty(fileMenu.textProperty(), FILE); UiResourceBundle.bindStringProperty(fileMenu.textProperty(), FILE);
newItem = new MenuItem(); newItem = new MenuItem();
UIResourceBundle.bindStringProperty(newItem.textProperty(), NEW); UiResourceBundle.bindStringProperty(newItem.textProperty(), NEW);
itemMap.put("newItem", newItem); itemMap.put("newItem", newItem);
openItem = new MenuItem(); openItem = new MenuItem();
UIResourceBundle.bindStringProperty(openItem.textProperty(), OPEN); UiResourceBundle.bindStringProperty(openItem.textProperty(), OPEN);
itemMap.put("openItem", openItem); itemMap.put("openItem", openItem);
saveItem = new MenuItem(); saveItem = new MenuItem();
UIResourceBundle.bindStringProperty(saveItem.textProperty(), SAVE); UiResourceBundle.bindStringProperty(saveItem.textProperty(), SAVE);
itemMap.put("saveItem", saveItem); itemMap.put("saveItem", saveItem);
saveAsItem = new MenuItem(); saveAsItem = new MenuItem();
UIResourceBundle.bindStringProperty(saveAsItem.textProperty(), SAVE_AS); UiResourceBundle.bindStringProperty(saveAsItem.textProperty(), SAVE_AS);
itemMap.put("saveAsItem", saveAsItem); itemMap.put("saveAsItem", saveAsItem);
renameItem = new MenuItem(); renameItem = new MenuItem();
UIResourceBundle.bindStringProperty(renameItem.textProperty(), RENAME); UiResourceBundle.bindStringProperty(renameItem.textProperty(), RENAME);
itemMap.put("renameItem", renameItem); itemMap.put("renameItem", renameItem);
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem, renameItem); fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem, renameItem);
@ -235,19 +231,19 @@ public class JNotepadMenuBar extends MenuBar {
logger.info("初始化设置菜单"); logger.info("初始化设置菜单");
// 设置菜单 // 设置菜单
setMenu = new Menu(); setMenu = new Menu();
UIResourceBundle.bindStringProperty(setMenu.textProperty(), SET); UiResourceBundle.bindStringProperty(setMenu.textProperty(), SET);
lineFeedItem = new CheckMenuItem(); lineFeedItem = new CheckMenuItem();
UIResourceBundle.bindStringProperty(lineFeedItem.textProperty(), WORD_WRAP); UiResourceBundle.bindStringProperty(lineFeedItem.textProperty(), WORD_WRAP);
itemMap.put("lineFeedItem", lineFeedItem); itemMap.put("lineFeedItem", lineFeedItem);
lineFeedItem.selectedProperty().set(true); lineFeedItem.selectedProperty().set(true);
topItem = new CheckMenuItem(); topItem = new CheckMenuItem();
UIResourceBundle.bindStringProperty(topItem.textProperty(), TOP); UiResourceBundle.bindStringProperty(topItem.textProperty(), TOP);
itemMap.put("topItem", topItem); itemMap.put("topItem", topItem);
openConfigItem = new MenuItem(); openConfigItem = new MenuItem();
UIResourceBundle.bindStringProperty(openConfigItem.textProperty(), OPEN_CONFIGURATION_FILE); UiResourceBundle.bindStringProperty(openConfigItem.textProperty(), OPEN_CONFIGURATION_FILE);
itemMap.put("openConfigItem", openConfigItem); itemMap.put("openConfigItem", openConfigItem);
itemMap.put("languageMenu", languageMenu); itemMap.put("languageMenu", languageMenu);
@ -261,23 +257,19 @@ public class JNotepadMenuBar extends MenuBar {
logger.info("初始化插件菜单!"); logger.info("初始化插件菜单!");
// 插件菜单 // 插件菜单
pluginMenu = new Menu(); pluginMenu = new Menu();
UIResourceBundle.bindStringProperty(pluginMenu.textProperty(), PLUGIN); UiResourceBundle.bindStringProperty(pluginMenu.textProperty(), PLUGIN);
addItem = new MenuItem(); addItem = new MenuItem();
UIResourceBundle.bindStringProperty(addItem.textProperty(), ADD_PLUGIN); UiResourceBundle.bindStringProperty(addItem.textProperty(), ADD_PLUGIN);
itemMap.put("addItem", addItem); itemMap.put("addItem", addItem);
countItem = new MenuItem(); countItem = new MenuItem();
UIResourceBundle.bindStringProperty(countItem.textProperty(), STATISTICS); UiResourceBundle.bindStringProperty(countItem.textProperty(), STATISTICS);
itemMap.put("countItem", countItem); itemMap.put("countItem", countItem);
pluginMenu.getItems().addAll(addItem, countItem); pluginMenu.getItems().addAll(addItem, countItem);
} }
public static JNotepadMenuBar getInstance() {
return MENU_BAR;
}
/** /**
* 初始化事件处理 * 初始化事件处理
*/ */

View File

@ -26,11 +26,11 @@ public class JNotepadToolBar extends ToolBar {
} }
public Button getSetButton() {
return setButton;
}
public static JNotepadToolBar getInstance() { public static JNotepadToolBar getInstance() {
return INSTANCE; return INSTANCE;
} }
public Button getSetButton() {
return setButton;
}
} }

View File

@ -18,6 +18,4 @@ public class ToolHBox extends HBox {
} }
} }

View File

@ -4,10 +4,11 @@ import javafx.scene.Scene;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.SplitPane; import javafx.scene.control.SplitPane;
import javafx.scene.layout.StackPane;
import javafx.scene.control.TitledPane; import javafx.scene.control.TitledPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.jcnc.jnotepad.tool.UiUtil;
/** /**
* 设置窗口管理类实现了单例模式 * 设置窗口管理类实现了单例模式
@ -16,7 +17,9 @@ import javafx.stage.Stage;
*/ */
public class SetStage { public class SetStage {
// 唯一的 SetStage 实例使用单例模式 /**
* 唯一的 SetStage 实例使用单例模式
*/
private static final SetStage SET_STAGE = new SetStage(); private static final SetStage SET_STAGE = new SetStage();
private StackPane contentDisplay; private StackPane contentDisplay;
@ -24,6 +27,10 @@ public class SetStage {
private ListView<String> appearanceListView; private ListView<String> appearanceListView;
private ListView<String> securityListView; private ListView<String> securityListView;
private SetStage() {
// 私有构造方法以实现单例模式
}
/** /**
* 获取 SetStage 的唯一实例 * 获取 SetStage 的唯一实例
* *
@ -33,10 +40,6 @@ public class SetStage {
return SET_STAGE; return SET_STAGE;
} }
private SetStage() {
// 私有构造方法以实现单例模式
}
/** /**
* 打开设置窗口 * 打开设置窗口
*/ */
@ -65,7 +68,8 @@ public class SetStage {
// 创建一个分割面板左侧是设置列表右侧是内容显示区域 // 创建一个分割面板左侧是设置列表右侧是内容显示区域
SplitPane splitPane = new SplitPane(titledPaneContainer, contentDisplay); SplitPane splitPane = new SplitPane(titledPaneContainer, contentDisplay);
splitPane.setDividerPositions(0.3); // 设置分割位置 // 设置分割位置
splitPane.setDividerPositions(0.3);
// 创建设置窗口的场景 // 创建设置窗口的场景
Scene scene = new Scene(splitPane, 800, 600); Scene scene = new Scene(splitPane, 800, 600);
@ -74,6 +78,7 @@ public class SetStage {
Stage setStage = new Stage(); Stage setStage = new Stage();
setStage.setScene(scene); setStage.setScene(scene);
setStage.setTitle("设置窗口"); setStage.setTitle("设置窗口");
setStage.getIcons().add(UiUtil.getIcon());
setStage.show(); setStage.show();
} }
@ -101,7 +106,4 @@ public class SetStage {
contentDisplay.getChildren().setAll(new Label(selectedItem + " 的设置内容")); contentDisplay.getChildren().setAll(new Label(selectedItem + " 的设置内容"));
} }
} }
} }

View File

@ -15,27 +15,26 @@ import org.jcnc.jnotepad.ui.root.top.RootTopVBox;
*/ */
public class ViewManager { public class ViewManager {
private int tabIndex = 0; private static ViewManager instance = null;
// 主界面布局 // 主界面布局
private int tabIndex = 0;
/** /**
* 主布局 * 主布局
*/ */
private BorderPane root; private BorderPane root;
private static ViewManager instance = null;
/** /**
* 自增并获取标签页索引 * 构造函数设置场景和根布局
* *
* @return int 标签页索引 * @param scene 与视图相关联的JavaFX场景
* @apiNote ++tabIndex
*/ */
public int selfIncreaseAndGetTabIndex() { private ViewManager(Scene scene) {
return ++tabIndex; root = new BorderPane();
} scene.setRoot(root);
}
/** /**
* 获取ViewManager的实例如果实例不存在则创建一个新实例 * 获取ViewManager的实例如果实例不存在则创建一个新实例
@ -59,14 +58,13 @@ public class ViewManager {
} }
/** /**
* 构造函数设置场景和根布局 * 自增并获取标签页索引
* *
* @param scene 与视图相关联的JavaFX场景 * @return int 标签页索引
* @apiNote ++tabIndex
*/ */
private ViewManager(Scene scene) { public int selfIncreaseAndGetTabIndex() {
root = new BorderPane(); return ++tabIndex;
scene.setRoot(root);
} }
/** /**

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="67px" height="67px" <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="67px" height="67px"
viewBox="0 0 67 67" enable-background="new 0 0 67 67" xml:space="preserve"> <image id="image0" width="67" height="67" x="0" y="0" viewBox="0 0 67 67" enable-background="new 0 0 67 67" xml:space="preserve"> <image id="image0" width="67"
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABDCAMAAADwFEhBAAAABGdBTUEAALGPC/xhBQAAACBjSFJN height="67" x="0" y="0"
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABDCAMAAADwFEhBAAAABGdBTUEAALGPC/xhBQAAACBjSFJN
AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAQlBMVEUAAABpzLppy7lqzLpq AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAQlBMVEUAAABpzLppy7lqzLpq
zLpqy7lqzLrg9PHi9fF30MD+//7///960sKZ3NDM7efY8u1vzry05dzG7OWa3dDN7uin4dYGHsA1 zLpqy7lqzLrg9PHi9fF30MD+//7///960sKZ3NDM7efY8u1vzry05dzG7OWa3dDN7uin4dYGHsA1
AAAABnRSTlMAyPPm062MDfhZAAAAAWJLR0QLH9fEwAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0 AAAABnRSTlMAyPPm062MDfhZAAAAAWJLR0QLH9fEwAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0
@ -11,5 +12,5 @@ Vld6GC7XZTF+YxSlsOraqBthLcbbjC6o9ytDOBjldzp5Y75xpxgYGBgYGBgYGM8ylvVsUxiSML5t
ZE6XifKF2QHvQXAVNbACvwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMy0wOC0xM1QwMjozNTowOSsw ZE6XifKF2QHvQXAVNbACvwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMy0wOC0xM1QwMjozNTowOSsw
MDowMBgk9FsAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjMtMDgtMTNUMDI6MzU6MDkrMDA6MDBpeUzn MDowMBgk9FsAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjMtMDgtMTNUMDI6MzU6MDkrMDA6MDBpeUzn
AAAAKHRFWHRkYXRlOnRpbWVzdGFtcAAyMDIzLTA4LTEzVDAyOjM1OjA5KzAwOjAwPmxtOAAAAABJ AAAAKHRFWHRkYXRlOnRpbWVzdGFtcAAyMDIzLTA4LTEzVDAyOjM1OjA5KzAwOjAwPmxtOAAAAABJ
RU5ErkJggg==" /> RU5ErkJggg=="/>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB