@@ -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
|
||||
@@ -151,7 +158,7 @@ public class BeanInspector {
|
||||
}
|
||||
// try the object itself
|
||||
if (obj instanceof String) {
|
||||
return (String)obj;
|
||||
return (String) obj;
|
||||
} // directly return a string object
|
||||
Class<? extends Object> type = obj.getClass();
|
||||
|
||||
@@ -162,13 +169,13 @@ public class BeanInspector {
|
||||
sbuf.append(" ");
|
||||
}
|
||||
int len = Array.getLength(obj);
|
||||
for (int i=0; i<len; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
// sbuf.append(toString(Array.get(obj, i)));
|
||||
if (withNewlines) {
|
||||
sbuf.append('\n');
|
||||
}
|
||||
sbuf.append(toString(Array.get(obj, i), delim, tight, indentStr, indentDepth, withNewlines));
|
||||
if (i<len-1) {
|
||||
if (i < len - 1) {
|
||||
// sbuf.append(delim);
|
||||
if (!tight) {
|
||||
sbuf.append(" ");
|
||||
@@ -196,7 +203,7 @@ public class BeanInspector {
|
||||
if (!tight) {
|
||||
sbuf.append(" ");
|
||||
}
|
||||
List<?> lst = (List<?>)obj;
|
||||
List<?> lst = (List<?>) obj;
|
||||
for (Object o : lst) {
|
||||
sbuf.append(o.toString());
|
||||
sbuf.append(delim);
|
||||
@@ -204,10 +211,10 @@ public class BeanInspector {
|
||||
sbuf.append(" ");
|
||||
}
|
||||
}
|
||||
if (!tight && (sbuf.charAt(sbuf.length()-2) == delim)) {
|
||||
sbuf.setCharAt(sbuf.length()-2, ' ');
|
||||
if (!tight && (sbuf.charAt(sbuf.length() - 2) == delim)) {
|
||||
sbuf.setCharAt(sbuf.length() - 2, ' ');
|
||||
} // delete the delim
|
||||
sbuf.setCharAt(sbuf.length()-1, ']');
|
||||
sbuf.setCharAt(sbuf.length() - 1, ']');
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
@@ -218,19 +225,16 @@ 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());
|
||||
System.err.println(" ERROR +" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise try introspection and collect all public properties as strings
|
||||
|
||||
Pair<String[],Object[]> nameVals = getPublicPropertiesOf(obj, true, true);
|
||||
Pair<String[], Object[]> nameVals = getPublicPropertiesOf(obj, true, true);
|
||||
|
||||
StringBuffer sbuf = new StringBuffer();
|
||||
if (withNewlines) {
|
||||
@@ -239,15 +243,15 @@ public class BeanInspector {
|
||||
addIndent(sbuf, indentStr, indentDepth);
|
||||
sbuf.append(type.getName());
|
||||
sbuf.append("{");
|
||||
for (int i=0; i<nameVals.head.length; i++) {
|
||||
if (nameVals.head[i]!=null) {
|
||||
for (int i = 0; i < nameVals.head.length; i++) {
|
||||
if (nameVals.head[i] != null) {
|
||||
if (withNewlines) {
|
||||
sbuf.append('\n');
|
||||
}
|
||||
addIndent(sbuf, indentStr, indentDepth);
|
||||
sbuf.append(nameVals.head[i]);
|
||||
sbuf.append("=");
|
||||
sbuf.append(toString(nameVals.tail[i], delim, tight, indentStr, indentDepth+1, withNewlines));
|
||||
sbuf.append(toString(nameVals.tail[i], delim, tight, indentStr, indentDepth + 1, withNewlines));
|
||||
sbuf.append(delim);
|
||||
if (!tight) {
|
||||
sbuf.append(" ");
|
||||
@@ -260,21 +264,20 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
private static void addIndent(StringBuffer sbuf, String indentStr, int indentDepth) {
|
||||
if (indentStr!=null && (indentDepth>0)) {
|
||||
for (int i=0; i<indentDepth; i++) {
|
||||
if (indentStr != null && (indentDepth > 0)) {
|
||||
for (int i = 0; i < indentDepth; i++) {
|
||||
sbuf.append(indentStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String makeIndent(String indentStr, int indentDepth) {
|
||||
if (indentStr!=null) {
|
||||
if (indentDepth<1) {
|
||||
if (indentStr != null) {
|
||||
if (indentDepth < 1) {
|
||||
return "";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
StringBuffer sbuf = new StringBuffer(indentStr);
|
||||
for (int i=2; i<=indentDepth; i++) {
|
||||
for (int i = 2; i <= indentDepth; i++) {
|
||||
sbuf.append(indentStr);
|
||||
}
|
||||
return sbuf.toString();
|
||||
@@ -300,14 +303,15 @@ 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
|
||||
*/
|
||||
public static Pair<String[],Object[]> getPublicPropertiesOf(Object target, boolean requireSetter, boolean showHidden) {
|
||||
public static Pair<String[], Object[]> getPublicPropertiesOf(Object target, boolean requireSetter, boolean showHidden) {
|
||||
BeanInfo Info = null;
|
||||
PropertyDescriptor[] Properties = null;
|
||||
// MethodDescriptor[] Methods = null;
|
||||
@@ -343,19 +347,18 @@ public class BeanInspector {
|
||||
//System.out.println("m_obj"+m_obj.toString());
|
||||
|
||||
try {
|
||||
nameArray[i]=name;
|
||||
nameArray[i] = name;
|
||||
valArray[i] = getter.invoke(target, args);
|
||||
} catch (Exception e) {
|
||||
System.err.println("BeanTest ERROR +"+ e.getMessage());
|
||||
System.err.println("BeanTest ERROR +" + e.getMessage());
|
||||
}
|
||||
}
|
||||
Pair<String[],Object[]> nameVals = new Pair<String[],Object[]>(nameArray, valArray);
|
||||
Pair<String[], Object[]> nameVals = new Pair<String[], Object[]>(nameArray, valArray);
|
||||
return nameVals;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*@param obj Description of the Parameter
|
||||
* @param obj Description of the Parameter
|
||||
*/
|
||||
public static void showInfo(Object obj) {
|
||||
System.out.println("Inspecting " + obj.getClass().getName());
|
||||
@@ -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
|
||||
@@ -437,8 +440,8 @@ public class BeanInspector {
|
||||
if (meth != null) {
|
||||
try {
|
||||
return meth.invoke(obj, args);
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error on calling method "+mName + " on " + obj.getClass().getName());
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error on calling method " + mName + " on " + obj.getClass().getName());
|
||||
System.err.println("Object: " + obj.toString() + ", method name: " + mName);
|
||||
System.err.println("Arguments were " + BeanInspector.toString(args));
|
||||
e.printStackTrace();
|
||||
@@ -450,27 +453,26 @@ 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
|
||||
*/
|
||||
public static Class[] toClassArray(Object[] o) {
|
||||
if (o==null) {
|
||||
if (o == null) {
|
||||
return null;
|
||||
}
|
||||
Class[] clz = new Class[o.length];
|
||||
for (int i=0; i<o.length; i++) {
|
||||
clz[i]=o[i].getClass();
|
||||
for (int i = 0; i < o.length; i++) {
|
||||
clz[i] = o[i].getClass();
|
||||
}
|
||||
return clz;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@@ -497,15 +499,16 @@ public class BeanInspector {
|
||||
for (Method method : meths) {
|
||||
if (method.getName().equals(mName)) { // name match
|
||||
Class[] methParamTypes = method.getParameterTypes();
|
||||
if (paramTypes==null && methParamTypes.length==0) {
|
||||
if (paramTypes == null && methParamTypes.length == 0) {
|
||||
return method;
|
||||
} // full match
|
||||
else {
|
||||
if (paramTypes!=null && (methParamTypes.length==paramTypes.length)) {
|
||||
boolean mismatch = false; int i=0;
|
||||
while ((i<methParamTypes.length) && (!mismatch)) {
|
||||
if (paramTypes != null && (methParamTypes.length == paramTypes.length)) {
|
||||
boolean mismatch = false;
|
||||
int i = 0;
|
||||
while ((i < methParamTypes.length) && (!mismatch)) {
|
||||
if (!methParamTypes[i].isAssignableFrom(paramTypes[i]) && !isBoxableFrom(methParamTypes[i], paramTypes[i])) {
|
||||
mismatch=true;
|
||||
mismatch = true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -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
|
||||
@@ -528,7 +532,7 @@ public class BeanInspector {
|
||||
*/
|
||||
private static boolean isBoxableFrom(Class clz1, Class clz2) {
|
||||
Class box = getBoxedType(clz1);
|
||||
if (box!=null && (clz2.isAssignableFrom(box))) {
|
||||
if (box != null && (clz2.isAssignableFrom(box))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -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
|
||||
@@ -642,14 +631,14 @@ public class BeanInspector {
|
||||
infoBf.append(obj.getClass().getName());
|
||||
infoBf.append("\t");
|
||||
|
||||
Object args[] = { };
|
||||
Object args[] = {};
|
||||
Object ret;
|
||||
|
||||
for (String meth : new String[]{"getName", "globalInfo"}) {
|
||||
ret = callIfAvailable(obj, meth, args);
|
||||
if (ret != null) {
|
||||
infoBf.append("\t");
|
||||
infoBf.append((String)ret);
|
||||
infoBf.append((String) ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -670,7 +660,7 @@ public class BeanInspector {
|
||||
BeanInfo bi;
|
||||
try {
|
||||
bi = Introspector.getBeanInfo(obj.getClass());
|
||||
} catch(IntrospectionException e) {
|
||||
} catch (IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -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();
|
||||
@@ -695,7 +682,7 @@ public class BeanInspector {
|
||||
}
|
||||
|
||||
try {
|
||||
Object args[] = { };
|
||||
Object args[] = {};
|
||||
Object value = getter.invoke(obj, args);
|
||||
|
||||
// Don't try to set null values:
|
||||
@@ -703,7 +690,7 @@ public class BeanInspector {
|
||||
// If it's a user-defined property we give a warning.
|
||||
String getterClass = m_Properties[i].getReadMethod().getDeclaringClass().getName();
|
||||
if (getterClass.indexOf("java.") != 0) {
|
||||
System.err.println("Warning: Property \"" + name+ "\" has null initial value. Skipping.");
|
||||
System.err.println("Warning: Property \"" + name + "\" has null initial value. Skipping.");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -721,11 +708,11 @@ public class BeanInspector {
|
||||
}
|
||||
String typeName = value.getClass().getName();
|
||||
if (value instanceof SelectedTag) {
|
||||
Tag[] tags = ((SelectedTag)value).getTags();
|
||||
Tag[] tags = ((SelectedTag) value).getTags();
|
||||
memberInfoBf.append("String in {");
|
||||
for (int k=0; k<tags.length; k++) {
|
||||
for (int k = 0; k < tags.length; k++) {
|
||||
memberInfoBf.append(tags[k].getString());
|
||||
if (k+1<tags.length) {
|
||||
if (k + 1 < tags.length) {
|
||||
memberInfoBf.append(", ");
|
||||
}
|
||||
}
|
||||
@@ -752,7 +739,7 @@ public class BeanInspector {
|
||||
memberInfoBf.append('\n');
|
||||
memberInfoList.add(memberInfoBf.toString());
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Skipping property "+name+" ; exception: " + ex.getMessage());
|
||||
System.err.println("Skipping property " + name + " ; exception: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
} // end try
|
||||
} // end for
|
||||
@@ -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
|
||||
@@ -768,37 +756,30 @@ public class BeanInspector {
|
||||
*/
|
||||
public static double toDouble(Object val) throws IllegalArgumentException {
|
||||
if (val instanceof Integer) {
|
||||
return ((Integer)val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Double) {
|
||||
return ((Double)val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Boolean) {
|
||||
return (((Boolean)val) ? 1. : 0.);
|
||||
}
|
||||
else if (val instanceof Character) {
|
||||
return ((Character)val).charValue();
|
||||
}
|
||||
else if (val instanceof Byte) {
|
||||
return ((Byte)val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Short) {
|
||||
return ((Short)val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Long) {
|
||||
return ((Long)val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Float) {
|
||||
return ((Float)val).doubleValue();
|
||||
}
|
||||
else if (val instanceof Void) {
|
||||
return ((Integer) val).doubleValue();
|
||||
} else if (val instanceof Double) {
|
||||
return ((Double) val).doubleValue();
|
||||
} else if (val instanceof Boolean) {
|
||||
return (((Boolean) val) ? 1. : 0.);
|
||||
} else if (val instanceof Character) {
|
||||
return ((Character) val).charValue();
|
||||
} else if (val instanceof Byte) {
|
||||
return ((Byte) val).doubleValue();
|
||||
} else if (val instanceof Short) {
|
||||
return ((Short) val).doubleValue();
|
||||
} else if (val instanceof Long) {
|
||||
return ((Long) val).doubleValue();
|
||||
} else if (val instanceof Float) {
|
||||
return ((Float) val).doubleValue();
|
||||
} 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)) {
|
||||
return (d!=0) ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
else if ((destType == Byte.class) || (destType == byte.class)) {
|
||||
} else if ((destType == Boolean.class) || (destType == boolean.class)) {
|
||||
return (d != 0) ? Boolean.TRUE : Boolean.FALSE;
|
||||
} 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,18 +907,17 @@ 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)) {
|
||||
try {
|
||||
if (value.getClass() == String.class) {
|
||||
return stringToPrimitive((String)value, destType);
|
||||
return stringToPrimitive((String) value, destType);
|
||||
} else {
|
||||
return doubleToPrimitive(toDouble(value), destType);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error in converting type of " + value + " to " + destType.getName() + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
@@ -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
|
||||
@@ -978,7 +938,7 @@ public class BeanInspector {
|
||||
BeanInfo bi;
|
||||
try {
|
||||
bi = Introspector.getBeanInfo(obj.getClass());
|
||||
} catch(IntrospectionException e) {
|
||||
} catch (IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -994,7 +954,7 @@ public class BeanInspector {
|
||||
try {
|
||||
return getter.invoke(obj, (Object[]) null);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Exception in invoking setter: "+e.getMessage());
|
||||
System.err.println("Exception in invoking setter: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
@@ -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
|
||||
@@ -1017,7 +977,7 @@ public class BeanInspector {
|
||||
BeanInfo bi;
|
||||
try {
|
||||
bi = Introspector.getBeanInfo(obj.getClass());
|
||||
} catch(IntrospectionException e) {
|
||||
} catch (IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -1038,7 +998,7 @@ public class BeanInspector {
|
||||
if (setter != null) {
|
||||
try {
|
||||
// System.out.println("setting value...");
|
||||
Object[] args = new Object[]{ decodeType(type, val) };
|
||||
Object[] args = new Object[]{decodeType(type, val)};
|
||||
if (args[0] != null) {
|
||||
setter.invoke(obj, args);
|
||||
return true;
|
||||
@@ -1047,8 +1007,7 @@ public class BeanInspector {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Exception in invoking setter: "+e.getMessage());
|
||||
// e.printStackTrace();
|
||||
System.err.println("Exception in invoking setter: " + e.getMessage());
|
||||
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,92 +9,91 @@ 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 class JExtMenu extends JMenu {
|
||||
|
||||
public final static String ACTION = "Action";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JExtMenu(){
|
||||
public JExtMenu() {
|
||||
//super();
|
||||
//Mnemonic m = new Mnemonic(s);
|
||||
//setText(m.getText());
|
||||
//setMnemonic(m.getMnemonic());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public JExtMenu(String s){
|
||||
public JExtMenu(String s) {
|
||||
super();
|
||||
Mnemonic m = new Mnemonic(s);
|
||||
setText(m.getText());
|
||||
setMnemonic(m.getMnemonic());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public JMenuItem add(Action a){
|
||||
public JMenuItem add(Action a) {
|
||||
JMenuItem item = super.add(a);
|
||||
Object o;
|
||||
o = a.getValue(ExtAction.MNEMONIC);
|
||||
if(o != null) {
|
||||
item.setMnemonic(((Character)o).charValue());
|
||||
if (o != null) {
|
||||
item.setMnemonic(((Character) o).charValue());
|
||||
}
|
||||
o = a.getValue(ExtAction.TOOLTIP);
|
||||
if(o != null) {
|
||||
item.setToolTipText((String)o);
|
||||
if (o != null) {
|
||||
item.setToolTipText((String) o);
|
||||
}
|
||||
o = a.getValue(ExtAction.KEYSTROKE);
|
||||
if(o != null) {
|
||||
item.setAccelerator((KeyStroke)o);
|
||||
if (o != null) {
|
||||
item.setAccelerator((KeyStroke) o);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
protected PropertyChangeListener createActionChangeListener(JMenuItem b){
|
||||
return new ExtActionChangedListener(b){
|
||||
protected PropertyChangeListener createActionChangeListener(JMenuItem b) {
|
||||
return new ExtActionChangedListener(b) {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent e) {
|
||||
JMenuItem menuItem = (JMenuItem)component;
|
||||
if(menuItem == null) {
|
||||
JMenuItem menuItem = (JMenuItem) component;
|
||||
if (menuItem == null) {
|
||||
return;
|
||||
}
|
||||
String propertyName = e.getPropertyName();
|
||||
if(propertyName.equals(Action.NAME)) {
|
||||
menuItem.setText((String)e.getNewValue());
|
||||
}
|
||||
else if(propertyName.equals("enabled")) {
|
||||
menuItem.setEnabled(((Boolean)e.getNewValue()).booleanValue());
|
||||
}
|
||||
else if(propertyName.equals(Action.SMALL_ICON)){
|
||||
Icon icon = (Icon)e.getNewValue();
|
||||
if (propertyName.equals(Action.NAME)) {
|
||||
menuItem.setText((String) e.getNewValue());
|
||||
} else if (propertyName.equals("enabled")) {
|
||||
menuItem.setEnabled(((Boolean) e.getNewValue()).booleanValue());
|
||||
} 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)) {
|
||||
menuItem.setMnemonic(((Character)e.getNewValue()).charValue());
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.TOOLTIP)) {
|
||||
menuItem.setToolTipText((String)e.getNewValue());
|
||||
}
|
||||
else if(propertyName.equals(ExtAction.KEYSTROKE)) {
|
||||
menuItem.setAccelerator((KeyStroke)e.getNewValue());
|
||||
} else if (propertyName.equals(ExtAction.MNEMONIC)) {
|
||||
menuItem.setMnemonic(((Character) e.getNewValue()).charValue());
|
||||
} else if (propertyName.equals(ExtAction.TOOLTIP)) {
|
||||
menuItem.setToolTipText((String) e.getNewValue());
|
||||
} 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,22 +155,24 @@ 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.
|
||||
**/
|
||||
public static Object loadObject (InputStream inputStream) {
|
||||
* 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.
|
||||
**/
|
||||
public static Object loadObject (InputStream inputStream, boolean casually) {
|
||||
* 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;
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user