增加img
This commit is contained in:
parent
8f97a3e150
commit
cb749074c0
@ -7,14 +7,14 @@ import javafx.scene.control.TextArea;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
import org.jcnc.jnotepad.controller.controller;
|
||||
import org.jcnc.jnotepad.controller.Controller;
|
||||
import org.jcnc.jnotepad.view.view;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.jcnc.jnotepad.ViewManager.tabPane;
|
||||
import static org.jcnc.jnotepad.controller.controller.updateStatusLabel;
|
||||
import static org.jcnc.jnotepad.controller.Controller.updateStatusLabel;
|
||||
|
||||
/**
|
||||
* 启动器
|
||||
@ -54,7 +54,7 @@ public class MainApp extends Application {
|
||||
private void initApp() {
|
||||
List<String> rawParameters = getParameters().getRaw();
|
||||
|
||||
TextArea textArea = controller.openRelevance(rawParameters);
|
||||
TextArea textArea = Controller.openAssociatedFileAndCreateTextArea(rawParameters);
|
||||
if (isRelevance) {
|
||||
Tab tab = new Tab("新建文件 " + ++ViewManager.tabIndex); // 创建新的Tab页
|
||||
tab.setContent(textArea);
|
||||
|
||||
@ -6,87 +6,86 @@ import javafx.scene.control.*;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
|
||||
|
||||
/**
|
||||
* 视图管理类
|
||||
* 该类管理记事本应用程序的视图组件。
|
||||
*/
|
||||
public class ViewManager {
|
||||
|
||||
public static Label encodingLabel; // 新增属性用于显示文本编码
|
||||
public static Label encodingLabel; // 显示文本编码
|
||||
|
||||
public static int tabIndex = 0;
|
||||
public static int tabIndex = 0;
|
||||
|
||||
// 定义菜单栏
|
||||
public static MenuBar menuBar;
|
||||
public static Menu fileMenu;
|
||||
public static MenuItem newItem, openItem, saveItem, saveAsItem;
|
||||
// 菜单栏组件
|
||||
public static MenuBar menuBar; //菜单栏
|
||||
public static Menu fileMenu; //文件菜单
|
||||
public static MenuItem newItem, openItem, saveItem, saveAsItem; //新建/打开/保存/保存至 菜单
|
||||
|
||||
// 定义主界面
|
||||
public static BorderPane root;
|
||||
// 主界面布局
|
||||
public static BorderPane root; //主布局
|
||||
|
||||
// 定义多个Tab页
|
||||
public static TabPane tabPane;
|
||||
// 多个标签页
|
||||
public static TabPane tabPane; //标签页栏
|
||||
|
||||
// 定义状态栏
|
||||
public static Label statusLabel;
|
||||
// 状态栏
|
||||
public static Label statusLabel;
|
||||
|
||||
private static ViewManager instance = null;
|
||||
private static ViewManager instance = null;
|
||||
|
||||
/**
|
||||
* 获取ViewManager的实例。如果实例不存在,则创建一个新实例。
|
||||
*
|
||||
* @param scene 与视图相关联的JavaFX场景。
|
||||
* @return ViewManager的实例。
|
||||
*/
|
||||
public static ViewManager getInstance(Scene scene) {
|
||||
if (instance == null) {
|
||||
instance = new ViewManager(scene);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ViewManager getInstance(Scene scene) {
|
||||
if(instance == null) {
|
||||
instance = new ViewManager(scene);
|
||||
}
|
||||
/**
|
||||
* 构造函数。设置场景和根布局。
|
||||
*
|
||||
* @param scene 与视图相关联的JavaFX场景。
|
||||
*/
|
||||
private ViewManager(Scene scene) {
|
||||
root = new BorderPane();
|
||||
scene.setRoot(root);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* 初始化屏幕组件。
|
||||
*
|
||||
* @param scene 与视图相关联的JavaFX场景。
|
||||
*/
|
||||
public void initScreen(Scene scene) {
|
||||
// 创建菜单栏并添加菜单项
|
||||
menuBar = new MenuBar();
|
||||
fileMenu = new Menu("文件");
|
||||
newItem = new MenuItem("新建");
|
||||
openItem = new MenuItem("打开");
|
||||
saveItem = new MenuItem("保存");
|
||||
saveAsItem = new MenuItem("另存为");
|
||||
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem);
|
||||
menuBar.getMenus().add(fileMenu);
|
||||
|
||||
/**
|
||||
* 构造函数,设置场景和根布局
|
||||
* @param scene 场景
|
||||
*/
|
||||
private ViewManager(Scene scene){
|
||||
// 创建主界面布局
|
||||
root = new BorderPane();
|
||||
root.setTop(menuBar);
|
||||
|
||||
root = new BorderPane();
|
||||
// 创建标签页和文本编辑区域
|
||||
tabPane = new TabPane();
|
||||
root.setCenter(tabPane);
|
||||
|
||||
scene.setRoot(root);
|
||||
}
|
||||
// 创建状态栏
|
||||
statusLabel = new Label("行数:1 \t列数:1 \t字数:0 ");
|
||||
|
||||
public void initScreen(Scene scene){
|
||||
// 创建菜单栏并添加菜单项
|
||||
menuBar = new MenuBar();
|
||||
fileMenu = new Menu("文件");
|
||||
newItem = new MenuItem("新建");
|
||||
openItem = new MenuItem("打开");
|
||||
saveItem = new MenuItem("保存");
|
||||
saveAsItem = new MenuItem("另存为");
|
||||
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem);
|
||||
menuBar.getMenus().add(fileMenu);
|
||||
|
||||
// 创建主界面
|
||||
root = new BorderPane();
|
||||
root.setTop(menuBar);
|
||||
|
||||
// 创建Tab页和文本编辑区
|
||||
tabPane = new TabPane();
|
||||
root.setCenter(tabPane);
|
||||
|
||||
// 创建状态栏
|
||||
statusLabel = new Label("行: 1 \t列: 1 \t字数: 0 ");
|
||||
|
||||
|
||||
encodingLabel = new Label(); // 创建新的标签用于显示编码信息
|
||||
HBox statusBox = new HBox(statusLabel, encodingLabel); // 使用 HBox 放置状态标签和编码标签
|
||||
root.setBottom(statusBox);
|
||||
BorderPane.setMargin(statusBox, new Insets(5, 10, 5, 10));
|
||||
|
||||
scene.setRoot(root);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
encodingLabel = new Label(); // 创建新的标签以显示编码信息
|
||||
HBox statusBox = new HBox(statusLabel, encodingLabel); // 使用HBox放置状态标签和编码标签
|
||||
root.setBottom(statusBox);
|
||||
BorderPane.setMargin(statusBox, new Insets(5, 10, 5, 10));
|
||||
|
||||
scene.setRoot(root);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,11 +13,10 @@ import java.util.List;
|
||||
|
||||
import static org.jcnc.jnotepad.ViewManager.*;
|
||||
|
||||
public class controller {
|
||||
|
||||
public class Controller {
|
||||
|
||||
//关联文件打开
|
||||
public static TextArea openRelevance(List<String> rawParameters) {
|
||||
public static TextArea openAssociatedFileAndCreateTextArea(List<String> rawParameters) {
|
||||
if (!rawParameters.isEmpty()) {
|
||||
String filePath = rawParameters.get(0);
|
||||
openAssociatedFile(filePath);
|
||||
@ -1,19 +1,19 @@
|
||||
package org.jcnc.jnotepad.view;
|
||||
|
||||
import javafx.scene.control.TextArea;
|
||||
import org.jcnc.jnotepad.controller.controller;
|
||||
import org.jcnc.jnotepad.controller.Controller;
|
||||
|
||||
import static org.jcnc.jnotepad.ViewManager.*;
|
||||
import static org.jcnc.jnotepad.controller.controller.updateStatusLabel;
|
||||
import static org.jcnc.jnotepad.controller.Controller.updateStatusLabel;
|
||||
|
||||
public class view {
|
||||
|
||||
public static void initItem() {
|
||||
// 为菜单项添加事件处理器
|
||||
newItem.setOnAction(new controller.NewFileEventHandler());
|
||||
openItem.setOnAction(new controller.OpenFileEventHandler());
|
||||
saveItem.setOnAction(new controller.SaveFileEventHandler());
|
||||
saveAsItem.setOnAction(new controller.SaveAsFileEventHandler());
|
||||
newItem.setOnAction(new Controller.NewFileEventHandler());
|
||||
openItem.setOnAction(new Controller.OpenFileEventHandler());
|
||||
saveItem.setOnAction(new Controller.SaveFileEventHandler());
|
||||
saveAsItem.setOnAction(new Controller.SaveAsFileEventHandler());
|
||||
}
|
||||
|
||||
public static void initTabPane() {
|
||||
@ -26,7 +26,7 @@ public class view {
|
||||
textArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> updateStatusLabel(textArea));
|
||||
|
||||
// Update encoding label
|
||||
controller.updateEncodingLabel(textArea.getText());
|
||||
Controller.updateEncodingLabel(textArea.getText());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user