解决spring的Bug以及实现了EL表达式绑定基本元素属性

This commit is contained in:
billkiller
2019-07-24 23:00:38 +08:00
parent 6fcd94e94b
commit 34ae7db92f
48 changed files with 1852 additions and 1220 deletions

View File

@@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: log4j:log4j:1.2.17">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.17/log4j-1.2.17.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.17/log4j-1.2.17-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.17/log4j-1.2.17-sources.jar!/" />
</SOURCES>
</library>
</component>

1383
.idea/workspace.xml generated
View File

File diff suppressed because it is too large Load Diff

View File

@@ -27,6 +27,5 @@
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.13.RELEASE" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
</component>
</module>

View File

Binary file not shown.

View File

@@ -40,13 +40,6 @@
<version>4.3.13.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>

View File

@@ -10,5 +10,5 @@ import java.lang.annotation.*;
@Target(ElementType.FIELD)
@Inherited
public @interface FXBind {
String [] bind();
String [] value();
}

View File

@@ -0,0 +1,14 @@
package cn.edu.scau.biubiusuisui.annotation;
import java.lang.annotation.*;
/**
* @Author jack
* @Date:2019/6/25 1:36
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Inherited
public @interface FXData {
String fx_id() default "";
}

View File

@@ -1,9 +1,6 @@
package cn.edu.scau.biubiusuisui.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**
* @Author jack
@@ -11,5 +8,6 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface FXEntity {
}

View File

@@ -13,8 +13,12 @@ import java.lang.annotation.Target;
@Target(ElementType.FIELD)
public @interface FXField {
boolean readOnly() default false;
String setter() default "";
String add() default "";
String delete() default "";
String edit() default "";
}

View File

@@ -1,9 +0,0 @@
package cn.edu.scau.biubiusuisui.annotation;
/**
* @Author jack
* @Date:2019/6/25 1:36
*/
public @interface FXView {
}

View File

@@ -1,8 +1,56 @@
package cn.edu.scau.biubiusuisui.config;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.expression.MyBeanAdapter;
import cn.edu.scau.biubiusuisui.expression.MyExpressionValue;
import cn.edu.scau.biubiusuisui.factory.FXFactory;
import javafx.fxml.*;
import com.sun.javafx.beans.IDProperty;
import com.sun.javafx.fxml.BeanAdapter;
import com.sun.javafx.fxml.LoadListener;
import com.sun.javafx.fxml.ParseTraceElement;
import com.sun.javafx.fxml.PropertyNotFoundException;
import com.sun.javafx.fxml.expression.Expression;
import com.sun.javafx.fxml.expression.KeyPath;
import com.sun.javafx.util.Logging;
import javafx.beans.DefaultProperty;
import javafx.beans.InvalidationListener;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.*;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.fxml.LoadException;
import javafx.util.Builder;
import javafx.util.BuilderFactory;
import javafx.util.Callback;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import sun.reflect.misc.ConstructorUtil;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
import javax.script.*;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.StreamReaderDelegate;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.AccessController;
import java.security.AllPermission;
import java.security.PrivilegedAction;
import java.util.*;
import java.util.regex.Pattern;
/*
* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
@@ -29,80 +77,9 @@ import javafx.fxml.*;
*
*/
import com.sun.javafx.util.Logging;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URL;
import java.nio.charset.Charset;
import java.security.AllPermission;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.regex.Pattern;
import javafx.beans.DefaultProperty;
import javafx.beans.InvalidationListener;
import javafx.beans.property.Property;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.*;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.util.Builder;
import javafx.util.BuilderFactory;
import javafx.util.Callback;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.util.StreamReaderDelegate;
import com.sun.javafx.beans.IDProperty;
import com.sun.javafx.fxml.BeanAdapter;
import com.sun.javafx.fxml.LoadListener;
import com.sun.javafx.fxml.ParseTraceElement;
import com.sun.javafx.fxml.PropertyNotFoundException;
import com.sun.javafx.fxml.expression.Expression;
import com.sun.javafx.fxml.expression.ExpressionValue;
import com.sun.javafx.fxml.expression.KeyPath;
import java.net.MalformedURLException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EnumMap;
import java.util.Locale;
import java.util.StringTokenizer;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import sun.reflect.misc.ConstructorUtil;
import sun.reflect.misc.MethodUtil;
import sun.reflect.misc.ReflectUtil;
/**
* Loads an object hierarchy from an XML document.
*
* @since JavaFX 2.0
*/
public class FXMLLoaderPlus {
@@ -164,14 +141,14 @@ public class FXMLLoaderPlus {
// to that (coerce to the appropriate type)
List<Object> list;
if (value instanceof List<?>) {
list = (List<Object>)value;
list = (List<Object>) value;
} else {
Class<?> type = value.getClass();
DefaultProperty defaultProperty = type.getAnnotation(DefaultProperty.class);
String defaultPropertyName = defaultProperty.value();
// Get the list value
list = (List<Object>)getProperties().get(defaultPropertyName);
list = (List<Object>) getProperties().get(defaultPropertyName);
// Coerce the element to the list item type
if (!Map.class.isAssignableFrom(type)) {
@@ -217,7 +194,7 @@ public class FXMLLoaderPlus {
@SuppressWarnings("unchecked")
public Map<String, Object> getProperties() {
return (isTyped()) ? getValueAdapter() : (Map<String, Object>)value;
return (isTyped()) ? getValueAdapter() : (Map<String, Object>) value;
}
public void processStartElement() throws IOException {
@@ -253,7 +230,7 @@ public class FXMLLoaderPlus {
}
public void processAttribute(String prefix, String localName, String value)
throws IOException{
throws IOException {
if (prefix == null) {
// Add the attribute to the appropriate list
if (localName.startsWith(EVENT_HANDLER_PREFIX)) {
@@ -326,12 +303,12 @@ public class FXMLLoaderPlus {
expression = Expression.valueOf(value);
// Create the binding
BeanAdapter targetAdapter = new BeanAdapter(this.value);
MyBeanAdapter targetAdapter = new MyBeanAdapter(this.value);
ObservableValue<Object> propertyModel = targetAdapter.getPropertyModel(attribute.name);
Class<?> type = targetAdapter.getType(attribute.name);
if (propertyModel instanceof Property<?>) {
((Property<Object>) propertyModel).bind(new ExpressionValue(namespace, expression, type));
((Property<Object>) propertyModel).bind(new MyExpressionValue(namespace, expression, type));
}
}
} else if (isBidirectionalBindingExpression(value)) {
@@ -466,7 +443,7 @@ public class FXMLLoaderPlus {
* the array becomes relative to document location.
*/
private Object populateArrayFromString(
Class<?>type,
Class<?> type,
String stringValue) throws LoadException {
Object propertyValue = null;
@@ -497,22 +474,22 @@ public class FXMLLoaderPlus {
String listPropertyName,
String stringValue) throws LoadException {
// Split the string and add the values to the list
List<Object> list = (List<Object>)valueAdapter.get(listPropertyName);
List<Object> list = (List<Object>) valueAdapter.get(listPropertyName);
Type listType = valueAdapter.getGenericType(listPropertyName);
Type itemType = (Class<?>)BeanAdapter.getGenericListItemType(listType);
Type itemType = (Class<?>) BeanAdapter.getGenericListItemType(listType);
if (itemType instanceof ParameterizedType) {
itemType = ((ParameterizedType)itemType).getRawType();
itemType = ((ParameterizedType) itemType).getRawType();
}
if (stringValue.length() > 0) {
String[] values = stringValue.split(ARRAY_COMPONENT_DELIMITER);
for (String aValue: values) {
for (String aValue : values) {
aValue = aValue.trim();
list.add(
BeanAdapter.coerce(resolvePrefixedValue(aValue),
(Class<?>)itemType));
(Class<?>) itemType));
}
}
}
@@ -530,7 +507,7 @@ public class FXMLLoaderPlus {
}
}
private Object getExpressionObject(String handlerValue) throws LoadException{
private Object getExpressionObject(String handlerValue) throws LoadException {
if (handlerValue.startsWith(EXPRESSION_PREFIX)) {
handlerValue = handlerValue.substring(EXPRESSION_PREFIX.length());
@@ -547,13 +524,13 @@ public class FXMLLoaderPlus {
return null;
}
private <T> T getExpressionObjectOfType(String handlerValue, Class<T> type) throws LoadException{
private <T> T getExpressionObjectOfType(String handlerValue, Class<T> type) throws LoadException {
Object expression = getExpressionObject(handlerValue);
if (expression != null) {
if (type.isInstance(expression)) {
return (T) expression;
}
throw constructLoadException("Error resolving \"" + handlerValue +"\" expression."
throw constructLoadException("Error resolving \"" + handlerValue + "\" expression."
+ "Does not point to a " + type.getName());
}
return null;
@@ -637,7 +614,7 @@ public class FXMLLoaderPlus {
}
private void processObservableListHandler(String handlerValue) throws LoadException {
ObservableList list = (ObservableList)value;
ObservableList list = (ObservableList) value;
if (handlerValue.startsWith(CONTROLLER_METHOD_PREFIX)) {
cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.MethodHandler handler = getControllerMethodHandle(handlerValue, cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.LIST_CHANGE_LISTENER);
if (handler != null) {
@@ -659,7 +636,7 @@ public class FXMLLoaderPlus {
}
private void processObservableMapHandler(String handlerValue) throws LoadException {
ObservableMap map = (ObservableMap)value;
ObservableMap map = (ObservableMap) value;
if (handlerValue.startsWith(CONTROLLER_METHOD_PREFIX)) {
cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.MethodHandler handler = getControllerMethodHandle(handlerValue, cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.MAP_CHANGE_LISTENER);
if (handler != null) {
@@ -681,7 +658,7 @@ public class FXMLLoaderPlus {
}
private void processObservableSetHandler(String handlerValue) throws LoadException {
ObservableSet set = (ObservableSet)value;
ObservableSet set = (ObservableSet) value;
if (handlerValue.startsWith(CONTROLLER_METHOD_PREFIX)) {
cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.MethodHandler handler = getControllerMethodHandle(handlerValue, cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.SET_CHANGE_LISTENER);
if (handler != null) {
@@ -761,7 +738,6 @@ public class FXMLLoaderPlus {
updateValue(constructValue());
//如果是FXBaseController对象需要注入fxml
//因为如果只是单纯反射不具有FXPlus功能只有FX功能
if (value instanceof Builder<?>) {
processInstancePropertyAttributes();
} else {
@@ -775,8 +751,9 @@ public class FXMLLoaderPlus {
super.processEndElement();
// Build the value, if necessary
if (value instanceof Builder<?>) {
Builder<Object> builder = (Builder<Object>)value;
Builder<Object> builder = (Builder<Object>) value;
updateValue(builder.build());
processValue();
@@ -818,10 +795,10 @@ public class FXMLLoaderPlus {
Type itemType = BeanAdapter.getGenericListItemType(listType);
if (itemType instanceof ParameterizedType) {
itemType = ((ParameterizedType)itemType).getRawType();
itemType = ((ParameterizedType) itemType).getRawType();
}
value = BeanAdapter.coerce(value, (Class<?>)itemType);
value = BeanAdapter.coerce(value, (Class<?>) itemType);
}
}
@@ -892,7 +869,7 @@ public class FXMLLoaderPlus {
if (valueAdapter.isReadOnly(defaultPropertyName)
&& List.class.isAssignableFrom(valueAdapter.getType(defaultPropertyName))) {
List<Object> list = (List<Object>)valueAdapter.get(defaultPropertyName);
List<Object> list = (List<Object>) valueAdapter.get(defaultPropertyName);
list.add(getListValue(this, defaultPropertyName, text));
} else {
valueAdapter.put(defaultPropertyName, text.trim());
@@ -904,7 +881,7 @@ public class FXMLLoaderPlus {
@Override
public void processAttribute(String prefix, String localName, String value)
throws IOException{
throws IOException {
if (prefix != null
&& prefix.equals(FX_NAMESPACE_PREFIX)) {
if (localName.equals(FX_ID_ATTRIBUTE)) {
@@ -1002,13 +979,13 @@ public class FXMLLoaderPlus {
} else if (factory != null) {
Method factoryMethod;
try {
factoryMethod = MethodUtil.getMethod(type, factory, new Class[] {});
factoryMethod = MethodUtil.getMethod(type, factory, new Class[]{});
} catch (NoSuchMethodException exception) {
throw constructLoadException(exception);
}
try {
value = MethodUtil.invoke(factoryMethod, null, new Object [] {});
value = MethodUtil.invoke(factoryMethod, null, new Object[]{});
} catch (IllegalAccessException exception) {
throw constructLoadException(exception);
} catch (InvocationTargetException exception) {
@@ -1023,9 +1000,9 @@ public class FXMLLoaderPlus {
if (value == null) {
try {
if(FXBaseController.class.isAssignableFrom(type)) {
value = FXFactory.getFXController(type,fx_id);
}else{
if (FXBaseController.class.isAssignableFrom(type)) {
value = FXFactory.getFXController(type, fx_id);
} else {
value = type.newInstance();
}
} catch (InstantiationException exception) {
@@ -1182,6 +1159,9 @@ public class FXMLLoaderPlus {
if (fields != null) {
try {
for (Field f : fields) {
if(baseController!=null) {
f.set(baseController, value);
}
f.set(controller, value);
}
} catch (IllegalAccessException exception) {
@@ -1266,7 +1246,7 @@ public class FXMLLoaderPlus {
Constructor<?> constructor = null;
try {
constructor = ConstructorUtil.getConstructor(sourceValueType, new Class[] { sourceValueType });
constructor = ConstructorUtil.getConstructor(sourceValueType, new Class[]{sourceValueType});
} catch (NoSuchMethodException exception) {
// No-op
}
@@ -1571,7 +1551,7 @@ public class FXMLLoaderPlus {
try {
scriptReader = new InputStreamReader(location.openStream(), charset);
engine.eval(scriptReader);
} catch(ScriptException exception) {
} catch (ScriptException exception) {
exception.printStackTrace();
} finally {
if (scriptReader != null) {
@@ -1591,7 +1571,7 @@ public class FXMLLoaderPlus {
if (value != null && !staticLoad) {
// Evaluate the script
try {
scriptEngine.eval((String)value);
scriptEngine.eval((String) value);
} catch (ScriptException exception) {
System.err.println(exception.getMessage());
}
@@ -1648,7 +1628,7 @@ public class FXMLLoaderPlus {
@Override
public void processAttribute(String prefix, String localName, String value)
throws LoadException{
throws LoadException {
throw constructLoadException("Element does not support attributes.");
}
}
@@ -1702,7 +1682,7 @@ public class FXMLLoaderPlus {
// Execute the script
try {
scriptEngine.eval(script);
} catch (ScriptException exception){
} catch (ScriptException exception) {
throw new RuntimeException(exception);
}
@@ -1790,7 +1770,7 @@ public class FXMLLoaderPlus {
if (type != cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.PARAMETERLESS) {
MethodUtil.invoke(method, controller, params);
} else {
MethodUtil.invoke(method, controller, new Object[] {});
MethodUtil.invoke(method, controller, new Object[]{});
}
} catch (InvocationTargetException exception) {
throw new RuntimeException(exception);
@@ -1807,11 +1787,21 @@ public class FXMLLoaderPlus {
private Object root = null;
private Object controller = null;
private Object baseController = null;
private BuilderFactory builderFactory;
private Callback<Class<?>, Object> controllerFactory;
private Charset charset;
public Object getBaseController() {
return baseController;
}
public void setBaseController(Object baseController) {
this.baseController = baseController;
}
private final LinkedList<cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus> loaders;
private ClassLoader classLoader = null;
@@ -1868,6 +1858,7 @@ public class FXMLLoaderPlus {
public static final String FX_VALUE_ATTRIBUTE = "value";
/**
* The tag name of 'fx:constant'
*
* @since JavaFX 2.2
*/
public static final String FX_CONSTANT_ATTRIBUTE = "constant";
@@ -1922,11 +1913,13 @@ public class FXMLLoaderPlus {
/**
* The tag name of &lt;fx:root&gt;
*
* @since JavaFX 2.2
*/
public static final String ROOT_TAG = "root";
/**
* &lt;fx:root&gt; 'type' attribute
*
* @since JavaFX 2.2
*/
public static final String ROOT_TYPE_ATTRIBUTE = "type";
@@ -1963,6 +1956,7 @@ public class FXMLLoaderPlus {
* Escape prefix for escaping special characters inside attribute values.
* Serves as an escape for {@link #ESCAPE_PREFIX}, {@link #RELATIVE_PATH_PREFIX},
* {@link #RESOURCE_KEY_PREFIX, {@link #EXPRESSION_PREFIX}, {@link #BI_DIRECTIONAL_BINDING_PREFIX}
*
* @since JavaFX 2.1
*/
public static final String ESCAPE_PREFIX = "\\";
@@ -1989,29 +1983,34 @@ public class FXMLLoaderPlus {
/**
* Prefix for bidirectional-binding expression resolution
*
* @since JavaFX 2.1
*/
public static final String BI_DIRECTIONAL_BINDING_PREFIX = "#{";
/**
* Suffix for bidirectional-binding expression resolution
*
* @since JavaFX 2.1
*/
public static final String BI_DIRECTIONAL_BINDING_SUFFIX = "}";
/**
* Delimiter for arrays as values
*
* @since JavaFX 2.1
*/
public static final String ARRAY_COMPONENT_DELIMITER = ",";
/**
* A key for location URL in namespace map
*
* @see #getNamespace()
* @since JavaFX 2.2
*/
public static final String LOCATION_KEY = "location";
/**
* A key for ResourceBundle in namespace map
*
* @see #getNamespace()
* @since JavaFX 2.2
*/
@@ -2023,6 +2022,7 @@ public class FXMLLoaderPlus {
public static final String CONTROLLER_METHOD_PREFIX = "#";
/**
* A key for controller in namespace map
*
* @see #getNamespace()
* @since JavaFX 2.1
*/
@@ -2030,6 +2030,7 @@ public class FXMLLoaderPlus {
/**
* A suffix for controllers of included fxml files.
* The full key is stored in namespace map.
*
* @see #getNamespace()
* @since JavaFX 2.2
*/
@@ -2037,18 +2038,21 @@ public class FXMLLoaderPlus {
/**
* The name of initialize method
*
* @since JavaFX 2.2
*/
public static final String INITIALIZE_METHOD_NAME = "initialize";
/**
* Contains the current javafx version
*
* @since JavaFX 8.0
*/
public static final String JAVAFX_VERSION;
/**
* Contains the current fx namepsace version
*
* @since JavaFX 8.0
*/
public static final String FX_NAMESPACE_VERSION = "1";
@@ -2066,7 +2070,7 @@ public class FXMLLoaderPlus {
* Creates a new FXMLLoader instance.
*/
public FXMLLoaderPlus() {
this((URL)null);
this((URL) null);
}
/**
@@ -2112,7 +2116,7 @@ public class FXMLLoaderPlus {
* @since JavaFX 2.1
*/
public FXMLLoaderPlus(URL location, ResourceBundle resources, BuilderFactory builderFactory,
Callback<Class<?>, Object> controllerFactory) {
Callback<Class<?>, Object> controllerFactory) {
this(location, resources, builderFactory, controllerFactory, Charset.forName(DEFAULT_CHARSET_NAME));
}
@@ -2136,7 +2140,7 @@ public class FXMLLoaderPlus {
* @since JavaFX 2.1
*/
public FXMLLoaderPlus(URL location, ResourceBundle resources, BuilderFactory builderFactory,
Callback<Class<?>, Object> controllerFactory, Charset charset) {
Callback<Class<?>, Object> controllerFactory, Charset charset) {
this(location, resources, builderFactory, controllerFactory, charset,
new LinkedList<cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus>());
}
@@ -2153,8 +2157,8 @@ public class FXMLLoaderPlus {
* @since JavaFX 2.1
*/
public FXMLLoaderPlus(URL location, ResourceBundle resources, BuilderFactory builderFactory,
Callback<Class<?>, Object> controllerFactory, Charset charset,
LinkedList<cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus> loaders) {
Callback<Class<?>, Object> controllerFactory, Charset charset,
LinkedList<cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus> loaders) {
setLocation(location);
setResources(resources);
setBuilderFactory(builderFactory);
@@ -2208,7 +2212,7 @@ public class FXMLLoaderPlus {
*/
@SuppressWarnings("unchecked")
public <T> T getRoot() {
return (T)root;
return (T) root;
}
/**
@@ -2217,8 +2221,7 @@ public class FXMLLoaderPlus {
* must be called prior to loading the document when using
* <tt>&lt;fx:root&gt;</tt>.
*
* @param root
* The root of the object hierarchy.
* @param root The root of the object hierarchy.
* @since JavaFX 2.2
*/
public void setRoot(Object root) {
@@ -2228,7 +2231,7 @@ public class FXMLLoaderPlus {
@Override
public boolean equals(Object obj) {
if (obj instanceof cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus) {
cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus loader = (cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus)obj;
cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus loader = (cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus) obj;
if (location == null || loader.location == null) {
return loader.location == location;
}
@@ -2255,7 +2258,7 @@ public class FXMLLoaderPlus {
*/
@SuppressWarnings("unchecked")
public <T> T getController() {
return (T)controller;
return (T) controller;
}
/**
@@ -2265,8 +2268,7 @@ public class FXMLLoaderPlus {
* controller event handlers when an <tt>fx:controller</tt> attribute is not
* specified in the document.
*
* @param controller
* The controller to associate with the root object.
* @param controller The controller to associate with the root object.
* @since JavaFX 2.2
*/
public void setController(Object controller) {
@@ -2299,6 +2301,7 @@ public class FXMLLoaderPlus {
/**
* Returns the controller cn.edu.scau.biubiusuisui.factory used by this serializer.
*
* @since JavaFX 2.1
*/
public Callback<Class<?>, Object> getControllerFactory() {
@@ -2338,6 +2341,7 @@ public class FXMLLoaderPlus {
/**
* Returns the classloader used by this serializer.
*
* @since JavaFX 2.1
*/
@CallerSensitive
@@ -2384,7 +2388,6 @@ public class FXMLLoaderPlus {
* Sets the static load flag.
*
* @param staticLoad
*
* @treatAsPrivate
* @deprecated
*/
@@ -2408,7 +2411,6 @@ public class FXMLLoaderPlus {
* Sets this loader's load listener.
*
* @param loadListener
*
* @treatAsPrivate
* @deprecated
*/
@@ -2422,8 +2424,7 @@ public class FXMLLoaderPlus {
* the document will be loaded must have been set by a prior call to
* {@link #setLocation(URL)}.
*
* @return
* The loaded object hierarchy.
* @return The loaded object hierarchy.
* @since JavaFX 2.1
*/
@CallerSensitive
@@ -2436,11 +2437,8 @@ public class FXMLLoaderPlus {
/**
* Loads an object hierarchy from a FXML document.
*
* @param inputStream
* An input stream containing the FXML data to load.
*
* @return
* The loaded object hierarchy.
* @param inputStream An input stream containing the FXML data to load.
* @return The loaded object hierarchy.
*/
@CallerSensitive
public <T> T load(InputStream inputStream) throws IOException {
@@ -2470,7 +2468,7 @@ public class FXMLLoaderPlus {
return value;
}
@SuppressWarnings({ "dep-ann", "unchecked" })
@SuppressWarnings({"dep-ann", "unchecked"})
private <T> T loadImpl(InputStream inputStream,
Class<?> callerClass) throws IOException {
if (inputStream == null) {
@@ -2567,7 +2565,7 @@ public class FXMLLoaderPlus {
if (controller != null) {
if (controller instanceof Initializable) {
((Initializable)controller).initialize(location, resources);
((Initializable) controller).initialize(location, resources);
} else {
// Inject controller fields
if (!show) {
@@ -2609,7 +2607,7 @@ public class FXMLLoaderPlus {
xmlStreamReader = null;
}
return (T)root;
return (T) root;
}
private void clearImports() {
@@ -2617,7 +2615,7 @@ public class FXMLLoaderPlus {
classes.clear();
}
private LoadException constructLoadException(String message){
private LoadException constructLoadException(String message) {
return new LoadException(message + constructFXMLTrace());
}
@@ -2625,7 +2623,7 @@ public class FXMLLoaderPlus {
return new LoadException(constructFXMLTrace(), cause);
}
private LoadException constructLoadException(String message, Throwable cause){
private LoadException constructLoadException(String message, Throwable cause) {
return new LoadException(message + constructFXMLTrace(), cause);
}
@@ -2649,8 +2647,8 @@ public class FXMLLoaderPlus {
* Returns the current line number.
*
* @treatAsPrivate
* @deprecated
* @since JavaFX 2.2
* @deprecated
*/
public int impl_getLineNumber() {
return xmlStreamReader.getLocation().getLineNumber();
@@ -2660,8 +2658,8 @@ public class FXMLLoaderPlus {
* Returns the current parse trace.
*
* @treatAsPrivate
* @deprecated
* @since JavaFX 2.1
* @deprecated
*/
// SB-dependency: RT-21475 has been filed to track this
public ParseTraceElement[] impl_getParseTrace() {
@@ -2942,7 +2940,6 @@ public class FXMLLoaderPlus {
private static enum SupportedType {
PARAMETERLESS {
@Override
protected boolean methodIsOfType(Method m) {
return m.getParameterTypes().length == 0;
@@ -2950,7 +2947,6 @@ public class FXMLLoaderPlus {
},
EVENT {
@Override
protected boolean methodIsOfType(Method m) {
return m.getParameterTypes().length == 1 &&
@@ -2959,7 +2955,6 @@ public class FXMLLoaderPlus {
},
LIST_CHANGE_LISTENER {
@Override
protected boolean methodIsOfType(Method m) {
return m.getParameterTypes().length == 1 &&
@@ -2968,7 +2963,6 @@ public class FXMLLoaderPlus {
},
MAP_CHANGE_LISTENER {
@Override
protected boolean methodIsOfType(Method m) {
return m.getParameterTypes().length == 1 &&
@@ -2977,7 +2971,6 @@ public class FXMLLoaderPlus {
},
SET_CHANGE_LISTENER {
@Override
protected boolean methodIsOfType(Method m) {
return m.getParameterTypes().length == 1 &&
@@ -2986,7 +2979,6 @@ public class FXMLLoaderPlus {
},
PROPERTY_CHANGE_LISTENER {
@Override
protected boolean methodIsOfType(Method m) {
return m.getParameterTypes().length == 3 &&
@@ -3022,9 +3014,7 @@ public class FXMLLoaderPlus {
*
* @param packageName
* @param className
*
* @deprecated
* This method now delegates to {@link #getDefaultClassLoader()}.
* @deprecated This method now delegates to {@link #getDefaultClassLoader()}.
*/
public static Class<?> loadType(String packageName, String className) throws ClassNotFoundException {
return loadType(packageName + "." + className.replace('.', '$'));
@@ -3034,9 +3024,7 @@ public class FXMLLoaderPlus {
* Loads a type using the default class loader.
*
* @param className
*
* @deprecated
* This method now delegates to {@link #getDefaultClassLoader()}.
* @deprecated This method now delegates to {@link #getDefaultClassLoader()}.
*/
public static Class<?> loadType(String className) throws ClassNotFoundException {
ReflectUtil.checkPackageAccess(className);
@@ -3081,6 +3069,7 @@ public class FXMLLoaderPlus {
/**
* Returns the default class loader.
*
* @since JavaFX 2.1
*/
@CallerSensitive
@@ -3095,8 +3084,7 @@ public class FXMLLoaderPlus {
/**
* Sets the default class loader.
*
* @param defaultClassLoader
* The default class loader to use when loading classes.
* @param defaultClassLoader The default class loader to use when loading classes.
* @since JavaFX 2.1
*/
public static void setDefaultClassLoader(ClassLoader defaultClassLoader) {
@@ -3145,7 +3133,7 @@ public class FXMLLoaderPlus {
private static <T> T loadImpl(URL location, ResourceBundle resources,
Class<?> callerClass) throws IOException {
return loadImpl(location, resources, null,
return loadImpl(location, resources, null,
callerClass);
}
@@ -3240,10 +3228,11 @@ public class FXMLLoaderPlus {
/**
* Utility method for comparing two JavaFX version strings (such as 2.2.5, 8.0.0-ea)
*
* @param rtVer String representation of JavaFX runtime version, including - or _ appendix
* @param nsVer String representation of JavaFX version to compare against runtime version
* @return number &lt; 0 if runtime version is lower, 0 when both versions are the same,
* number &gt; 0 if runtime is higher version
* number &gt; 0 if runtime is higher version
*/
static int compareJFXVersions(String rtVer, String nsVer) {
@@ -3388,7 +3377,7 @@ public class FXMLLoaderPlus {
Map<cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType, Map<String, Method>> getControllerMethods() {
if (controllerMethods == null) {
controllerMethods = new EnumMap<>(cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.class);
for (cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType t: cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.values()) {
for (cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType t : cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus.SupportedType.values()) {
controllerMethods.put(t, new HashMap<String, Method>());
}

View File

@@ -1,6 +1,7 @@
package cn.edu.scau.biubiusuisui.config;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.factory.BeanBuilder;
import cn.edu.scau.biubiusuisui.factory.FXBuilder;
import cn.edu.scau.biubiusuisui.factory.FXFactory;
@@ -57,6 +58,9 @@ public class FXPlusApplication {
private static void loadFXPlusClass(String className,BeanBuilder beanBuilder) throws ClassNotFoundException {
Class clazz = Class.forName(className);
FXFactory.loadFXController(clazz,beanBuilder);
if(clazz.getAnnotation(FXWindow.class)!=null) {
System.out.println(className);
FXFactory.loadFXController(clazz, beanBuilder);
}
}
}

View File

@@ -2,15 +2,12 @@ package cn.edu.scau.biubiusuisui.entity;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.config.FXMLLoaderPlus;
import javafx.fxml.Initializable;
import javafx.scene.layout.Pane;
import cn.edu.scau.biubiusuisui.utils.StringUtils;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.ResourceBundle;
/**
* @Author jack
@@ -107,4 +104,6 @@ public class FXBaseController extends Pane {
public void setStage(Stage stage) {
this.stage = stage;
}
}

View File

@@ -1,10 +1,5 @@
package cn.edu.scau.biubiusuisui.entity;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
import java.lang.reflect.Method;
/**
* @Author jack
* @Date:2019/6/28 10:03

View File

@@ -1,6 +1,6 @@
package cn.edu.scau.biubiusuisui.entity;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXEntityProxy;
import cn.edu.scau.biubiusuisui.proxy.FXEntityProxy;
import javafx.beans.property.Property;
import java.util.LinkedList;
@@ -25,7 +25,7 @@ public class FXPlusContext {
private static Map<Object, FXEntityProxy> beanProxyMap = new ConcurrentHashMap<>(); // Object注册为FXEntityObject
public static Property getEntityPropertyByName(Object object, String fieldName){
FXEntityProxy fxEntityProxy = FXPlusContext.getProryByBeanObject(object);
FXEntityProxy fxEntityProxy = FXPlusContext.getProxyByBeanObject(object);
if(fxEntityProxy == null){
return null;
}
@@ -46,7 +46,7 @@ public class FXPlusContext {
return controllerContext.get(key);
}
public static FXEntityProxy getProryByBeanObject(Object object){
public static FXEntityProxy getProxyByBeanObject(Object object){
return beanProxyMap.get(object);
}

View File

@@ -1,8 +0,0 @@
package cn.edu.scau.biubiusuisui.example;
/**
* @Author jack
* @Date:2019/7/7 10:44
*/
public class HelloFXPlusDemo {
}

View File

@@ -1,23 +0,0 @@
package cn.edu.scau.biubiusuisui.example;
import cn.edu.scau.biubiusuisui.annotation.FXController;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import javafx.stage.StageStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "Main.fxml")
@Component
@FXWindow(title = "hello",resizable = true,style = StageStyle.UNDECORATED)
public class Main2 extends FXBaseController {
@Autowired
Student student;
}

View File

@@ -1,70 +0,0 @@
package cn.edu.scau.biubiusuisui.example;
import cn.edu.scau.biubiusuisui.annotation.*;
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.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.stage.StageStyle;
import java.net.URL;
import java.util.ResourceBundle;
/**
* @Author jack
* @Date:2019/6/25 1:47
*/
@FXController(path = "Main.fxml")
//@FXWindow(title = "demo1", draggable = true, resizable = true,style = StageStyle.UNDECORATED)
public class MainController extends FXBaseController{
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private Button addBtn;
@FXML
private Button delBtn;
@FXML
private ListView<String> list;
@FXML
@FXBind(bind = {"text=${student.name}"})
Label label;
Student student;
@FXML
@FXSender
void addWord(ActionEvent event) {
student.addList("hello" );
}
@FXML
void delWord(ActionEvent event) {
student.delList("hello");
}
@FXReceiver(name = "MainController#haha:addWord")
void test2(){
System.out.println("?--?");
}
@Override
public void initialize() {
student = (Student) FXEntityFactory.createJavaBeanProxy(Student.class);
Property property = FXPlusContext.getEntityPropertyByName(student, "list");
list.itemsProperty().bind(property);
}
}

View File

@@ -6,6 +6,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @Author jack
* @Date:2019/6/27 20:02
@@ -18,14 +19,10 @@ public class Student {
@FXField
private String name;
private int age;
private String gender;
private String code;
@FXField
private List<String> list = new ArrayList<>();
private String password;
public String getName() {
return name;
@@ -35,35 +32,11 @@ public class Student {
this.name = name;
}
public int getAge() {
return age;
public String getPassword() {
return password;
}
public void setAge(int age) {
this.age = age;
public void setPassword(String password) {
this.password = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public void addList(String word){
list.add(word);
}
public void delList(String word){
list.remove(word);
}
}

View File

@@ -0,0 +1,19 @@
package cn.edu.scau.biubiusuisui.example.expressionDemo;
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.expressionDemo"})
//项目目录中带有中文字符会导致无法启动
public class Demo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXPlusApplication.start(Demo.class);
}
}

View File

@@ -0,0 +1,74 @@
package cn.edu.scau.biubiusuisui.example.expressionDemo;
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.stage.StageStyle;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "Main.fxml")
@FXWindow(title = "hello", resizable = true, style = StageStyle.UNDECORATED)
public class Main2 extends FXBaseController {
@FXData
@FXBind(
{
"name=${usr.text}",
"password=${psw.text}"
}
)
Student student = new Student();
@FXML
private Label label;
@FXML
private TextField usr;
@FXML
private Button resetBtn;
@FXML
private Button loginBtn;
@FXML
private Label usrMsg;
@FXML
private PasswordField psw;
@FXML
private Label pswMsg;
@FXML
void login(ActionEvent event) {
System.out.println("user:" + student.getName());
System.out.println("psw:"+student.getPassword());
if("admin".equals(student.getName())&&"admin".equals(student.getPassword())){
System.out.println("Ok");
}else{
System.out.println("fail");
}
}
@FXML
void reset(ActionEvent event) {
psw.setText("");
usr.setText("");
}
}

View File

@@ -0,0 +1,19 @@
package cn.edu.scau.biubiusuisui.example.listViewExpressionDemo;
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/7/24 22:56
*/
@FXScan(base = {"cn.edu.scau.biubiusuisui.example.expressionDemo"})
//项目目录中带有中文字符会导致无法启动
public class Demo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXPlusApplication.start(Demo.class);
}
}

View File

@@ -0,0 +1,11 @@
package cn.edu.scau.biubiusuisui.example.listViewExpressionDemo;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
/**
* @Author jack
* @Date:2019/7/24 22:58
*/
public class MainController extends FXBaseController {
//待开发
}

View File

@@ -19,14 +19,14 @@ import org.springframework.stereotype.Component;
* @Date:2019/7/4 11:36
*/
@FXController(path = "springDemo.fxml")
@Component
@FXWindow(title = "hello",resizable = true,style = StageStyle.UNDECORATED)
//@Component
//@FXWindow(title = "hello",resizable = true,style = StageStyle.UNDECORATED)
public class SpringController extends FXBaseController {
@Autowired
Student student;
@Autowired
Student studentProxy;
@FXML
@@ -36,15 +36,19 @@ public class SpringController extends FXBaseController {
@Override
public void initialize() {
studentProxy = (Student) FXEntityFactory.createJavaBeanProxy(student);
Property property = FXPlusContext.getEntityPropertyByName(studentProxy, "name");
label.textProperty().bind(property);
System.out.println("為什麼");
}
@FXML
public void add(){
studentProxy.setName("Jack : " + count);
count++;
System.out.println("add");
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
}

View File

@@ -2,7 +2,6 @@ package cn.edu.scau.biubiusuisui.example.springDemo;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.example.Demo;
import cn.edu.scau.biubiusuisui.factory.BeanBuilder;
import javafx.application.Application;
import javafx.stage.Stage;
@@ -21,7 +20,6 @@ public class SpringDemo extends Application {
FXPlusApplication.start(SpringDemo.class, new BeanBuilder() {
@Override
public Object getBean(Class type) {
System.out.println(type);
return context.getBean(type);
}
});

View File

@@ -0,0 +1,35 @@
package cn.edu.scau.biubiusuisui.example.springDemo2;
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.example.springDemo.SpringController;
import javafx.fxml.FXML;
import javafx.stage.StageStyle;
import org.springframework.stereotype.Component;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "springDemo2.fxml")
@Component
//@FXWindow(title = "hello",resizable = true,style = StageStyle.UNDECORATED)
public class SpringController2 extends FXBaseController {
@FXML
SpringController springController;
int count = 1;
@Override
public void initialize() {
}
@FXML
public void test(){
System.out.println("student"+springController.getStudent());
}
}

View File

@@ -1,4 +1,4 @@
package cn.edu.scau.biubiusuisui.example;
package cn.edu.scau.biubiusuisui.example.springDemo2;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
@@ -10,15 +10,14 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @Author jack
* @Date:2019/6/25 7:05
* @Date:2019/7/7 10:43
*/
@FXScan(base = {"cn.edu.scau.biubiusuisui.example"})
//项目目录中带有中文字符会导致无法启动
public class Demo extends Application {
@FXScan(base = {"cn.edu.scau.biubiusuisui.example.springDemo2"})
public class SpringDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
FXPlusApplication.start(Demo.class, new BeanBuilder() {
FXPlusApplication.start(SpringDemo.class, new BeanBuilder() {
@Override
public Object getBean(Class type) {
return context.getBean(type);

View File

@@ -0,0 +1,29 @@
package cn.edu.scau.biubiusuisui.example.springExpressionDemo;
import cn.edu.scau.biubiusuisui.annotation.FXScan;
import cn.edu.scau.biubiusuisui.config.FXPlusApplication;
import cn.edu.scau.biubiusuisui.example.springDemo.SpringDemo;
import cn.edu.scau.biubiusuisui.factory.BeanBuilder;
import javafx.application.Application;
import javafx.stage.Stage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @Author jack
* @Date:2019/6/25 7:05
*/
@FXScan(base = {"cn.edu.scau.biubiusuisui.example.springExpressionDemo"})
//项目目录中带有中文字符会导致无法启动
public class SpringExpressionDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
FXPlusApplication.start(SpringExpressionDemo.class, new BeanBuilder() {
@Override
public Object getBean(Class type) {
return context.getBean(type);
}
});
}
}

View File

@@ -0,0 +1,78 @@
package cn.edu.scau.biubiusuisui.example.springExpressionDemo;
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.stage.StageStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @Author jack
* @Date:2019/7/4 11:36
*/
@FXController(path = "SpringExpressionDemo.fxml")
@Component
@FXWindow(title = "hello", resizable = true, style = StageStyle.UNDECORATED,draggable = true)
public class SpringExpressionDemoController extends FXBaseController {
@FXData
@Autowired
@FXBind(
{
"name=${usr.text}",
"password=${psw.text}"
}
)
Student student;
@FXML
private Label label;
@FXML
private TextField usr;
@FXML
private Button resetBtn;
@FXML
private Button loginBtn;
@FXML
private Label usrMsg;
@FXML
private PasswordField psw;
@FXML
private Label pswMsg;
@FXML
void login(ActionEvent event) {
System.out.println("user:" + student.getName());
System.out.println("psw:"+student.getPassword());
if("admin".equals(student.getName())&&"admin".equals(student.getPassword())){
System.out.println("Ok");
}else{
System.out.println("fail");
}
}
@FXML
void reset(ActionEvent event) {
psw.setText("");
usr.setText("");
}
}

View File

@@ -0,0 +1,78 @@
package cn.edu.scau.biubiusuisui.expression;
import com.sun.istack.internal.NotNull;
import com.sun.javafx.fxml.expression.Expression;
import com.sun.javafx.fxml.expression.ExpressionValue;
import javafx.beans.property.Property;
/**
* 将FXBind中表达式建立绑定
* 格式如下
* 语法如下:
* FXBind("S")
* S -> left=right
* left -> property
* right -> ${expression}
* expression -> bean.field
*
* FXBind("text=${bean.field})
* textProperty 通过 adapter.getModelProeprty --> textProperty实例
* bean 通过namespace 获取因为bean有FXEntity标签所以返回包装过后的bean的property
* 最后
* left.bind(right)
*
* @Author jack
* @Date:2019/7/23 15:05
*/
public class ExpressionParser {
private Object namespace;
private static final String BIND_PREFIX = "${";
private static final String BIND_SUFIX = "}";
private static final String PROEPRTY = "Property";
public ExpressionParser(Object namespace) {
this.namespace = namespace;
}
private Property getLeftProperty(MyBeanAdapter myBeanAdapter, String key) {
return (Property) myBeanAdapter.getPropertyModel(key);
}
private MyExpressionValue getRightExpreesion(MyBeanAdapter myBeanAdapter,String key ,String rightExpression) {
Expression expression = Expression.valueOf(rightExpression);
Class clazz = myBeanAdapter.getType(key);
MyExpressionValue myExpressionValue = new MyExpressionValue(namespace, expression, clazz);
return myExpressionValue;
}
public void parse(Object object, @NotNull String expression) {
//check expression
int index = expression.indexOf("=");
if (index == -1) {
return;
}
String[] items = expression.split("=");
if (items.length != 2) {
return;
}
String left = items[0];
String right = items[1];
if (left == null || right == null) {
return;
}
right = right.trim();
if (right.startsWith(BIND_PREFIX) && right.endsWith(BIND_SUFIX)){
int length = right.length();
right = right.substring(2,length-1);
}
MyBeanAdapter myBeanAdapter = new MyBeanAdapter(object);
Property leftProperty = getLeftProperty(myBeanAdapter, left);
MyExpressionValue rightProperty = getRightExpreesion(myBeanAdapter,left,right);
leftProperty.bind(rightProperty);
}
}

View File

@@ -0,0 +1,38 @@
package cn.edu.scau.biubiusuisui.expression;
import cn.edu.scau.biubiusuisui.annotation.FXEntity;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import com.sun.javafx.fxml.BeanAdapter;
import javafx.beans.value.ObservableValue;
/**
* @Author jack
* @Date:2019/7/23 15:16
*/
public class MyBeanAdapter extends BeanAdapter {
private Object object;
/**
* Creates a new Bean adapter.
*
* @param bean The Bean object to wrap.
*/
public MyBeanAdapter(Object bean) {
super(bean);
this.object = bean;
}
@Override
public <T> ObservableValue<T> getPropertyModel(String key) {
if (object.getClass().getAnnotation(FXEntity.class) == null) {
return super.getPropertyModel(key);
} else {
return FXPlusContext.getEntityPropertyByName(object, key);
}
}
public String valueOf(String value) {
return value;
}
}

View File

@@ -0,0 +1,225 @@
package cn.edu.scau.biubiusuisui.expression;
import com.sun.javafx.fxml.BeanAdapter;
import com.sun.javafx.fxml.expression.Expression;
import com.sun.javafx.fxml.expression.ExpressionValue;
import com.sun.javafx.fxml.expression.KeyPath;
import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValueBase;
import javafx.collections.ListChangeListener;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @Author jack
* @Date:2019/7/24 0:37
*/
public class MyExpressionValue extends ObservableValueBase<Object> {
// Monitors a namespace for changes along a key path
private class KeyPathMonitor {
private String key;
private KeyPathMonitor next;
private Object namespace = null;
private ListChangeListener<Object> listChangeListener = new ListChangeListener<Object>() {
@Override
public void onChanged(Change<? extends Object> change) {
while (change.next()) {
int index = Integer.parseInt(key);
if (index >= change.getFrom() && index < change.getTo()) {
fireValueChangedEvent();
remonitor();
}
}
}
};
private MapChangeListener<String, Object> mapChangeListener = new MapChangeListener<String, Object>() {
@Override
public void onChanged(Change<? extends String, ? extends Object> change) {
if (key.equals(change.getKey())) {
fireValueChangedEvent();
remonitor();
}
}
};
private ChangeListener<Object> propertyChangeListener = new ChangeListener<Object>() {
@Override
public void changed(ObservableValue<? extends Object> observable, Object oldValue, Object newValue) {
fireValueChangedEvent();
remonitor();
}
};
public KeyPathMonitor(Iterator<String> keyPathIterator) {
this.key = keyPathIterator.next();
if (keyPathIterator.hasNext()) {
next = new KeyPathMonitor(keyPathIterator);
} else {
next = null;
}
}
@SuppressWarnings("unchecked")
public void monitor(Object namespace) {
if (namespace instanceof ObservableList<?>) {
((ObservableList<Object>)namespace).addListener(listChangeListener);
} else if (namespace instanceof ObservableMap<?, ?>) {
((ObservableMap<String, Object>)namespace).addListener(mapChangeListener);
} else {
MyBeanAdapter namespaceAdapter = new MyBeanAdapter(namespace);
ObservableValue<Object> propertyModel = namespaceAdapter.getPropertyModel(key);
if (propertyModel != null) {
propertyModel.addListener(propertyChangeListener);
}
namespace = namespaceAdapter;
}
this.namespace = namespace;
if (next != null) {
Object value = Expression.get(namespace, key);
if (value != null) {
next.monitor(value);
}
}
}
@SuppressWarnings("unchecked")
public void unmonitor() {
if (namespace instanceof ObservableList<?>) {
((ObservableList<Object>)namespace).removeListener(listChangeListener);
} else if (namespace instanceof ObservableMap<?, ?>) {
((ObservableMap<String, Object>)namespace).removeListener(mapChangeListener);
} else if (namespace != null) {
MyBeanAdapter namespaceAdapter = (MyBeanAdapter)namespace;
ObservableValue<Object> propertyModel = namespaceAdapter.getPropertyModel(key);
if (propertyModel != null) {
propertyModel.removeListener(propertyChangeListener);
}
}
namespace = null;
if (next != null) {
next.unmonitor();
}
}
public void remonitor() {
if (next != null) {
next.unmonitor();
Object value = Expression.get(namespace, key);
if (value != null) {
next.monitor(value);
}
}
}
}
private Object namespace;
private Expression expression;
private Class<?> type;
private ArrayList<KeyPathMonitor> argumentMonitors;
private int listenerCount = 0;
public MyExpressionValue(Object namespace, Expression expression, Class<?> type) {
if (namespace == null) {
throw new NullPointerException();
}
if (expression == null) {
throw new NullPointerException();
}
if (type == null) {
throw new NullPointerException();
}
this.namespace = namespace;
this.expression = expression;
this.type = type;
List<KeyPath> arguments = expression.getArguments();
argumentMonitors = new ArrayList<KeyPathMonitor>(arguments.size());
for (KeyPath argument : arguments) {
argumentMonitors.add(new KeyPathMonitor(argument.iterator()));
}
}
@Override
public Object getValue() {
return BeanAdapter.coerce(expression.evaluate(namespace), type);
}
@Override
public void addListener(InvalidationListener listener) {
if (listenerCount == 0) {
monitorArguments();
}
super.addListener(listener);
listenerCount++;
}
@Override
public void removeListener(InvalidationListener listener) {
super.removeListener(listener);
listenerCount--;
if (listenerCount == 0) {
unmonitorArguments();
}
}
@Override
public void addListener(ChangeListener<? super Object> listener) {
if (listenerCount == 0) {
monitorArguments();
}
super.addListener(listener);
listenerCount++;
}
@Override
public void removeListener(ChangeListener<? super Object> listener) {
super.removeListener(listener);
listenerCount--;
if (listenerCount == 0) {
unmonitorArguments();
}
}
private void monitorArguments() {
for (KeyPathMonitor argumentMonitor : argumentMonitors) {
argumentMonitor.monitor(namespace);
}
}
private void unmonitorArguments() {
for (KeyPathMonitor argumentMonitor : argumentMonitors) {
argumentMonitor.unmonitor();
}
}
}

View File

@@ -5,5 +5,10 @@ package cn.edu.scau.biubiusuisui.factory;
* @Date:2019/7/4 11:16
*/
public interface BeanBuilder {
/**
* 万能工厂方法
* @param type 类型
* @return 实例对象
*/
Object getBean(Class type);
}

View File

@@ -3,7 +3,7 @@ package cn.edu.scau.biubiusuisui.factory;
import cn.edu.scau.biubiusuisui.annotation.FXField;
import cn.edu.scau.biubiusuisui.entity.FXFieldPropertyMapping;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXEntityProxy;
import cn.edu.scau.biubiusuisui.proxy.FXEntityProxy;
import cn.edu.scau.biubiusuisui.utils.ClassUtils;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
@@ -25,6 +25,7 @@ public class FXEntityFactory {
public static Object createJavaBeanProxy(Class clazz){
return createJavaBeanProxy(clazz, new FXBuilder());
}
public static Object createJavaBeanProxy(Class clazz,BeanBuilder beanBuilder) {
Object object = null;
object = beanBuilder.getBean(clazz);
@@ -61,6 +62,7 @@ public class FXEntityFactory {
FXField fxField = (FXField)annotation;
FXFieldPropertyMapping fieldPropertyMapping = new FXFieldPropertyMapping();
fieldPropertyMapping.setReadOnly(fxField.readOnly());
fieldPropertyMapping.setType(field.getType());

View File

@@ -1,25 +1,25 @@
package cn.edu.scau.biubiusuisui.factory;
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.config.FXMLLoaderPlus;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.example.Student;
import cn.edu.scau.biubiusuisui.function.FXExpressionParser;
import cn.edu.scau.biubiusuisui.expression.ExpressionParser;
import cn.edu.scau.biubiusuisui.function.FXWindowParser;
import cn.edu.scau.biubiusuisui.messageQueue.MessageQueue;
import cn.edu.scau.biubiusuisui.proxy.classProxy.FXControllerProxy;
import com.sun.javafx.fxml.BeanAdapter;
import cn.edu.scau.biubiusuisui.proxy.FXControllerProxy;
import javafx.collections.ObservableMap;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Map;
/**
* @Author jack
@@ -30,12 +30,147 @@ public class FXFactory {
private static final BeanBuilder BEAN_BUILDER = new FXBuilder();
private static FXWindowParser windowAnnotationParser = new FXWindowParser();
private static FXExpressionParser expressionParser = new FXExpressionParser();
/**
* 控制类的注入流程
* 这是一个即将被创建的控制类
* <pre>
* <code>
* class MainController{
* @Autowired
* Student stu; //普通属性
* @FXML
* Button btn; //FX属性
* }
* </code>
* </pre>
* 1. 实现对普通属性的注入
* 如果使用了Spring那么这类会自动注入那些@Autowired的属性请不要将这个方法用在控制器属性中
* <pre>
* <code>
* class MainController{
* @Autowired
* Student stu ; //初始化完成
* @FXML
* Button btn; // null
* }
* </code>
* </pre>
* 2. 通过loadFXML实现对FX属性的注入
* <pre>
* <code>
* class MainController{
* @Autowired
* Student stu ; //初始化完成
* @FXML
* Button btn; // 初始化完成
* }
* </code>
* </pre>
* <p>
* 3. 完成对FXBind的注解的解析
* <p>
* <p>
* <p>
* 4. 完成注册
*
* @param clazz instance that extends by FXBaseController
* @param controllerName
* @return
*/
private static FXBaseController getFxBaseController(Class clazz, String controllerName, BeanBuilder beanBuilder) {
URL fxmlPath;
FXWindow fxWindow = null;
FXController fxController = null; //reflect and get FXController cn.edu.scau.biubiusuisui.annotation
fxController = (FXController) clazz.getDeclaredAnnotation(FXController.class);
fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
Pane parent = null;
FXBaseController fxControllerProxy = null;
FXBaseController fxBaseController = null;
if (fxController != null) {
String name = fxController.path();
fxmlPath = clazz.getClassLoader().getResource(name);
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); //产生代理从而实现赋能
fxmlLoader.setRoot(fxControllerProxy);
fxmlLoader.setController(fxControllerProxy);
fxmlLoader.setBaseController(fxBaseController);
try {
parent = fxmlLoader.load();
if (controllerName != null) {
fxControllerProxy.setName(controllerName);
fxBaseController.setName(controllerName);
} else {
fxBaseController.setName(parent.getId());
}
ObservableMap namespace = fxmlLoader.getNamespace();
addDataInNameSpace(namespace, fxBaseController);
scanBind(namespace, fxBaseController);
register(fxBaseController, fxControllerProxy);
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
} else {
return null;
}
//register
if (fxWindow != null) {
createWindow(fxWindow, fxControllerProxy, fxBaseController);
}
return fxControllerProxy;
}
/**
* 将代理对象和目标对象注册
*
* @param fxBaseController 目标对象
* @param fxBaseControllerProxy 代理对象
*/
private static void register(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
FXPlusContext.addController(fxBaseController); //保存
MessageQueue.getInstance().registerCosumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
}
private static void createWindow(FXWindow fxWindow, FXBaseController fxControllerProxy, FXBaseController fxBaseController) {
Stage stage = new Stage();
fxControllerProxy.setStage(stage);
fxBaseController.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);
stage.setScene(scene);
windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
stage.show();
}
private FXFactory() {
}
private static FXBaseController getFxBaseController(Class clazz, String controllerName) {
return null;
}
public static void loadFXController(Class clazz, BeanBuilder beanBuilder) {
if (clazz.getDeclaredAnnotation(FXWindow.class) != null) {
getFXController(clazz, null, beanBuilder);
@@ -60,86 +195,71 @@ public class FXFactory {
return fxBaseController;
}
private static void register(FXBaseController fxBaseController, FXBaseController fxBaseControllerProxy) {
FXPlusContext.addController(fxBaseController); //保存
MessageQueue.getInstance().registerCosumer(fxBaseController, fxBaseControllerProxy); // 添加进入消息队列 信号功能
}
private static FXBaseController getFxBaseController(Class clazz, String controllerName) {
return null;
}
/**
* @param clazz instance that extends by FXBaseController
* @param controllerName
* @return
*/
private static FXBaseController getFxBaseController(Class clazz, String controllerName, BeanBuilder beanBuilder) {
Boolean isController = false;
URL fxmlPath;
Boolean isWindow = false;
FXWindow fxWindow = null;
FXController fxController = null;
//reflect and get FXController cn.edu.scau.biubiusuisui.annotation
fxController = (FXController) clazz.getDeclaredAnnotation(FXController.class);
fxWindow = (FXWindow) clazz.getDeclaredAnnotation(FXWindow.class);
Pane parent = null;
FXBaseController fxControllerProxy = null;
FXBaseController fxBaseController = null;
if (fxController != null) {
String name = fxController.path();
fxmlPath = clazz.getClassLoader().getResource(name);
FXMLLoaderPlus fxmlLoader = new FXMLLoaderPlus(fxmlPath);
// create a cn.edu.scau.biubiusuisui.proxy for monitoring methods
fxBaseController = (FXBaseController) beanBuilder.getBean(clazz);
if (fxBaseController != null) {
FXControllerProxy controllerProxy = new FXControllerProxy();
fxControllerProxy = (FXBaseController) controllerProxy.getInstance(fxBaseController);
fxmlLoader.setRoot(fxControllerProxy);
fxmlLoader.setController(fxControllerProxy);
private static void parseData(Object object) {
Class clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
FXData annotation = field.getAnnotation(FXData.class);
if (annotation != null) {
field.setAccessible(true);
//建立代理
try {
parent = fxmlLoader.load();
if (controllerName != null) {
fxControllerProxy.setName(controllerName);
fxBaseController.setName(controllerName);
} else {
fxBaseController.setName(parent.getId());
}
register(fxBaseController, fxControllerProxy);
} catch (IOException exception) {
throw new RuntimeException(exception);
Object fieldValue = field.get(object);
Object objectProxy = FXEntityFactory.createJavaBeanProxy(fieldValue);
field.set(object, objectProxy);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
} else {
return null;
}
//register
}
if (fxWindow != null) {
createWindow(fxWindow, fxControllerProxy, fxBaseController);
private static void addDataInNameSpace(ObservableMap namespace, Object object) {
Class clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
FXData annotation = field.getAnnotation(FXData.class);
if (annotation != null) {
field.setAccessible(true);
try {
String fx_id;
field.setAccessible(true);
if ("".equals(annotation.fx_id())) {
fx_id = field.getName();
} else {
fx_id = annotation.fx_id();
}
Object fieldValue = field.get(object);
namespace.put(fx_id, fieldValue);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
return fxControllerProxy;
}
private static void createWindow(FXWindow fxWindow, FXBaseController fxControllerProxy, FXBaseController fxBaseController) {
Stage stage = new Stage();
fxControllerProxy.setStage(stage);
fxBaseController.setStage(stage);
double preWidth = fxWindow.preWidth() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preWidth();
double preHeight = fxWindow.preHeight() == 0 ? fxControllerProxy.getPrefWidth() : fxWindow.preHeight();
Scene scene = new Scene(fxControllerProxy, preWidth, preHeight);
stage.setScene(scene);
windowAnnotationParser.parse(stage, fxControllerProxy, fxWindow);
stage.show();
private static void scanBind(ObservableMap namespace, Object object) {
Class clazz = object.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
parseBind(namespace, object, field);
}
}
private static void parseControllerBindExpression(FXBaseController fxBaseController, ObservableMap<String, Object> namespaces) {
expressionParser.parse(fxBaseController, namespaces);
private static void parseBind(ObservableMap namespace, Object object, Field field) {
FXBind fxBind = field.getAnnotation(FXBind.class);
field.setAccessible(true);
ExpressionParser expressionParser = new ExpressionParser(namespace);
if (fxBind != null) {
String[] expressions = fxBind.value();
try {
Object objectValue = field.get(object);
for (String e : expressions) {
expressionParser.parse(objectValue, e);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -1,19 +0,0 @@
package cn.edu.scau.biubiusuisui.function;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
/**
* @Author jack
* @Date:2019/6/28 15:57
*/
public class DefaultEventFunction implements ChangeListener {
public DefaultEventFunction() {}
@Override
public void changed(ObservableValue observable, Object oldValue, Object newValue) {
}
}

View File

@@ -1,56 +0,0 @@
package cn.edu.scau.biubiusuisui.function;
import cn.edu.scau.biubiusuisui.annotation.FXBind;
import cn.edu.scau.biubiusuisui.entity.FXBaseController;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import com.sun.javafx.fxml.BeanAdapter;
import com.sun.javafx.fxml.expression.Expression;
import com.sun.javafx.fxml.expression.ExpressionValue;
import javafx.beans.property.Property;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableMap;
import java.lang.reflect.Field;
import java.util.Map;
/**
* @Author jack
* @Date:2019/7/4 13:55
*/
public class FXExpressionParser {
private static final String BIND_EXPRESSION_PREFIX = "${";
private static final String BIND_EXPRESSION_SUFIX = "}";
public static void parse(FXBaseController fxBaseController, ObservableMap<String, Object> namespaces) {
// Class clazz = fxBaseController.getClass();
// Field[] fields = clazz.getDeclaredFields();
// for (Field field : fields) {
// FXBind fxBind = field.getDeclaredAnnotation(FXBind.class);
// if (fxBind != null) {
// String[] names = fxBind.bind();
// for (String propertyName : names) {
// String args[] = propertyName.split("=");
// String name = args[0];
// String value = args[1];
// if (value.startsWith(BIND_EXPRESSION_PREFIX) && value.endsWith(BIND_EXPRESSION_SUFIX)) {
// value = value.substring(BIND_EXPRESSION_PREFIX.length(), value.length() - 1);
// Object object = null;
// try {
// field.setAccessible(true);
// object = field.get(fxBaseController);
// } catch (IllegalAccessException e) {
// e.printStackTrace();
// }
//
// BeanAdapter targetAdapter = new BeanAdapter(object);
// ObservableValue<Object> propertyModel = targetAdapter.getPropertyModel(name);
// Class<?> type = targetAdapter.getType(name);
// if (propertyModel instanceof Property<?>) {
// ((Property<Object>) propertyModel).bind(FXPlusContext.getEntityPropertyByName(fxBaseController,));
// }
// }
// }
// }
}
}

View File

@@ -1,7 +1,6 @@
package cn.edu.scau.biubiusuisui.function;
import cn.edu.scau.biubiusuisui.annotation.FXWindow;
import cn.edu.scau.biubiusuisui.function.DragWindowHandlerImpl;
import javafx.event.EventHandler;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

View File

@@ -1,8 +1,9 @@
package cn.edu.scau.biubiusuisui.proxy.classProxy;
package cn.edu.scau.biubiusuisui.proxy;
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 net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
@@ -32,6 +33,7 @@ public class FXControllerProxy implements MethodInterceptor {
enhancer.setSuperclass(this.target.getClass());
enhancer.setCallback(this);
Object proxy = enhancer.create();
// target.* -> proxy.*
inject(target, proxy);
return proxy;
}
@@ -40,7 +42,6 @@ public class FXControllerProxy implements MethodInterceptor {
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
Object o1 = methodProxy.invokeSuper(o, objects);
Annotation []annotations = method.getDeclaredAnnotations();
// System.out.println("name" +target.getName());
for(Annotation annotation : annotations){
if(FXSender.class.equals(annotation.annotationType())){
FXSender fxSender = (FXSender)annotation;
@@ -50,21 +51,22 @@ public class FXControllerProxy implements MethodInterceptor {
}else{
name += fxSender.name();
}
System.out.println("method" + name);
MessageQueue.getInstance().sendMsg(name,o1);
}
}
return o1;
}
private void inject(Object target,Object proxy){
Field[] fields = target.getClass().getDeclaredFields();
Class clazz = target.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
try {
Object filedValue = field.get(target);
System.out.println(filedValue);
field.set(proxy,filedValue);
Object value = field.get(target);
field.set(proxy, value);
} catch (IllegalAccessException e) {
e.printStackTrace();
}

View File

@@ -1,4 +1,4 @@
package cn.edu.scau.biubiusuisui.proxy.classProxy;
package cn.edu.scau.biubiusuisui.proxy;
import cn.edu.scau.biubiusuisui.entity.FXFieldPropertyMapping;
import cn.edu.scau.biubiusuisui.utils.StringUtils;
@@ -55,7 +55,6 @@ public class FXEntityProxy implements MethodInterceptor {
if(fxFieldPropertyMapping == null || property == null){
return o1;
}
System.out.println("??? <--->");
Class type = fxFieldPropertyMapping.getType();
if (methodName.startsWith("set")) {
if(Boolean.class.equals(type)){

View File

@@ -2,6 +2,7 @@ package cn.edu.scau.biubiusuisui.utils;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Arrays;
import java.util.LinkedList;
@@ -97,4 +98,15 @@ public class ClassUtils {
}
return null;
}
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.setAccessible(true);
// Field field1 = targetClass.getField(field.getName());
}
}
}

View File

@@ -1,16 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<fx:root id="haha" prefHeight="403.0" prefWidth="625.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.MainController">
<children>
<Label fx:id="label" layoutX="18.0" layoutY="166.0" prefHeight="68.0" prefWidth="304.0" text="${input.text}">
<font>
<Font size="20.0" />
</font></Label>
<TextField fx:id="input" layoutX="316.0" layoutY="185.0" prefHeight="30.0" prefWidth="277.0" />
</children>
<fx:root id="haha" prefHeight="253.0" prefWidth="625.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.expressionDemo.Main2">
<children>
<Label fx:id="label" layoutX="33.0" layoutY="53.0" prefHeight="37.0" prefWidth="100.0" text="账号:">
<font>
<Font size="20.0" />
</font>
</Label>
<TextField fx:id="usr" layoutX="162.0" layoutY="57.0" prefHeight="30.0" prefWidth="277.0" />
<Button fx:id="resetBtn" layoutX="33.0" layoutY="187.0" mnemonicParsing="false" onAction="#reset" text="重置" />
<Label layoutX="33.0" layoutY="116.0" prefHeight="27.0" prefWidth="69.0" text="密码">
<font>
<Font size="20.0" />
</font>
</Label>
<Button fx:id="loginBtn" layoutX="370.0" layoutY="187.0" mnemonicParsing="false" onAction="#login" text="登录" />
<Label fx:id="usrMsg" layoutX="450.0" layoutY="62.0" prefHeight="19.0" prefWidth="157.0" />
<PasswordField fx:id="psw" layoutX="162.0" layoutY="128.0" prefHeight="30.0" prefWidth="277.0" />
<Label fx:id="pswMsg" layoutX="450.0" layoutY="133.0" prefHeight="20.0" prefWidth="157.0" />
</children>
</fx:root>

View File

@@ -4,7 +4,7 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.Pane?>
<fx:root prefHeight="709.0" prefWidth="995.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.Main2">
<fx:root prefHeight="709.0" prefWidth="995.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.expressionDemo.Main2">
<children>
<Button fx:id="btn" layoutX="793.0" layoutY="146.0" mnemonicParsing="false" text="Button" />
<MainController layoutX="85.0" layoutY="123.0" />

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.PasswordField?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<fx:root id="haha" prefHeight="253.0" prefWidth="625.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.springExpressionDemo.SpringExpressionDemoController">
<children>
<Label fx:id="label" layoutX="33.0" layoutY="53.0" prefHeight="37.0" prefWidth="100.0" text="账号:">
<font>
<Font size="20.0" />
</font>
</Label>
<TextField fx:id="usr" layoutX="162.0" layoutY="57.0" prefHeight="30.0" prefWidth="277.0" />
<Button fx:id="resetBtn" layoutX="33.0" layoutY="187.0" mnemonicParsing="false" onAction="#reset" text="重置" />
<Label layoutX="33.0" layoutY="116.0" prefHeight="27.0" prefWidth="69.0" text="密码">
<font>
<Font size="20.0" />
</font>
</Label>
<Button fx:id="loginBtn" layoutX="370.0" layoutY="187.0" mnemonicParsing="false" onAction="#login" text="登录" />
<Label fx:id="usrMsg" layoutX="450.0" layoutY="62.0" prefHeight="19.0" prefWidth="157.0" />
<PasswordField fx:id="psw" layoutX="162.0" layoutY="128.0" prefHeight="30.0" prefWidth="277.0" />
<Label fx:id="pswMsg" layoutX="450.0" layoutY="133.0" prefHeight="20.0" prefWidth="157.0" />
</children>
</fx:root>

View File

@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<fx:root id="haha" prefHeight="403.0" prefWidth="625.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.springDemo.SpringController">
<children>
<Label fx:id="label" layoutX="18.0" layoutY="166.0" prefHeight="68.0" prefWidth="304.0" text=""></Label>
<Button onAction="#add"></Button>
<Label fx:id="label" layoutX="18.0" layoutY="166.0" prefHeight="68.0" prefWidth="304.0" text="我是控制器属性" />
<Button layoutX="52.0" layoutY="98.0" onAction="#add" prefHeight="30.0" prefWidth="129.0" text="控制器1的按钮" />
</children>
</fx:root>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import cn.edu.scau.biubiusuisui.example.springDemo.SpringController?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<fx:root id="haha" prefHeight="629.0" prefWidth="934.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.springDemo2.SpringController2">
<children>
<SpringController layoutX="20.0" layoutY="129.0" fx:id="springController"/>
<Button layoutX="135.0" layoutY="552.0" mnemonicParsing="false" text="Button" onAction="#test"/>
<Label layoutX="14.0" layoutY="81.0" text="Controller属性" />
<Label layoutX="20.0" layoutY="557.0" text="本控制器属性" />
<Label layoutX="385.0" layoutY="25.0" text="两个控制器之间信号传递" />
</children>
</fx:root>

View File

@@ -0,0 +1,43 @@
package cn.edu.scau.biubiusuisui.expression;
import cn.edu.scau.biubiusuisui.annotation.FXEntity;
import cn.edu.scau.biubiusuisui.example.Student;
import cn.edu.scau.biubiusuisui.factory.FXEntityFactory;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
import javafx.scene.control.Label;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @Author jack
* @Date:2019/7/24 11:55
*/
public class ExpressionParserTest extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// test - ok
Label label = new Label("text");
ObservableMap<String, Object> namespace = FXCollections.observableHashMap();
Student student = new Student();
Student studentProxy = (Student) FXEntityFactory.createJavaBeanProxy(student);
studentProxy.setName("jack");
namespace.put("student", studentProxy);
ExpressionParser expressionParser = new ExpressionParser(namespace);
expressionParser.parse(label,"text=${student.name}");
System.out.println(label.textProperty());
studentProxy.setName("jack-modified");
System.out.println(label.textProperty());
System.out.println(label.textProperty().getValue());
}
public void testValueFactory(){
new PropertyValueFactory("password");
}
}

View File

@@ -2,11 +2,8 @@ package cn.edu.scau.biubiusuisui.factory;
import cn.edu.scau.biubiusuisui.entity.FXPlusContext;
import cn.edu.scau.biubiusuisui.example.Student;
import javafx.beans.property.Property;
import org.junit.Test;
import java.util.Map;
/**
* @Author jack
* @Date:2019/6/28 1:32
@@ -34,15 +31,14 @@ public class FXEntityFactoryTest {
@Test
public void createJavaBeanProxy() {
Student student = new Student();
student.setName("NAME");
}
@Test
public void createJavaBeanProxy2() throws InstantiationException, IllegalAccessException {
Student student1 = (Student) FXEntityFactory.createJavaBeanProxy(Student.class);
System.out.println(student1);
FXPlusContext.getProryByBeanObject(student1).getStringPropertyMap().forEach((k,v)->{
FXPlusContext.getProxyByBeanObject(student1).getStringPropertyMap().forEach((k, v)->{
System.out.println("k " +k +"v" + v);
});
student1.setName("Jack");