Further cleanup of logging.
This commit is contained in:
Fabian Becker 2013-01-31 15:56:53 +00:00
parent d474eebfa2
commit d93c8bf2b0
7 changed files with 1194 additions and 1258 deletions

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,6 @@ public class GOEPanel extends JPanel implements ItemListener {
private Object backupObject; private Object backupObject;
private PropertyChangeSupport propChangeSupport; private PropertyChangeSupport propChangeSupport;
private static boolean TRACE = false;
/** /**
* The chooser component * The chooser component
*/ */

View File

@ -264,7 +264,6 @@ public class GenericObjectEditor implements PropertyEditor {
* @param type a value of type 'Class' * @param type a value of type 'Class'
*/ */
public void setClassType(Class<?> type) { public void setClassType(Class<?> type) {
//if (TRACE) System.out.println("GOE setClassType("+ (type == null? "<null>" : type.getName()) + ")");
classType = type; classType = type;
if (editorComponent != null) { if (editorComponent != null) {
editorComponent.updateClassType(); editorComponent.updateClassType();
@ -337,7 +336,6 @@ public class GenericObjectEditor implements PropertyEditor {
*/ */
private void setObject(Object c) { private void setObject(Object c) {
// This should really call equals() for comparison. // This should really call equals() for comparison.
//if (TRACE) System.out.println("setObject "+ c.getClass().getName() + " " + c);
boolean trueChange = (c != getValue()); boolean trueChange = (c != getValue());
m_Backup = m_Object; m_Backup = m_Object;

View File

@ -6,13 +6,14 @@ package eva2.gui;
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* It represents one plot window in the client GUI. * It represents one plot window in the client GUI.
*/ */
public class GraphWindow { public class GraphWindow {
private static final Logger LOGGER = Logger.getLogger(GraphWindow.class.getName());
public static boolean TRACE = false;
static private int graphCounter = -1; static private int graphCounter = -1;
static private PlotContainer plotContainer; static private PlotContainer plotContainer;
private PlotInterface plotter; private PlotInterface plotter;
@ -57,9 +58,6 @@ public class GraphWindow {
* *
*/ */
private GraphWindow(String plotName, String strx, String stry) { private GraphWindow(String plotName, String strx, String stry) {
if (TRACE) {
System.out.println("Constructor GraphWindow");
}
name = plotName; name = plotName;
plotter = new Plot(plotName, strx, stry, true); plotter = new Plot(plotName, strx, stry, true);
} }
@ -76,9 +74,7 @@ public class GraphWindow {
*/ */
public Graph getNewGraph(String infoString) { public Graph getNewGraph(String infoString) {
graphCounter++; graphCounter++;
if (TRACE) { LOGGER.log(Level.FINEST, "Graph.getNewGraph No:{0} - {1} created.", new Object[]{graphCounter, infoString});
System.out.println("Graph.getNewGraph No:" + graphCounter + " - " + infoString);
}
return new Graph(infoString, plotter, graphCounter); return new Graph(infoString, plotter, graphCounter);
} }
} }
@ -104,7 +100,7 @@ class PlotContainer extends ArrayList<GraphWindow> {
* *
*/ */
public boolean containsName(String name) { public boolean containsName(String name) {
GraphWindow temp = null; GraphWindow temp;
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
temp = (GraphWindow) (get(i)); temp = (GraphWindow) (get(i));
if (name.equals(temp.getName())) { if (name.equals(temp.getName())) {
@ -130,7 +126,7 @@ class PlotContainer extends ArrayList<GraphWindow> {
return actualPlot; return actualPlot;
} }
} }
GraphWindow temp = null; GraphWindow temp;
for (int i = 0; i < size(); i++) { for (int i = 0; i < size(); i++) {
temp = (GraphWindow) (get(i)); temp = (GraphWindow) (get(i));
if (name.equals(temp.getName())) { if (name.equals(temp.getName())) {

View File

@ -9,94 +9,93 @@ package eva2.gui;
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $ * $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
* $Author: streiche $ * $Author: streiche $
*/ */
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import java.beans.*; import java.beans.*;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
/** /**
* *
*/ */
public class JExtMenu extends JMenu{ public class JExtMenu extends JMenu {
public final static String ACTION = "Action";
/** public final static String ACTION = "Action";
*
*/ /**
public JExtMenu(){ *
//super(); */
//Mnemonic m = new Mnemonic(s); public JExtMenu() {
//setText(m.getText()); //super();
//setMnemonic(m.getMnemonic()); //Mnemonic m = new Mnemonic(s);
} //setText(m.getText());
/** //setMnemonic(m.getMnemonic());
* }
*/
public JExtMenu(String s){ /**
super(); *
Mnemonic m = new Mnemonic(s); */
setText(m.getText()); public JExtMenu(String s) {
setMnemonic(m.getMnemonic()); super();
} Mnemonic m = new Mnemonic(s);
/** setText(m.getText());
* setMnemonic(m.getMnemonic());
*/ }
/**
*
*/
@Override @Override
public JMenuItem add(Action a){ public JMenuItem add(Action a) {
JMenuItem item = super.add(a); JMenuItem item = super.add(a);
Object o; Object o;
o = a.getValue(ExtAction.MNEMONIC); o = a.getValue(ExtAction.MNEMONIC);
if(o != null) { if (o != null) {
item.setMnemonic(((Character)o).charValue()); item.setMnemonic(((Character) o).charValue());
}
o = a.getValue(ExtAction.TOOLTIP);
if(o != null) {
item.setToolTipText((String)o);
}
o = a.getValue(ExtAction.KEYSTROKE);
if(o != null) {
item.setAccelerator((KeyStroke)o);
}
return item;
}
/**
*
*/
@Override
protected PropertyChangeListener createActionChangeListener(JMenuItem b){
return new ExtActionChangedListener(b){
@Override
public void propertyChange(PropertyChangeEvent e) {
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();
menuItem.setIcon(icon);
menuItem.invalidate();
menuItem.repaint();
} }
else if(propertyName.equals(ExtAction.MNEMONIC)) { o = a.getValue(ExtAction.TOOLTIP);
menuItem.setMnemonic(((Character)e.getNewValue()).charValue()); if (o != null) {
} item.setToolTipText((String) o);
else if(propertyName.equals(ExtAction.TOOLTIP)) { }
menuItem.setToolTipText((String)e.getNewValue()); o = a.getValue(ExtAction.KEYSTROKE);
} if (o != null) {
else if(propertyName.equals(ExtAction.KEYSTROKE)) { item.setAccelerator((KeyStroke) o);
menuItem.setAccelerator((KeyStroke)e.getNewValue()); }
} return item;
} }
};
} /**
*
*/
@Override
protected PropertyChangeListener createActionChangeListener(JMenuItem b) {
return new ExtActionChangedListener(b) {
@Override
public void propertyChange(PropertyChangeEvent e) {
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();
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());
}
}
};
}
} }

View File

@ -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()]; String[] x = new String[moduleNameList.size()];
moduleNameList.toArray(x); moduleNameList.toArray(x);
@ -176,21 +163,6 @@ public class ModuleServer {
return (ModuleAdapter) moduleAdapter; 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); LOGGER.log(Level.SEVERE, "No valid module defined: {0}", selectedModuleName);
return null; return null;

View File

@ -6,12 +6,14 @@ import java.util.logging.Logger;
/** /**
* This class defines utility routines that use Java serialization. Any * This class defines utility routines that use Java serialization. Any
* serializable object can be stored to a file, loaded, and cloned (returning * serializable object can be stored to a file, loaded, and cloned (returning a
* a deep copy). * deep copy).
* *
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher, Marcel Kronfeld * @author Holger Ulmer, Felix Streichert, Hannes Planatscher, Marcel Kronfeld
**/ *
*/
public class Serializer { public class Serializer {
/** /**
* The logging instance for this class. * The logging instance for this class.
*/ */
@ -20,149 +22,158 @@ public class Serializer {
/** /**
* Private constructor to prevent instantiating module class. * Private constructor to prevent instantiating module class.
*/ */
private Serializer() { } private Serializer() {
}
/** /**
* Serialize the object o (and any Serializable objects it refers to) and * 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 * store its serialized state in File f. If serializeInMem is true, the
* is wrapped in a SerializedObject first, which seems to be more efficient than * object is wrapped in a SerializedObject first, which seems to be more
* writing a nested object directly to a file. * 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
* @throws IOException
* *
* @param o the object to write */
* @param outStream The stream to write to private static void store(Serializable o, OutputStream outStream, boolean serializeInMem) throws IOException {
* @param serializeInMem flag whether to wrap the object in a SerializedObject ObjectOutputStream out = new ObjectOutputStream(outStream);
* @throws IOException try {
**/ Object objToStore = o;
private static void store(Serializable o, OutputStream outStream, boolean serializeInMem) throws IOException { if (serializeInMem) {
ObjectOutputStream out = new ObjectOutputStream(outStream);
try {
Object objToStore = o;
if (serializeInMem) {
objToStore = new SerializedObject((Object) o); objToStore = new SerializedObject((Object) o);
} }
out.writeObject(objToStore); out.writeObject(objToStore);
} catch (java.io.NotSerializableException ex) { } catch (java.io.NotSerializableException ex) {
LOGGER.log(Level.SEVERE, "Object is not serializable!", ex); LOGGER.log(Level.SEVERE, "Object is not serializable!", ex);
} }
out.flush(); out.flush();
out.close(); out.close();
} }
/** /**
* Deserialize the contents of File f and return the resulting object. * Deserialize the contents of File f and return the resulting object. A
* A SerializedObject is unwrapped once. * SerializedObject is unwrapped once.
* *
* @param inputStream The Input stream to read from * @param inputStream The Input stream to read from
* @throws ClassNotFoundException * @throws ClassNotFoundException
* @throws IOException * @throws IOException
* @return The deserialized Object from the file * @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();
if (ret instanceof SerializedObject) {
ret = ((SerializedObject) ret).getObject();
}
objInputStream.close();
return ret;
}
/**
* 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 {
// Write the object out to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(o);
out.flush();
out.close();
// Make an input stream from the byte array and read
// a copy of the object back in.
ObjectInputStream inputStream = new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray()));
obj = inputStream.readObject();
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Error while cloning object.", ex);
} catch (ClassNotFoundException ex) {
LOGGER.log(Level.WARNING, "Object class was not found.", ex);
}
return obj;
}
/**
* Serialize the string data and write it to the OutputStream.
* *
* @param outStream The output stream */
* @param data The string data private static Object load(final InputStream inputStream) throws IOException, ClassNotFoundException {
**/ ObjectInputStream objInputStream = new ObjectInputStream(inputStream);
public static void storeString(final OutputStream outStream, final String data) { Object ret = objInputStream.readObject();
try { if (ret instanceof SerializedObject) {
outStream.write(data.getBytes()); ret = ((SerializedObject) ret).getObject();
} catch (Exception ex) { }
LOGGER.log(Level.SEVERE, "Could not write string to stream", ex); objInputStream.close();
} return ret;
} }
/** /**
* Deserialize the contents of the InputStream containing * Use object serialization to make a "deep clone" of the object o. This
* a string and return the resulting string. * 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 {
// Write the object out to a byte array
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(o);
out.flush();
out.close();
// Make an input stream from the byte array and read
// a copy of the object back in.
ObjectInputStream inputStream = new ObjectInputStream(
new ByteArrayInputStream(bos.toByteArray()));
obj = inputStream.readObject();
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Error while cloning object.", ex);
} catch (ClassNotFoundException ex) {
LOGGER.log(Level.WARNING, "Object class was not found.", ex);
}
return obj;
}
/**
* Serialize the string data and write it to the OutputStream.
*
* @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());
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Could not write string to stream", ex);
}
}
/**
* Deserialize the contents of the InputStream containing a string and
* return the resulting string.
* *
* @param inputStream The input stream to read from * @param inputStream The input stream to read from
* @return The deserialized data from the stream * @return The deserialized data from the stream
**/ *
public static String loadString(final InputStream inputStream) { */
StringBuilder sBuilder = new StringBuilder(); public static String loadString(final InputStream inputStream) {
try { StringBuilder sBuilder = new StringBuilder();
try {
int data = inputStream.read(); int data = inputStream.read();
while (data != -1) { while (data != -1) {
sBuilder.append((char) data); sBuilder.append((char) data);
data = inputStream.read(); data = inputStream.read();
} }
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Could not load string from stream!", ex); LOGGER.log(Level.SEVERE, "Could not load string from stream!", ex);
} }
return sBuilder.toString(); return sBuilder.toString();
} }
/** /**
* Serialize the string s and * Serialize the string s and store its serialized state in File with name
* store its serialized state in File with name Filename. * Filename.
**/ */
public static void storeObject(OutputStream outStream, Serializable s) { public static void storeObject(OutputStream outStream, Serializable s) {
try { try {
store(s, outStream, true); store(s, outStream, true);
} catch (Exception ex) { } catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Could not write object to stream.", ex); LOGGER.log(Level.SEVERE, "Could not write object to stream.", ex);
} }
} }
/** /**
* Deserialize the contents of File with given name containing * Deserialize the contents of File with given name containing a string and
* a string and return the resulting string. If the indicated file * return the resulting string. If the indicated file doesn't exist or an
* doesnt exist or an error occurs, null is returned. * error occurs, null is returned.
**/ *
public static Object loadObject (InputStream inputStream) { */
return loadObject(inputStream, true); public static Object loadObject(InputStream inputStream) {
} return loadObject(inputStream, true);
}
/** /**
* Deserialize the contents of File with given name containing * Deserialize the contents of File with given name containing a string and
* a string and return the resulting string. If the indicated file * return the resulting string. If the indicated file doesn't exist or an
* doesnt exist or an error occurs, null is returned. * error occurs, null is returned. If casually is false, an error message is
* If casually is false, an error message is printed and an exception * printed and an exception is raised if the file was not found or an error
* is raised if the file was not found or an error occured on loading. * occured on loading.
**/ *
public static Object loadObject (InputStream inputStream, boolean casually) { */
Object serializedObject = null; public static Object loadObject(InputStream inputStream, boolean casually) {
Object serializedObject = null;
try { try {
serializedObject = (Object) load(inputStream); serializedObject = (Object) load(inputStream);
@ -179,5 +190,5 @@ public class Serializer {
} }
return serializedObject; return serializedObject;
} }
} }