增加自动换行功能
This commit is contained in:
parent
beb703fc22
commit
f979240c85
@ -1,7 +1,7 @@
|
|||||||
jpackage `
|
jpackage `
|
||||||
--name JNotepad `
|
--name JNotepad `
|
||||||
--type app-image `
|
--type app-image `
|
||||||
-m org.jcnc.jnotepad/org.jcnc.jnotepad.MainApp `
|
-m org.jcnc.jnotepad/org.jcnc.jnotepad.LunchApp `
|
||||||
--runtime-image .\target\JNotepad\ `
|
--runtime-image .\target\JNotepad\ `
|
||||||
--icon src/main/resources/img/icon.ico `
|
--icon src/main/resources/img/icon.ico `
|
||||||
--app-version 1.1.6 `
|
--app-version 1.1.6 `
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@ -49,7 +49,7 @@
|
|||||||
<!-- Default configuration for running with: mvn clean javafx:run -->
|
<!-- Default configuration for running with: mvn clean javafx:run -->
|
||||||
<id>default-cli</id>
|
<id>default-cli</id>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>org.jcnc.jnotepad/org.jcnc.jnotepad.MainApp</mainClass>
|
<mainClass>org.jcnc.jnotepad/org.jcnc.jnotepad.LunchApp</mainClass>
|
||||||
<launcher>JNotepad</launcher>
|
<launcher>JNotepad</launcher>
|
||||||
<jlinkZipName>JNotepad</jlinkZipName>
|
<jlinkZipName>JNotepad</jlinkZipName>
|
||||||
<jlinkImageName>JNotepad</jlinkImageName>
|
<jlinkImageName>JNotepad</jlinkImageName>
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import java.util.Objects;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class MainApp extends Application {
|
public class LunchApp extends Application {
|
||||||
private static final ExecutorService threadPool = Executors.newCachedThreadPool();
|
private static final ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||||
public static boolean isRelevance = true;
|
public static boolean isRelevance = true;
|
||||||
|
|
||||||
@ -15,10 +15,12 @@ public class ViewManager {
|
|||||||
|
|
||||||
public static int tabIndex = 0;
|
public static int tabIndex = 0;
|
||||||
|
|
||||||
|
public static Boolean Line = true;
|
||||||
|
|
||||||
// 菜单栏组件
|
// 菜单栏组件
|
||||||
public static MenuBar menuBar; //菜单栏
|
public static MenuBar menuBar; //菜单栏
|
||||||
public static Menu fileMenu; //文件菜单
|
public static Menu fileMenu, setMenu; //文件菜单
|
||||||
public static MenuItem newItem, openItem, saveItem, saveAsItem; //新建/打开/保存/保存至 菜单
|
public static MenuItem newItem, openItem, saveItem, saveAsItem, lineFeedItem; //新建/打开/保存/保存至 菜单
|
||||||
|
|
||||||
// 主界面布局
|
// 主界面布局
|
||||||
public static BorderPane root; //主布局
|
public static BorderPane root; //主布局
|
||||||
@ -63,12 +65,15 @@ public class ViewManager {
|
|||||||
// 创建菜单栏并添加菜单项
|
// 创建菜单栏并添加菜单项
|
||||||
menuBar = new MenuBar();
|
menuBar = new MenuBar();
|
||||||
fileMenu = new Menu("文件");
|
fileMenu = new Menu("文件");
|
||||||
|
setMenu = new Menu("设置");
|
||||||
newItem = new MenuItem("新建");
|
newItem = new MenuItem("新建");
|
||||||
openItem = new MenuItem("打开");
|
openItem = new MenuItem("打开");
|
||||||
saveItem = new MenuItem("保存");
|
saveItem = new MenuItem("保存");
|
||||||
saveAsItem = new MenuItem("另存为");
|
saveAsItem = new MenuItem("另存为");
|
||||||
|
lineFeedItem = new CheckMenuItem("自动换行");
|
||||||
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem);
|
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem);
|
||||||
menuBar.getMenus().add(fileMenu);
|
setMenu.getItems().add(lineFeedItem);
|
||||||
|
menuBar.getMenus().addAll(fileMenu, setMenu);
|
||||||
|
|
||||||
// 创建主界面布局
|
// 创建主界面布局
|
||||||
root = new BorderPane();
|
root = new BorderPane();
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import javafx.event.EventHandler;
|
|||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import org.jcnc.jnotepad.MainApp;
|
import org.jcnc.jnotepad.LunchApp;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -35,6 +35,8 @@ public class Controller {
|
|||||||
|
|
||||||
TextArea textArea = new TextArea(); // 创建新的文本编辑区
|
TextArea textArea = new TextArea(); // 创建新的文本编辑区
|
||||||
|
|
||||||
|
// 自动换行
|
||||||
|
textArea.setWrapText(true);
|
||||||
upDateEncodingLabel(textArea.getText()); // 更新文本编码信息
|
upDateEncodingLabel(textArea.getText()); // 更新文本编码信息
|
||||||
updateStatusLabel(textArea);
|
updateStatusLabel(textArea);
|
||||||
|
|
||||||
@ -47,6 +49,22 @@ public class Controller {
|
|||||||
return textArea;
|
return textArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LineFeedEventHandler implements EventHandler<ActionEvent> {
|
||||||
|
private final TextArea textArea;
|
||||||
|
private boolean wrapText = true;
|
||||||
|
|
||||||
|
public LineFeedEventHandler(TextArea textArea) {
|
||||||
|
this.textArea = textArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent event) {
|
||||||
|
wrapText = !wrapText; // 切换自动换行状态
|
||||||
|
textArea.setWrapText(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 新建文件事件处理器
|
// 新建文件事件处理器
|
||||||
public static class NewFileEventHandler implements EventHandler<ActionEvent> {
|
public static class NewFileEventHandler implements EventHandler<ActionEvent> {
|
||||||
@Override
|
@Override
|
||||||
@ -181,7 +199,7 @@ public class Controller {
|
|||||||
// 根据给定的文件路径打开关联文件
|
// 根据给定的文件路径打开关联文件
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (file.exists() && file.isFile()) {
|
if (file.exists() && file.isFile()) {
|
||||||
MainApp.isRelevance = false;
|
LunchApp.isRelevance = false;
|
||||||
getText(file);// 调用读取文件方法
|
getText(file);// 调用读取文件方法
|
||||||
upDateEncodingLabel(((TextArea) tabPane.getSelectionModel().getSelectedItem().getContent()).getText()); // 更新文本编码信息
|
upDateEncodingLabel(((TextArea) tabPane.getSelectionModel().getSelectedItem().getContent()).getText()); // 更新文本编码信息
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public class View {
|
|||||||
openItem.setOnAction(new Controller.OpenFileEventHandler());
|
openItem.setOnAction(new Controller.OpenFileEventHandler());
|
||||||
saveItem.setOnAction(new Controller.SaveFileEventHandler());
|
saveItem.setOnAction(new Controller.SaveFileEventHandler());
|
||||||
saveAsItem.setOnAction(new Controller.SaveAsFileEventHandler());
|
saveAsItem.setOnAction(new Controller.SaveAsFileEventHandler());
|
||||||
|
lineFeedItem.setOnAction(new Controller.LineFeedEventHandler(new TextArea()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initTabPane() {
|
public static void initTabPane() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user