1 Commits
v1.1 ... v1.1.1

12 changed files with 172 additions and 39 deletions

View File

@@ -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 {
<ListView fx:id="list" layoutX="42.0" layoutY="51.0" prefHeight="275.0" prefWidth="334.0" />
</children>
</fx:root>
```
从我们代码可以看出我们很少有操作界面的操作并且我们操作的对象都是基本类型的对象这样的操作十分有利于我们将普通的项目转换为JavaFX项目最终运行起来将会是这样

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 MiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 MiB

View File

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 MiB

10
pom.xml
View File

@@ -61,10 +61,18 @@
<!--<verbose />-->
<!-- 解决maven命令编译报错因为rt.jar 和jce.jar在jre的lib下面不在jdk的lib下面
导致maven找不到java7以后会出现这个问题将这2个jar包拷贝到jdk的lib下面估计也好使-->
<bootclasspath>${java.home}\lib\rt.jar;${java.home}\lib\jce.jar</bootclasspath>
<bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -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<String, List<FXBaseController>> controllerContext = new ConcurrentHashMap<>(); //FXController控制器注册表
private static Map<Object, FXEntityProxy> beanMap = new ConcurrentHashMap<>(); // Object注册为FXEntityObject
public static void addController(FXBaseController fxBaseController){
public static void addController(FXBaseController fxBaseController) {
List<FXBaseController> controllers = controllerContext.get(fxBaseController.getName());
if(controllers == null){
if (controllers == null) {
controllers = new LinkedList<>();
}
controllers.add(fxBaseController);
}
public static List<FXBaseController> getControllers(String key){
public static List<FXBaseController> 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);
}
}

View File

@@ -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加强
}
}

View File

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

View File

@@ -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<String> list = new ArrayList<>();
public void addList(String word) {
list.add(word);
}
public void delList(String word) {
list.remove(word);
}
}

View File

@@ -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)) {

View File

@@ -38,7 +38,7 @@ public class StageManager {
}
public void redirectTo(Object controller) {
System.out.println("跳转->" + controller);
// System.out.println("跳转->" + controller);
windows.get(controller).showStage();
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.Pane?>
<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.firstDemo.MainController">
<children>
<Button fx:id="addHelloButton" layoutX="432.0" layoutY="83.0" mnemonicParsing="false" onAction="#addWord"
text="add"/>
<Button fx:id="deleteHelloButton" layoutX="432.0" layoutY="151.0" mnemonicParsing="false" onAction="#delWord"
text="del"/>
<ListView fx:id="list" layoutX="42.0" layoutY="51.0" prefHeight="275.0" prefWidth="334.0"/>
</children>
</fx:root>