Merge branch 'master' of https://gitee.com/jcnc-org/JNotepad
This commit is contained in:
commit
74ffd70c3a
@ -21,14 +21,6 @@ public interface ControllerInterface {
|
|||||||
*/
|
*/
|
||||||
LineNumberTextArea openAssociatedFileAndCreateTextArea(List<String> rawParameters);
|
LineNumberTextArea openAssociatedFileAndCreateTextArea(List<String> rawParameters);
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取换行符处理事件处理程序
|
|
||||||
*
|
|
||||||
* @param textArea 文本区域
|
|
||||||
* @return 换行符处理事件处理程序
|
|
||||||
*/
|
|
||||||
EventHandler<ActionEvent> getLineFeedEventHandler(LineNumberTextArea textArea);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取新建文件处理事件处理程序
|
* 获取新建文件处理事件处理程序
|
||||||
*
|
*
|
||||||
|
|||||||
46
src/main/java/org/jcnc/jnotepad/app/config/GlobalConfig.java
Normal file
46
src/main/java/org/jcnc/jnotepad/app/config/GlobalConfig.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package org.jcnc.jnotepad.app.config;
|
||||||
|
|
||||||
|
import org.jcnc.jnotepad.Interface.ConfigInterface;
|
||||||
|
import org.jcnc.jnotepad.init.Config;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内存中,运行过程中的全局配置项
|
||||||
|
*
|
||||||
|
* @author zhaoteng.song
|
||||||
|
*/
|
||||||
|
public class GlobalConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动换行配置key
|
||||||
|
*/
|
||||||
|
public static final String TEXT_WRAP = "text.wrap";
|
||||||
|
private static final GlobalConfig APP_GLOBAL_CONFIG = new GlobalConfig();
|
||||||
|
|
||||||
|
private ConfigInterface configLoader;
|
||||||
|
private Properties properties;
|
||||||
|
|
||||||
|
private GlobalConfig() {
|
||||||
|
this.configLoader = new Config();
|
||||||
|
properties = this.configLoader.readPropertiesFromFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自动换行设置,默认自动换行
|
||||||
|
*
|
||||||
|
* @return true, 自动换行;false,不自动换行
|
||||||
|
*/
|
||||||
|
public boolean getAutoLineConfig() {
|
||||||
|
return Boolean.parseBoolean(this.properties.getProperty(TEXT_WRAP, "true"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAutoLineConfig(boolean isAutoLine) {
|
||||||
|
String autoLineConfig = String.valueOf(isAutoLine);
|
||||||
|
this.properties.setProperty(TEXT_WRAP, autoLineConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GlobalConfig getConfig() {
|
||||||
|
return APP_GLOBAL_CONFIG;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,32 +2,36 @@ package org.jcnc.jnotepad.controller.event.handler;
|
|||||||
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 换行程序。
|
* 换行事件处理,针对当前选中tab进行格式化。
|
||||||
|
* 配置变更时:
|
||||||
|
* 1. 更新内存全局配置, see {@linkplain org.jcnc.jnotepad.app.config.GlobalConfig}
|
||||||
|
* 2. 对当前tab生效配置。每次tab切换,根据全局配置设置进行变更
|
||||||
* <p>
|
* <p>
|
||||||
* 用于在文本区域中插入一个换行符。
|
* 用于在文本区域中插入一个换行符。
|
||||||
|
*
|
||||||
|
* @Deprecated 事件处理使用item的listener实现
|
||||||
|
*
|
||||||
* @author 许轲
|
* @author 许轲
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class LineFeed implements EventHandler<ActionEvent> {
|
public class LineFeed implements EventHandler<ActionEvent> {
|
||||||
private final LineNumberTextArea textArea;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数,初始化 LineFeed 对象。
|
* 构造函数,初始化 LineFeed 对象。
|
||||||
* @param textArea 要操作的文本区域
|
|
||||||
*/
|
*/
|
||||||
public LineFeed(LineNumberTextArea textArea) {
|
public LineFeed() {
|
||||||
this.textArea = textArea;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理事件的方法,将一个换行符插入到文本区域的末尾。
|
* 处理事件的方法,将一个换行符插入到文本区域的末尾。
|
||||||
|
*
|
||||||
* @param event 触发的事件对象
|
* @param event 触发的事件对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
String text = textArea.getMainTextArea().getText();
|
//
|
||||||
textArea.getMainTextArea().setText(text + "\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,17 +64,6 @@ public class Controller implements ControllerInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取行分隔事件处理程序。
|
|
||||||
*
|
|
||||||
* @param textArea 文本区域
|
|
||||||
* @return 行分隔事件处理程序
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public EventHandler<ActionEvent> getLineFeedEventHandler(LineNumberTextArea textArea) {
|
|
||||||
return new LineFeed(textArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取新建文件事件处理程序。
|
* 获取新建文件事件处理程序。
|
||||||
*
|
*
|
||||||
|
|||||||
@ -4,11 +4,11 @@ import javafx.scene.control.CheckMenuItem;
|
|||||||
import javafx.scene.control.Menu;
|
import javafx.scene.control.Menu;
|
||||||
import javafx.scene.control.MenuBar;
|
import javafx.scene.control.MenuBar;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
|
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.LineFeed;
|
import org.jcnc.jnotepad.controller.event.handler.LineFeed;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.NewFile;
|
import org.jcnc.jnotepad.controller.event.handler.NewFile;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.OpenFile;
|
import org.jcnc.jnotepad.controller.event.handler.OpenFile;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.SaveAsFile;
|
import org.jcnc.jnotepad.controller.event.handler.SaveAsFile;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
||||||
|
|
||||||
@ -143,7 +143,13 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
newItem.setOnAction(new NewFile());
|
newItem.setOnAction(new NewFile());
|
||||||
openItem.setOnAction(new OpenFile());
|
openItem.setOnAction(new OpenFile());
|
||||||
saveAsItem.setOnAction(new SaveAsFile());
|
saveAsItem.setOnAction(new SaveAsFile());
|
||||||
lineFeedItem.setOnAction(new LineFeed(new LineNumberTextArea()));
|
lineFeedItem.setOnAction(new LineFeed());
|
||||||
|
lineFeedItem.selectedProperty().addListener((observableValue, before, after) -> {
|
||||||
|
// 1. 更新全局配置
|
||||||
|
GlobalConfig.getConfig().setAutoLineConfig(after);
|
||||||
|
// 2. 对当前tab生效配置
|
||||||
|
JNotepadTabPane.getInstance().fireTabSelected();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, MenuItem> getItemMap() {
|
public Map<String, MenuItem> getItemMap() {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package org.jcnc.jnotepad.ui.tab;
|
package org.jcnc.jnotepad.ui.tab;
|
||||||
|
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
|
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +26,7 @@ public class JNotepadTab extends Tab {
|
|||||||
super(tabTitle);
|
super(tabTitle);
|
||||||
lineNumberTextArea = textArea;
|
lineNumberTextArea = textArea;
|
||||||
this.setContent(lineNumberTextArea);
|
this.setContent(lineNumberTextArea);
|
||||||
|
setAutoLine(GlobalConfig.getConfig().getAutoLineConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAutoLine() {
|
public boolean isAutoLine() {
|
||||||
@ -33,6 +35,7 @@ public class JNotepadTab extends Tab {
|
|||||||
|
|
||||||
public void setAutoLine(boolean autoLine) {
|
public void setAutoLine(boolean autoLine) {
|
||||||
this.autoLine = autoLine;
|
this.autoLine = autoLine;
|
||||||
|
lineNumberTextArea.getMainTextArea().setWrapText(autoLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LineNumberTextArea getLineNumberTextArea() {
|
public LineNumberTextArea getLineNumberTextArea() {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package org.jcnc.jnotepad.ui.tab;
|
package org.jcnc.jnotepad.ui.tab;
|
||||||
|
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
|
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
||||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +46,7 @@ public class JNotepadTabPane extends TabPane {
|
|||||||
}
|
}
|
||||||
this.getTabs().add(tab);
|
this.getTabs().add(tab);
|
||||||
this.getSelectionModel().select(tab);
|
this.getSelectionModel().select(tab);
|
||||||
|
fireTabSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,4 +57,13 @@ public class JNotepadTabPane extends TabPane {
|
|||||||
public JNotepadTab getSelected() {
|
public JNotepadTab getSelected() {
|
||||||
return (JNotepadTab) this.getSelectionModel().getSelectedItem();
|
return (JNotepadTab) this.getSelectionModel().getSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tab选中行为。
|
||||||
|
* 应用当前菜单上选中的自动换行设置。
|
||||||
|
*/
|
||||||
|
public void fireTabSelected() {
|
||||||
|
JNotepadTab selectedTab = getSelected();
|
||||||
|
selectedTab.setAutoLine(GlobalConfig.getConfig().getAutoLineConfig());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user