refactor: 重构了布局
This commit is contained in:
@@ -43,7 +43,7 @@ public class Controller implements Initializable {
|
|||||||
@FXML
|
@FXML
|
||||||
private AnchorPane drawingCanvasContainer;
|
private AnchorPane drawingCanvasContainer;
|
||||||
@FXML
|
@FXML
|
||||||
private VBox propertyPanel;
|
private VBox propertyPanelContainer;
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane scenePane;
|
private AnchorPane scenePane;
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ public class Controller implements Initializable {
|
|||||||
|
|
||||||
// 移除旧的Canvas
|
// 移除旧的Canvas
|
||||||
drawingCanvasContainer.getChildren().clear();
|
drawingCanvasContainer.getChildren().clear();
|
||||||
propertyPanel.getChildren().clear();
|
propertyPanelContainer.getChildren().clear();
|
||||||
|
|
||||||
// 创建新的Canvas
|
// 创建新的Canvas
|
||||||
PageContent pageContent = page.getPageContent();
|
PageContent pageContent = page.getPageContent();
|
||||||
@@ -149,7 +149,7 @@ public class Controller implements Initializable {
|
|||||||
|
|
||||||
// 创建属性面板
|
// 创建属性面板
|
||||||
propertyPanelComponent = new PropertyPanel(drawingCanvas);
|
propertyPanelComponent = new PropertyPanel(drawingCanvas);
|
||||||
propertyPanel.getChildren().add(propertyPanelComponent);
|
propertyPanelContainer.getChildren().add(propertyPanelComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class Main extends Application {
|
|||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
try {
|
try {
|
||||||
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
|
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
|
||||||
Scene scene = new Scene(root, 1200, 600);
|
Scene scene = new Scene(root, 1300, 700);
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
|
|
||||||
Image icon = new Image(getClass().getResourceAsStream("icon.png"));
|
Image icon = new Image(getClass().getResourceAsStream("icon.png"));
|
||||||
|
|||||||
@@ -1,119 +1,103 @@
|
|||||||
package dev.bytevibe.hyperpoint;
|
package dev.bytevibe.hyperpoint;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.*;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 属性编辑面板,用于编辑选中对象的属性
|
* 属性编辑面板,用于编辑选中对象的属性
|
||||||
|
* 使用FXML加载UI布局
|
||||||
*/
|
*/
|
||||||
public class PropertyPanel extends VBox {
|
public class PropertyPanel extends VBox implements Initializable {
|
||||||
private DrawingCanvas canvas;
|
@FXML
|
||||||
private Label objectTypeLabel;
|
private Label objectTypeLabel;
|
||||||
|
@FXML
|
||||||
private Label positionLabel;
|
private Label positionLabel;
|
||||||
|
@FXML
|
||||||
private TextField textContentField;
|
private TextField textContentField;
|
||||||
|
@FXML
|
||||||
private ComboBox<String> fontFamilyCombo;
|
private ComboBox<String> fontFamilyCombo;
|
||||||
|
@FXML
|
||||||
private Spinner<Double> fontSizeSpinner;
|
private Spinner<Double> fontSizeSpinner;
|
||||||
|
@FXML
|
||||||
private ComboBox<String> fontStyleCombo;
|
private ComboBox<String> fontStyleCombo;
|
||||||
|
@FXML
|
||||||
private ColorPicker textColorPicker;
|
private ColorPicker textColorPicker;
|
||||||
|
@FXML
|
||||||
private ColorPicker fillColorPicker;
|
private ColorPicker fillColorPicker;
|
||||||
|
@FXML
|
||||||
private ColorPicker strokeColorPicker;
|
private ColorPicker strokeColorPicker;
|
||||||
|
@FXML
|
||||||
private Spinner<Double> strokeWidthSpinner;
|
private Spinner<Double> strokeWidthSpinner;
|
||||||
|
@FXML
|
||||||
private Button deleteButton;
|
private Button deleteButton;
|
||||||
|
|
||||||
|
private DrawingCanvas canvas;
|
||||||
|
|
||||||
public PropertyPanel(DrawingCanvas canvas) {
|
public PropertyPanel(DrawingCanvas canvas) {
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
setPrefWidth(200);
|
loadFXML();
|
||||||
setPadding(new Insets(10));
|
}
|
||||||
setSpacing(8);
|
|
||||||
setStyle("-fx-border-color: #e0e0e0; -fx-border-width: 1 0 0 0;");
|
|
||||||
|
|
||||||
// 对象类型标签
|
/**
|
||||||
objectTypeLabel = new Label("未选中对象");
|
* 加载FXML文件
|
||||||
objectTypeLabel.setStyle("-fx-font-size: 14; -fx-font-weight: bold;");
|
*/
|
||||||
|
private void loadFXML() {
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("propertyPanel.fxml"));
|
||||||
|
loader.setRoot(this);
|
||||||
|
loader.setController(this);
|
||||||
|
loader.load();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("无法加载propertyPanel.fxml文件");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 位置标签
|
@Override
|
||||||
positionLabel = new Label("X: 0, Y: 0");
|
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||||
|
// 初始化字体列表
|
||||||
// 文本内容
|
fontFamilyCombo.getItems().addAll(
|
||||||
Label textLabel = new Label("文本内容:");
|
"Arial",
|
||||||
textContentField = new TextField();
|
"Times New Roman",
|
||||||
textContentField.setOnKeyReleased(e -> updateTextContent());
|
"Courier New",
|
||||||
|
"Verdana",
|
||||||
// 字体选择
|
"Georgia"
|
||||||
Label fontLabel = new Label("字体:");
|
|
||||||
fontFamilyCombo = new ComboBox<>();
|
|
||||||
fontFamilyCombo.getItems().addAll("Arial", "Times New Roman", "Courier New", "Verdana", "Georgia");
|
|
||||||
fontFamilyCombo.setValue("Arial");
|
|
||||||
fontFamilyCombo.setOnAction(e -> updateTextStyle());
|
|
||||||
|
|
||||||
// 字体大小
|
|
||||||
Label sizeLabel = new Label("大小:");
|
|
||||||
fontSizeSpinner = new Spinner<>(8.0, 72.0, 16.0, 2.0);
|
|
||||||
fontSizeSpinner.setEditable(true);
|
|
||||||
fontSizeSpinner.valueProperty().addListener((obs, oldVal, newVal) -> updateTextStyle());
|
|
||||||
|
|
||||||
// 字体风格
|
|
||||||
Label styleLabel = new Label("风格:");
|
|
||||||
fontStyleCombo = new ComboBox<>();
|
|
||||||
fontStyleCombo.getItems().addAll("NORMAL", "BOLD", "ITALIC", "BOLD_ITALIC");
|
|
||||||
fontStyleCombo.setValue("NORMAL");
|
|
||||||
fontStyleCombo.setOnAction(e -> updateTextStyle());
|
|
||||||
|
|
||||||
// 文本颜色
|
|
||||||
Label textColorLabel = new Label("文本颜色:");
|
|
||||||
textColorPicker = new ColorPicker(Color.BLACK);
|
|
||||||
textColorPicker.setOnAction(e -> updateTextColor());
|
|
||||||
|
|
||||||
// 填充颜色
|
|
||||||
Label fillColorLabel = new Label("填充颜色:");
|
|
||||||
fillColorPicker = new ColorPicker(Color.WHITE);
|
|
||||||
fillColorPicker.setOnAction(e -> updateFillColor());
|
|
||||||
|
|
||||||
// 边框颜色
|
|
||||||
Label strokeColorLabel = new Label("边框颜色:");
|
|
||||||
strokeColorPicker = new ColorPicker(Color.BLACK);
|
|
||||||
strokeColorPicker.setOnAction(e -> updateStrokeColor());
|
|
||||||
|
|
||||||
// 边框宽度
|
|
||||||
Label strokeWidthLabel = new Label("边框宽度:");
|
|
||||||
strokeWidthSpinner = new Spinner<>(1.0, 10.0, 2.0, 1.0);
|
|
||||||
strokeWidthSpinner.setEditable(true);
|
|
||||||
strokeWidthSpinner.valueProperty().addListener((obs, oldVal, newVal) -> updateStrokeWidth());
|
|
||||||
|
|
||||||
// 删除按钮
|
|
||||||
deleteButton = new Button("删除对象");
|
|
||||||
deleteButton.setStyle("-fx-font-size: 12;");
|
|
||||||
deleteButton.setOnAction(e -> deleteSelectedObject());
|
|
||||||
|
|
||||||
// 添加所有控件到面板
|
|
||||||
getChildren().addAll(
|
|
||||||
objectTypeLabel,
|
|
||||||
new Separator(),
|
|
||||||
positionLabel,
|
|
||||||
new Separator(),
|
|
||||||
textLabel,
|
|
||||||
textContentField,
|
|
||||||
fontLabel,
|
|
||||||
fontFamilyCombo,
|
|
||||||
sizeLabel,
|
|
||||||
fontSizeSpinner,
|
|
||||||
styleLabel,
|
|
||||||
fontStyleCombo,
|
|
||||||
textColorLabel,
|
|
||||||
textColorPicker,
|
|
||||||
fillColorLabel,
|
|
||||||
fillColorPicker,
|
|
||||||
strokeColorLabel,
|
|
||||||
strokeColorPicker,
|
|
||||||
strokeWidthLabel,
|
|
||||||
strokeWidthSpinner,
|
|
||||||
new Separator(),
|
|
||||||
deleteButton
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 初始化风格列表
|
||||||
|
fontStyleCombo.getItems().addAll(
|
||||||
|
"NORMAL",
|
||||||
|
"BOLD",
|
||||||
|
"ITALIC",
|
||||||
|
"BOLD_ITALIC"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 设置默认值
|
||||||
|
fontFamilyCombo.setValue("Arial");
|
||||||
|
fontStyleCombo.setValue("NORMAL");
|
||||||
|
textColorPicker.setValue(Color.BLACK);
|
||||||
|
fillColorPicker.setValue(Color.WHITE);
|
||||||
|
strokeColorPicker.setValue(Color.BLACK);
|
||||||
|
|
||||||
|
// 添加事件监听
|
||||||
|
textContentField.setOnKeyReleased(e -> updateTextContent());
|
||||||
|
fontFamilyCombo.setOnAction(e -> updateTextStyle());
|
||||||
|
fontSizeSpinner.valueProperty().addListener((obs, oldVal, newVal) -> updateTextStyle());
|
||||||
|
fontStyleCombo.setOnAction(e -> updateTextStyle());
|
||||||
|
textColorPicker.setOnAction(e -> updateTextColor());
|
||||||
|
fillColorPicker.setOnAction(e -> updateFillColor());
|
||||||
|
strokeColorPicker.setOnAction(e -> updateStrokeColor());
|
||||||
|
strokeWidthSpinner.valueProperty().addListener((obs, oldVal, newVal) -> updateStrokeWidth());
|
||||||
|
deleteButton.setOnAction(e -> deleteSelectedObject());
|
||||||
|
|
||||||
// 默认隐藏所有编辑控件
|
// 默认隐藏所有编辑控件
|
||||||
setEditingVisible(false);
|
setEditingVisible(false);
|
||||||
|
|
||||||
@@ -174,6 +158,8 @@ public class PropertyPanel extends VBox {
|
|||||||
fillColorPicker.setDisable(true);
|
fillColorPicker.setDisable(true);
|
||||||
strokeColorPicker.setDisable(true);
|
strokeColorPicker.setDisable(true);
|
||||||
strokeWidthSpinner.setDisable(true);
|
strokeWidthSpinner.setDisable(true);
|
||||||
|
|
||||||
|
deleteButton.setDisable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,6 +174,8 @@ public class PropertyPanel extends VBox {
|
|||||||
fillColorPicker.setDisable(false);
|
fillColorPicker.setDisable(false);
|
||||||
strokeColorPicker.setDisable(false);
|
strokeColorPicker.setDisable(false);
|
||||||
strokeWidthSpinner.setDisable(false);
|
strokeWidthSpinner.setDisable(false);
|
||||||
|
|
||||||
|
deleteButton.setDisable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -202,6 +190,8 @@ public class PropertyPanel extends VBox {
|
|||||||
fillColorPicker.setDisable(true);
|
fillColorPicker.setDisable(true);
|
||||||
strokeColorPicker.setDisable(true);
|
strokeColorPicker.setDisable(true);
|
||||||
strokeWidthSpinner.setDisable(true);
|
strokeWidthSpinner.setDisable(true);
|
||||||
|
|
||||||
|
deleteButton.setDisable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,16 +7,18 @@
|
|||||||
<?import javafx.scene.layout.HBox?>
|
<?import javafx.scene.layout.HBox?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
<AnchorPane fx:id="scenePane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.bytevibe.hyperpoint.Controller">
|
<AnchorPane fx:id="scenePane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="1300.0" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.bytevibe.hyperpoint.Controller">
|
||||||
<children>
|
<children>
|
||||||
<!-- 顶部菜单栏 -->
|
<!-- 顶部菜单栏 -->
|
||||||
<VBox layoutX="0" layoutY="0" prefHeight="50.0" prefWidth="1200.0" style="-fx-border-color: #cccccc; -fx-border-width: 0 0 1 0;">
|
<VBox layoutX="0" layoutY="0" prefHeight="50.0" prefWidth="1300.0" style="-fx-border-color: #cccccc; -fx-border-width: 0 0 1 0;">
|
||||||
<children>
|
<children>
|
||||||
<HBox spacing="5" style="-fx-padding: 5;">
|
<HBox spacing="5" style="-fx-padding: 5;">
|
||||||
<children>
|
<children>
|
||||||
<Button fx:id="newSlideButton" mnemonicParsing="false" onAction="#onNewSlide" text="新建幻灯片" />
|
<Button fx:id="newSlideButton" mnemonicParsing="false" onAction="#onNewSlide" text="新建幻灯片" />
|
||||||
|
<Button mnemonicParsing="false" text="打开幻灯片" />
|
||||||
<Button fx:id="newPageButton" mnemonicParsing="false" onAction="#onNewPage" text="新建页面" />
|
<Button fx:id="newPageButton" mnemonicParsing="false" onAction="#onNewPage" text="新建页面" />
|
||||||
<Button fx:id="deletePageButton" mnemonicParsing="false" onAction="#onDeletePage" text="删除页面" />
|
<Button fx:id="deletePageButton" mnemonicParsing="false" onAction="#onDeletePage" text="删除页面" />
|
||||||
|
<Button mnemonicParsing="false" text="保存幻灯片" />
|
||||||
<Label text=" | " />
|
<Label text=" | " />
|
||||||
<Button fx:id="addTextButton" mnemonicParsing="false" onAction="#onAddText" text="添加文本" />
|
<Button fx:id="addTextButton" mnemonicParsing="false" onAction="#onAddText" text="添加文本" />
|
||||||
<Button fx:id="addLineButton" mnemonicParsing="false" onAction="#onAddLine" text="直线" />
|
<Button fx:id="addLineButton" mnemonicParsing="false" onAction="#onAddLine" text="直线" />
|
||||||
@@ -32,23 +34,22 @@
|
|||||||
</VBox>
|
</VBox>
|
||||||
|
|
||||||
<!-- 主内容区域 -->
|
<!-- 主内容区域 -->
|
||||||
<HBox layoutX="0" layoutY="50" prefHeight="550.0" prefWidth="1200.0">
|
<HBox layoutX="0" layoutY="50" prefHeight="652.0" prefWidth="1300.0">
|
||||||
<!-- 左侧页面列表 -->
|
<!-- 左侧页面列表 -->
|
||||||
<VBox prefWidth="200.0" style="-fx-border-color: #e0e0e0; -fx-border-width: 0 1 0 0;">
|
<VBox prefHeight="657.0" prefWidth="200.0" style="-fx-border-color: #e0e0e0; -fx-border-width: 0 1 0 0;">
|
||||||
<Label text="页面列表" style="-fx-padding: 5; -fx-font-weight: bold;" />
|
<Label style="-fx-padding: 5; -fx-font-weight: bold;" text="页面列表" />
|
||||||
<ListView fx:id="pageListView" VBox.vgrow="ALWAYS" />
|
<ListView fx:id="pageListView" prefHeight="619.0" prefWidth="195.0" VBox.vgrow="ALWAYS" />
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|
||||||
<!-- 右侧编辑区域 -->
|
<!-- 右侧编辑区域 -->
|
||||||
<VBox HBox.hgrow="ALWAYS" spacing="10" style="-fx-padding: 10;">
|
<VBox spacing="10" style="-fx-padding: 10;" HBox.hgrow="ALWAYS">
|
||||||
<Label fx:id="pageNameLabel" text="页面名称:" style="-fx-font-size: 14; -fx-font-weight: bold;" />
|
<Label fx:id="pageNameLabel" style="-fx-font-size: 14; -fx-font-weight: bold;" text="页面名称:" />
|
||||||
<!-- 绘图Canvas将在这里动态添加 -->
|
<!-- 绘图Canvas将在这里动态添加 -->
|
||||||
<AnchorPane fx:id="drawingCanvasContainer" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS" />
|
<AnchorPane fx:id="drawingCanvasContainer" HBox.hgrow="ALWAYS" VBox.vgrow="ALWAYS" />
|
||||||
</VBox>
|
</VBox>
|
||||||
|
|
||||||
<!-- 右侧属性编辑面板 -->
|
<!-- 右侧属性编辑面板 -->
|
||||||
<VBox fx:id="propertyPanel" prefWidth="200.0" />
|
<VBox fx:id="propertyPanelContainer" prefWidth="200.0" />
|
||||||
</HBox>
|
</HBox>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.ColorPicker?>
|
||||||
|
<?import javafx.scene.control.ComboBox?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.Separator?>
|
||||||
|
<?import javafx.scene.control.Spinner?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
|
<fx:root type="javafx.scene.layout.VBox" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
prefWidth="200.0" spacing="8"
|
||||||
|
style="-fx-padding: 10; -fx-border-color: #e0e0e0; -fx-border-width: 1 0 0 0;">
|
||||||
|
|
||||||
|
<!-- 对象类型标签 -->
|
||||||
|
<Label fx:id="objectTypeLabel" text="未选中对象" style="-fx-font-size: 14; -fx-font-weight: bold;"/>
|
||||||
|
|
||||||
|
<Separator/>
|
||||||
|
|
||||||
|
<!-- 位置标签 -->
|
||||||
|
<Label fx:id="positionLabel" text="X: 0, Y: 0"/>
|
||||||
|
|
||||||
|
<Separator/>
|
||||||
|
|
||||||
|
<!-- 文本内容 -->
|
||||||
|
<Label text="文本内容:"/>
|
||||||
|
<TextField fx:id="textContentField"/>
|
||||||
|
|
||||||
|
<!-- 字体选择 -->
|
||||||
|
<Label text="字体:"/>
|
||||||
|
<ComboBox fx:id="fontFamilyCombo" prefWidth="180.0"/>
|
||||||
|
|
||||||
|
<!-- 字体大小 -->
|
||||||
|
<Label text="大小:"/>
|
||||||
|
<Spinner fx:id="fontSizeSpinner" initialValue="16.0" min="8.0" max="72.0" amountToStepBy="2.0"/>
|
||||||
|
|
||||||
|
<!-- 字体风格 -->
|
||||||
|
<Label text="风格:"/>
|
||||||
|
<ComboBox fx:id="fontStyleCombo" prefWidth="180.0"/>
|
||||||
|
|
||||||
|
<!-- 文本颜色 -->
|
||||||
|
<Label text="文本颜色:"/>
|
||||||
|
<ColorPicker fx:id="textColorPicker"/>
|
||||||
|
|
||||||
|
<!-- 填充颜色 -->
|
||||||
|
<Label text="填充颜色:"/>
|
||||||
|
<ColorPicker fx:id="fillColorPicker"/>
|
||||||
|
|
||||||
|
<!-- 边框颜色 -->
|
||||||
|
<Label text="边框颜色:"/>
|
||||||
|
<ColorPicker fx:id="strokeColorPicker"/>
|
||||||
|
|
||||||
|
<!-- 边框宽度 -->
|
||||||
|
<Label text="边框宽度:"/>
|
||||||
|
<Spinner fx:id="strokeWidthSpinner" initialValue="2.0" min="1.0" max="10.0" amountToStepBy="1.0"/>
|
||||||
|
|
||||||
|
<Separator/>
|
||||||
|
|
||||||
|
<!-- 删除按钮 -->
|
||||||
|
<Button fx:id="deleteButton" text="删除对象" style="-fx-font-size: 12;"/>
|
||||||
|
|
||||||
|
</fx:root>
|
||||||
|
|
||||||
Reference in New Issue
Block a user