快速配置可拖动窗口,无标题窗口

This commit is contained in:
billkiller
2019-06-30 13:44:35 +08:00
parent 953c6b16ad
commit 059c5c8193
18 changed files with 517 additions and 706 deletions

1110
.idea/workspace.xml generated
View File

File diff suppressed because it is too large Load Diff

View File

Binary file not shown.

View File

@@ -1,5 +1,7 @@
package cn.edu.scau.biubiusuisui.annotation; package cn.edu.scau.biubiusuisui.annotation;
import javafx.stage.StageStyle;
import java.lang.annotation.*; import java.lang.annotation.*;
/** /**
@@ -12,5 +14,11 @@ import java.lang.annotation.*;
public @interface FXWindow { public @interface FXWindow {
double preWidth() default 0.0; double preWidth() default 0.0;
double preHeight()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 () ; String title () ;
} }

View File

@@ -5,6 +5,7 @@ import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import cn.edu.scau.biubiusuisui.utils.StringUtils; import cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.stage.Stage;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
@@ -29,6 +30,9 @@ public class FXBaseController extends Pane {
protected String name = ""; protected String name = "";
private Stage stage;
private boolean isController = false; private boolean isController = false;
private boolean isWindows = false; private boolean isWindows = false;
@@ -94,4 +98,12 @@ public class FXBaseController extends Pane {
public void setWindows(boolean windows) { public void setWindows(boolean windows) {
isWindows = windows; isWindows = windows;
} }
public Stage getStage() {
return stage;
}
public void setStage(Stage stage) {
this.stage = stage;
}
} }

View File

@@ -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;
}
}

View File

@@ -10,6 +10,7 @@ import javafx.stage.Stage;
* @Date:2019/6/25 7:05 * @Date:2019/6/25 7:05
*/ */
@FXScan(base = {"cn.edu.scau.biubiusuisui.example"}) @FXScan(base = {"cn.edu.scau.biubiusuisui.example"})
//项目目录中带有中文字符会导致无法启动
public class Demo extends Application { public class Demo extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {

View File

@@ -10,6 +10,7 @@ import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.stage.StageStyle;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@@ -19,7 +20,7 @@ import java.util.ResourceBundle;
* @Date:2019/6/25 1:47 * @Date:2019/6/25 1:47
*/ */
@FXController(path = "Main.fxml") @FXController(path = "Main.fxml")
@FXWindow(title = "demo1") @FXWindow(title = "demo1",dragable = true,fix = true,style = StageStyle.UNDECORATED)
public class MainController extends FXBaseController{ public class MainController extends FXBaseController{
@FXML @FXML

View File

@@ -1,7 +1,7 @@
package cn.edu.scau.biubiusuisui.factory; package cn.edu.scau.biubiusuisui.factory;
import cn.edu.scau.biubiusuisui.annotation.FXField; 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.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXEntityProxy; import cn.edu.scau.biubiusuisui.proxy.classProxy.FXEntityProxy;
import cn.edu.scau.biubiusuisui.utils.ClassUtils; 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 { public static void processFXEntityProxy(Object entity, Object proxy,FXEntityProxy fxEntityProxy) throws IllegalAccessException {
Map<String, Property> stringPropertyMap = new HashMap<>(); Map<String, Property> stringPropertyMap = new HashMap<>();
Map<String, FXFieldViewFieldMapping> stringFXFieldMethodMappingMap = new HashMap<>(); Map<String, FXFieldPropertyMapping> fxFieldPropertyMappingHashMap = new HashMap<>();
Field []fields = entity.getClass().getDeclaredFields(); Field []fields = entity.getClass().getDeclaredFields();
for(Field field:fields){ for(Field field:fields){
Annotation annotation = ClassUtils.getAnnotationInList( FXField.class,field.getDeclaredAnnotations()); Annotation annotation = ClassUtils.getAnnotationInList( FXField.class,field.getDeclaredAnnotations());
@@ -59,10 +59,11 @@ public class FXEntityFactory {
field.setAccessible(true); field.setAccessible(true);
FXField fxField = (FXField)annotation; FXField fxField = (FXField)annotation;
FXFieldViewFieldMapping fieldMethodMapping = new FXFieldViewFieldMapping(); FXFieldPropertyMapping fieldPropertyMapping = new FXFieldPropertyMapping();
fieldMethodMapping.setReadOnly(fxField.readOnly()); fieldPropertyMapping.setReadOnly(fxField.readOnly());
fieldMethodMapping.setType(field.getType()); fieldPropertyMapping.setType(field.getType());
stringFXFieldMethodMappingMap.put(field.getName(), fieldMethodMapping);
fxFieldPropertyMappingHashMap.put(field.getName(), fieldPropertyMapping);
if(field.get(entity) == null){ if(field.get(entity) == null){
property = getFieldDefalutProperty(field); property = getFieldDefalutProperty(field);
@@ -88,7 +89,7 @@ public class FXEntityFactory {
} }
} }
fxEntityProxy.setStringPropertyMap(stringPropertyMap); fxEntityProxy.setStringPropertyMap(stringPropertyMap);
fxEntityProxy.setStringFXFieldMethodMappingMap(stringFXFieldMethodMappingMap); fxEntityProxy.setFxFieldPropertyMappingMap(fxFieldPropertyMappingHashMap);
} }

View File

@@ -5,6 +5,9 @@ import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus; import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.entity.FXBaseController; import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext; 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.Scene;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
@@ -21,10 +24,10 @@ import java.net.URL;
*/ */
public class FXFactory { public class FXFactory {
private static WindowAnnotationParser windowAnnotationParser = new WindowAnnotationParser();;
private FXFactory() { private FXFactory() {
}
}
public static void loadFXController(Class clazz) { public static void loadFXController(Class clazz) {
getFXController(clazz, ""); getFXController(clazz, "");
@@ -105,11 +108,13 @@ public class FXFactory {
register(fxBaseController, fxControllerProxy); register(fxBaseController, fxControllerProxy);
if (isWindow) { if (isWindow) {
Stage stage = new Stage(); Stage stage = new Stage();
double preWidth = fxWindow.preWidth() == 0 ? parent.getPrefWidth() : fxWindow.preWidth(); fxControllerProxy.setStage(stage);
double preHeight = fxWindow.preHeight() == 0 ? parent.getPrefWidth() : fxWindow.preHeight(); 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); Scene scene = new Scene(fxControllerProxy, preWidth, preHeight);
stage.setScene(scene); stage.setScene(scene);
stage.setTitle(fxWindow.title()); windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
stage.show(); stage.show();
} }
return fxControllerProxy; return fxControllerProxy;

View File

@@ -1,6 +1,6 @@
package cn.edu.scau.biubiusuisui.proxy.classProxy; 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 cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.beans.property.*; import javafx.beans.property.*;
import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.Enhancer;
@@ -19,7 +19,7 @@ public class FXEntityProxy implements MethodInterceptor {
Object target; Object target;
private Map<String, Property> stringPropertyMap; private Map<String, Property> stringPropertyMap;
private Map<String, FXFieldViewFieldMapping> stringFXFieldMethodMappingMap; private Map<String, FXFieldPropertyMapping> fxFieldPropertyMappingMap;
public Object getInstance(Object target) { public Object getInstance(Object target) {
this.target = target; this.target = target;
@@ -50,13 +50,13 @@ public class FXEntityProxy implements MethodInterceptor {
} else { } else {
return o1; return o1;
} }
FXFieldViewFieldMapping fieldMethodMapping = stringFXFieldMethodMappingMap.get(fieldName); FXFieldPropertyMapping fxFieldPropertyMapping = fxFieldPropertyMappingMap.get(fieldName);
Property property = stringPropertyMap.get(fieldName); Property property = stringPropertyMap.get(fieldName);
if(fieldMethodMapping == null || property == null){ if(fxFieldPropertyMapping == null || property == null){
return o1; return o1;
} }
Class type = fieldMethodMapping.getType(); Class type = fxFieldPropertyMapping.getType();
if (methodName.startsWith("set")) { if (methodName.startsWith("set")) {
if(Boolean.class.equals(type)){ if(Boolean.class.equals(type)){
((SimpleBooleanProperty)property).set((Boolean)objects[0]); ((SimpleBooleanProperty)property).set((Boolean)objects[0]);
@@ -75,6 +75,8 @@ public class FXEntityProxy implements MethodInterceptor {
((SimpleListProperty)(property)).add(objects[0]); ((SimpleListProperty)(property)).add(objects[0]);
}else if(methodName.startsWith("del")){ }else if(methodName.startsWith("del")){
((SimpleListProperty)(property)).remove(objects[0]); ((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; this.stringPropertyMap = stringPropertyMap;
} }
public Map<String, FXFieldViewFieldMapping> getStringFXFieldMethodMappingMap() { public Map<String, FXFieldPropertyMapping> getFxFieldPropertyMappingMap() {
return stringFXFieldMethodMappingMap; return fxFieldPropertyMappingMap;
} }
public void setStringFXFieldMethodMappingMap(Map<String, FXFieldViewFieldMapping> stringFXFieldMethodMappingMap) { public void setFxFieldPropertyMappingMap(Map<String, FXFieldPropertyMapping> fxFieldPropertyMappingMap) {
this.stringFXFieldMethodMappingMap = stringFXFieldMethodMappingMap; this.fxFieldPropertyMappingMap = fxFieldPropertyMappingMap;
} }
} }

View File

@@ -6,8 +6,8 @@
<fx:root prefHeight="400.0" prefWidth="600.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cn.edu.scau.biubiusuisui.example.MainController"> <fx:root prefHeight="400.0" prefWidth="600.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cn.edu.scau.biubiusuisui.example.MainController">
<children> <children>
<Button fx:id="addBtn" layoutX="454.0" layoutY="98.0" mnemonicParsing="false" onAction="#addWord" text="add" /> <Button fx:id="addBtn" layoutX="432.0" layoutY="83.0" mnemonicParsing="false" onAction="#addWord" text="add" />
<Button fx:id="delBtn" layoutX="454.0" layoutY="144.0" mnemonicParsing="false" onAction="#delWord" text="del" /> <Button fx:id="delBtn" layoutX="432.0" layoutY="151.0" mnemonicParsing="false" onAction="#delWord" text="del" />
<ListView fx:id="list" layoutX="40.0" layoutY="68.0" prefHeight="183.0" prefWidth="373.0" /> <ListView fx:id="list" layoutX="42.0" layoutY="51.0" prefHeight="275.0" prefWidth="334.0" />
</children> </children>
</fx:root> </fx:root>