解决了基本类型错误bug

This commit is contained in:
billkiller
2019-07-25 10:04:34 +08:00
parent 34ae7db92f
commit 48889c54a9
11 changed files with 645 additions and 458 deletions

892
.idea/workspace.xml generated
View File

File diff suppressed because it is too large Load Diff

View File

@@ -27,7 +27,10 @@ public class FXPlusApplication {
private static BeanBuilder beanBuilder;
public static boolean IS_SCENE_BUILDER = true;
public static void start(Class clazz, BeanBuilder beanBuilder){
IS_SCENE_BUILDER = false;
FXPlusApplication.beanBuilder = beanBuilder;
Annotation []annotations = clazz.getDeclaredAnnotations();
for(Annotation annotation : annotations){

View File

@@ -2,6 +2,7 @@ package cn.edu.scau.biubiusuisui.entity;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
@@ -49,11 +50,12 @@ public class FXBaseController extends Pane {
}
}
//load fxml file to show panel in scene builder
if(isController) {
if(isController && FXPlusApplication.IS_SCENE_BUILDER == true) {
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(getClass().getClassLoader().getResource(fxController.path()));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
fxmlLoader.setShow(true);
System.out.println("?");
try {
fxmlLoader.load();
} catch (IOException e) {

View File

@@ -19,7 +19,7 @@ import javafx.stage.StageStyle;
* @Date:2019/7/4 11:36
*/
@FXController(path = "Main.fxml")
@FXWindow(title = "hello", resizable = true, style = StageStyle.UNDECORATED)
@FXWindow(title = "hello", resizable = true, draggable = true)
public class Main2 extends FXBaseController {
@FXData
@@ -31,6 +31,8 @@ public class Main2 extends FXBaseController {
)
Student student = new Student();
@FXML
private PasswordField psw;
@FXML
private Label label;
@@ -47,9 +49,7 @@ public class Main2 extends FXBaseController {
@FXML
private Label usrMsg;
@FXML
private PasswordField psw;
@FXBind("text=${student.name}")
@FXML
private Label pswMsg;

View File

@@ -0,0 +1,42 @@
package cn.edu.scau.biubiusuisui.example.moveDemo;
import cn.edu.scau.biubiusuisui.annotation.FXEntity;
import cn.edu.scau.biubiusuisui.annotation.FXField;
/**
* @Author jack
* @Date:2019/7/25 9:24
*/
@FXEntity
public class CircleBean {
@FXField
double x = 0;
@FXField
double y = 0;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
@Override
public String toString() {
return "CircleBean{" +
"x=" + x +
", y=" + y +
'}';
}
}

View File

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

View File

@@ -0,0 +1,72 @@
package cn.edu.scau.biubiusuisui.example.moveDemo;
import cn.edu.scau.biubiusuisui.annotation.FXBind;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXData;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.example.Student;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.shape.Circle;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "moveDemo.fxml")
@FXWindow(title = "hello", resizable = true, draggable = true)
public class Main2 extends FXBaseController {
@FXML
@FXBind({"layoutX=${bean.x}","layoutY=${bean.y}"})
private Circle circle;
@FXData
CircleBean bean = new CircleBean();
@FXML
@FXBind("text=${bean.x}")
private TextField xinput;
@FXML
@FXBind("text=${bean.y}")
private TextField yinput;
@FXML
private Button xSub;
@FXML
private Button xAdd;
@FXML
private Button ySub;
@FXML
private Button yAdd;
@FXML
public void addX(){
double x = bean.getX() + 5 ;
bean.setX(x);
System.out.println("? ? " + bean);
}
@FXML
public void subX(){
double x = bean.getX() - 5 ;
bean.setX(x);
}
@FXML
public void addY(){
double y = bean.getY() + 5 ;
bean.setY(y);
}
@FXML
public void subY(){
double y = bean.getY() - 5 ;
bean.setY(y);
}
}

View File

@@ -25,6 +25,10 @@ import org.springframework.stereotype.Component;
@FXWindow(title = "hello", resizable = true, style = StageStyle.UNDECORATED,draggable = true)
public class SpringExpressionDemoController extends FXBaseController {
@FXData
@Autowired
@FXBind(

View File

@@ -100,16 +100,18 @@ public class FXEntityFactory {
private static Property getFieldProperty(Object object,Field field) throws IllegalAccessException {
Class type = field.getType();
Object value = field.get(object);
Property property = null;
if(Boolean.class.equals(type)){
if(Boolean.class.equals(type) || boolean.class.equals(type)){
property = new SimpleBooleanProperty((Boolean) value);
}else if(Double.class.equals(type)){
}else if(Double.class.equals(type)||double.class.equals(type)){
property = new SimpleDoubleProperty((Double) value);
}else if (Float.class.equals(type)){
}else if (Float.class.equals(type) || float.class.equals(type)){
property = new SimpleFloatProperty((Float) value);
}else if(Integer.class.equals(type)){
}else if(Integer.class.equals(type) || int.class.equals(type)){
property = new SimpleIntegerProperty((Integer) value);
}else if(Long.class.equals(type)){
}else if(Long.class.equals(type) || long.class.equals(property)){
property = new SimpleLongProperty((Long) value);
}else if(String.class.equals(type)){
property = new SimpleStringProperty((String) value);
@@ -123,15 +125,15 @@ public class FXEntityFactory {
private static Property getFieldDefalutProperty(Field field) throws IllegalAccessException{
Class type = field.getType();
Property property = null;
if(Boolean.class.equals(type)){
if(Boolean.class.equals(type) || boolean.class.equals(type)){
property = new SimpleBooleanProperty();
}else if(Double.class.equals(type)){
}else if(Double.class.equals(type)||double.class.equals(type)){
property = new SimpleDoubleProperty();
}else if (Float.class.equals(type)){
}else if (Float.class.equals(type) || float.class.equals(type)){
property = new SimpleFloatProperty();
}else if(Integer.class.equals(type)){
}else if(Integer.class.equals(type) || int.class.equals(type)){
property = new SimpleIntegerProperty();
}else if(Long.class.equals(type)){
}else if(Long.class.equals(type) || long.class.equals(property)){
property = new SimpleLongProperty();
}else if(String.class.equals(type)){
property = new SimpleStringProperty();

View File

@@ -57,15 +57,15 @@ public class FXEntityProxy implements MethodInterceptor {
}
Class type = fxFieldPropertyMapping.getType();
if (methodName.startsWith("set")) {
if(Boolean.class.equals(type)){
if(Boolean.class.equals(type) || boolean.class.equals(type)){
((SimpleBooleanProperty)property).set((Boolean)objects[0]);
}else if(Double.class.equals(type)){
}else if(Double.class.equals(type)||double.class.equals(type)){
((SimpleDoubleProperty)property).set((Double)objects[0]);
}else if (Float.class.equals(type)){
}else if (Float.class.equals(type) || float.class.equals(type)){
((SimpleFloatProperty)property).set((Float) objects[0]);
}else if(Integer.class.equals(type)){
}else if(Integer.class.equals(type) || int.class.equals(type)){
((SimpleIntegerProperty)property).set((Integer) objects[0]);
}else if(Long.class.equals(type)){
}else if(Long.class.equals(type) ||long.class.equals(type)){
((SimpleLongProperty)property).set((Long)objects[0]);
}else if(String.class.equals(type)){
((SimpleStringProperty)property).set((String)objects[0]);

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.shape.Circle?>
<fx:root prefHeight="600.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.moveDemo.Main2">
<children>
<Circle fx:id="circle" fill="DODGERBLUE" layoutX="99.0" layoutY="191.0" radius="39.0" stroke="BLACK" strokeType="INSIDE" />
<TextField layoutX="199.0" layoutY="310.0" text="123" fx:id="xinput" />
<TextField fx:id="yinput" layoutX="199.0" layoutY="367.0" text="123" />
<Label layoutX="14.0" layoutY="315.0" text="X" />
<Label layoutX="14.0" layoutY="372.0" text="Y" />
<Button layoutX="148.0" layoutY="310.0" mnemonicParsing="false" text="-" fx:id="xSub" onAction="#subX"/>
<Button layoutX="415.0" layoutY="310.0" mnemonicParsing="false" text="+" fx:id="xAdd" onAction="#addX"/>
<Button fx:id="ySub" layoutX="148.0" layoutY="367.0" mnemonicParsing="false" text="-" onAction="#subY"/>
<Button fx:id="yAdd" layoutX="415.0" layoutY="367.0" mnemonicParsing="false" text="+" onAction="#addY"/>
</children>
</fx:root>