parent
d474eebfa2
commit
d93c8bf2b0
@ -1,5 +1,6 @@
|
||||
package eva2.gui;
|
||||
|
||||
import eva2.client.EvAClient;
|
||||
import eva2.server.go.populations.Population;
|
||||
import eva2.server.go.strategies.GeneticAlgorithm;
|
||||
import eva2.tools.Pair;
|
||||
@ -15,44 +16,46 @@ import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Some miscellaneous functions to help with Beans, reflection, conversion and generic display.
|
||||
* Some miscellaneous functions to help with Beans, reflection, conversion and
|
||||
* generic display.
|
||||
*
|
||||
* @author mkron, Holger Ulmer, Felix Streichert, Hannes Planatscher
|
||||
*
|
||||
*/
|
||||
public class BeanInspector {
|
||||
public static boolean TRACE = false;
|
||||
private static final Logger LOGGER = Logger.getLogger(BeanInspector.class.getName());
|
||||
|
||||
/**
|
||||
* Check for equality based on bean properties of two target objects.
|
||||
*/
|
||||
public static boolean equalProperties(Object obj_1, Object obj_2) {
|
||||
if (obj_1 == null || obj_2 == null) {
|
||||
public static boolean equalProperties(Object obj1, Object obj2) {
|
||||
if (obj1 == null || obj2 == null) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
System.out.println("equalProperties: " + obj_1.getClass().getName() + " " + obj_2.getClass().getName());
|
||||
if (obj_1.getClass().getName().equals(obj_2.getClass().getName()) == false) {
|
||||
System.out.println("equalProperties: " + obj1.getClass().getName() + " " + obj2.getClass().getName());
|
||||
if (obj1.getClass().getName().equals(obj2.getClass().getName()) == false) {
|
||||
System.out.println("");
|
||||
return false;
|
||||
}
|
||||
// compare each of the properties !!
|
||||
BeanInfo Info_1 = null;
|
||||
BeanInfo Info_2 = null;
|
||||
BeanInfo beanInfo1;
|
||||
BeanInfo beanInfo2;
|
||||
PropertyDescriptor[] Properties_1 = null;
|
||||
PropertyDescriptor[] Properties_2 = null;
|
||||
try {
|
||||
|
||||
Info_1 = Introspector.getBeanInfo(obj_1.getClass());
|
||||
Info_2 = Introspector.getBeanInfo(obj_2.getClass());
|
||||
Properties_1 = Info_1.getPropertyDescriptors();
|
||||
Properties_2 = Info_2.getPropertyDescriptors();
|
||||
Info_1.getMethodDescriptors();
|
||||
beanInfo1 = Introspector.getBeanInfo(obj1.getClass());
|
||||
beanInfo2 = Introspector.getBeanInfo(obj2.getClass());
|
||||
Properties_1 = beanInfo1.getPropertyDescriptors();
|
||||
Properties_2 = beanInfo2.getPropertyDescriptors();
|
||||
beanInfo1.getMethodDescriptors();
|
||||
} catch (IntrospectionException ex) {
|
||||
System.out.println("BeanTest: Couldn't introspect !!!!!!!!!");
|
||||
LOGGER.log(Level.FINEST, "Could not introspect object.", ex);
|
||||
return false;
|
||||
}
|
||||
boolean BeansInside = false;
|
||||
@ -76,8 +79,8 @@ public class BeanInspector {
|
||||
Object args_2[] = {};
|
||||
//System.out.println("m_Target"+m_Target.toString());
|
||||
try {
|
||||
Object value_1 = getter_1.invoke(obj_1, args_1);
|
||||
Object value_2 = getter_2.invoke(obj_2, args_2);
|
||||
Object value_1 = getter_1.invoke(obj1, args_1);
|
||||
Object value_2 = getter_2.invoke(obj2, args_2);
|
||||
BeansInside = true;
|
||||
if (BeanInspector.equalProperties(value_1, value_2) == false) {
|
||||
BeansEqual = false;
|
||||
@ -90,13 +93,13 @@ public class BeanInspector {
|
||||
return BeansEqual;
|
||||
}
|
||||
// here we have Integer or Double ...
|
||||
if (obj_1 instanceof Integer ||
|
||||
obj_1 instanceof Boolean ||
|
||||
obj_1 instanceof Float ||
|
||||
obj_1 instanceof Double ||
|
||||
obj_1 instanceof Long ||
|
||||
obj_1 instanceof String) {
|
||||
return obj_1.equals(obj_2);
|
||||
if (obj1 instanceof Integer
|
||||
|| obj1 instanceof Boolean
|
||||
|| obj1 instanceof Float
|
||||
|| obj1 instanceof Double
|
||||
|| obj1 instanceof Long
|
||||
|| obj1 instanceof String) {
|
||||
return obj1.equals(obj2);
|
||||
}
|
||||
|
||||
System.err.println(" Attention no match !!!");
|
||||
@ -115,7 +118,9 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a string with newlines and indentation (easier readable for if an object has many properties).
|
||||
* Produce a string with newlines and indentation (easier readable for if an
|
||||
* object has many properties).
|
||||
*
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
@ -124,10 +129,11 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the accessible properties of an object and their values in a string with indentations.
|
||||
* Special cases: Arrays and Lists are concatenations of their elements, Population is excepted from lists.
|
||||
* If the object has its own toString method, this one is preferred. Hidden or expert properties are not
|
||||
* shown.
|
||||
* Collect the accessible properties of an object and their values in a
|
||||
* string with indentations. Special cases: Arrays and Lists are
|
||||
* concatenations of their elements, Population is excepted from lists. If
|
||||
* the object has its own toString method, this one is preferred. Hidden or
|
||||
* expert properties are not shown.
|
||||
*
|
||||
* @param obj an arbitrary object
|
||||
* @return a String description of the object
|
||||
@ -137,10 +143,11 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the accessible properties of an object and their values in a string.
|
||||
* Special cases: Arrays and Lists are concatenations of their elements, Population is excepted from lists.
|
||||
* If the object has its own toString method, this one is preferred. Hidden or expert properties are not
|
||||
* shown.
|
||||
* Collect the accessible properties of an object and their values in a
|
||||
* string. Special cases: Arrays and Lists are concatenations of their
|
||||
* elements, Population is excepted from lists. If the object has its own
|
||||
* toString method, this one is preferred. Hidden or expert properties are
|
||||
* not shown.
|
||||
*
|
||||
* @param obj Description of the Parameter
|
||||
* @return Description of the Return Value
|
||||
@ -218,9 +225,6 @@ public class BeanInspector {
|
||||
//args[0] = obj;
|
||||
try {
|
||||
String ret = (String) methods[ii].invoke(obj, args);
|
||||
if (TRACE) {
|
||||
System.out.println("toString on "+ obj.getClass() + " gave me " + ret);
|
||||
}
|
||||
return makeIndent(indentStr, indentDepth) + ret;
|
||||
} catch (Exception e) {
|
||||
System.err.println(" ERROR +" + e.getMessage());
|
||||
@ -271,8 +275,7 @@ public class BeanInspector {
|
||||
if (indentStr != null) {
|
||||
if (indentDepth < 1) {
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
StringBuffer sbuf = new StringBuffer(indentStr);
|
||||
for (int i = 2; i <= indentDepth; i++) {
|
||||
sbuf.append(indentStr);
|
||||
@ -300,9 +303,10 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve names and values of instance fields which are accessible by getter method, optionally
|
||||
* by both getter and setter method. The returned arrays may contain null entries.
|
||||
* Properties marked as hidden or expert are skipped.
|
||||
* Retrieve names and values of instance fields which are accessible by
|
||||
* getter method, optionally by both getter and setter method. The returned
|
||||
* arrays may contain null entries. Properties marked as hidden or expert
|
||||
* are skipped.
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
@ -353,7 +357,6 @@ public class BeanInspector {
|
||||
return nameVals;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param obj Description of the Parameter
|
||||
*/
|
||||
@ -422,10 +425,10 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Call a method by a given name with given arguments, if the method is available.
|
||||
* Returns the return values of the call or null if it isnt found.
|
||||
* This of course means that the caller is unable to distinguish between "method not found"
|
||||
* and "method found and it returned null".
|
||||
* Call a method by a given name with given arguments, if the method is
|
||||
* available. Returns the return values of the call or null if it isnt
|
||||
* found. This of course means that the caller is unable to distinguish
|
||||
* between "method not found" and "method found and it returned null".
|
||||
*
|
||||
* @param obj
|
||||
* @param mName
|
||||
@ -450,8 +453,8 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce an array of Class instances matching the types of
|
||||
* the given object array.
|
||||
* Produce an array of Class instances matching the types of the given
|
||||
* object array.
|
||||
*
|
||||
* @param o
|
||||
* @return
|
||||
@ -468,9 +471,8 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an object has a method by the given name and with
|
||||
* matching signature considering the arguments. Return
|
||||
* it if found, or null if not.
|
||||
* Check whether an object has a method by the given name and with matching
|
||||
* signature considering the arguments. Return it if found, or null if not.
|
||||
*
|
||||
* @param obj
|
||||
* @param mName the method name
|
||||
@ -482,13 +484,13 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an object has a method by the given name and
|
||||
* with the given parameter signature. Return
|
||||
* it if found, or null if not.
|
||||
* Check whether an object has a method by the given name and with the given
|
||||
* parameter signature. Return it if found, or null if not.
|
||||
*
|
||||
* @param obj
|
||||
* @param mName the method name
|
||||
* @param paramTypes the parameter types, null allowed if no parameters are expected
|
||||
* @param paramTypes the parameter types, null allowed if no parameters are
|
||||
* expected
|
||||
* @return the method or null if it isn't found
|
||||
*/
|
||||
public static Method hasMethod(Object obj, String mName, Class[] paramTypes) {
|
||||
@ -502,7 +504,8 @@ public class BeanInspector {
|
||||
} // full match
|
||||
else {
|
||||
if (paramTypes != null && (methParamTypes.length == paramTypes.length)) {
|
||||
boolean mismatch = false; int i=0;
|
||||
boolean mismatch = false;
|
||||
int i = 0;
|
||||
while ((i < methParamTypes.length) && (!mismatch)) {
|
||||
if (!methParamTypes[i].isAssignableFrom(paramTypes[i]) && !isBoxableFrom(methParamTypes[i], paramTypes[i])) {
|
||||
mismatch = true;
|
||||
@ -520,7 +523,8 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given first class is a primitive type and can be boxed to match the second class.
|
||||
* Check if the given first class is a primitive type and can be boxed to
|
||||
* match the second class.
|
||||
*
|
||||
* @param clz1
|
||||
* @param clz2
|
||||
@ -536,8 +540,8 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* For a primitive type, return the boxed referenced type.
|
||||
* Return null for any non-primitive type.
|
||||
* For a primitive type, return the boxed referenced type. Return null for
|
||||
* any non-primitive type.
|
||||
*
|
||||
* @param clz1
|
||||
* @return
|
||||
@ -546,29 +550,21 @@ public class BeanInspector {
|
||||
if (cls.isPrimitive()) {
|
||||
if (cls == double.class) {
|
||||
return Double.class;
|
||||
}
|
||||
else if (cls == char.class) {
|
||||
} else if (cls == char.class) {
|
||||
return Character.class;
|
||||
}
|
||||
else if (cls == int.class) {
|
||||
} else if (cls == int.class) {
|
||||
return Integer.class;
|
||||
}
|
||||
else if (cls == boolean.class) {
|
||||
} else if (cls == boolean.class) {
|
||||
return Boolean.class;
|
||||
}
|
||||
else if (cls == byte.class) {
|
||||
} else if (cls == byte.class) {
|
||||
return Byte.class;
|
||||
}
|
||||
else if (cls == short.class) {
|
||||
} else if (cls == short.class) {
|
||||
return Short.class;
|
||||
}
|
||||
else if (cls == long.class) {
|
||||
} else if (cls == long.class) {
|
||||
return Long.class;
|
||||
}
|
||||
else if (cls == float.class) {
|
||||
} else if (cls == float.class) {
|
||||
return Float.class;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return Void.class;
|
||||
}
|
||||
} else {
|
||||
@ -577,44 +573,37 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* For a Java primitive wrapper class return the corresponding
|
||||
* primitive class.
|
||||
**/
|
||||
* For a Java primitive wrapper class return the corresponding primitive
|
||||
* class.
|
||||
*
|
||||
*/
|
||||
public static Class getUnboxedType(Class cls) {
|
||||
if (cls == Double.class) {
|
||||
return double.class;
|
||||
}
|
||||
else if (cls == Character.class) {
|
||||
} else if (cls == Character.class) {
|
||||
return char.class;
|
||||
}
|
||||
else if (cls == Integer.class) {
|
||||
} else if (cls == Integer.class) {
|
||||
return int.class;
|
||||
}
|
||||
else if (cls == Boolean.class) {
|
||||
} else if (cls == Boolean.class) {
|
||||
return boolean.class;
|
||||
}
|
||||
else if (cls == Byte.class) {
|
||||
} else if (cls == Byte.class) {
|
||||
return byte.class;
|
||||
}
|
||||
else if (cls == Short.class) {
|
||||
} else if (cls == Short.class) {
|
||||
return short.class;
|
||||
}
|
||||
else if (cls == Long.class) {
|
||||
} else if (cls == Long.class) {
|
||||
return long.class;
|
||||
}
|
||||
else if (cls == Float.class) {
|
||||
} else if (cls == Float.class) {
|
||||
return float.class;
|
||||
}
|
||||
else if (cls == Void.class) {
|
||||
} else if (cls == Void.class) {
|
||||
return void.class;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Just concatenates getClassDescription(obj) and getMemberDescriptions(obj, withValues).
|
||||
* Just concatenates getClassDescription(obj) and getMemberDescriptions(obj,
|
||||
* withValues).
|
||||
*
|
||||
* @param obj target object
|
||||
* @param withValues if true, member values are displayed as well
|
||||
@ -631,8 +620,8 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for info methods on the object to be provided by the developer
|
||||
* and return their text as String.
|
||||
* Check for info methods on the object to be provided by the developer and
|
||||
* return their text as String.
|
||||
*
|
||||
* @param obj
|
||||
* @return String information about the object's class
|
||||
@ -657,9 +646,10 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an info string on the members of the object class, containing name, type, optional
|
||||
* value and tool tip text if available. The type is accompanied by a tag "common" or "restricted",
|
||||
* indicating whether the member property is normal or hidden, meaning it may have effect depending
|
||||
* Return an info string on the members of the object class, containing
|
||||
* name, type, optional value and tool tip text if available. The type is
|
||||
* accompanied by a tag "common" or "restricted", indicating whether the
|
||||
* member property is normal or hidden, meaning it may have effect depending
|
||||
* on settings of other members only, for instance.
|
||||
*
|
||||
* @param obj target object
|
||||
@ -683,9 +673,6 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
String name = m_Properties[i].getDisplayName();
|
||||
if (TRACE) {
|
||||
System.out.println("PSP looking at "+ name);
|
||||
}
|
||||
|
||||
Method getter = m_Properties[i].getReadMethod();
|
||||
Method setter = m_Properties[i].getWriteMethod();
|
||||
@ -760,7 +747,8 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Take an object of primitive type (like int, Integer etc) and convert it to double.
|
||||
* Take an object of primitive type (like int, Integer etc) and convert it
|
||||
* to double.
|
||||
*
|
||||
* @param val
|
||||
* @return
|
||||
@ -769,36 +757,29 @@ public class BeanInspector {
|
||||
public static double toDouble(Object val) throws IllegalArgumentException {
|
||||
if (val instanceof Integer) {
|
||||
return ((Integer) val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Double) {
|
||||
} else if (val instanceof Double) {
|
||||
return ((Double) val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Boolean) {
|
||||
} else if (val instanceof Boolean) {
|
||||
return (((Boolean) val) ? 1. : 0.);
|
||||
}
|
||||
else if (val instanceof Character) {
|
||||
} else if (val instanceof Character) {
|
||||
return ((Character) val).charValue();
|
||||
}
|
||||
else if (val instanceof Byte) {
|
||||
} else if (val instanceof Byte) {
|
||||
return ((Byte) val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Short) {
|
||||
} else if (val instanceof Short) {
|
||||
return ((Short) val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Long) {
|
||||
} else if (val instanceof Long) {
|
||||
return ((Long) val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Float) {
|
||||
} else if (val instanceof Float) {
|
||||
return ((Float) val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Void) {
|
||||
} else if (val instanceof Void) {
|
||||
return 0;
|
||||
}
|
||||
throw new IllegalArgumentException("Illegal type, cant convert " + val.getClass() + " to double.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a String and convert it to a destined data type using the appropriate function.
|
||||
* Take a String and convert it to a destined data type using the
|
||||
* appropriate function.
|
||||
*
|
||||
* @param str
|
||||
* @param destType
|
||||
@ -807,29 +788,21 @@ public class BeanInspector {
|
||||
public static Object stringToPrimitive(String str, Class<?> destType) throws NumberFormatException {
|
||||
if ((destType == Integer.class) || (destType == int.class)) {
|
||||
return Integer.valueOf(str);
|
||||
}
|
||||
else if ((destType == Double.class) || (destType == double.class)) {
|
||||
} else if ((destType == Double.class) || (destType == double.class)) {
|
||||
return Double.valueOf(str);
|
||||
}
|
||||
else if ((destType == Boolean.class) || (destType == boolean.class)) {
|
||||
} else if ((destType == Boolean.class) || (destType == boolean.class)) {
|
||||
return Boolean.valueOf(str);
|
||||
}
|
||||
else if ((destType == Byte.class) || (destType == byte.class)) {
|
||||
} else if ((destType == Byte.class) || (destType == byte.class)) {
|
||||
return Byte.valueOf(str);
|
||||
}
|
||||
else if ((destType == Short.class) || (destType == short.class)) {
|
||||
} else if ((destType == Short.class) || (destType == short.class)) {
|
||||
return Short.valueOf(str);
|
||||
}
|
||||
else if ((destType == Long.class) || (destType == long.class)) {
|
||||
} else if ((destType == Long.class) || (destType == long.class)) {
|
||||
return Long.valueOf(str);
|
||||
}
|
||||
else if ((destType == Float.class) || (destType == float.class)) {
|
||||
} else if ((destType == Float.class) || (destType == float.class)) {
|
||||
return Float.valueOf(str);
|
||||
}
|
||||
else if ((destType == Character.class) || (destType == char.class)) {
|
||||
} else if ((destType == Character.class) || (destType == char.class)) {
|
||||
return str.charAt(0);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// if (destType == Void.class)
|
||||
System.err.println("warning, value interpreted as void type");
|
||||
return 0;
|
||||
@ -849,28 +822,21 @@ public class BeanInspector {
|
||||
}
|
||||
if ((destType == Integer.class) || (destType == int.class)) {
|
||||
return new Integer(d.intValue());
|
||||
}
|
||||
else if ((destType == Boolean.class) || (destType == boolean.class)) {
|
||||
} else if ((destType == Boolean.class) || (destType == boolean.class)) {
|
||||
return (d != 0) ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
else if ((destType == Byte.class) || (destType == byte.class)) {
|
||||
} else if ((destType == Byte.class) || (destType == byte.class)) {
|
||||
return new Byte(d.byteValue());
|
||||
}
|
||||
else if ((destType == Short.class) || (destType == short.class)) {
|
||||
} else if ((destType == Short.class) || (destType == short.class)) {
|
||||
return new Short(d.shortValue());
|
||||
}
|
||||
else if ((destType == Long.class) || (destType == long.class)) {
|
||||
} else if ((destType == Long.class) || (destType == long.class)) {
|
||||
return new Long(d.longValue());
|
||||
}
|
||||
else if ((destType == Float.class) || (destType == float.class)) {
|
||||
} else if ((destType == Float.class) || (destType == float.class)) {
|
||||
return new Float(d.floatValue());
|
||||
}
|
||||
else { // this makes hardly sense...
|
||||
} else { // this makes hardly sense...
|
||||
System.err.println("warning: converting from double to character or void...");
|
||||
if ((destType == Character.class) || (destType == char.class)) {
|
||||
return new Character(d.toString().charAt(0));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -895,8 +861,9 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primitive class of a Java primitive encapsulation, or null if not applicable.
|
||||
* E.g., returns int for Integer, long for Long, Boolean for Boolean etc.
|
||||
* Get the primitive class of a Java primitive encapsulation, or null if not
|
||||
* applicable. E.g., returns int for Integer, long for Long, Boolean for
|
||||
* Boolean etc.
|
||||
*
|
||||
* @param cls
|
||||
* @return
|
||||
@ -907,30 +874,25 @@ public class BeanInspector {
|
||||
}
|
||||
if (cls == Double.class) {
|
||||
return double.class;
|
||||
}
|
||||
else if (cls == Integer.class) {
|
||||
} else if (cls == Integer.class) {
|
||||
return int.class;
|
||||
}
|
||||
else if (cls == Boolean.class) {
|
||||
} else if (cls == Boolean.class) {
|
||||
return Boolean.class;
|
||||
}
|
||||
else if (cls == Byte.class) {
|
||||
} else if (cls == Byte.class) {
|
||||
return byte.class;
|
||||
}
|
||||
else if (cls == Short.class) {
|
||||
} else if (cls == Short.class) {
|
||||
return short.class;
|
||||
}
|
||||
else if (cls == Long.class) {
|
||||
} else if (cls == Long.class) {
|
||||
return long.class;
|
||||
}
|
||||
else if (cls == Float.class) {
|
||||
} else if (cls == Float.class) {
|
||||
return float.class;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to convert an object to a destination type, especially for primitive types (int, double etc.
|
||||
* but also Integer, Double etc.).
|
||||
* Try to convert an object to a destination type, especially for primitive
|
||||
* types (int, double etc. but also Integer, Double etc.).
|
||||
*
|
||||
* @param destType
|
||||
* @param value
|
||||
@ -945,8 +907,7 @@ public class BeanInspector {
|
||||
if (destType == String.class || destType == SelectedTag.class) {
|
||||
if (value.getClass() == String.class) {
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return value.toString();
|
||||
}
|
||||
} else if (isJavaPrimitive(destType)) {
|
||||
@ -965,10 +926,9 @@ public class BeanInspector {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to get an object member value using the default getter.
|
||||
* Returns null if not successful.
|
||||
* Try to get an object member value using the default getter. Returns null
|
||||
* if not successful.
|
||||
*
|
||||
* @param obj
|
||||
* @param mem
|
||||
@ -1004,9 +964,9 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to set an object member to a given value.
|
||||
* Returns true if successful, else false. The types are adapted as generally as possible,
|
||||
* converting using the decodeType() method.
|
||||
* Try to set an object member to a given value. Returns true if successful,
|
||||
* else false. The types are adapted as generally as possible, converting
|
||||
* using the decodeType() method.
|
||||
*
|
||||
* @param obj
|
||||
* @param mem
|
||||
@ -1048,7 +1008,6 @@ public class BeanInspector {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Exception in invoking setter: " + e.getMessage());
|
||||
// e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@ -1057,11 +1016,13 @@ public class BeanInspector {
|
||||
}
|
||||
}
|
||||
|
||||
/** This method simply looks for an appropriate tiptext
|
||||
/**
|
||||
* This method simply looks for an appropriate tiptext
|
||||
*
|
||||
* @param name The name of the property
|
||||
* @param methods A list of methods to search.
|
||||
* @param target The target object
|
||||
* @return String for the tooltip.
|
||||
* @return String for the ToolTip.
|
||||
*/
|
||||
public static String getToolTipText(String name, MethodDescriptor[] methods, Object target, boolean stripToolTipToFirstPoint, int toHTMLLen) {
|
||||
String result = "";
|
||||
@ -1100,7 +1061,7 @@ public class BeanInspector {
|
||||
* @param name The name of the property
|
||||
* @param methods A list of methods to search.
|
||||
* @param target The target object
|
||||
* @return String for the tooltip.
|
||||
* @return String for the ToolTip.
|
||||
*/
|
||||
public static String getToolTipText(String name, MethodDescriptor[] methods, Object target) {
|
||||
return getToolTipText(name, methods, target, false, 0);
|
||||
|
@ -29,7 +29,6 @@ public class GOEPanel extends JPanel implements ItemListener {
|
||||
|
||||
private Object backupObject;
|
||||
private PropertyChangeSupport propChangeSupport;
|
||||
private static boolean TRACE = false;
|
||||
/**
|
||||
* The chooser component
|
||||
*/
|
||||
|
@ -264,7 +264,6 @@ public class GenericObjectEditor implements PropertyEditor {
|
||||
* @param type a value of type 'Class'
|
||||
*/
|
||||
public void setClassType(Class<?> type) {
|
||||
//if (TRACE) System.out.println("GOE setClassType("+ (type == null? "<null>" : type.getName()) + ")");
|
||||
classType = type;
|
||||
if (editorComponent != null) {
|
||||
editorComponent.updateClassType();
|
||||
@ -337,7 +336,6 @@ public class GenericObjectEditor implements PropertyEditor {
|
||||
*/
|
||||
private void setObject(Object c) {
|
||||
// This should really call equals() for comparison.
|
||||
//if (TRACE) System.out.println("setObject "+ c.getClass().getName() + " " + c);
|
||||
boolean trueChange = (c != getValue());
|
||||
|
||||
m_Backup = m_Object;
|
||||
|
@ -6,13 +6,14 @@ package eva2.gui;
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* It represents one plot window in the client GUI.
|
||||
*/
|
||||
public class GraphWindow {
|
||||
|
||||
public static boolean TRACE = false;
|
||||
private static final Logger LOGGER = Logger.getLogger(GraphWindow.class.getName());
|
||||
static private int graphCounter = -1;
|
||||
static private PlotContainer plotContainer;
|
||||
private PlotInterface plotter;
|
||||
@ -57,9 +58,6 @@ public class GraphWindow {
|
||||
*
|
||||
*/
|
||||
private GraphWindow(String plotName, String strx, String stry) {
|
||||
if (TRACE) {
|
||||
System.out.println("Constructor GraphWindow");
|
||||
}
|
||||
name = plotName;
|
||||
plotter = new Plot(plotName, strx, stry, true);
|
||||
}
|
||||
@ -76,9 +74,7 @@ public class GraphWindow {
|
||||
*/
|
||||
public Graph getNewGraph(String infoString) {
|
||||
graphCounter++;
|
||||
if (TRACE) {
|
||||
System.out.println("Graph.getNewGraph No:" + graphCounter + " - " + infoString);
|
||||
}
|
||||
LOGGER.log(Level.FINEST, "Graph.getNewGraph No:{0} - {1} created.", new Object[]{graphCounter, infoString});
|
||||
return new Graph(infoString, plotter, graphCounter);
|
||||
}
|
||||
}
|
||||
@ -104,7 +100,7 @@ class PlotContainer extends ArrayList<GraphWindow> {
|
||||
*
|
||||
*/
|
||||
public boolean containsName(String name) {
|
||||
GraphWindow temp = null;
|
||||
GraphWindow temp;
|
||||
for (int i = 0; i < size(); i++) {
|
||||
temp = (GraphWindow) (get(i));
|
||||
if (name.equals(temp.getName())) {
|
||||
@ -130,7 +126,7 @@ class PlotContainer extends ArrayList<GraphWindow> {
|
||||
return actualPlot;
|
||||
}
|
||||
}
|
||||
GraphWindow temp = null;
|
||||
GraphWindow temp;
|
||||
for (int i = 0; i < size(); i++) {
|
||||
temp = (GraphWindow) (get(i));
|
||||
if (name.equals(temp.getName())) {
|
||||
|
@ -9,20 +9,21 @@ package eva2.gui;
|
||||
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
|
||||
* $Author: streiche $
|
||||
*/
|
||||
/*==========================================================================*
|
||||
* IMPORTS
|
||||
*==========================================================================*/
|
||||
|
||||
import java.beans.*;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class JExtMenu extends JMenu {
|
||||
|
||||
public final static String ACTION = "Action";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -32,6 +33,7 @@ public class JExtMenu extends JMenu{
|
||||
//setText(m.getText());
|
||||
//setMnemonic(m.getMnemonic());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -41,6 +43,7 @@ public class JExtMenu extends JMenu{
|
||||
setText(m.getText());
|
||||
setMnemonic(m.getMnemonic());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -62,6 +65,7 @@ public class JExtMenu extends JMenu{
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -77,23 +81,18 @@ public class JExtMenu extends JMenu{
|
||||
String propertyName = e.getPropertyName();
|
||||
if (propertyName.equals(Action.NAME)) {
|
||||
menuItem.setText((String) e.getNewValue());
|
||||
}
|
||||
else if(propertyName.equals("enabled")) {
|
||||
} else if (propertyName.equals("enabled")) {
|
||||
menuItem.setEnabled(((Boolean) e.getNewValue()).booleanValue());
|
||||
}
|
||||
else if(propertyName.equals(Action.SMALL_ICON)){
|
||||
} else if (propertyName.equals(Action.SMALL_ICON)) {
|
||||
Icon icon = (Icon) e.getNewValue();
|
||||
menuItem.setIcon(icon);
|
||||
menuItem.invalidate();
|
||||
menuItem.repaint();
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.MNEMONIC)) {
|
||||
} else if (propertyName.equals(ExtAction.MNEMONIC)) {
|
||||
menuItem.setMnemonic(((Character) e.getNewValue()).charValue());
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.TOOLTIP)) {
|
||||
} else if (propertyName.equals(ExtAction.TOOLTIP)) {
|
||||
menuItem.setToolTipText((String) e.getNewValue());
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.KEYSTROKE)) {
|
||||
} else if (propertyName.equals(ExtAction.KEYSTROKE)) {
|
||||
menuItem.setAccelerator((KeyStroke) e.getNewValue());
|
||||
}
|
||||
}
|
||||
|
@ -92,19 +92,6 @@ public class ModuleServer {
|
||||
}
|
||||
|
||||
}
|
||||
// and the running modules
|
||||
// @todo running modules sind abgeschaltet
|
||||
|
||||
// for (int i = 0; i < m_RunnungModules.size(); i++) {
|
||||
// String AdapterName = null;
|
||||
// try {
|
||||
// AdapterName = ( (ModuleAdapter) m_RunnungModules.get(i)).getAdapterName();
|
||||
// }
|
||||
// catch (Exception ee) {
|
||||
// System.err.println("Error: GetAdapterName" + ee.getMessage());
|
||||
// }
|
||||
// ModuleNameList.add(AdapterName);
|
||||
// }
|
||||
|
||||
String[] x = new String[moduleNameList.size()];
|
||||
moduleNameList.toArray(x);
|
||||
@ -176,21 +163,6 @@ public class ModuleServer {
|
||||
return (ModuleAdapter) moduleAdapter;
|
||||
}
|
||||
}
|
||||
// // @todo running modules sind gerade noch abgeschaltet
|
||||
// for (int i = 0; i < m_RunnungModules.size(); i++) {
|
||||
// try {
|
||||
// adapterName = ( (ModuleAdapter) m_RunnungModules.get(i)).getAdapterName();
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// System.out.println("Error : GetAdapterName" + e);
|
||||
// }
|
||||
// if (adapterName.equals(selectedModuleName)) {
|
||||
// if (TRACE)
|
||||
// System.out.println(" Choose a running Module!!! " + adapterName);
|
||||
// m_ModuleAdapter = ( (ModuleAdapter) m_RunnungModules.get(i));
|
||||
// return (ModuleAdapter) m_ModuleAdapter;
|
||||
// }
|
||||
// }
|
||||
|
||||
LOGGER.log(Level.SEVERE, "No valid module defined: {0}", selectedModuleName);
|
||||
return null;
|
||||
|
@ -6,12 +6,14 @@ import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* This class defines utility routines that use Java serialization. Any
|
||||
* serializable object can be stored to a file, loaded, and cloned (returning
|
||||
* a deep copy).
|
||||
* serializable object can be stored to a file, loaded, and cloned (returning a
|
||||
* deep copy).
|
||||
*
|
||||
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher, Marcel Kronfeld
|
||||
**/
|
||||
*
|
||||
*/
|
||||
public class Serializer {
|
||||
|
||||
/**
|
||||
* The logging instance for this class.
|
||||
*/
|
||||
@ -20,19 +22,22 @@ public class Serializer {
|
||||
/**
|
||||
* Private constructor to prevent instantiating module class.
|
||||
*/
|
||||
private Serializer() { }
|
||||
private Serializer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the object o (and any Serializable objects it refers to) and
|
||||
* store its serialized state in File f. If serializeInMem is true, the object
|
||||
* is wrapped in a SerializedObject first, which seems to be more efficient than
|
||||
* writing a nested object directly to a file.
|
||||
* store its serialized state in File f. If serializeInMem is true, the
|
||||
* object is wrapped in a SerializedObject first, which seems to be more
|
||||
* efficient than writing a nested object directly to a file.
|
||||
*
|
||||
* @param o the object to write
|
||||
* @param outStream The stream to write to
|
||||
* @param serializeInMem flag whether to wrap the object in a SerializedObject
|
||||
* @param serializeInMem flag whether to wrap the object in a
|
||||
* SerializedObject
|
||||
* @throws IOException
|
||||
**/
|
||||
*
|
||||
*/
|
||||
private static void store(Serializable o, OutputStream outStream, boolean serializeInMem) throws IOException {
|
||||
ObjectOutputStream out = new ObjectOutputStream(outStream);
|
||||
try {
|
||||
@ -49,14 +54,15 @@ public class Serializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the contents of File f and return the resulting object.
|
||||
* A SerializedObject is unwrapped once.
|
||||
* Deserialize the contents of File f and return the resulting object. A
|
||||
* SerializedObject is unwrapped once.
|
||||
*
|
||||
* @param inputStream The Input stream to read from
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
* @return The deserialized Object from the file
|
||||
**/
|
||||
*
|
||||
*/
|
||||
private static Object load(final InputStream inputStream) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream objInputStream = new ObjectInputStream(inputStream);
|
||||
Object ret = objInputStream.readObject();
|
||||
@ -68,13 +74,14 @@ public class Serializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use object serialization to make a "deep clone" of the object o.
|
||||
* This method serializes o and all of its member objects, and then
|
||||
* deserializes that graph of objects, which means that everything is
|
||||
* copied. This differs from the clone() method of an object which is
|
||||
* usually implemented to produce a "shallow" clone that copies references
|
||||
* to other objects, instead of copying all referenced objects.
|
||||
**/
|
||||
* Use object serialization to make a "deep clone" of the object o. This
|
||||
* method serializes o and all of its member objects, and then deserializes
|
||||
* that graph of objects, which means that everything is copied. This
|
||||
* differs from the clone() method of an object which is usually implemented
|
||||
* to produce a "shallow" clone that copies references to other objects,
|
||||
* instead of copying all referenced objects.
|
||||
*
|
||||
*/
|
||||
public static Object deepClone(Object o) {
|
||||
Object obj = null;
|
||||
try {
|
||||
@ -103,7 +110,8 @@ public class Serializer {
|
||||
*
|
||||
* @param outStream The output stream
|
||||
* @param data The string data
|
||||
**/
|
||||
*
|
||||
*/
|
||||
public static void storeString(final OutputStream outStream, final String data) {
|
||||
try {
|
||||
outStream.write(data.getBytes());
|
||||
@ -113,12 +121,13 @@ public class Serializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the contents of the InputStream containing
|
||||
* a string and return the resulting string.
|
||||
* Deserialize the contents of the InputStream containing a string and
|
||||
* return the resulting string.
|
||||
*
|
||||
* @param inputStream The input stream to read from
|
||||
* @return The deserialized data from the stream
|
||||
**/
|
||||
*
|
||||
*/
|
||||
public static String loadString(final InputStream inputStream) {
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
try {
|
||||
@ -134,9 +143,9 @@ public class Serializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the string s and
|
||||
* store its serialized state in File with name Filename.
|
||||
**/
|
||||
* Serialize the string s and store its serialized state in File with name
|
||||
* Filename.
|
||||
*/
|
||||
public static void storeObject(OutputStream outStream, Serializable s) {
|
||||
try {
|
||||
store(s, outStream, true);
|
||||
@ -146,21 +155,23 @@ public class Serializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the contents of File with given name containing
|
||||
* a string and return the resulting string. If the indicated file
|
||||
* doesnt exist or an error occurs, null is returned.
|
||||
**/
|
||||
* Deserialize the contents of File with given name containing a string and
|
||||
* return the resulting string. If the indicated file doesn't exist or an
|
||||
* error occurs, null is returned.
|
||||
*
|
||||
*/
|
||||
public static Object loadObject(InputStream inputStream) {
|
||||
return loadObject(inputStream, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the contents of File with given name containing
|
||||
* a string and return the resulting string. If the indicated file
|
||||
* doesnt exist or an error occurs, null is returned.
|
||||
* If casually is false, an error message is printed and an exception
|
||||
* is raised if the file was not found or an error occured on loading.
|
||||
**/
|
||||
* Deserialize the contents of File with given name containing a string and
|
||||
* return the resulting string. If the indicated file doesn't exist or an
|
||||
* error occurs, null is returned. If casually is false, an error message is
|
||||
* printed and an exception is raised if the file was not found or an error
|
||||
* occured on loading.
|
||||
*
|
||||
*/
|
||||
public static Object loadObject(InputStream inputStream, boolean casually) {
|
||||
Object serializedObject = null;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user