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

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