快速配置可拖动窗口,无标题窗口
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package cn.edu.scau.biubiusuisui.annotation;
|
||||
|
||||
import javafx.stage.StageStyle;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
@@ -12,5 +14,11 @@ import java.lang.annotation.*;
|
||||
public @interface FXWindow {
|
||||
double preWidth() default 0.0;
|
||||
double preHeight()default 0.0;
|
||||
double minWidth() default 0.0;
|
||||
double minHeight() default 0.0;
|
||||
boolean fix() default false;
|
||||
boolean dragable() default false;
|
||||
|
||||
StageStyle style() default StageStyle.DECORATED;
|
||||
String title () ;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.layout.Pane;
|
||||
import cn.edu.scau.biubiusuisui.utils.StringUtils;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
@@ -29,6 +30,9 @@ public class FXBaseController extends Pane {
|
||||
|
||||
protected String name = "";
|
||||
|
||||
|
||||
private Stage stage;
|
||||
|
||||
private boolean isController = false;
|
||||
|
||||
private boolean isWindows = false;
|
||||
@@ -94,4 +98,12 @@ public class FXBaseController extends Pane {
|
||||
public void setWindows(boolean windows) {
|
||||
isWindows = windows;
|
||||
}
|
||||
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
public void setStage(Stage stage) {
|
||||
this.stage = stage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
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 FXFieldViewFieldMapping {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import javafx.stage.Stage;
|
||||
* @Date:2019/6/25 7:05
|
||||
*/
|
||||
@FXScan(base = {"cn.edu.scau.biubiusuisui.example"})
|
||||
//项目目录中带有中文字符会导致无法启动
|
||||
public class Demo extends Application {
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
|
||||
@@ -10,6 +10,7 @@ import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.stage.StageStyle;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -19,7 +20,7 @@ import java.util.ResourceBundle;
|
||||
* @Date:2019/6/25 1:47
|
||||
*/
|
||||
@FXController(path = "Main.fxml")
|
||||
@FXWindow(title = "demo1")
|
||||
@FXWindow(title = "demo1",dragable = true,fix = true,style = StageStyle.UNDECORATED)
|
||||
public class MainController extends FXBaseController{
|
||||
|
||||
@FXML
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.edu.scau.biubiusuisui.factory;
|
||||
|
||||
import cn.edu.scau.biubiusuisui.annotation.FXField;
|
||||
import cn.edu.scau.biubiusuisui.entity.FXFieldViewFieldMapping;
|
||||
import cn.edu.scau.biubiusuisui.entity.FXFieldPropertyMapping;
|
||||
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
|
||||
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXEntityProxy;
|
||||
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
|
||||
@@ -50,7 +50,7 @@ public class FXEntityFactory {
|
||||
|
||||
public static void processFXEntityProxy(Object entity, Object proxy,FXEntityProxy fxEntityProxy) throws IllegalAccessException {
|
||||
Map<String, Property> stringPropertyMap = new HashMap<>();
|
||||
Map<String, FXFieldViewFieldMapping> stringFXFieldMethodMappingMap = new HashMap<>();
|
||||
Map<String, FXFieldPropertyMapping> fxFieldPropertyMappingHashMap = new HashMap<>();
|
||||
Field []fields = entity.getClass().getDeclaredFields();
|
||||
for(Field field:fields){
|
||||
Annotation annotation = ClassUtils.getAnnotationInList( FXField.class,field.getDeclaredAnnotations());
|
||||
@@ -59,10 +59,11 @@ public class FXEntityFactory {
|
||||
field.setAccessible(true);
|
||||
FXField fxField = (FXField)annotation;
|
||||
|
||||
FXFieldViewFieldMapping fieldMethodMapping = new FXFieldViewFieldMapping();
|
||||
fieldMethodMapping.setReadOnly(fxField.readOnly());
|
||||
fieldMethodMapping.setType(field.getType());
|
||||
stringFXFieldMethodMappingMap.put(field.getName(), fieldMethodMapping);
|
||||
FXFieldPropertyMapping fieldPropertyMapping = new FXFieldPropertyMapping();
|
||||
fieldPropertyMapping.setReadOnly(fxField.readOnly());
|
||||
fieldPropertyMapping.setType(field.getType());
|
||||
|
||||
fxFieldPropertyMappingHashMap.put(field.getName(), fieldPropertyMapping);
|
||||
|
||||
if(field.get(entity) == null){
|
||||
property = getFieldDefalutProperty(field);
|
||||
@@ -88,7 +89,7 @@ public class FXEntityFactory {
|
||||
}
|
||||
}
|
||||
fxEntityProxy.setStringPropertyMap(stringPropertyMap);
|
||||
fxEntityProxy.setStringFXFieldMethodMappingMap(stringFXFieldMethodMappingMap);
|
||||
fxEntityProxy.setFxFieldPropertyMappingMap(fxFieldPropertyMappingHashMap);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ 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 javafx.scene.Scene;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
@@ -21,10 +24,10 @@ import java.net.URL;
|
||||
*/
|
||||
public class FXFactory {
|
||||
|
||||
|
||||
private static WindowAnnotationParser windowAnnotationParser = new WindowAnnotationParser();;
|
||||
private FXFactory() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void loadFXController(Class clazz) {
|
||||
getFXController(clazz, "");
|
||||
@@ -105,11 +108,13 @@ public class FXFactory {
|
||||
register(fxBaseController, fxControllerProxy);
|
||||
if (isWindow) {
|
||||
Stage stage = new Stage();
|
||||
double preWidth = fxWindow.preWidth() == 0 ? parent.getPrefWidth() : fxWindow.preWidth();
|
||||
double preHeight = fxWindow.preHeight() == 0 ? parent.getPrefWidth() : fxWindow.preHeight();
|
||||
fxControllerProxy.setStage(stage);
|
||||
fxBaseController.setStage(stage);
|
||||
double preWidth = fxWindow.preWidth() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preWidth();
|
||||
double preHeight = fxWindow.preHeight() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preHeight();
|
||||
Scene scene = new Scene(fxControllerProxy, preWidth, preHeight);
|
||||
stage.setScene(scene);
|
||||
stage.setTitle(fxWindow.title());
|
||||
windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
|
||||
stage.show();
|
||||
}
|
||||
return fxControllerProxy;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.edu.scau.biubiusuisui.proxy.classProxy;
|
||||
|
||||
import cn.edu.scau.biubiusuisui.entity.FXFieldViewFieldMapping;
|
||||
import cn.edu.scau.biubiusuisui.entity.FXFieldPropertyMapping;
|
||||
import cn.edu.scau.biubiusuisui.utils.StringUtils;
|
||||
import javafx.beans.property.*;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
@@ -19,7 +19,7 @@ public class FXEntityProxy implements MethodInterceptor {
|
||||
Object target;
|
||||
|
||||
private Map<String, Property> stringPropertyMap;
|
||||
private Map<String, FXFieldViewFieldMapping> stringFXFieldMethodMappingMap;
|
||||
private Map<String, FXFieldPropertyMapping> fxFieldPropertyMappingMap;
|
||||
|
||||
public Object getInstance(Object target) {
|
||||
this.target = target;
|
||||
@@ -50,13 +50,13 @@ public class FXEntityProxy implements MethodInterceptor {
|
||||
} else {
|
||||
return o1;
|
||||
}
|
||||
FXFieldViewFieldMapping fieldMethodMapping = stringFXFieldMethodMappingMap.get(fieldName);
|
||||
FXFieldPropertyMapping fxFieldPropertyMapping = fxFieldPropertyMappingMap.get(fieldName);
|
||||
Property property = stringPropertyMap.get(fieldName);
|
||||
if(fieldMethodMapping == null || property == null){
|
||||
if(fxFieldPropertyMapping == null || property == null){
|
||||
return o1;
|
||||
}
|
||||
|
||||
Class type = fieldMethodMapping.getType();
|
||||
Class type = fxFieldPropertyMapping.getType();
|
||||
if (methodName.startsWith("set")) {
|
||||
if(Boolean.class.equals(type)){
|
||||
((SimpleBooleanProperty)property).set((Boolean)objects[0]);
|
||||
@@ -75,6 +75,8 @@ public class FXEntityProxy implements MethodInterceptor {
|
||||
((SimpleListProperty)(property)).add(objects[0]);
|
||||
}else if(methodName.startsWith("del")){
|
||||
((SimpleListProperty)(property)).remove(objects[0]);
|
||||
}else if(methodName.startsWith("cls")){
|
||||
((SimpleListProperty)(property)).clear();
|
||||
}
|
||||
|
||||
//修改
|
||||
@@ -101,11 +103,11 @@ public class FXEntityProxy implements MethodInterceptor {
|
||||
this.stringPropertyMap = stringPropertyMap;
|
||||
}
|
||||
|
||||
public Map<String, FXFieldViewFieldMapping> getStringFXFieldMethodMappingMap() {
|
||||
return stringFXFieldMethodMappingMap;
|
||||
public Map<String, FXFieldPropertyMapping> getFxFieldPropertyMappingMap() {
|
||||
return fxFieldPropertyMappingMap;
|
||||
}
|
||||
|
||||
public void setStringFXFieldMethodMappingMap(Map<String, FXFieldViewFieldMapping> stringFXFieldMethodMappingMap) {
|
||||
this.stringFXFieldMethodMappingMap = stringFXFieldMethodMappingMap;
|
||||
public void setFxFieldPropertyMappingMap(Map<String, FXFieldPropertyMapping> fxFieldPropertyMappingMap) {
|
||||
this.fxFieldPropertyMappingMap = fxFieldPropertyMappingMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user