增加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.image.Image;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.jcnc.jnotepad.controller.controller;
|
import org.jcnc.jnotepad.controller.Controller;
|
||||||
import org.jcnc.jnotepad.view.view;
|
import org.jcnc.jnotepad.view.view;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.ViewManager.tabPane;
|
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() {
|
private void initApp() {
|
||||||
List<String> rawParameters = getParameters().getRaw();
|
List<String> rawParameters = getParameters().getRaw();
|
||||||
|
|
||||||
TextArea textArea = controller.openRelevance(rawParameters);
|
TextArea textArea = Controller.openAssociatedFileAndCreateTextArea(rawParameters);
|
||||||
if (isRelevance) {
|
if (isRelevance) {
|
||||||
Tab tab = new Tab("新建文件 " + ++ViewManager.tabIndex); // 创建新的Tab页
|
Tab tab = new Tab("新建文件 " + ++ViewManager.tabIndex); // 创建新的Tab页
|
||||||
tab.setContent(textArea);
|
tab.setContent(textArea);
|
||||||
|
|||||||
@ -6,87 +6,86 @@ import javafx.scene.control.*;
|
|||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视图管理类
|
* 该类管理记事本应用程序的视图组件。
|
||||||
*/
|
*/
|
||||||
public class ViewManager {
|
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 MenuBar menuBar; //菜单栏
|
||||||
public static Menu fileMenu;
|
public static Menu fileMenu; //文件菜单
|
||||||
public static MenuItem newItem, openItem, saveItem, saveAsItem;
|
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);
|
||||||
|
|
||||||
/**
|
// 创建主界面布局
|
||||||
* 构造函数,设置场景和根布局
|
root = new BorderPane();
|
||||||
* @param scene 场景
|
root.setTop(menuBar);
|
||||||
*/
|
|
||||||
private ViewManager(Scene scene){
|
|
||||||
|
|
||||||
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){
|
encodingLabel = new Label(); // 创建新的标签以显示编码信息
|
||||||
// 创建菜单栏并添加菜单项
|
HBox statusBox = new HBox(statusLabel, encodingLabel); // 使用HBox放置状态标签和编码标签
|
||||||
menuBar = new MenuBar();
|
root.setBottom(statusBox);
|
||||||
fileMenu = new Menu("文件");
|
BorderPane.setMargin(statusBox, new Insets(5, 10, 5, 10));
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
scene.setRoot(root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,11 +13,10 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.jcnc.jnotepad.ViewManager.*;
|
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()) {
|
if (!rawParameters.isEmpty()) {
|
||||||
String filePath = rawParameters.get(0);
|
String filePath = rawParameters.get(0);
|
||||||
openAssociatedFile(filePath);
|
openAssociatedFile(filePath);
|
||||||
@ -1,19 +1,19 @@
|
|||||||
package org.jcnc.jnotepad.view;
|
package org.jcnc.jnotepad.view;
|
||||||
|
|
||||||
import javafx.scene.control.TextArea;
|
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.ViewManager.*;
|
||||||
import static org.jcnc.jnotepad.controller.controller.updateStatusLabel;
|
import static org.jcnc.jnotepad.controller.Controller.updateStatusLabel;
|
||||||
|
|
||||||
public class view {
|
public class view {
|
||||||
|
|
||||||
public static void initItem() {
|
public static void initItem() {
|
||||||
// 为菜单项添加事件处理器
|
// 为菜单项添加事件处理器
|
||||||
newItem.setOnAction(new controller.NewFileEventHandler());
|
newItem.setOnAction(new Controller.NewFileEventHandler());
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initTabPane() {
|
public static void initTabPane() {
|
||||||
@ -26,7 +26,7 @@ public class view {
|
|||||||
textArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> updateStatusLabel(textArea));
|
textArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> updateStatusLabel(textArea));
|
||||||
|
|
||||||
// Update encoding label
|
// Update encoding label
|
||||||
controller.updateEncodingLabel(textArea.getText());
|
Controller.updateEncodingLabel(textArea.getText());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user