diff --git a/README.md b/README.md index 460bed6..230cc34 100644 --- a/README.md +++ b/README.md @@ -574,7 +574,7 @@ public class MainController extends FXBaseController implements Initializable { 在JavaFX-Plus中所有Controller对象和FXEnity对象都必须通过工厂创建。 ```java -student = (Student) FXEntityFactory.getInstance().createJavaBeanProxy(Student.class); //工厂产生一个学生 +student = (Student) FXEntityFactory.getInstance().wrapFxBean(Student.class); //工厂产生一个学生 ``` 通过工厂创建JavaBean,在创建的同时,工厂会对JavaBean代理并且包装对应的Property属性。 @@ -633,7 +633,6 @@ public class Demo extends Application { FXPlusApplication.start(Demo.class); //其他配置和JavaFX相同,这里要调用FXPlusAppcalition的start方法,开始FX-plus加强 } } - ``` 2. 接下来我们生成FXML和Controller @@ -666,7 +665,7 @@ public class MainController extends FXBaseController{ @Override public void initialize() { - student = (Student) FXEntityFactory.createJavaBeanProxy(Student.class); // 从工厂中拿到将JavaBean转换得到的JavaFXBean + student = (Student) FXEntityFactory.wrapFxBean(Student.class); // 从工厂中拿到将JavaBean转换得到的JavaFXBean Property listProperty = FXPlusContext.getEntityPropertyByName(student, "list"); list.itemsProperty().bind(listProperty); } @@ -676,7 +675,6 @@ public class MainController extends FXBaseController{ Studen类的定义如下 ```java - @FXEntity public class Student { @@ -711,7 +709,6 @@ public class Student { - ``` 从我们代码可以看出,我们很少有操作界面的操作,并且我们操作的对象都是基本类型的对象,这样的操作十分有利于我们将普通的项目转换为JavaFX项目,最终运行起来将会是这样 diff --git a/README/20191208-124401-close.gif b/README/20191208-124401-close.gif deleted file mode 100644 index 04ea179..0000000 Binary files a/README/20191208-124401-close.gif and /dev/null differ diff --git a/README/20191210-175409-actionDemo-5971713.gif b/README/20191210-175409-actionDemo-5971713.gif deleted file mode 100644 index 3b2dd30..0000000 Binary files a/README/20191210-175409-actionDemo-5971713.gif and /dev/null differ diff --git a/README/20191210-175409-actionDemo.gif b/README/20191210-175409-actionDemo.gif deleted file mode 100644 index 3b2dd30..0000000 Binary files a/README/20191210-175409-actionDemo.gif and /dev/null differ diff --git a/pom.xml b/pom.xml index 0a02ddb..b1b011b 100644 --- a/pom.xml +++ b/pom.xml @@ -44,29 +44,37 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - -Xlint:deprecation - - - - - - ${java.home}\lib\rt.jar;${java.home}\lib\jce.jar - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + -Xlint:deprecation + + + + + + ${java.home}/lib/rt.jar:${java.home}/lib/jce.jar + + + + + maven-assembly-plugin + + + jar-with-dependencies + + + + + diff --git a/src/main/java/cn/edu/scau/biubiusuisui/entity/FXPlusContext.java b/src/main/java/cn/edu/scau/biubiusuisui/entity/FXPlusContext.java index dd3959b..a74922f 100644 --- a/src/main/java/cn/edu/scau/biubiusuisui/entity/FXPlusContext.java +++ b/src/main/java/cn/edu/scau/biubiusuisui/entity/FXPlusContext.java @@ -1,6 +1,7 @@ package cn.edu.scau.biubiusuisui.entity; import cn.edu.scau.biubiusuisui.proxy.FXEntityProxy; +import javafx.beans.property.Property; import java.util.LinkedList; import java.util.List; @@ -8,7 +9,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** - * * Context is use for storing Controller * In addition,you can store an instance into Session to use it everywhere * @@ -17,30 +17,35 @@ import java.util.concurrent.ConcurrentHashMap; */ public class FXPlusContext { - private FXPlusContext(){} + private FXPlusContext() { + } private static Map> controllerContext = new ConcurrentHashMap<>(); //FXController控制器注册表 private static Map beanMap = new ConcurrentHashMap<>(); // Object注册为FXEntityObject - public static void addController(FXBaseController fxBaseController){ + public static void addController(FXBaseController fxBaseController) { List controllers = controllerContext.get(fxBaseController.getName()); - if(controllers == null){ + if (controllers == null) { controllers = new LinkedList<>(); } controllers.add(fxBaseController); } - public static List getControllers(String key){ + public static List getControllers(String key) { return controllerContext.get(key); } - public static FXEntityProxy getProxyByBeanObject(Object object){ + public static FXEntityProxy getProxyByBeanObject(Object object) { return beanMap.get(object); } - public static void setProxyByBeanObject(Object object,FXEntityProxy fxEntityProxy){ - beanMap.put(object,fxEntityProxy); + public static void setProxyByBeanObject(Object object, FXEntityProxy fxEntityProxy) { + beanMap.put(object, fxEntityProxy); + } + + public static Property getEntityPropertyByName(Object object, String fieldName) { + return getProxyByBeanObject(object).getPropertyByFieldName(fieldName); } } diff --git a/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/Demo.java b/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/Demo.java new file mode 100644 index 0000000..bba000c --- /dev/null +++ b/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/Demo.java @@ -0,0 +1,20 @@ +package cn.edu.scau.biubiusuisui.example.firstDemo; + +import cn.edu.scau.biubiusuisui.annotation.FXScan; +import cn.edu.scau.biubiusuisui.config.FXPlusApplication; +import javafx.application.Application; +import javafx.stage.Stage; + +/** + * @author suiyu_yang + * @description 第一个示例 + * @date 2020/1/1 23:06 + * @email suiyu_yang@163.com + */ +@FXScan(base = {"cn.edu.scau.biubiusuisui.example.firstDemo"}) //会扫描带FXController和FXEntity的类进行初始化 +public class Demo extends Application { + @Override + public void start(Stage primaryStage) throws Exception { + FXPlusApplication.start(Demo.class); //其他配置和JavaFX相同,这里要调用FXPlusAppcalition的start方法,开始FX-plus加强 + } +} \ No newline at end of file diff --git a/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/MainController.java b/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/MainController.java new file mode 100644 index 0000000..a74eb65 --- /dev/null +++ b/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/MainController.java @@ -0,0 +1,55 @@ +package cn.edu.scau.biubiusuisui.example.firstDemo; + +import cn.edu.scau.biubiusuisui.annotation.FXController; +import cn.edu.scau.biubiusuisui.annotation.FXWindow; +import cn.edu.scau.biubiusuisui.entity.FXBaseController; +import cn.edu.scau.biubiusuisui.entity.FXPlusContext; +import cn.edu.scau.biubiusuisui.factory.FXEntityFactory; +import javafx.beans.property.Property; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.ListView; + +import java.net.URL; +import java.util.ResourceBundle; + +/** + * @author suiyu_yang + * @description + * @date 2020/1/1 23:06 + * @email suiyu_yang@163.com + */ +@FXController(path = "firstDemo/firstDemo.fxml") +@FXWindow(title = "firstDemo", mainStage = true) +public class MainController extends FXBaseController implements Initializable { + + @FXML + private Button addHelloButton; + @FXML + private Button deleteHelloButton; + + @FXML + private ListView list; + + private Student student; + + @FXML + void addWord(ActionEvent event) { + student.addList("hello"); + } + + @FXML + void delWord(ActionEvent event) { + student.delList("hello"); + } + + @Override + public void initialize(URL location, ResourceBundle resources) { + student = (Student) FXEntityFactory.wrapFxBean(Student.class); // 从工厂中拿到将JavaBean转换得到的JavaFXBean + Property listProperty = FXPlusContext.getEntityPropertyByName(student, "list"); + list.itemsProperty().bind(listProperty); + } +} + diff --git a/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/Student.java b/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/Student.java new file mode 100644 index 0000000..ca11c7c --- /dev/null +++ b/src/main/java/cn/edu/scau/biubiusuisui/example/firstDemo/Student.java @@ -0,0 +1,33 @@ +package cn.edu.scau.biubiusuisui.example.firstDemo; + +import cn.edu.scau.biubiusuisui.annotation.FXEntity; +import cn.edu.scau.biubiusuisui.annotation.FXField; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author suiyu_yang + * @description + * @date 2020/1/1 23:07 + * @email suiyu_yang@163.com + */ + +@FXEntity +public class Student { + + @FXField //标记该属性是否被生成对应的Property + private int age = 0; + + @FXField + private List list = new ArrayList<>(); + + public void addList(String word) { + list.add(word); + } + + public void delList(String word) { + list.remove(word); + } + +} \ No newline at end of file diff --git a/src/main/java/cn/edu/scau/biubiusuisui/factory/FXEntityFactory.java b/src/main/java/cn/edu/scau/biubiusuisui/factory/FXEntityFactory.java index 7a1b337..5250de3 100644 --- a/src/main/java/cn/edu/scau/biubiusuisui/factory/FXEntityFactory.java +++ b/src/main/java/cn/edu/scau/biubiusuisui/factory/FXEntityFactory.java @@ -63,7 +63,7 @@ public class FXEntityFactory { fieldWrapper.setFxField(fxField); fieldWrapper.setType(field.getType()); if (field.get(entity) == null) { - property = getFieldDefalutProperty(field); + property = getFieldDefaultProperty(field); } else { property = getFieldProperty(entity, field); } @@ -114,7 +114,7 @@ public class FXEntityFactory { return property; } - private static Property getFieldDefalutProperty(Field field) throws IllegalAccessException { + private static Property getFieldDefaultProperty(Field field) throws IllegalAccessException { Class type = field.getType(); Property property = null; if (Boolean.class.equals(type) || boolean.class.equals(type)) { diff --git a/src/main/java/cn/edu/scau/biubiusuisui/stage/StageManager.java b/src/main/java/cn/edu/scau/biubiusuisui/stage/StageManager.java index 910e871..62e04ad 100644 --- a/src/main/java/cn/edu/scau/biubiusuisui/stage/StageManager.java +++ b/src/main/java/cn/edu/scau/biubiusuisui/stage/StageManager.java @@ -38,7 +38,7 @@ public class StageManager { } public void redirectTo(Object controller) { - System.out.println("跳转->" + controller); +// System.out.println("跳转->" + controller); windows.get(controller).showStage(); } } diff --git a/src/main/resources/firstDemo/firstDemo.fxml b/src/main/resources/firstDemo/firstDemo.fxml new file mode 100644 index 0000000..87f8b77 --- /dev/null +++ b/src/main/resources/firstDemo/firstDemo.fxml @@ -0,0 +1,15 @@ + + + + + + + +