Author: jflesch
Date: 2007-07-25 19:55:33 +0000 (Wed, 25 Jul 2007)
New Revision: 14351
Modified:
trunk/apps/Thaw/src/thaw/core/LogListener.java
trunk/apps/Thaw/src/thaw/core/Logger.java
trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
trunk/apps/Thaw/src/thaw/plugins/LogConsole.java
trunk/apps/Thaw/src/thaw/plugins/StatusBar.java
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
Log:
#1555 : Display the warnings and the errors in the status bar
Modified: trunk/apps/Thaw/src/thaw/core/LogListener.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/LogListener.java 2007-07-25 19:38:51 UTC
(rev 14350)
+++ trunk/apps/Thaw/src/thaw/core/LogListener.java 2007-07-25 19:55:33 UTC
(rev 14351)
@@ -3,6 +3,6 @@
public interface LogListener {
- public void newLogLine(String line);
+ public void newLogLine(int level, Object src, String line);
}
Modified: trunk/apps/Thaw/src/thaw/core/Logger.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Logger.java 2007-07-25 19:38:51 UTC (rev
14350)
+++ trunk/apps/Thaw/src/thaw/core/Logger.java 2007-07-25 19:55:33 UTC (rev
14351)
@@ -24,88 +24,111 @@
*/
public final static int LOG_LEVEL = 3;
+
+ public final static String[] PREFIXES = new String[] {
+ "[ ERROR ]",
+ "[WARNING]",
+ "[NOTICE ]",
+ "[ INFO ]",
+ "[ DEBUG ]",
+ "[VERBOSE]"
+ };
+
+
private static Vector logListeners = null;
- protected static void displayErr(final String msg) {
+ private static void displayErr(final String msg) {
System.err.println(msg);
- Logger.notifyLogListeners(msg);
}
- protected static void display(final String msg) {
+ private static void display(final String msg) {
System.out.println(msg);
- Logger.notifyLogListeners(msg);
}
+ private static void log(final int level, final Object o, final String
msg) {
+ log(level, o, msg, false);
+ }
+
+ private static void log(final int level, final Object o, final String
msg,
+ final boolean manda) {
+ if (Logger.LOG_LEVEL < level && !manda)
+ return;
+
+ String str = ((o != null) ? o.getClass().getName()+": " : "");
+
+ if (level <= 1)
+ displayErr(PREFIXES[level]+" "+str+msg);
+ else
+ display(PREFIXES[level]+" "+str+msg);
+
+ notify(level, o, msg);
+ }
+
+
/**
* Errors.
+ * A process ended because of it.
*/
public static void error(final Object o, final String message) {
- Logger.displayErr("[ ERROR ] "+o.getClass().getName()+":
"+message);
+ log(0, o, message);
}
/**
* Warnings.
+ * Some informations will probably be / are probably missing.
+ * Or: Can't do something, but it's normal.
*/
public static void warning(final Object o, final String message) {
- if(Logger.LOG_LEVEL >= 1)
- Logger.displayErr("[WARNING]
"+o.getClass().getName()+": "+message);
+ log(1, o, message);
}
/**
* Notices.
+ * Strange event, but probably not unusual.
+ * Or: Normal event, but who can create troubles.
*/
public static void notice(final Object o, final String msg) {
- if(Logger.LOG_LEVEL >= 2)
- Logger.display("[NOTICE ] " +o.getClass().getName()+":
"+msg);
+ log(2, o, msg);
}
+ /**
+ * Infos.
+ * Normal process.
+ */
public static void info(final Object o, final String msg) {
- Logger.info(o, msg, false);
+ log(3, o, msg);
}
/**
* Infos.
+ * @param manda force the display of these informations
*/
public static void info(final Object o, final String msg, final boolean
manda) {
- if((Logger.LOG_LEVEL >= 3) || manda)
- Logger.display("[ INFO ] "+o.getClass().getName()+":
"+msg);
+ log(3, o, msg, manda);
}
/**
* Debug.
+ * Details about a normal process.
*/
public static void debug(final Object o, final String msg) {
- if(Logger.LOG_LEVEL >= 4)
- Logger.display("[ DEBUG ] "+o.getClass().getName()+":
"+msg);
+ log(4, o, msg);
}
/**
* Verbose. Too Verbose.
+ * Details, a LOT of details.
*/
public static void verbose(final Object o, final String msg) {
- if(Logger.LOG_LEVEL >= 5) {
- System.out.println("[VERBOSE] "+
o.getClass().getName()+": "+msg);
- Logger.notifyLogListeners(msg);
- }
+ log(5, o, msg);
}
- /**
- * As it. Similar to verbose()
- */
- public static void asIt(final Object o, final String msg) {
- if(Logger.LOG_LEVEL >= 5) {
- System.out.println(msg);
- Logger.notifyLogListeners(msg);
- }
- }
-
-
public static void addLogListener(final LogListener logListener) {
if(Logger.logListeners == null)
Logger.logListeners = new Vector();
@@ -118,10 +141,16 @@
return;
Logger.logListeners.remove(logListener);
+
+ if (logListeners.size() == 0)
+ logListeners = null;
}
- private static void notifyLogListeners(final String line) {
+ /**
+ * notify the observers if there is.
+ */
+ private static void notify(final int level, final Object src, final
String line) {
if(Logger.logListeners == null)
return;
@@ -129,7 +158,7 @@
it.hasNext(); ) {
final LogListener logListener = (LogListener)it.next();
- logListener.newLogLine(line);
+ logListener.newLogLine(level, src, line);
}
}
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2007-07-25 19:38:51 UTC
(rev 14350)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2007-07-25 19:55:33 UTC
(rev 14351)
@@ -25,7 +25,8 @@
private final static boolean DEBUG_MODE = true;
private final static int MAX_RECV = 1024;
- private final byte[] recvBytes = new byte[FCPConnection.MAX_RECV]; /*
global to avoid each time free() / malloc() */
+ /* global to avoid each time free() / malloc() */
+ private final byte[] recvBytes = new byte[FCPConnection.MAX_RECV];
private FCPBufferedStream bufferedOut = null;
private int maxUploadSpeed = 0;
@@ -55,7 +56,8 @@
/**
* Don't connect. Call connect() for that.
* @param maxUploadSpeed in KB: -1 means no limit
- * @param duplicationAllowed FCPClientGet and FCPClientPut will be
allowed to open a separate socket to transfer the files
+ * @param duplicationAllowed FCPClientGet and FCPClientPut will be
allowed to
+ * open a separate socket to transfer the
files
*/
public FCPConnection(final String nodeAddress,
final int port,
@@ -116,7 +118,8 @@
Logger.info(this, "Disconnect(): Already
disconnected.");
}
} catch(final java.io.IOException e) {
- Logger.warning(this, "Unable to close cleanly the
connection : "+e.toString() +" ; "+e.getMessage());
+ Logger.warning(this, "Unable to close cleanly the
connection : "
+ +e.toString() +" ; "+e.getMessage());
}
socket = null;
@@ -171,7 +174,8 @@
in = socket.getInputStream();
out = socket.getOutputStream();
} catch(final java.io.IOException e) {
- Logger.error(this, "Socket and connection established,
but unable to get in/output streams ?! : "+e.toString()+ " ; "+e.getMessage() );
+ Logger.error(this, "Socket and connection established,
but unable to get "+
+ "in/output streams ?! : "+e.toString()+ "
; "+e.getMessage() );
return false;
}
@@ -228,7 +232,8 @@
out.write(data);
out.flush();
} catch(final java.io.IOException e) {
- Logger.warning(this, "Unable to write() on the
socket ?! : "+ e.toString()+ " ; "+e.getMessage());
+ Logger.warning(this, "Unable to write() on the
socket ?! : "
+ + e.toString()+ " ;
"+e.getMessage());
disconnect();
return false;
}
@@ -284,8 +289,10 @@
addToWriterQueue();
}
- Logger.asIt(this, "Thaw >>> Node :");
- Logger.asIt(this, toWrite);
+ if (DEBUG_MODE) {
+ Logger.debug(this, "Thaw >>> Node :");
+ Logger.debug(this, toWrite);
+ }
if((out != null) && (socket != null) && socket.isConnected()) {
@@ -423,9 +430,9 @@
if(FCPConnection.DEBUG_MODE) {
if(result.matches("[\\-\\
\\?.a-zA-Z0-9\\,~%@/_=\\[\\]\\(\\)]*"))
- Logger.asIt(this, "Thaw <<<
Node : "+result);
+ Logger.debug(this, "Thaw <<<
Node : "+result);
else
- Logger.asIt(this, "Thaw <<<
Node : Unknow chars in message. Not displayed");
+ Logger.debug(this, "Thaw <<<
Node : Unknow chars in message. Not displayed");
}
@@ -433,9 +440,11 @@
} catch (final java.io.IOException e) {
if(isConnected())
- Logger.error(this, "IOException while
reading but still connected, wtf? : "+e.toString()+ " ; "+e.getMessage() );
+ Logger.error(this, "IOException while
reading but still connected, wtf? : "
+ +e.toString()+ " ;
"+e.getMessage() );
else
- Logger.notice(this, "IOException.
Disconnected. : "+e.toString() + " ; "+e.getMessage());
+ Logger.notice(this, "IOException.
Disconnected. : "+e.toString() + " ; "
+ +e.getMessage());
disconnect();
@@ -450,7 +459,8 @@
/**
- * If duplicationAllowed, returns a copy of this object, using a
different socket and differents lock / buffer.
+ * If duplicationAllowed, returns a copy of this object, using a
different
+ * socket and differents lock / buffer.
* If !duplicationAllowed, returns this object.
* The duplicate socket is just connected but not initialized
(ClientHello, etc).
*/
@@ -462,7 +472,10 @@
FCPConnection newConnection;
- newConnection = new FCPConnection(nodeAddress, port, -1,
duplicationAllowed, localSocket); /* upload limit is useless here, since we
can't do a global limit on all the connections */
+ /* upload limit is useless here, since we can't do a global
limit
+ * on all the connections */
+ newConnection = new FCPConnection(nodeAddress, port, -1,
+ duplicationAllowed,
localSocket);
if (!newConnection.connect()) {
Logger.warning(this, "Unable to duplicate socket !");
Modified: trunk/apps/Thaw/src/thaw/plugins/LogConsole.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/LogConsole.java 2007-07-25 19:38:51 UTC
(rev 14350)
+++ trunk/apps/Thaw/src/thaw/plugins/LogConsole.java 2007-07-25 19:55:33 UTC
(rev 14351)
@@ -138,8 +138,12 @@
}
}
- public void newLogLine(final String line) {
- addLine(line + "\n");
+
+ public void newLogLine(int level, Object src, String line) {
+ if (src != null)
+ addLine(Logger.PREFIXES[level] + "
"+src.getClass().getName()+": "+line + "\n");
+ else
+ addLine(Logger.PREFIXES[level] + " "+line+"\n");
}
Modified: trunk/apps/Thaw/src/thaw/plugins/StatusBar.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/StatusBar.java 2007-07-25 19:38:51 UTC
(rev 14350)
+++ trunk/apps/Thaw/src/thaw/plugins/StatusBar.java 2007-07-25 19:55:33 UTC
(rev 14351)
@@ -3,16 +3,20 @@
import java.util.Iterator;
import java.util.Vector;
+import java.awt.Color;
+
+
import thaw.core.Core;
import thaw.core.I18n;
import thaw.core.Logger;
import thaw.core.Main;
import thaw.core.Plugin;
+import thaw.core.LogListener;
import thaw.gui.IconBox;
import thaw.fcp.FCPTransferQuery;
-public class StatusBar implements Runnable, Plugin {
+public class StatusBar implements Runnable, Plugin, LogListener {
public final static int INTERVAL = 3000; /* in ms */
public final static String SEPARATOR = " ";
@@ -22,6 +26,12 @@
private boolean advancedMode = false;
+ private boolean dropNextRefresh = false;
+
+ private Object barLock = new Object();
+
+ public final static Color ORANGE = new Color(240, 160, 0);
+
public boolean run(final Core core) {
this.core = core;
@@ -32,6 +42,8 @@
refresher.start();
+ Logger.addLogListener(this);
+
return true;
}
@@ -44,12 +56,30 @@
// pfff :P
}
- updateStatusBar();
+ if (!dropNextRefresh)
+ updateStatusBar();
+ else
+ dropNextRefresh = false;
}
}
+
+ public void newLogLine(int level, Object src, String line) {
+ if (level <= 1) { /* error / warnings */
+ dropNextRefresh = true;
+
+ String str = Logger.PREFIXES[level]+" "
+ + ((src != null) ? (src.getClass().getName() +
": ") : "")
+ + line;
+
+ core.getMainWindow().setStatus(IconBox.minStop, str,
+ ((level == 0) ?
Color.RED : ORANGE));
+ }
+ }
+
+
public void updateStatusBar() {
if (core.isReconnecting()) {
@@ -135,7 +165,6 @@
+ Integer.toString(pending) + "/" +
Integer.toString(total);
core.getMainWindow().setStatus(IconBox.minConnectAction,
status);
-
}
Modified:
trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-25 19:38:51 UTC (rev 14350)
+++ trunk/apps/Thaw/src/thaw/plugins/miniFrost/frostKSK/KSKBoardFactory.java
2007-07-25 19:55:33 UTC (rev 14351)
@@ -252,7 +252,7 @@
ResultSet set = st.executeQuery();
if (set.next()) {
- Logger.notice(this, "Board already
added");
+ Logger.warning(this, "Board already
added");
return;
}