1. 新增了多窗口切换功能

2. 新增多个example示例可供使用参考
3. 修正信号收发机制的bug
4. 规范化部分代码,并加以部分注释
5. 修改README
This commit is contained in:
suisui
2019-12-10 23:04:44 +08:00
parent 5cc7e57a88
commit c0684c7501
44 changed files with 1438 additions and 1528 deletions

View File

@@ -0,0 +1,17 @@
package cn.edu.scau.biubiusuisui.annotation;
import java.lang.annotation.*;
/**
* @author suiyu_yang
* @description 重定向的注解
* @date 2019/12/3 12:53
* @email suiyu_yang@163.com
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Inherited
public @interface FXRedirect {
boolean close() default true;
}

View File

@@ -8,17 +8,16 @@ import cn.edu.scau.biubiusuisui.factory.FXControllerFactory;
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
import java.util.List;
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @Author jack
* @Date:2019/6/25 2:54
*/
public class FXPlusApplication {
public class FXPlusApplication {
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
@@ -26,26 +25,26 @@ public class FXPlusApplication {
private static BeanBuilder beanBuilder;
public static boolean IS_SCENE_BUILDER = true;
public static boolean IS_SCENE_BUILDER = true;
public static void start(Class clazz, BeanBuilder beanBuilder){
public static void start(Class clazz, BeanBuilder beanBuilder) {
IS_SCENE_BUILDER = false;
FXPlusApplication.beanBuilder = beanBuilder;
Annotation []annotations = clazz.getDeclaredAnnotations();
for(Annotation annotation : annotations){
if(FXScan.class.equals(annotation.annotationType())){
String []dirs = ((FXScan)annotation).base();
Annotation[] annotations = clazz.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
if (FXScan.class.equals(annotation.annotationType())) {
String[] dirs = ((FXScan) annotation).base();
Set<String> sets = new HashSet<>();
for(String dir : dirs){
for (String dir : dirs) {
sets.add(dir);
}
Set<String> classNames = new HashSet<>();
for(String dir:sets){
for (String dir : sets) {
ClassUtils classUtils = new ClassUtils();
List<String> temps = classUtils.scanAllClassName(dir);
for(String className:temps){
for (String className : temps) {
try {
loadFXPlusClass(className,beanBuilder);
loadFXPlusClass(className, beanBuilder);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
@@ -54,14 +53,15 @@ public class FXPlusApplication {
}
}
}
public static void start(Class clazz){
start(clazz,DEFALUT_BEAN_FACTORY);
public static void start(Class clazz) {
start(clazz, DEFALUT_BEAN_FACTORY);
}
private static void loadFXPlusClass(String className,BeanBuilder beanBuilder) throws ClassNotFoundException {
private static void loadFXPlusClass(String className, BeanBuilder beanBuilder) throws ClassNotFoundException {
Class clazz = Class.forName(className);
if(clazz.getAnnotation(FXWindow.class)!=null) {
FXControllerFactory.loadMainStage(clazz, beanBuilder);
if (clazz.getAnnotation(FXWindow.class) != null) {
FXControllerFactory.loadStage(clazz, beanBuilder);
}
}
}

View File

@@ -1,10 +1,10 @@
package cn.edu.scau.biubiusuisui.entity;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
@@ -17,31 +17,25 @@ import java.lang.annotation.Annotation;
*/
/**
* In JavaFX-Plus Framework Controller
* We use MVC model
* V means view which stand for fxml
* C means controller which stand for FXBaseController instance
* M means model which is base cn.edu.scau.biubiusuisui.entity in your program
* Every BaseController has a name which is used for identifying different <strong>instance</strong>
*
* In JavaFX-Plus Framework Controller
* We use MVC model
* V means view which stand for fxml
* C means controller which stand for FXBaseController instance
* M means model which is base cn.edu.scau.biubiusuisui.entity in your program
* Every BaseController has a name which is used for identifying different <strong>instance</strong>
*/
public class FXBaseController extends Pane {
public class FXBaseController extends Pane {
protected String name = "";
private Stage stage;
private boolean isController = false;
private boolean isWindow = false;
private boolean isWindows = false;
public FXBaseController(String name){
public FXBaseController(String name) {
this.name = name;
}
public FXBaseController(){
public FXBaseController() {
FXController fxController = null;
Annotation[] annotations = getClass().getAnnotations();
// Find FXController cn.edu.scau.biubiusuisui.annotation
@@ -50,36 +44,52 @@ public class FXBaseController extends Pane {
fxController = (FXController) annotation;
isController = true;
}
// 添加赋予是否为窗口的逻辑
if (annotation.annotationType().equals(FXWindow.class)) {
isWindow = true;
}
}
//load fxml file to show panel in scene builder
if(isController && FXPlusApplication.IS_SCENE_BUILDER == true) {
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("?");
// System.out.println("?");
try {
fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void initialize() {
}
public String getName() {
if("".equals(name)){
return StringUtils.getBaseClassName(getClass().getSimpleName());
}else{
return StringUtils.getBaseClassName(getClass().getSimpleName()) +"#"+name;
/**
* 唤起舞台
*/
public void showStage() {
if (isWindow) {
this.stage.show();
}
}
public void closeStage() {
if (isWindow) {
this.stage.close();
}
}
public String getName() {
if ("".equals(name) || name == null) { // 原本无“name == null”判断条件会出错
return StringUtils.getBaseClassName(getClass().getSimpleName());
} else {
return StringUtils.getBaseClassName(getClass().getSimpleName()) + "#" + name;
}
}
public void doInit(){}
public void setName(String name) {
this.name = name;
@@ -93,12 +103,12 @@ public class FXBaseController extends Pane {
isController = controller;
}
public boolean isWindows() {
return isWindows;
public boolean isWindow() {
return isWindow;
}
public void setWindows(boolean windows) {
isWindows = windows;
public void setWindow(boolean window) {
isWindow = window;
}
public Stage getStage() {

View File

@@ -4,10 +4,11 @@ import cn.edu.scau.biubiusuisui.annotation.FXField;
import javafx.beans.property.Property;
/**
* 将Controller中的JavaFX的field包装成FXFieldWrapper
* @Author jack
* @Date:2019/6/28 10:03
*/
public class FXFieldWarpper {
public class FXFieldWrapper {
private FXField fxField;

View File

@@ -1,7 +1,6 @@
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;
@@ -44,5 +43,4 @@ public class FXPlusContext {
public static void setProxyByBeanObject(Object object,FXEntityProxy fxEntityProxy){
beanMap.put(object,fxEntityProxy);
}
}

View File

@@ -1,7 +1,6 @@
package cn.edu.scau.biubiusuisui.example.actionDemo;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.annotation.FXSender;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import javafx.application.Application;
import javafx.stage.Stage;

View File

@@ -2,27 +2,25 @@ package cn.edu.scau.biubiusuisui.example.actionDemo;
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 javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import java.text.SimpleDateFormat;
import java.net.URL;
import java.util.ResourceBundle;
/**
* @Author jack
* @Date:2019/7/27 1:43
*/
@FXController(path = "actionDemo.fxml")
@FXWindow(title = "actionDemo")
public class MainController extends FXBaseController {
@FXController(path = "actionDemo/actionDemo.fxml")
@FXWindow(title = "actionDemo", mainStage = true)
public class MainController extends FXBaseController implements Initializable {
@FXML
@FXBind("text=${@toUs(time.text)}")
private Label us;
@@ -31,28 +29,43 @@ public class MainController extends FXBaseController {
@FXBind("text=${@toJp(time.text)}")
private Label jp;
@FXML
private TextField time;
@FXML
@FXBind("text=${@toUk(time.text)}")
private Label uk;
public String toUs(String value){
@FXML
private TextField time;
public String toUs(String value) {
double money = Double.valueOf(value);
double percent = 0.1454;
return String.valueOf(money * percent);
}
public String toJp(String value){
public String toJp(String value) {
double money = Double.valueOf(value);
double percent = 15.797;
return String.valueOf(money * percent);
}
public String toUk(String value){
public String toUk(String value) {
double money = Double.valueOf(value);
double percent = 0.1174;
return String.valueOf(money * percent);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
time.setText("0");
time.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
if (null == newValue || "".equals(newValue)) {
time.setText("0");
} else if (!newValue.matches("^[0-9]*$")) {
time.setText(oldValue);
}
}
});
}
}

View File

@@ -5,13 +5,10 @@ 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 javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import java.util.ArrayList;
@@ -19,29 +16,29 @@ import java.util.ArrayList;
* @Author jack
* @Date:2019/7/27 1:43
*/
@FXController(path = "listDemo.fxml")
@FXWindow(title = "actionDemo",mainStage = true)
@FXController(path = "listDemo/listDemo.fxml")
@FXWindow(title = "listDemo", mainStage = true)
public class MainController extends FXBaseController {
private static int count = 0;
@FXData
User user = new User();
@FXML
@FXBind("items=${@toList(user.names)}")
private ListView<String> list;
private ListView<String> userNameListView;
public ObservableList hello(){
return FXCollections.observableList(new ArrayList<String>(){{add("hello");}});
}
public ObservableList toList(ArrayList list){
return FXCollections.observableList(list);
}
@FXML
public void addName(){
user.addNames("hello");
public void addUserName() {
user.addNames("Jack\t" + (count++));
}
public ObservableList toList(ArrayList list) {
if (list == null) {
return null;
}
return FXCollections.observableList(list);
}
}

View File

@@ -17,20 +17,20 @@ public class User {
@FXField
private String password;
public User() {
names.add("hello ");
names.add("test");
}
public void addNames(String name){
names.add(name);
}
@FXField
private ArrayList<String> names = new ArrayList<>();
public User() {
// names.add("hello ");
// names.add("test");
}
public void addNames(String name) {
names.add(name);
}
public String getName() {
return name;
}

View File

@@ -0,0 +1,20 @@
package cn.edu.scau.biubiusuisui.example.mqDemo;
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 2019/12/8 13:17
* @email suiyu_yang@163.com
*/
@FXScan(base = "cn.edu.scau.biubiusuisui.example.mqDemo")
public class MQDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXPlusApplication.start(MQDemo.class);
}
}

View File

@@ -0,0 +1,36 @@
package cn.edu.scau.biubiusuisui.example.mqDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXReceiver;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
/**
* @author suiyu_yang
* @description 主界面
* @date 2019/12/8 13:17
* @email suiyu_yang@163.com
*/
@FXController(path = "mqDemo/main.fxml")
@FXWindow(mainStage = true, title = "MQDemo")
public class MainController extends FXBaseController {
@FXML
private TextArea outTA;
/**
* 接收者必须指定要订阅的[发送者类名:方法名]
* 发送函数的返回值会注入到接收函数的参数中
*
* @param msg
*/
@FXReceiver(name = "TopBarController:sendToMain")
public void handleTopBar(String msg) {
// TODO: 2019/12/8
// 处理导航栏的点击事件
outTA.appendText(msg + "\n");
}
}

View File

@@ -0,0 +1,47 @@
package cn.edu.scau.biubiusuisui.example.mqDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXSender;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.fxml.FXML;
/**
* @author suiyu_yang
* @description 导航栏示例
* @date 2019/12/8 13:17
* @email suiyu_yang@163.com
*/
@FXController(path = "mqDemo/topBar.fxml")
public class TopBarController extends FXBaseController {
@FXML
public void indexClick() {
sendToMain("点击[首页]");
}
@FXML
public void scoreClick() {
sendToMain("点击[积分中心]");
}
@FXML
public void questionClick() {
sendToMain("点击[问答中心]");
}
@FXML
public void selfClick() {
sendToMain("点击[个人中心]");
}
/**
* 系统会通过发射信号,调用所有订阅这个发射信号函数的方法,从而响应信号
*
* @param msg
* @return
*/
@FXSender //标注为信号发射函数
public String sendToMain(String msg) {
return msg;
}
}

View File

@@ -0,0 +1,16 @@
package cn.edu.scau.biubiusuisui.example.redirectDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
/**
* @author suiyu_yang
* @description
* @date 2019/12/4 21:00
* @email suiyu_yang@163.com
*/
@FXController(path = "redirectDemo/dialog.fxml")
@FXWindow(title = "弹窗")
public class DialogController extends FXBaseController {
}

View File

@@ -0,0 +1,43 @@
package cn.edu.scau.biubiusuisui.example.redirectDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
/**
* @author suiyu_yang
* @description
* @date 2019/12/3 11:53
* @email suiyu_yang@163.com
*/
@FXController(path = "redirectDemo/login.fxml")
@FXWindow(title = "redirectDemo", mainStage = true)
public class LoginController extends FXBaseController {
@FXML
private TextField usernameTF;
@FXML
private PasswordField passwordPF;
@FXML
public void registerClick() {
System.out.println("点击注册.....");
redirectToRegister();
}
@FXRedirect
public String redirectToRegister() {
return "RegisterController";
}
@FXML
@FXRedirect(close = false) //弹窗
public String redirectToDialog() {
return "DialogController";
}
}

View File

@@ -0,0 +1,20 @@
package cn.edu.scau.biubiusuisui.example.redirectDemo;
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 测试重定向功能的Application
* @date 2019/12/3 11:52
* @email suiyu_yang@163.com
*/
@FXScan(base = "cn.edu.scau.biubiusuisui.example.redirectDemo")
public class RedirectDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXPlusApplication.start(RedirectDemo.class);
}
}

View File

@@ -0,0 +1,46 @@
package cn.edu.scau.biubiusuisui.example.redirectDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.fxml.FXML;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
/**
* @author suiyu_yang
* @description
* @date 2019/12/4 00:07
* @email suiyu_yang@163.com
*/
@FXController(path = "redirectDemo/register.fxml")
@FXWindow(title = "register")
public class RegisterController extends FXBaseController {
@FXML
private TextField usernameTF;
@FXML
private TextField emailTF;
@FXML
private PasswordField passwordPF;
@FXML
private PasswordField confirmPasswordPF;
@FXML
public void registerClick() {
}
@FXML
public void loginClick() {
redirectToLogin();
}
@FXRedirect
public String redirectToLogin() {
return "LoginController";
}
}

View File

@@ -0,0 +1,42 @@
package cn.edu.scau.biubiusuisui.example.redirectDemo;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import java.net.URL;
import java.util.ResourceBundle;
/**
* @author suiyu_yang
* @description 登录成功的Controller
* @date 2019/12/3 12:43
* @email suiyu_yang@163.com
*/
@FXController(path = "redirectDemo/success.fxml")
@FXWindow(title = "success")
public class SuccessController extends FXBaseController implements Initializable {
@FXML
private Label usernameLabel;
@FXML
private Label passwordLabel;
@FXML
@FXRedirect
public String redirectToLogin() {
return "LoginController";
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}

View File

@@ -12,13 +12,13 @@ import cn.edu.scau.biubiusuisui.expression.data.ExpressionParser;
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
import cn.edu.scau.biubiusuisui.messageQueue.MessageQueue;
import cn.edu.scau.biubiusuisui.proxy.FXControllerProxy;
import cn.edu.scau.biubiusuisui.stage.StageManager;
import javafx.collections.ObservableMap;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.URL;
@@ -92,13 +92,14 @@ public class FXControllerFactory {
FXBaseController fxBaseController = null;
FXBaseController fxControllerProxy = null;
if (fxController != null) {
String name = fxController.path();
fxmlPath = clazz.getClassLoader().getResource(name);
String fxmlPathName = fxController.path();
fxmlPath = clazz.getClassLoader().getResource(fxmlPathName);
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(fxmlPath);
// create a cn.edu.scau.biubiusuisui.proxy for monitoring methods
fxBaseController = (FXBaseController) beanBuilder.getBean(clazz); //获取controller实例
parseData(fxBaseController);
if (fxBaseController != null) {
FXControllerProxy controllerProxy = new FXControllerProxy();
fxControllerProxy = (FXBaseController) controllerProxy.getInstance(fxBaseController); //产生代理从而实现赋能
@@ -114,8 +115,8 @@ public class FXControllerFactory {
fxBaseController.setName(parent.getId());
}
ObservableMap namespace = fxmlLoader.getNamespace();
addDataInNameSpace(namespace, fxBaseController);
scanBind(namespace, fxBaseController);
addDataInNameSpace(namespace, fxBaseController); //处理fxBaseController里面的@FXData
scanBind(namespace, fxBaseController); //处理@FXBind
register(fxBaseController, fxControllerProxy);
} catch (IOException exception) {
throw new RuntimeException(exception);
@@ -136,28 +137,48 @@ public class FXControllerFactory {
*/
private static void register(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
FXPlusContext.addController(fxBaseController); //保存
MessageQueue.getInstance().registerCosumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
MessageQueue.getInstance().registerConsumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
}
private static Stage createWindow(FXWindow fxWindow, FXBaseController fxControllerProxy) {
/**
* 为有FXWindow注解的类创建Stage
*
* @param fxWindow
* @param fxBaseControllerProxy
* @return
*/
private static Stage createWindow(FXWindow fxWindow, FXBaseController fxBaseControllerProxy) {
Stage stage = new Stage();
fxControllerProxy.setStage(stage);
double preWidth = fxWindow.preWidth() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preWidth();
double preHeight = fxWindow.preHeight() == 0 ? fxControllerProxy.getPrefHeight() : fxWindow.preHeight();
Scene scene = new Scene(fxControllerProxy, preWidth, preHeight);
fxBaseControllerProxy.setStage(stage);
double preWidth = fxWindow.preWidth() == 0 ? fxBaseControllerProxy.getPrefWidth() : fxWindow.preWidth();
double preHeight = fxWindow.preHeight() == 0 ? fxBaseControllerProxy.getPrefHeight() : fxWindow.preHeight();
Scene scene = new Scene(fxBaseControllerProxy, preWidth, preHeight);
stage.setScene(scene);
windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
stage.show();
return stage;
windowAnnotationParser.parse(stage, fxBaseControllerProxy, fxWindow);
StageManager.getInstance().registerWindow(fxBaseControllerProxy); //注册舞台
if (fxWindow.mainStage() == true) { //当是主舞台时先show为敬
// System.out.println("FXControllerFactory: "+(fxControllerProxy.getStage() == null));
fxBaseControllerProxy.showStage();
}
return stage;
}
private FXControllerFactory() {
}
public static void loadMainStage(Class clazz, BeanBuilder beanBuilder) {
/**
* 加载舞台
* 原函数名为loadMainStage(Class clazz, BeanBuilder beanBuilder)
*
* @param clazz
* @param beanBuilder
*/
public static void loadStage(Class clazz, BeanBuilder beanBuilder) {
FXWindow declaredAnnotation = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if ( declaredAnnotation != null && declaredAnnotation.mainStage() == true ) {
//只有当用了FXWindow注解才会注册Stage
if (declaredAnnotation != null) {
getFXWindow(clazz, null, beanBuilder);
}
}
@@ -179,45 +200,50 @@ public class FXControllerFactory {
FXBaseController fxBaseController = getFxBaseController(clazz, controllerName, beanBuilder);
return fxBaseController;
}
public static Stage getFXWindow(Class clazz){
public static Stage getFXWindow(Class clazz) {
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if(fxWindow !=null){
if (fxWindow != null) {
FXBaseController fxController = getFXController(clazz, null, BEAN_BUILDER);
return createWindow(fxWindow, fxController);
}else{
return null;
}
}
public static Stage getFXWindow(Class clazz, BeanBuilder beanBuilder) {
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if(fxWindow !=null){
FXBaseController fxController = getFXController(clazz, null, beanBuilder);
return createWindow(fxWindow, fxController);
}else{
return null;
}
}
public static Stage getFXWindow(Class clazz, String controllerName) {
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if(fxWindow !=null){
FXBaseController fxController = getFXController(clazz, controllerName, BEAN_BUILDER);
return createWindow(fxWindow, fxController);
}else{
} else {
return null;
}
}
public static Stage getFXWindow(Class clazz, String controllerName, BeanBuilder beanBuilder){
public static Stage getFXWindow(Class clazz, BeanBuilder beanBuilder) {
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if(fxWindow !=null){
FXBaseController fxController = getFXController(clazz, controllerName, beanBuilder);
if (fxWindow != null) {
FXBaseController fxController = getFXController(clazz, null, beanBuilder);
return createWindow(fxWindow, fxController);
}else{
} else {
return null;
}
}
private static void parseData(Object object) {
Class clazz = object.getClass();
public static Stage getFXWindow(Class clazz, String controllerName) {
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if (fxWindow != null) {
FXBaseController fxController = getFXController(clazz, controllerName, BEAN_BUILDER);
return createWindow(fxWindow, fxController);
} else {
return null;
}
}
public static Stage getFXWindow(Class clazz, String controllerName, BeanBuilder beanBuilder) {
FXWindow fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
if (fxWindow != null) {
FXBaseController fxController = getFXController(clazz, controllerName, beanBuilder);
return createWindow(fxWindow, fxController);
} else {
return null;
}
}
private static void parseData(Object fxControllerObject) {
Class clazz = fxControllerObject.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
FXData annotation = field.getAnnotation(FXData.class);
@@ -225,9 +251,9 @@ public class FXControllerFactory {
field.setAccessible(true);
//建立代理
try {
Object fieldValue = field.get(object);
Object objectProxy = FXEntityFactory.warpFxBean(fieldValue);
field.set(object, objectProxy);
Object fieldValue = field.get(fxControllerObject);
Object fieldValueProxy = FXEntityFactory.wrapFxBean(fieldValue);
field.set(fxControllerObject, fieldValueProxy);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
@@ -270,7 +296,7 @@ public class FXControllerFactory {
private static void parseBind(ObservableMap namespace, Object object, Field field) {
FXBind fxBind = field.getAnnotation(FXBind.class);
field.setAccessible(true);
ExpressionParser expressionParser = new ExpressionParser(namespace,object);
ExpressionParser expressionParser = new ExpressionParser(namespace, object);
if (fxBind != null) {
String[] expressions = fxBind.value();
try {
@@ -286,10 +312,10 @@ public class FXControllerFactory {
}
}
private boolean isFXWindow(Class clazz){
if(clazz.getDeclaredAnnotation(FXWindow.class)!=null){
private static boolean isFXWindow(Class clazz) {
if (clazz.getDeclaredAnnotation(FXWindow.class) != null) {
return true;
}else{
} else {
return false;
}
}

View File

@@ -1,7 +1,7 @@
package cn.edu.scau.biubiusuisui.factory;
import cn.edu.scau.biubiusuisui.annotation.FXField;
import cn.edu.scau.biubiusuisui.entity.FXFieldWarpper;
import cn.edu.scau.biubiusuisui.entity.FXFieldWrapper;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.proxy.FXEntityProxy;
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
@@ -11,8 +11,8 @@ import javafx.collections.FXCollections;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Map;
/**
* @Author jack
@@ -20,28 +20,29 @@ import java.util.List;
*/
public class FXEntityFactory {
private FXEntityFactory(){}
public static Object warpFxBean(Class clazz){
return warpFxBean(clazz, new FXBuilder());
private FXEntityFactory() {
}
public static Object warpFxBean(Class clazz, BeanBuilder beanBuilder) {
public static Object wrapFxBean(Class clazz) {
return wrapFxBean(clazz, new FXBuilder());
}
public static Object wrapFxBean(Class clazz, BeanBuilder beanBuilder) {
Object object = null;
object = beanBuilder.getBean(clazz);
if(object !=null){
return warpFxBean(object);
}else {
if (object != null) {
return wrapFxBean(object);
} else {
return null;
}
}
public static Object warpFxBean(Object object){
public static Object wrapFxBean(Object object) {
FXEntityProxy fxEntityProxy = new FXEntityProxy();
Object objectProxy = null;
try {
objectProxy = fxEntityProxy.getInstance(object);
processFXEntityProxy(object,objectProxy,fxEntityProxy);
objectProxy = fxEntityProxy.getInstance(object); // 初始化代理类
processFXEntityProxy(object, objectProxy, fxEntityProxy);
FXPlusContext.setProxyByBeanObject(objectProxy, fxEntityProxy);
} catch (IllegalAccessException e) {
e.printStackTrace();
@@ -49,28 +50,27 @@ public class FXEntityFactory {
return objectProxy;
}
private static void processFXEntityProxy(Object entity, Object proxy,FXEntityProxy fxEntityProxy) throws IllegalAccessException {
Map<String, FXFieldWarpper> fxFieldWarpperMap = new HashMap<>();
Field []fields = entity.getClass().getDeclaredFields();
for(Field field:fields){
Annotation annotation = ClassUtils.getAnnotationInList( FXField.class,field.getDeclaredAnnotations());
if(annotation != null){
private static void processFXEntityProxy(Object entity, Object proxy, FXEntityProxy fxEntityProxy) throws IllegalAccessException {
Map<String, FXFieldWrapper> fxFieldWrapperMap = new HashMap<>();
Field[] fields = entity.getClass().getDeclaredFields();
for (Field field : fields) {
Annotation annotation = ClassUtils.getAnnotationInList(FXField.class, field.getDeclaredAnnotations());
if (annotation != null) {
Property property = null;
field.setAccessible(true);
FXField fxField = (FXField)annotation;
FXFieldWarpper fieldWarpper = new FXFieldWarpper();
fieldWarpper.setFxField(fxField);
fieldWarpper.setType(field.getType());
if(field.get(entity) == null){
property = getFieldDefalutProperty(field);
}else{
property = getFieldProperty(entity, field);
FXField fxField = (FXField) annotation;
FXFieldWrapper fieldWrapper = new FXFieldWrapper();
fieldWrapper.setFxField(fxField);
fieldWrapper.setType(field.getType());
if (field.get(entity) == null) {
property = getFieldDefalutProperty(field);
} else {
property = getFieldProperty(entity, field);
}
if(property !=null) {
property.addListener((object,oldVal,newVal)->{
if(!fxField.readOnly()) {
if(!List.class.isAssignableFrom(field.getType())) {
if (property != null) {
property.addListener((object, oldVal, newVal) -> {
if (!fxField.readOnly()) {
if (!List.class.isAssignableFrom(field.getType())) {
try {
field.set(proxy, newVal);
} catch (IllegalAccessException e) {
@@ -80,63 +80,62 @@ public class FXEntityFactory {
}
});
}
fieldWarpper.setProperty(property);
fxFieldWarpperMap.put(field.getName(), fieldWarpper);
fieldWrapper.setProperty(property);
fxFieldWrapperMap.put(field.getName(), fieldWrapper);
}
}
fxEntityProxy.setFxFieldWarpperMap(fxFieldWarpperMap);
fxEntityProxy.setFxFieldWrapperMap(fxFieldWrapperMap);
}
private static Property getFieldProperty(Object object,Field field) throws IllegalAccessException {
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) || boolean.class.equals(type)){
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
property = new SimpleBooleanProperty((Boolean) value);
}else if(Double.class.equals(type)||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) || 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) || int.class.equals(type)){
} else if (Integer.class.equals(type) || int.class.equals(type)) {
property = new SimpleIntegerProperty((Integer) value);
}else if(Long.class.equals(type) || long.class.equals(property)){
} else if (Long.class.equals(type) || long.class.equals(property)) {
property = new SimpleLongProperty((Long) value);
}else if(String.class.equals(type)){
} else if (String.class.equals(type)) {
property = new SimpleStringProperty((String) value);
}else if(List.class.isAssignableFrom(type)){
property = new SimpleListProperty(FXCollections.observableList((List)value));
}else if(Object.class.isAssignableFrom(type)){
} else if (List.class.isAssignableFrom(type)) {
property = new SimpleListProperty(FXCollections.observableList((List) value));
} else if (Object.class.isAssignableFrom(type)) {
property = new SimpleObjectProperty(value);
}
return property;
}
private static Property getFieldDefalutProperty(Field field) throws IllegalAccessException{
private static Property getFieldDefalutProperty(Field field) throws IllegalAccessException {
Class type = field.getType();
Property property = null;
if(Boolean.class.equals(type) || boolean.class.equals(type)){
if (Boolean.class.equals(type) || boolean.class.equals(type)) {
property = new SimpleBooleanProperty();
}else if(Double.class.equals(type)||double.class.equals(type)){
} else if (Double.class.equals(type) || double.class.equals(type)) {
property = new SimpleDoubleProperty();
}else if (Float.class.equals(type) || float.class.equals(type)){
} else if (Float.class.equals(type) || float.class.equals(type)) {
property = new SimpleFloatProperty();
}else if(Integer.class.equals(type) || int.class.equals(type)){
} else if (Integer.class.equals(type) || int.class.equals(type)) {
property = new SimpleIntegerProperty();
}else if(Long.class.equals(type) || long.class.equals(property)){
} else if (Long.class.equals(type) || long.class.equals(property)) {
property = new SimpleLongProperty();
}else if(String.class.equals(type)){
} else if (String.class.equals(type)) {
property = new SimpleStringProperty();
}else if(List.class.isAssignableFrom(type)){
} else if (List.class.isAssignableFrom(type)) {
property = new SimpleListProperty();
}else if(Object.class.isAssignableFrom(type)){
} else if (Object.class.isAssignableFrom(type)) {
property = new SimpleObjectProperty();
}
return property;
}
}

View File

@@ -11,17 +11,17 @@ import javafx.stage.Stage;
*/
public class FXWindowParser {
public void parse(Stage stage, Pane fxControllerProxy, FXWindow fxWindow){
public void parse(Stage stage, Pane fxControllerProxy, FXWindow fxWindow) {
stage.setTitle(fxWindow.title());
if(fxWindow.resizable()){
if (fxWindow.resizable()) {
stage.setResizable(false);
}
if(fxWindow.draggable()) {
final int RESIZE_WIDTH = 5;// 判定是否为调整窗口状态的范围与边界距离
EventHandler dragWindowHandler= new DragWindowHandlerImpl(stage,fxWindow.minWidth(),fxWindow.minHeight(),fxControllerProxy,fxWindow.resizable());
if (fxWindow.draggable()) {
final int RESIZE_WIDTH = 5;// 判定是否为调整窗口状态的范围与边界距离
EventHandler dragWindowHandler = new DragWindowHandlerImpl(stage, fxWindow.minWidth(), fxWindow.minHeight(), fxControllerProxy, fxWindow.resizable());
fxControllerProxy.setOnMousePressed(dragWindowHandler);
fxControllerProxy.setOnMouseDragged(dragWindowHandler);
fxControllerProxy.setOnMouseMoved(dragWindowHandler);

View File

@@ -19,31 +19,32 @@ import java.util.concurrent.ConcurrentHashMap;
public class MessageQueue {
private static Map<String, List<FXMethodEntity>> receivers = new ConcurrentHashMap<>();
private static Map<String, List<FXMethodEntity>> receivers = new ConcurrentHashMap<>(); //Map<主题,订阅了主题的所有方法>
private static MessageQueue messageQueue = null;
private MessageQueue(){ }
private MessageQueue() {
}
public static synchronized MessageQueue getInstance(){
if(messageQueue == null){
public static synchronized MessageQueue getInstance() {
if (messageQueue == null) {
messageQueue = new MessageQueue();
}
return messageQueue;
}
public void registerCosumer(FXBaseController fxBaseController,FXBaseController fxBaseControllerProxy){
public void registerConsumer(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
Class clazz = fxBaseController.getClass();
Method [] methods = clazz.getDeclaredMethods();
for(Method method : methods){
Annotation[]annotations = method.getDeclaredAnnotations();
for(Annotation annotation : annotations){
if(FXReceiver.class.equals(annotation.annotationType())){
FXReceiver receiver = (FXReceiver)annotation;
FXMethodEntity fxMethodEntity = new FXMethodEntity(fxBaseControllerProxy,method);
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
Annotation[] annotations = method.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
if (FXReceiver.class.equals(annotation.annotationType())) {
// System.out.println("FXReceiver");
FXReceiver receiver = (FXReceiver) annotation;
FXMethodEntity fxMethodEntity = new FXMethodEntity(fxBaseControllerProxy, method);
List<FXMethodEntity> fxMethodEntities = receivers.get(receiver.name());
if(fxMethodEntities == null){
if (fxMethodEntities == null) {
fxMethodEntities = new ArrayList<>();
}
fxMethodEntities.add(fxMethodEntity);
@@ -53,7 +54,7 @@ public class MessageQueue {
}
}
public void sendMsg(String id,Object msg) {
public void sendMsg(String id, Object msg) {
List<FXMethodEntity> lists = receivers.get(id);
if (lists != null) {
for (FXMethodEntity fxMethodEntity : lists) {

View File

@@ -1,9 +1,10 @@
package cn.edu.scau.biubiusuisui.proxy;
import cn.edu.scau.biubiusuisui.annotation.FXRedirect;
import cn.edu.scau.biubiusuisui.annotation.FXSender;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.messageQueue.MessageQueue;
import net.sf.cglib.beans.BeanCopier;
import cn.edu.scau.biubiusuisui.stage.StageManager;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@@ -13,7 +14,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
*
* This proxy class intercept Methods that has special annotation such as
* FXSender which is a mark for message queue
*
@@ -26,9 +26,9 @@ public class FXControllerProxy implements MethodInterceptor {
FXBaseController target;
public Object getInstance(FXBaseController target) {
this.target = target;
// System.out.println(target.toString());
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(this.target.getClass());
enhancer.setCallback(this);
@@ -40,26 +40,34 @@ public class FXControllerProxy implements MethodInterceptor {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Annotation []annotations = method.getDeclaredAnnotations();
for(Annotation annotation : annotations){
if(FXSender.class.equals(annotation.annotationType())){
FXSender fxSender = (FXSender)annotation;
String name = target.getName() +":";
if("".equals(fxSender.name())){
name += method.getName();
}else{
name += fxSender.name();
Object o1 = methodProxy.invokeSuper(o, objects); //获取该方法运行后的结果
Annotation[] annotations = method.getDeclaredAnnotations();
for (Annotation annotation : annotations) {
if (FXSender.class.equals(annotation.annotationType())) { // 拦截是否发送消息函数
FXSender fxSender = (FXSender) annotation;
// System.out.println("FXSender");
String name = target.getName() + ":";
// System.out.println("FXControllerProxy:" + name);
if ("".equals(fxSender.name())) {
name += method.getName();
} else {
name += fxSender.name();
}
MessageQueue.getInstance().sendMsg(name,o1);
MessageQueue.getInstance().sendMsg(name, o1);
}
if (FXRedirect.class.equals((annotation.annotationType()))) { //拦截是否重定向函数
FXRedirect fxRedirect = (FXRedirect) annotation;
if (fxRedirect.close()) { //关闭原窗口
StageManager.getInstance().closeStage(target.getName());
}
StageManager.getInstance().redirectTo(o1);
}
}
return o1;
}
private void inject(Object target,Object proxy){
private void inject(Object target, Object proxy) {
Class clazz = target.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {

View File

@@ -1,6 +1,6 @@
package cn.edu.scau.biubiusuisui.proxy;
import cn.edu.scau.biubiusuisui.entity.FXFieldWarpper;
import cn.edu.scau.biubiusuisui.entity.FXFieldWrapper;
import cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.beans.property.*;
import net.sf.cglib.proxy.Enhancer;
@@ -17,7 +17,7 @@ import java.util.Map;
public class FXEntityProxy implements MethodInterceptor {
Object target;
private Map<String, FXFieldWarpper> fxFieldWarpperMap;
private Map<String, FXFieldWrapper> fxFieldWrapperMap;
public Object getInstance(Object target) {
this.target = target;
@@ -39,20 +39,20 @@ public class FXEntityProxy implements MethodInterceptor {
*/
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Object o1 = methodProxy.invokeSuper(o, objects); //获取该方法运行后的结果
String methodName = method.getName();
String fieldName = null;
if (methodName.length() >= 3) {
fieldName = StringUtils.toInstanceName(methodName.substring(3));
fieldName = StringUtils.toInstanceName(methodName.substring(3)); // 该method有可能是getter和setter方法进行处理
} else {
return o1;
}
FXFieldWarpper fxFieldWarpper = fxFieldWarpperMap.get(fieldName);
FXFieldWrapper fxFieldWrapper = fxFieldWrapperMap.get(fieldName);
Property property = getPropertyByFieldName(fieldName);
if(fxFieldWarpper == null || property == null){
if (fxFieldWrapper == null || property == null) {
return o1;
}
Class type = fxFieldWarpper.getType();
Class type = fxFieldWrapper.getType();
if (methodName.startsWith("set")) {
if(Boolean.class.equals(type) || boolean.class.equals(type)){
((SimpleBooleanProperty)property).set((Boolean)objects[0]);
@@ -86,17 +86,17 @@ public class FXEntityProxy implements MethodInterceptor {
}
public Property getPropertyByFieldName(String name) {
if(fxFieldWarpperMap.get(name) ==null){
if (fxFieldWrapperMap.get(name) == null) {
return null;
}
return fxFieldWarpperMap.get(name).getProperty() ;
return fxFieldWrapperMap.get(name).getProperty();
}
public Map<String, FXFieldWarpper> getFxFieldWarpperMap() {
return fxFieldWarpperMap;
public Map<String, FXFieldWrapper> getFxFieldWrapperMap() {
return fxFieldWrapperMap;
}
public void setFxFieldWarpperMap(Map<String, FXFieldWarpper> fxFieldWarpperMap) {
this.fxFieldWarpperMap = fxFieldWarpperMap;
public void setFxFieldWrapperMap(Map<String, FXFieldWrapper> fxFieldWrapperMap) {
this.fxFieldWrapperMap = fxFieldWrapperMap;
}
}

View File

@@ -0,0 +1,44 @@
package cn.edu.scau.biubiusuisui.stage;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author suiyu_yang
* @description 舞台管理器
* @date 2019/12/3 15:43
* @email suiyu_yang@163.com
*/
public class StageManager {
private static StageManager stageManager = null;
private static Map<String, FXBaseController> windows = new ConcurrentHashMap<>(); //
private StageManager() {
}
public static synchronized StageManager getInstance() {
if (stageManager == null) {
stageManager = new StageManager();
}
return stageManager;
}
public void registerWindow(FXBaseController fxBaseControllerProxy) {
if (fxBaseControllerProxy.isWindow()) {
// System.out.println("StageController: "+(fxBaseControllerProxy.getStage() == null));
windows.put(fxBaseControllerProxy.getName(), fxBaseControllerProxy);
}
}
public void closeStage(String controllerName) {
windows.get(controllerName).closeStage();
}
public void redirectTo(Object controller) {
System.out.println("跳转->" + controller);
windows.get(controller).showStage();
}
}

View File

@@ -14,6 +14,6 @@ public class BeanUtil {
if(fxEntityProxy == null){
return null;
}
return fxEntityProxy.getFxFieldWarpperMap().get(fieldName).getProperty();
return fxEntityProxy.getFxFieldWrapperMap().get(fieldName).getProperty();
}
}

View File

@@ -13,22 +13,22 @@ import java.util.List;
* @Date:2019/6/25 5:20
*/
public class ClassUtils {
private ClassLoader cl;
private ClassLoader classLoader;
public ClassUtils() {
cl = getClass().getClassLoader();
classLoader = getClass().getClassLoader();
}
private List<String> getAllFXControllerClassName(String base, List<String> nameList) {
String splashPath = StringUtils.dotToSplash(base);
URL url = cl.getResource(splashPath);
URL url = classLoader.getResource(splashPath);
String filePath = StringUtils.getRootPath(url);
List<String> names = null;
names = readFromDirectory(filePath);
for (String name : names) {
if (isClassFile(name)) {
nameList.add(toFullyQualifiedName(name, base));
} else if (isDirectory(name)){
} else if (isDirectory(name)) {
nameList = getAllFXControllerClassName(base + "." + name, nameList);
}
}
@@ -49,9 +49,11 @@ public class ClassUtils {
private static boolean isClassFile(String name) {
return name.endsWith(".class");
}
private static boolean isDirectory(String name){
private static boolean isDirectory(String name) {
return !name.contains(".");
}
private static List<String> readFromDirectory(String path) {
File file = new File(path);
String[] names = file.list();
@@ -63,8 +65,8 @@ public class ClassUtils {
}
public static boolean hasDeclaredAnnotation(Class clazz, Class annotation){
if(annotation == null){
public static boolean hasDeclaredAnnotation(Class clazz, Class annotation) {
if (annotation == null) {
return false;
}
if (hasAnnotationInList(annotation, clazz.getDeclaredAnnotations())) return true;
@@ -72,7 +74,7 @@ public class ClassUtils {
}
public static boolean hasAnnotation(Class clazz, Class annotation) {
if(annotation == null){
if (annotation == null) {
return false;
}
if (hasAnnotationInList(annotation, clazz.getAnnotations())) return true;
@@ -80,16 +82,16 @@ public class ClassUtils {
}
public static boolean hasAnnotationInList(Class annotation, Annotation[] annotations2) {
if(getAnnotationInList(annotation,annotations2) == null){
if (getAnnotationInList(annotation, annotations2) == null) {
return false;
}else{
} else {
return true;
}
}
public static Annotation getAnnotationInList(Class annotation,Annotation[]annotations){
if(annotations == null || annotation == null){
return null;
public static Annotation getAnnotationInList(Class annotation, Annotation[] annotations) {
if (annotations == null || annotation == null) {
return null;
}
for (Annotation annotation1 : annotations) {
if (annotation1.annotationType().equals(annotation)) {
@@ -99,11 +101,11 @@ public class ClassUtils {
return null;
}
public static void copyField(Object target,Object base){
public static void copyField(Object target, Object base) {
Class clazz = base.getClass();
Class targetClass = target.getClass();
Field []fields = clazz.getDeclaredFields();
for(Field field:fields){
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
// Field field1 = targetClass.getField(field.getName());

View File

@@ -4,6 +4,7 @@ package cn.edu.scau.biubiusuisui.utils;
* @Author jack
* @Date:2019/6/25 3:46
*/
import java.net.URL;
public class StringUtils {
@@ -61,21 +62,34 @@ public class StringUtils {
return trimmed.substring(splashIndex);
}
public static String getBaseClassName(String name){
public static String getBaseClassName(String name) {
int index = name.indexOf("$");
if(index == -1){
if (index == -1) {
return name;
}
return name.substring(0,index);
// System.out.println(name.substring(0,index));
return name.substring(0, index);
}
public static String toInstanceName(String name){
/**
* Object -> object ; Student -> student
*
* @param name
* @return
*/
public static String toInstanceName(String name) {
String result = name.substring(0, 1).toLowerCase().concat(name.substring(1));
return result;
}
public static String toClassName(String name){
/**
* object -> Object ; student -> Student
*
* @param name
* @return
*/
public static String toClassName(String name) {
String result = name.substring(0, 1).toUpperCase().concat(name.substring(1));
return result;
}

View File

@@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<fx:root prefHeight="191.0" prefWidth="607.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.actionDemo.MainController">
<children>
<TextField fx:id="time" layoutX="108.0" layoutY="28.0" prefHeight="28.0" prefWidth="330.0" />
<Label fx:id="us" layoutX="108.0" layoutY="75.0" prefHeight="24.0" prefWidth="330.0" text="US:" />
<Label fx:id="jp" layoutX="108.0" layoutY="107.0" prefHeight="24.0" prefWidth="330.0" text="JP:" />
<Label fx:id="uk" layoutX="108.0" layoutY="142.0" prefHeight="24.0" prefWidth="330.0" text="UK:" />
<Label layoutX="67.0" layoutY="77.0" text="US" />
<Label layoutX="69.0" layoutY="109.0" text="JP" />
<Label layoutX="66.0" layoutY="144.0" text="UK" />
</children>
</fx:root>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.Pane?>
<fx:root prefHeight="191.0" prefWidth="607.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.actionDemo.MainController">
<children>
<TextField fx:id="time" layoutX="108.0" layoutY="28.0" prefHeight="28.0" prefWidth="330.0"/>
<Label fx:id="us" layoutX="108.0" layoutY="75.0" prefHeight="24.0" prefWidth="330.0" text="US:"/>
<Label fx:id="jp" layoutX="108.0" layoutY="107.0" prefHeight="24.0" prefWidth="330.0" text="JP:"/>
<Label fx:id="uk" layoutX="108.0" layoutY="142.0" prefHeight="24.0" prefWidth="330.0" text="UK:"/>
<Label layoutX="67.0" layoutY="77.0" text="US"/>
<Label layoutX="69.0" layoutY="109.0" text="JP"/>
<Label layoutX="66.0" layoutY="144.0" text="UK"/>
</children>
</fx:root>

View File

@@ -3,10 +3,9 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.Pane?>
<fx:root prefHeight="600.0" prefWidth="800.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.listDemo.MainController">
<children>
<ListView fx:id="list" layoutX="32.0" layoutY="62.0" prefHeight="489.0" prefWidth="728.0" />
<Button layoutX="691.0" layoutY="564.0" mnemonicParsing="false" onAction="#addName" text="Button" />
</children>
<children>
<ListView fx:id="userNameListView" layoutX="144.0" layoutY="46.0" prefHeight="457.0" prefWidth="423.0"/>
<Button layoutX="602.0" layoutY="489.0" mnemonicParsing="false" onAction="#addUserName" text="addUserName"/>
</children>
</fx:root>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import cn.edu.scau.biubiusuisui.example.mqDemo.TopBarController?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" type="Pane" xmlns="http://javafx.com/javafx/10.0.2-internal"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="cn.edu.scau.biubiusuisui.example.mqDemo.MainController">
<children>
<VBox prefHeight="400.0" prefWidth="600.0">
<children>
<TopBarController/>
<TextArea fx:id="outTA" editable="false" prefHeight="350.0" prefWidth="600.0" wrapText="true"/>
</children>
</VBox>
</children>
</fx:root>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="50.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.mqDemo.TopBarController">
<children>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="600.0" spacing="20.0">
<children>
<Button mnemonicParsing="false" onAction="#indexClick" prefHeight="50.0" prefWidth="100.0" text="首页"/>
<Button mnemonicParsing="false" onAction="#scoreClick" prefHeight="50.0" prefWidth="100.0" text="积分中心"/>
<Button mnemonicParsing="false" onAction="#questionClick" prefHeight="50.0" prefWidth="100.0"
text="问答中心"/>
<Button mnemonicParsing="false" onAction="#selfClick" prefHeight="50.0" prefWidth="100.0" text="个人中心"/>
</children>
</HBox>
</children>
</fx:root>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="400.0" type="Pane" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="103.0" layoutY="100.0" text="这是一个弹窗......">
<font>
<Font size="24.0"/>
</font>
</Label>
</children>
</fx:root>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0"
prefWidth="800.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.redirectDemo.LoginController">
<children>
<VBox alignment="CENTER" layoutX="265.0" layoutY="100.0" prefHeight="300.0" prefWidth="250.0" spacing="10.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="250.0" text="登录">
<font>
<Font size="27.0"/>
</font>
</Label>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="用户名:"/>
<TextField fx:id="usernameTF"/>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="密码:"/>
<PasswordField fx:id="passwordPF"/>
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="200.0">
<children>
<Label onMouseClicked="#registerClick" prefHeight="50.0" text="还没有账户,去注册" underline="true">
<HBox.margin>
<Insets right="10.0"/>
</HBox.margin>
</Label>
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="200.0">
<children>
<Button mnemonicParsing="false" onAction="#redirectToDialog" text="测试弹窗的按钮">
<HBox.margin>
<Insets right="20.0"/>
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
</fx:root>

View File

@@ -0,0 +1,8 @@
#content {
alignment: center;
}
#content .label {
-fx-pref-height: 50;
-fx-pref-width: 100;
}

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0"
prefWidth="600.0" stylesheets="@register.css" type="Pane" xmlns="http://javafx.com/javafx/8.0.171"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="cn.edu.scau.biubiusuisui.example.redirectDemo.RegisterController">
<children>
<VBox alignment="CENTER" layoutX="100.0" layoutY="55.0" prefHeight="350.0" prefWidth="400.0">
<children>
<HBox prefHeight="50.0" prefWidth="200.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="404.0" text="注册">
<font>
<Font size="24.0"/>
</font>
</Label>
</children>
</HBox>
<VBox id="content" alignment="CENTER" prefHeight="350.0" prefWidth="400.0">
<children>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label text="用户名:"/>
<TextField fx:id="usernameTF"/>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label text="电子邮箱:"/>
<TextField fx:id="emailTF"/>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label text="密码:"/>
<PasswordField fx:id="passwordPF"/>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label text="确认密码:"/>
<PasswordField fx:id="confirmPasswordPF"/>
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="200.0">
<children>
<Label minWidth="150.0" onMouseClicked="#loginClick" prefWidth="151.0" text="已有账号,前往登录"
underline="true"/>
</children>
</HBox>
<HBox alignment="CENTER_RIGHT" prefHeight="50.0" prefWidth="200.0">
<children>
<Button mnemonicParsing="false" onAction="#registerClick" text="注册">
<HBox.margin>
<Insets right="50.0"/>
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
</VBox>
</children>
</fx:root>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.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.redirectDemo.SuccessController">
<children>
<VBox alignment="CENTER" layoutX="158.0" layoutY="80.0" prefHeight="300.0" prefWidth="250.0" spacing="10.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="250.0" text="登录成功">
<font>
<Font size="27.0"/>
</font>
</Label>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="用户名:"/>
<Label fx:id="usernameLabel" alignment="CENTER" prefHeight="50.0" prefWidth="150.0"/>
</children>
</HBox>
<HBox alignment="CENTER" prefHeight="50.0" prefWidth="200.0">
<children>
<Label alignment="CENTER" prefHeight="50.0" prefWidth="50.0" text="密码:"/>
<Label fx:id="passwordLabel" alignment="CENTER" prefHeight="50.0" prefWidth="150.0"/>
</children>
</HBox>
</children>
</VBox>
<Button layoutX="421.0" layoutY="367.0" mnemonicParsing="false" onAction="#redirectToLogin" text="返回主界面"/>
</children>
</fx:root>