修复了文件丢失问题

This commit is contained in:
billkiller
2019-07-04 10:59:17 +08:00
parent 059c5c8193
commit 5cd92e9e8f
13 changed files with 661 additions and 320 deletions

777
.idea/workspace.xml generated
View File

File diff suppressed because it is too large Load Diff

View File

@@ -16,8 +16,8 @@ public @interface FXWindow {
double preHeight()default 0.0;
double minWidth() default 0.0;
double minHeight() default 0.0;
boolean fix() default false;
boolean dragable() default false;
boolean resizable() default false;
boolean draggable() default false;
StageStyle style() default StageStyle.DECORATED;
String title () ;

View File

@@ -0,0 +1,33 @@
package cn.edu.scau.biubiusuisui.entity;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
import java.lang.reflect.Method;
/**
* @Author jack
* @Date:2019/6/28 10:03
*/
public class FXFieldPropertyMapping {
private boolean readOnly;
private Class type;
public boolean isReadOnly() {
return readOnly;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
public Class getType() {
return type;
}
public void setType(Class type) {
this.type = type;
}
}

View File

@@ -20,7 +20,7 @@ import java.util.ResourceBundle;
* @Date:2019/6/25 1:47
*/
@FXController(path = "Main.fxml")
@FXWindow(title = "demo1",dragable = true,fix = true,style = StageStyle.UNDECORATED)
@FXWindow(title = "demo1", draggable = true, resizable = true,style = StageStyle.UNDECORATED)
public class MainController extends FXBaseController{
@FXML

View File

@@ -5,14 +5,12 @@ import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.function.DragWindowHandlerImpl;
import cn.edu.scau.biubiusuisui.parser.WindowAnnotationParser;
import javafx.event.EventHandler;
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
import cn.edu.scau.biubiusuisui.messageQueue.MessageQueue;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXControllerProxy;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import cn.edu.scau.biubiusuisui.messageQueue.MessageQueue;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXControllerProxy;
import java.io.IOException;
import java.lang.annotation.Annotation;
@@ -24,10 +22,9 @@ import java.net.URL;
*/
public class FXFactory {
private static WindowAnnotationParser windowAnnotationParser = new WindowAnnotationParser();;
private FXFactory() {
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
}
private FXFactory() { }
public static void loadFXController(Class clazz) {
getFXController(clazz, "");
@@ -38,6 +35,7 @@ public class FXFactory {
return fxBaseController;
}
public static FXBaseController getFXController(Class clazz, String controllerName) {
FXBaseController fxBaseController = getFxBaseController(clazz, controllerName);
return fxBaseController;

View File

@@ -0,0 +1,119 @@
package cn.edu.scau.biubiusuisui.function;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
/**
* @Author jack
* @Date:2019/6/30 10:11
*/
public class DragWindowHandlerImpl implements EventHandler<MouseEvent> {
//参考<a href="https://www.cnblogs.com/moonlightL/p/5982679.html"></a>
private Stage stage; //primaryStage为start方法头中的Stage
private double oldStageX;
private double oldStageY;
private double oldScreenX;
private double oldScreenY;
final int RESIZE_WIDTH = 5;// 判定是否为调整窗口状态的范围与边界距离
private double MIN_WIDTH = 300;// 窗口最小宽度
private double MIN_HEIGHT = 250;// 窗口最小高度
boolean isRight;// 是否处于右边界调整窗口状态
boolean isBottomRight;// 是否处于右下角调整窗口状态
boolean isBottom;// 是否处于下边界调整窗口状态
private Pane pane;
private boolean fix = false;
public DragWindowHandlerImpl(Stage primaryStage, Pane pane,boolean fix) { //构造器
this.stage = primaryStage;
this.pane = pane;
this.fix = fix;
}
public DragWindowHandlerImpl(Stage stage, double MIN_WIDTH, double MIN_HEIGHT, Pane pane, boolean fix) {
this.stage = stage;
this.MIN_WIDTH = MIN_WIDTH;
this.MIN_HEIGHT = MIN_HEIGHT;
this.pane = pane;
this.fix = fix;
}
@Override
public void handle(MouseEvent e) {
if (e.getEventType() == MouseEvent.MOUSE_PRESSED) { //鼠标按下的事件
this.oldStageX = this.stage.getX();
this.oldStageY = this.stage.getY();
this.oldScreenX = e.getScreenX();
this.oldScreenY = e.getScreenY();
} else if (e.getEventType() == MouseEvent.MOUSE_DRAGGED) { //鼠标拖动的事件
//
double nextX = stage.getX();
double nextY = stage.getY();
double nextWidth = stage.getWidth();
double nextHeight = stage.getHeight();
if(!fix) {
double x = e.getSceneX();
double y = e.getSceneY();
// 保存窗口改变后的x、y坐标和宽度、高度用于预判是否会小于最小宽度、最小高度
if (isRight || isBottomRight) {// 所有右边调整窗口状态
nextWidth = x;
}
if (isBottomRight || isBottom) {// 所有下边调整窗口状态
nextHeight = y;
}
if (nextWidth <= MIN_WIDTH) {// 如果窗口改变后的宽度小于最小宽度,则宽度调整到最小宽度
nextWidth = MIN_WIDTH;
}
if (nextHeight <= MIN_HEIGHT) {// 如果窗口改变后的高度小于最小高度,则高度调整到最小高度
nextHeight = MIN_HEIGHT;
}
}
// 最后统一改变窗口的x、y坐标和宽度、高度可以防止刷新频繁出现的屏闪情况
if(isBottom ||isBottomRight ||isRight) {
stage.setX(nextX);
stage.setY(nextY);
stage.setWidth(nextWidth);
stage.setHeight(nextHeight);
}else {
this.stage.setX(e.getScreenX() - this.oldScreenX + this.oldStageX);
this.stage.setY(e.getScreenY() - this.oldScreenY + this.oldStageY);
}
} else if (e.getEventType() == MouseEvent.MOUSE_MOVED) {
if(!fix) {
e.consume();
double x = e.getSceneX();
double y = e.getSceneY();
double width = stage.getWidth();
double height = stage.getHeight();
Cursor cursorType = Cursor.DEFAULT;// 鼠标光标初始为默认类型,若未进入调整窗口状态,保持默认类型
// 先将所有调整窗口状态重置
isRight = isBottomRight = isBottom = false;
if (y >= height - RESIZE_WIDTH) {
if (x <= RESIZE_WIDTH) {// 左下角调整窗口状态
} else if (x >= width - RESIZE_WIDTH) {// 右下角调整窗口状态
isBottomRight = true;
cursorType = Cursor.SE_RESIZE;
} else {// 下边界调整窗口状态
isBottom = true;
cursorType = Cursor.S_RESIZE;
}
} else if (x >= width - RESIZE_WIDTH) {// 右边界调整窗口状态
isRight = true;
cursorType = Cursor.E_RESIZE;
}
// 最后改变鼠标光标
pane.setCursor(cursorType);
}
}
}
}

View File

@@ -0,0 +1,32 @@
package cn.edu.scau.biubiusuisui.function;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.function.DragWindowHandlerImpl;
import javafx.event.EventHandler;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
/**
* @Author jack
* @Date:2019/6/30 10:40
*/
public class FXWindowParser {
public void parse(Stage stage, Pane fxControllerProxy, FXWindow fxWindow){
stage.setTitle(fxWindow.title());
if(fxWindow.resizable()){
stage.setResizable(false);
}
if(fxWindow.draggable()) {
final int RESIZE_WIDTH = 5;// 判定是否为调整窗口状态的范围与边界距离
EventHandler dragWindowHandler= new DragWindowHandlerImpl(stage,fxWindow.minWidth(),fxWindow.minHeight(),fxControllerProxy,fxWindow.resizable());
fxControllerProxy.setOnMousePressed(dragWindowHandler);
fxControllerProxy.setOnMouseDragged(dragWindowHandler);
fxControllerProxy.setOnMouseMoved(dragWindowHandler);
}
stage.initStyle(fxWindow.style());
}
}

View File

Binary file not shown.

View File

Binary file not shown.