重构代码结构
This commit is contained in:
parent
76dc73da84
commit
571b8dd56a
@ -5,7 +5,6 @@ package org.jcnc.jnotepad;
|
||||
*/
|
||||
|
||||
public class Constants {
|
||||
|
||||
public static final double SCREEN_WIDTH = 800; //宽度
|
||||
public static final double SCREEN_LENGTH = 600; //高度
|
||||
public static final String APP_NAME = "JNotepad"; //名字
|
||||
|
||||
@ -16,14 +16,17 @@ import java.util.Objects;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.jcnc.jnotepad.view.View.initItem;
|
||||
import static org.jcnc.jnotepad.view.View.initTabPane;
|
||||
|
||||
public class LunchApp extends Application {
|
||||
private static final ExecutorService threadPool = Executors.newCachedThreadPool();
|
||||
public static boolean isRelevance = true;
|
||||
|
||||
Controller controller=new Controller();
|
||||
Controller controller = new Controller();
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
View view=new View();
|
||||
Pane root = new Pane();
|
||||
|
||||
double width = Constants.SCREEN_WIDTH;
|
||||
@ -44,8 +47,8 @@ public class LunchApp extends Application {
|
||||
viewManager.initScreen(scene);
|
||||
|
||||
// 初始化菜单项和标签栏
|
||||
view.initItem();
|
||||
View.initTabPane();
|
||||
initItem();
|
||||
initTabPane();
|
||||
|
||||
if (isRelevance) {
|
||||
// 使用线程池加载关联文件并创建文本区域
|
||||
|
||||
@ -127,7 +127,7 @@ public class Controller implements ControllerInterface {
|
||||
autoSave(textArea);
|
||||
});
|
||||
} catch (IOException ignored) {
|
||||
// 适当地处理异常
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,6 @@ public class LineFeedEventHandler implements EventHandler<ActionEvent> {
|
||||
public LineFeedEventHandler(TextArea textArea) {
|
||||
this.textArea = textArea;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
String text = textArea.getText();
|
||||
|
||||
@ -9,11 +9,6 @@ import org.jcnc.jnotepad.ViewManager;
|
||||
import static org.jcnc.jnotepad.ViewManager.tabPane;
|
||||
|
||||
public class NewFileEventHandler implements EventHandler<ActionEvent> {
|
||||
|
||||
|
||||
public NewFileEventHandler() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
Controller controller = new Controller();
|
||||
|
||||
@ -14,7 +14,7 @@ import static org.jcnc.jnotepad.ViewManager.tabPane;
|
||||
public class OpenFileEventHandler implements EventHandler<ActionEvent> {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
Controller controller=new Controller();
|
||||
Controller controller = new Controller();
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
File file = fileChooser.showOpenDialog(null);
|
||||
if (file != null) {
|
||||
|
||||
@ -14,7 +14,7 @@ import static org.jcnc.jnotepad.ViewManager.tabPane;
|
||||
public class SaveFileEventHandler implements EventHandler<ActionEvent> {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
Controller controller=new Controller();
|
||||
Controller controller = new Controller();
|
||||
Tab selectedTab = tabPane.getSelectionModel().getSelectedItem();
|
||||
if (selectedTab != null) {
|
||||
File file = (File) selectedTab.getUserData();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package org.jcnc.jnotepad.tool;
|
||||
|
||||
import javafx.scene.control.TextArea;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@ -25,7 +26,7 @@ public class EncodingDetector {
|
||||
}
|
||||
|
||||
private static Charset[] commonCharsets() {
|
||||
return new Charset[] {
|
||||
return new Charset[]{
|
||||
StandardCharsets.UTF_8,
|
||||
StandardCharsets.UTF_16,
|
||||
StandardCharsets.UTF_16LE,
|
||||
|
||||
@ -19,7 +19,7 @@ public class View {
|
||||
}
|
||||
|
||||
public static void initTabPane() {
|
||||
Controller controller =new Controller();
|
||||
Controller controller = new Controller();
|
||||
|
||||
tabPane.getSelectionModel().selectedItemProperty().addListener((observable, oldTab, newTab) -> {
|
||||
if (newTab != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user