Commit 1828c48f authored by Alex Bowen's avatar Alex Bowen

removed system.out/err, now using java logging

parent 4e76d955
/*
* Copyright 2006 - 2013
* Stefan Balev <stefan.balev@graphstream-project.org>
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of GraphStream <http://graphstream-project.org>.
*
* GraphStream is a library whose purpose is to handle static or dynamic
* graph, create them from scratch, file or any source and display them.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
/*
* Copyright 2006 - 2013
* Stefan Balev <stefan.balev@graphstream-project.org>
* Julien Baudry <julien.baudry@graphstream-project.org>
* Antoine Dutot <antoine.dutot@graphstream-project.org>
* Yoann Pigné <yoann.pigne@graphstream-project.org>
* Guilhelm Savin <guilhelm.savin@graphstream-project.org>
*
* This file is part of GraphStream <http://graphstream-project.org>.
*
* GraphStream is a library whose purpose is to handle static or dynamic
* graph, create them from scratch, file or any source and display them.
*
* This program is free software distributed under the terms of two licenses, the
* CeCILL-C license that fits European law, and the GNU Lesser General Public
* License. You can use, modify and/ or redistribute the software under the terms
* of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following
* URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C and LGPL licenses and that you accept their terms.
*/
package org.graphstream.graph;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* An interface aimed at dynamically creating graph objects based on a class
* name.
......@@ -38,6 +41,9 @@ package org.graphstream.graph;
* @since september 2007
*/
public class GraphFactory {
private static final Logger logger = Logger.getLogger(GraphFactory.class.getSimpleName());
/**
* Create a new instance of graph.
*/
......@@ -65,28 +71,9 @@ public class GraphFactory {
Graph res = (Graph) clazz.getConstructor(String.class).newInstance(
id);
return res;
} catch (InstantiationException e) {
System.out
.println("GraphFactory newInstance InstantiationException : "
+ e.getMessage());
} catch (ClassNotFoundException e) {
System.out
.println("GraphFactory newInstance ClassNotFoundException : "
+ e.getMessage());
} catch (IllegalAccessException e) {
System.out
.println("GraphFactory newInstance IllegalAccessException : "
+ e.getMessage());
} catch (NoSuchMethodException e) {
System.out
.println("GraphFactory newInstance NoSuchMethodException : "
+ e.getMessage());
} catch (java.lang.reflect.InvocationTargetException e) {
System.out
.println("GraphFactory newInstance InvocationTargetException : "
+ e.getMessage());
}
} catch (final Exception e) {
logger.log(Level.SEVERE, "Error executing GraphFactory#newInstance.", e);
}
return null;
}
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import java.util.logging.Logger;
/**
* Path description.
......@@ -65,6 +66,12 @@ import java.util.Stack;
*
*/
public class Path implements Structure {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(Path.class.getSimpleName());
// ------------- ATTRIBUTES ------------
/**
......@@ -114,10 +121,8 @@ public class Path implements Structure {
this.root = root;
nodePath.push(root);
} else {
System.err
.printf("Error in org.miv.graphstream.graph.Path: root is not null. First use the clear method.%n");
logger.warning("Root node is not null - first use the clear method.");
}
}
/**
......@@ -207,9 +212,7 @@ public class Path implements Structure {
public void add(Node from, Edge edge) {
if (root == null) {
if (from == null) {
System.err
.print("Error using org.miv.graphstream.graph.Path: Use setRoot( ) first. %n");
System.exit(0);
throw new IllegalArgumentException("From node cannot be null.");
} else {
setRoot(from);
}
......@@ -227,8 +230,7 @@ public class Path implements Structure {
nodePath.push(edge.getOpposite(from));
edgePath.push(edge);
} else {
System.err
.printf("Path: Cannot add the specified edge, it cannot be part of the path! %n");
logger.warning("Cannot add the specified edge, it cannot be part of the path! %n");
}
}
......@@ -335,13 +337,6 @@ public class Path implements Structure {
*/
public void removeLoops() {
int n = nodePath.size();
/*
* System.err.printf( "removeLoop()%n" ); System.err.printf(
* " path size = %d==%d%n [ ", n, edgePath.size() );
*
* for( int i=0; i<n; i++ ) { System.err.printf( "%d=%s ", i,
* nodePath.get(i).getId() ); } System.err.printf( "]%n" );
*/
// For each node-edge pair
for (int i = 0; i < n; i++) {
// Lookup each other following node. We start
......@@ -351,7 +346,6 @@ public class Path implements Structure {
if (nodePath.get(i) == nodePath.get(j)) {
// We found a loop between i and j.
// Remove ]i,j].
// System.err.printf( "removed ]%d,%d]%n", i, j );
for (int k = i + 1; k <= j; k++) {
nodePath.remove(i + 1);
edgePath.remove(i);
......@@ -361,13 +355,7 @@ public class Path implements Structure {
}
}
}
/*
* System.err.printf( " NEW path size = %d==%d%n NEW [ ", n,
* edgePath.size() );
*
* for( int i=0; i<n; i++ ) { System.err.printf( "%d=%s ", i,
* nodePath.get(i).getId() ); } System.err.printf( "]%n" );
*/}
}
/**
* Compare the content of the current path and the specified path to decide
......
......@@ -31,16 +31,6 @@
*/
package org.graphstream.graph.implementations;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import org.graphstream.graph.Edge;
import org.graphstream.graph.EdgeFactory;
import org.graphstream.graph.EdgeRejectedException;
......@@ -59,8 +49,21 @@ import org.graphstream.stream.file.FileSink;
import org.graphstream.stream.file.FileSource;
import org.graphstream.ui.view.Viewer;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
public class Graphs {
private static final Logger logger = Logger.getLogger(Graphs.class.getSimpleName());
public static Graph unmutableGraph(Graph g) {
return null;
}
......@@ -104,9 +107,7 @@ public class Graphs {
Class<? extends Graph> cls = graphs[0].getClass();
result = cls.getConstructor(String.class).newInstance(id);
} catch (Exception e) {
System.err.printf("*** WARNING *** can not create a graph of %s\n",
graphs[0].getClass().getName());
logger.warning(String.format("Cannot create a graph of %s.", graphs[0].getClass().getName()));
result = new MultiGraph(id);
}
......@@ -154,9 +155,7 @@ public class Graphs {
Class<? extends Graph> cls = g.getClass();
copy = cls.getConstructor(String.class).newInstance(g.getId());
} catch (Exception e) {
System.err.printf("*** WARNING *** can not create a graph of %s\n",
g.getClass().getName());
logger.warning(String.format("Cannot create a graph of %s.", g.getClass().getName()));
copy = new AdjacencyListGraph(g.getId());
}
......
......@@ -31,12 +31,12 @@
*/
package org.graphstream.graph.implementations;
import org.graphstream.graph.Element;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import org.graphstream.graph.Element;
/**
* An implementation of an {@link org.graphstream.graph.Element}.
*
......@@ -177,20 +177,15 @@ public abstract class OneAttributeElement implements Element {
public void addAttribute(String attribute, Object value) {
this.attribute = value;
// System.out.println(attribute+" = "+value.toString());
}
public void changeAttribute(String attribute, Object value) {
addAttribute(attribute, value);
// System.out.println(attribute+" = "+value.toString());
}
public void addAttributes(Map<String, Object> attributes) {
// System.out.println(attributes.toString());
if (attributes.size() >= 1)
addAttribute("", attributes.get((attributes.keySet().toArray()[0])));
}
public void removeAttribute(String attribute) {
......
......@@ -31,11 +31,6 @@
*/
package org.graphstream.stream.thread;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import org.graphstream.graph.Graph;
import org.graphstream.stream.ProxyPipe;
import org.graphstream.stream.Replayable;
......@@ -44,6 +39,12 @@ import org.graphstream.stream.Sink;
import org.graphstream.stream.Source;
import org.graphstream.stream.SourceBase;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
/**
* Filter that allows to pass graph events between two threads without explicit
* synchronization.
......@@ -83,6 +84,11 @@ import org.graphstream.stream.SourceBase;
*/
public class ThreadProxyPipe extends SourceBase implements ProxyPipe {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(ThreadProxyPipe.class.getSimpleName());
/**
* Proxy id.
*/
......@@ -608,7 +614,7 @@ public class ThreadProxyPipe extends SourceBase implements ProxyPipe {
sendGraphCleared(graphId, timeId);
break;
default:
System.err.printf("ThreadProxy : Unknown message %s !!%n", e);
logger.warning(String.format("Unknown message %s.", e));
break;
}
}
......
......@@ -43,6 +43,9 @@ import org.miv.mbox.MBox;
import org.miv.mbox.MBoxListener;
import org.miv.mbox.MBoxStandalone;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Filter that allows to pass graph events between two threads without explicit
* synchronization.
......@@ -84,8 +87,12 @@ import org.miv.mbox.MBoxStandalone;
* {@link org.graphstream.stream.thread.ThreadProxyPipe}.
*/
@Deprecated
public class ThreadProxyPipeOld extends SourceBase implements ProxyPipe,
MBoxListener {
public class ThreadProxyPipeOld extends SourceBase implements ProxyPipe, MBoxListener {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(ThreadProxyPipe.class.getSimpleName());
/**
* Proxy id.
......@@ -323,9 +330,7 @@ public class ThreadProxyPipeOld extends SourceBase implements ProxyPipe,
Thread.yield();
}
} catch (CannotPostException e) {
System.err
.printf("GraphRendererRunner: cannot post message to listeners: %s%n",
e.getMessage());
logger.log(Level.WARNING, "Unable to post message to listeners.", e);
}
}
......@@ -527,8 +532,6 @@ public class ThreadProxyPipeOld extends SourceBase implements ProxyPipe,
// MBoxListener
public void processMessage(String from, Object[] data) {
// System.err.printf( " %s.msg(%s, %s, %s, %s)%n", from, data[1],
// data[2], data[0], data[3] );
if (data[0].equals(GraphEvents.ADD_NODE)) {
String graphId = (String) data[1];
Long timeId = (Long) data[2];
......@@ -640,8 +643,7 @@ public class ThreadProxyPipeOld extends SourceBase implements ProxyPipe,
sendGraphCleared(graphId, timeId);
} else {
System.err.printf("ThreadProxyFilter : Unknown message %s !!%n",
data[0]);
logger.warning(String.format("Unknown message %s.", data[0]));
}
}
}
\ No newline at end of file
......@@ -39,6 +39,8 @@ import org.graphstream.ui.geom.Point3;
import org.graphstream.ui.geom.Vector2;
import org.graphstream.ui.geom.Vector3;
import java.util.logging.Logger;
/**
* Lots of small often used measuring algorithms on graphs.
*
......@@ -47,6 +49,12 @@ import org.graphstream.ui.geom.Vector3;
* </p>
*/
public class GraphPosLengthUtils {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(GraphPosLengthUtils.class.getSimpleName());
/**
* Retrieve a node position from its attributes ("x", "y", "z", or "xy", or
* "xyz").
......@@ -324,7 +332,7 @@ public class GraphPosLengthUtils {
xyz[1] = oo.data[1];
xyz[2] = 0;
} else {
System.err.printf("Do not know how to handle xyz attribute %s%n", o.getClass().getName());
logger.warning(String.format("Do not know how to handle xyz attribute %s.", o.getClass().getName()));
}
}
......@@ -399,7 +407,7 @@ public class GraphPosLengthUtils {
pos.y = oo.data[1];
pos.z = 0;
} else {
System.err.printf("Do not know how to handle xyz attribute %s%n", o.getClass().getName());
logger.warning(String.format("Do not know how to handle xyz attribute %s%n", o.getClass().getName()));
}
}
......
......@@ -31,13 +31,15 @@
*/
package org.graphstream.ui.graphicGraph;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.graphstream.graph.implementations.AbstractElement;
import org.graphstream.ui.graphicGraph.stylesheet.Selector;
import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Super class of all graphic node, edge, and sprite elements.
*
......@@ -68,6 +70,12 @@ import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants;
* </p>
*/
public abstract class GraphicElement extends AbstractElement {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(GraphicElement.class.getSimpleName());
/**
* Interface for renderers registered in each style group.
*/
......@@ -219,17 +227,12 @@ public abstract class GraphicElement extends AbstractElement {
mygraph.styleSheet.parseStyleFromString(
new Selector(getSelectorType(), getId(),
null), (String) newValue);
} catch (java.io.IOException e) {
System.err.printf(
"Error while parsing style for %S '%s' :",
getSelectorType(), getId());
System.err.printf(" %s%n", e.getMessage());
System.err.printf(" The style was ignored");
} catch (Exception e) {
logger.log(Level.WARNING, String.format("Error while parsing style for %S '%s' :", getSelectorType(), getId()), e);
}
mygraph.graphChanged = true;
} else {
System.err.printf("ERROR !!%n");
logger.warning("Unknown value for style [" + newValue + "].");
}
} else if (attribute.equals("ui.hide")) {
hidden = true;
......
......@@ -31,15 +31,6 @@
*/
package org.graphstream.ui.graphicGraph;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.graphstream.graph.Edge;
import org.graphstream.graph.EdgeFactory;
import org.graphstream.graph.Element;
......@@ -65,6 +56,18 @@ import org.graphstream.ui.graphicGraph.stylesheet.Values;
import org.graphstream.ui.view.Viewer;
import org.graphstream.util.GraphListeners;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Graph representation used in display classes.
*
......@@ -131,8 +134,13 @@ import org.graphstream.util.GraphListeners;
*
* TODO : this graph cannot handle modification inside event listener methods !!
*/
public class GraphicGraph extends AbstractElement implements Graph,
StyleGroupListener {
public class GraphicGraph extends AbstractElement implements Graph, StyleGroupListener {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(GraphicGraph.class.getSimpleName());
/**
* Set of styles.
*/
......@@ -450,18 +458,11 @@ public class GraphicGraph extends AbstractElement implements Graph,
try {
styleSheet.load((String) newValue);
graphChanged = true;
} catch (IOException e) {
System.err
.printf("Error while parsing style sheet for graph '%s' : %n",
getId());
if (((String) newValue).startsWith("url"))
System.err.printf(" %s%n", ((String) newValue));
System.err.printf(" %s%n", e.getMessage());
} catch (Exception e) {
logger.log(Level.WARNING, String.format("Error while parsing style sheet for graph '%s'.", getId()), e);
}
} else {
System.err
.printf("Error with stylesheet specification what to do with '%s' ?%n",
newValue);
logger.warning(String.format("Error with stylesheet specification what to do with '%s'.", newValue));
}
} else // Remove the style.
{
......@@ -1213,7 +1214,7 @@ public class GraphicGraph extends AbstractElement implements Graph,
public GraphicSprite addSprite(String id) {
String prefix = String.format("ui.sprite.%s", id);
System.out.printf("add sprite %s\n", id);
logger.info(String.format("Added sprite %s.", id));
addAttribute(prefix, 0, 0, 0);
GraphicSprite s = styleGroups.getSprite(id);
assert (s != null);
......@@ -1260,8 +1261,7 @@ public class GraphicGraph extends AbstractElement implements Graph,
((Number) values[2]).doubleValue(),
(Style.Units) values[3]);
} else {
System.err
.printf("GraphicGraph : cannot parse values[4] for sprite position.%n");
logger.warning("Cannot parse values[4] for sprite position.");
}
} else if (values.length == 3) {
if (values[0] instanceof Number && values[1] instanceof Number
......@@ -1270,20 +1270,16 @@ public class GraphicGraph extends AbstractElement implements Graph,
((Number) values[1]).doubleValue(),
((Number) values[2]).doubleValue(), Units.GU);
} else {
System.err
.printf("GraphicGraph : cannot parse values[3] for sprite position.%n");
logger.warning("Cannot parse values[3] for sprite position.");
}
} else if (values.length == 1) {
if (values[0] instanceof Number) {
sprite.setPosition(((Number) values[0]).doubleValue());
} else {
System.err
.printf("GraphicGraph : sprite position percent is not a number.%n");
logger.warning("Sprite position percent is not a number.");
}
} else {
System.err
.printf("GraphicGraph : cannot transform value '%s' (length=%d) into a position%n",
Arrays.toString(values), values.length);
logger.warning(String.format("Cannot transform value '%s' (length=%d) into a position%n", Arrays.toString(values), values.length));
}
} else if (value instanceof Number) {
sprite.setPosition(((Number) value).doubleValue());
......@@ -1294,9 +1290,7 @@ public class GraphicGraph extends AbstractElement implements Graph,
} else if (value == null) {
throw new RuntimeException("What do you expect with a null value ?");
} else {
System.err
.printf("GraphicGraph : cannot place sprite with posiiton '%s' (instance of %s)%n",
value, value.getClass().getName());
logger.warning(String.format("Cannot place sprite with posiiton '%s' (instance of %s)%n", value, value.getClass().getName()));
}
}
......
......@@ -31,8 +31,6 @@
*/
package org.graphstream.ui.graphicGraph;
import java.util.Iterator;
import org.graphstream.graph.Node;
import org.graphstream.stream.SourceBase.ElementType;
import org.graphstream.ui.graphicGraph.stylesheet.Selector;
......@@ -40,6 +38,8 @@ import org.graphstream.ui.graphicGraph.stylesheet.Style;
import org.graphstream.ui.graphicGraph.stylesheet.StyleConstants;
import org.graphstream.ui.graphicGraph.stylesheet.Values;
import java.util.Iterator;
/**
* A small gentle sprite.
*/
......@@ -305,9 +305,6 @@ public class GraphicSprite extends GraphicElement {
if (values.getValueCount() > 2)
z = values.get(2);
// System.err.printf(
// "setting %s position x=%f y=%f z=%f units=%s (value in=%s)%n",
// getId(), x, y, z, values.units, values );
if (x == 1 && y == 1 && z == 1)
throw new RuntimeException("WTF !!!");
setPosition(x, y, z, values.units);
......@@ -333,8 +330,6 @@ public class GraphicSprite extends GraphicElement {
String completeAttr = String.format("ui.sprite.%s.%s", getId(),
attribute);
// System.err.printf( "GSprite add attribute %s %s (old=%s) (new=%s)%n",
// event, attribute, oldValue, newValue );
mygraph.listeners.sendAttributeChangedEvent(mygraph.getId(),
ElementType.GRAPH, completeAttr, event, oldValue, newValue);
......
......@@ -39,14 +39,6 @@ import org.graphstream.util.parser.TokenMgrError;
/** Token Manager. */
public class StyleSheetParserTokenManager implements StyleSheetParserConstants {
/** Debug output. */
public java.io.PrintStream debugStream = System.out;
/** Set debug output. */
public void setDebugStream(java.io.PrintStream ds) {
debugStream = ds;
}
private final int jjStopStringLiteralDfa_0(int pos, long active0,
long active1, long active2) {
switch (pos) {
......
......@@ -36,6 +36,9 @@ import org.graphstream.stream.ProxyPipe;
import org.graphstream.stream.Source;
import org.graphstream.stream.thread.ThreadProxyPipe;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Allows to run a layout in a distinct thread.
*
......@@ -66,6 +69,12 @@ import org.graphstream.stream.thread.ThreadProxyPipe;
* </p>
*/
public class LayoutRunner extends Thread {
/**
* class level logger
*/
private static final Logger logger = Logger.getLogger(LayoutRunner.class.getSimpleName());
/**
* The layout algorithm.
*/
......@@ -189,9 +198,7 @@ public class LayoutRunner extends Thread {
nap(shortNap);
}
}
System.out.printf("Layout '%s' process stopped.%n", layoutName);
System.out.flush();
logger.info(String.format("Layout '%s' process stopped.", layoutName));
}
/**
......@@ -207,9 +214,8 @@ public class LayoutRunner extends Thread {
if (Thread.currentThread() != this) {
try {
this.join();
} catch (InterruptedException e) {
e.printStackTrace();
System.err.printf("Layout can not stop ...\n");
} catch (Exception e) {
logger.log(Level.WARNING, "Unable to stop/release layout.", e);
}
}
......
......@@ -32,6 +32,8 @@
package org.graphstream.ui.layout;
import java.security.AccessControlException;
import java.util.logging.Level;
import java.util.logging.Logger;