优化代码
This commit is contained in:
parent
2f24113d98
commit
77bf1f0eb3
|
@ -1,6 +1,5 @@
|
|||
package org.rococy.roomit;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
|
@ -22,9 +21,9 @@ import java.io.IOException;
|
|||
/**
|
||||
* @author Rococy
|
||||
*/
|
||||
public class MainWindow extends Application {
|
||||
public class MainWindow {
|
||||
|
||||
private static Stage stage = new Stage();
|
||||
private static Stage stage;
|
||||
|
||||
static {
|
||||
// 设置全局快捷键
|
||||
|
@ -39,14 +38,25 @@ public class MainWindow extends Application {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) {
|
||||
launch(stage);
|
||||
/**
|
||||
* 显示或关闭窗口
|
||||
*/
|
||||
public static void toggleDisplay() {
|
||||
if (stage != null && stage.isShowing()) {
|
||||
stage.close();
|
||||
System.gc();
|
||||
} else {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
|
||||
public static void launch(Stage stage) {
|
||||
/**
|
||||
* 启动窗口
|
||||
*/
|
||||
private static void launch() {
|
||||
try {
|
||||
MainWindow.stage = stage;
|
||||
// 创建新窗口
|
||||
stage = new Stage();
|
||||
// 加载FXML文件
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(ResourceUtils.getResource("fxml/mainWindow.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load(), ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight());
|
||||
|
@ -69,20 +79,9 @@ public class MainWindow extends Application {
|
|||
stage.getIcons().add(new Image(ResourceUtils.getResourceAsStream(GlobalConsts.LOGO_PATH)));
|
||||
// 将窗口显示出来
|
||||
stage.show();
|
||||
} catch (
|
||||
IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void toggleDisplay() {
|
||||
if (stage.isShowing()) {
|
||||
stage.close();
|
||||
System.gc();
|
||||
} else {
|
||||
launch(new Stage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -229,56 +229,41 @@ public abstract class Resizer extends Pane {
|
|||
|
||||
|
||||
switch (rectangleCtrl) {
|
||||
case TOP_LEFT: {
|
||||
case TOP_LEFT -> {
|
||||
this.setLayoutX(screenX);
|
||||
this.setLayoutY(screenY);
|
||||
this.setPrefSize(width - x, height - y);
|
||||
break;
|
||||
}
|
||||
|
||||
case TOP_MIDDLE: {
|
||||
case TOP_MIDDLE -> {
|
||||
this.setLayoutY(screenY);
|
||||
this.setPrefHeight(height - y);
|
||||
break;
|
||||
}
|
||||
|
||||
case TOP_RIGHT: {
|
||||
case TOP_RIGHT -> {
|
||||
this.setLayoutY(screenY);
|
||||
this.setPrefSize(x, height - y);
|
||||
break;
|
||||
}
|
||||
|
||||
case CENTER_LEFT: {
|
||||
case CENTER_LEFT -> {
|
||||
this.setLayoutX(screenX);
|
||||
this.setPrefWidth(width - x);
|
||||
break;
|
||||
}
|
||||
|
||||
case CENTER_RIGHT: {
|
||||
this.setPrefWidth(x);
|
||||
break;
|
||||
}
|
||||
case CENTER_RIGHT -> this.setPrefWidth(x);
|
||||
|
||||
case BOTTOM_LEFT: {
|
||||
case BOTTOM_LEFT -> {
|
||||
this.setLayoutX(screenX);
|
||||
this.setPrefSize(width - x, y);
|
||||
break;
|
||||
}
|
||||
|
||||
case BOTTOM_MIDDLE: {
|
||||
this.setPrefHeight(y);
|
||||
break;
|
||||
}
|
||||
case BOTTOM_MIDDLE -> this.setPrefHeight(y);
|
||||
|
||||
case BOTTOM_RIGHT: {
|
||||
this.setPrefSize(x, y);
|
||||
break;
|
||||
}
|
||||
case BOTTOM_RIGHT -> this.setPrefSize(x, y);
|
||||
|
||||
case MOVE: {
|
||||
case MOVE -> {
|
||||
this.setLayoutX(screenX - moveX);
|
||||
this.setLayoutY(screenY - moveY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -301,11 +286,10 @@ public abstract class Resizer extends Pane {
|
|||
private void bindKeyPressedEvent() {
|
||||
this.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
|
||||
switch (e.getCode()) {
|
||||
case DELETE: {
|
||||
case DELETE -> {
|
||||
// 删除自身
|
||||
Pane parent = (Pane) this.getParent();
|
||||
parent.getChildren().remove(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue