Author: jflesch
Date: 2006-07-19 01:56:31 +0000 (Wed, 19 Jul 2006)
New Revision: 9659
Added:
trunk/apps/Thaw/src/thaw/core/LogListener.java
trunk/apps/Thaw/src/thaw/plugins/Console.java
Modified:
trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
trunk/apps/Thaw/src/thaw/core/Logger.java
trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
Log:
Adding a console plugin
Modified: trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/ConfigWindow.java 2006-07-18 22:46:16 UTC
(rev 9658)
+++ trunk/apps/Thaw/src/thaw/core/ConfigWindow.java 2006-07-19 01:56:31 UTC
(rev 9659)
@@ -92,7 +92,16 @@
configWin.setVisible(v);
}
+ public boolean addTab(String name, java.awt.Component panel) {
+ tabs.add(name, panel);
+ return true;
+ }
+ public boolean removeTab(java.awt.Component panel) {
+ tabs.remove(panel);
+ return true;
+ }
+
/**
* Get a ref to the JFrame.
*/
Added: trunk/apps/Thaw/src/thaw/core/LogListener.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/LogListener.java 2006-07-18 22:46:16 UTC
(rev 9658)
+++ trunk/apps/Thaw/src/thaw/core/LogListener.java 2006-07-19 01:56:31 UTC
(rev 9659)
@@ -0,0 +1,8 @@
+package thaw.core;
+
+
+public interface LogListener {
+
+ public void newLogLine(String line);
+
+}
Modified: trunk/apps/Thaw/src/thaw/core/Logger.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Logger.java 2006-07-18 22:46:16 UTC (rev
9658)
+++ trunk/apps/Thaw/src/thaw/core/Logger.java 2006-07-19 01:56:31 UTC (rev
9659)
@@ -1,5 +1,7 @@
package thaw.core;
+import java.util.Vector;
+import java.util.Iterator;
/**
* Manage all log message.
@@ -21,13 +23,17 @@
*/
private final static int LOG_LEVEL = 5;
+ private static Vector logListeners = null;
+
protected static void displayErr(String msg) {
System.err.println(msg);
+ notifyLogListeners(msg);
}
protected static void display(String msg) {
System.out.println(msg);
+ notifyLogListeners(msg);
}
/**
@@ -79,15 +85,52 @@
* Verbose. Too Verbose.
*/
public static void verbose(Object o, String msg) {
- if(LOG_LEVEL >= 5)
+ if(LOG_LEVEL >= 5) {
System.out.println("[VERBOSE] "+
o.getClass().getName()+": "+msg);
+ notifyLogListeners(msg);
+ }
}
/**
* As it. Similar to verbose()
*/
public static void asIt(Object o, String msg) {
- if(LOG_LEVEL >= 5)
+ if(LOG_LEVEL >= 5) {
System.out.println(msg);
+ notifyLogListeners(msg);
+ }
}
+
+
+
+
+
+ public static void addLogListener(LogListener logListener) {
+ if(logListeners == null)
+ logListeners = new Vector();
+
+ logListeners.add(logListener);
+
+ }
+
+ public static void removeLogListener(LogListener logListener) {
+ if(logListeners == null)
+ return;
+
+ logListeners.remove(logListener);
+ }
+
+
+ private static void notifyLogListeners(String line) {
+ if(logListeners == null)
+ return;
+
+ for(Iterator it = logListeners.iterator();
+ it.hasNext(); ) {
+ LogListener logListener = (LogListener)it.next();
+
+ logListener.newLogLine(line);
+ }
+ }
+
}
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java 2006-07-18 22:46:16 UTC
(rev 9658)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPQueryManager.java 2006-07-19 01:56:31 UTC
(rev 9659)
@@ -102,7 +102,7 @@
while(true) {
latestMessage = readMessage();
- Logger.debug(this, "Message received. Notifying
observers");
+ Logger.verbose(this, "Message received. Notifying
observers");
if(latestMessage != null) {
try {
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-07-18 22:46:16 UTC
(rev 9658)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2006-07-19 01:56:31 UTC
(rev 9659)
@@ -115,6 +115,10 @@
thaw.plugin.fetch.chooseDestination=Choose destination ...
thaw.plugin.fetch.pasteFromClipboard=Paste from clipboard
+thaw.plugin.console.console=Console
+thaw.plugin.console.saveToFile=Save log to file
+thaw.plugin.console.maxSize=Maximum memory allocated to store log (in Bytes)
+
## Warnings
thaw.warning.title=Warning
thaw.warning.isWriting=Warning ! Thaw is sending data to the node. It would be
better to quit when thaw will finish. Are you sure you want to quit ?
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-07-18 22:46:16 UTC
(rev 9658)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2006-07-19 01:56:31 UTC
(rev 9659)
@@ -114,6 +114,9 @@
thaw.plugin.fetch.chooseDestination=Choisissez la destination ...
thaw.plugin.fetch.pasteFromClipboard=Coller depuis le presse-papier
+thaw.plugin.console.console=Console
+thaw.plugin.console.saveToFile=Sauvegarder les logs dans un fichier
+thaw.plugin.console.maxSize=Taille m?moire maximum utilis?e pour m?moriser les
logs (en octets)
## Warnings
thaw.warning.title=Avertissement
Added: trunk/apps/Thaw/src/thaw/plugins/Console.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-07-18 22:46:16 UTC
(rev 9658)
+++ trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-07-19 01:56:31 UTC
(rev 9659)
@@ -0,0 +1,157 @@
+package thaw.plugins;
+
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import javax.swing.JFileChooser;
+
+import java.io.File;
+import java.io.FileOutputStream;
+
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import thaw.i18n.I18n;
+import thaw.core.*;
+
+
+/**
+ * Quick and dirty console showing Thaw logs, and allowing to save them.
+ */
+public class Console implements Plugin, LogListener, ActionListener {
+ private Core core;
+
+ private JPanel consolePanel;
+ private JTextArea logArea;
+ private JButton saveToFile;
+
+ private JPanel configPanel;
+ private JLabel sizeLabel;
+ private JTextField sizeField;
+
+ private long maxLogSize = 25600;
+
+ public boolean run(Core core) {
+ this.core = core;
+
+ consolePanel = new JPanel();
+ consolePanel.setLayout(new BorderLayout());
+
+ logArea = new JTextArea();
+ logArea.setEditable(false);
+ saveToFile = new
JButton(I18n.getMessage("thaw.plugin.console.saveToFile"));
+
+ saveToFile.addActionListener(this);
+
+ consolePanel.add(new JScrollPane(logArea), BorderLayout.CENTER);
+ consolePanel.add(saveToFile, BorderLayout.SOUTH);
+
+
core.getMainWindow().addTab(I18n.getMessage("thaw.plugin.console.console"),
consolePanel);
+
+ if(core.getConfig().getValue("consoleMaxLogSize") == null)
+ core.getConfig().setValue("consoleMaxLogSize", ((new
Long(maxLogSize)).toString()) );
+ else {
+ try {
+ maxLogSize = (new
Long(core.getConfig().getValue("consoleMaxLogSize"))).longValue();
+ } catch(Exception e) {
+ Logger.notice(this, "Invalide size given in
configuration ! Using default one.");
+ core.getConfig().setValue("consoleMaxLogSize",
(new Long(maxLogSize)).toString());
+ }
+ }
+
+ configPanel = new JPanel();
+ configPanel.setLayout(new GridLayout(15, 1));
+
+ sizeLabel = new
JLabel(I18n.getMessage("thaw.plugin.console.maxSize"));
+ sizeField = new
JTextField(core.getConfig().getValue("consoleMaxLogSize"));
+
+ configPanel.add(sizeLabel);
+ configPanel.add(sizeField);
+
+
core.getConfigWindow().addTab(I18n.getMessage("thaw.plugin.console.console"),
configPanel);
+
+ Logger.addLogListener(this);
+
+ return true;
+
+ }
+
+
+ public boolean stop() {
+ core.getConfig().setValue("consoleMaxLogSize",
sizeField.getText() );
+
+ core.getConfigWindow().removeTab(configPanel);
+ core.getMainWindow().removeTab(consolePanel);
+ return true;
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+ if(e.getSource() == saveToFile) {
+ FileChooser fileChooser = new FileChooser();
+
+
fileChooser.setTitle(I18n.getMessage("thaw.plugin.console.console"));
+ fileChooser.setDirectoryOnly(false);
+ fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
+
+ File file = fileChooser.askOneFile();
+
+ if(file != null) {
+ Logger.info(this, "Saving logs ...");
+ writeLogsToFile(file);
+ Logger.info(this, "Saving done.");
+ }
+
+ }
+
+ }
+
+ public void writeLogsToFile(File file) {
+ /* A la bourrin */
+
+ FileOutputStream output;
+
+ try {
+ output = new FileOutputStream(file);
+ } catch(java.io.FileNotFoundException e) {
+ Logger.error(this, "FileNotFoundException ? wtf ?");
+ return;
+ }
+
+ try {
+ output.write(logArea.getText().getBytes());
+ } catch(java.io.IOException e) {
+ Logger.error(this, "IOException while writing logs ...
out of space ?");
+ return;
+ }
+
+ try {
+ output.close();
+ } catch(java.io.IOException e) {
+ Logger.error(this, "IOException while closing log file
?!");
+ return;
+ }
+ }
+
+ public void newLogLine(String line) {
+ String text = logArea.getText() + "\n" + line;
+
+ if(text.length() > maxLogSize) {
+ text = text.substring((int)(text.length() -
maxLogSize));
+ }
+
+ logArea.setText(text);
+ }
+
+
+ public String getNameForUser() {
+ return I18n.getMessage("thaw.plugin.console.console");
+ }
+
+
+}
Modified: trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2006-07-18 22:46:16 UTC (rev 9658)
+++ trunk/apps/Thaw/src/thaw/plugins/queueWatcher/QueuePanel.java
2006-07-19 01:56:31 UTC (rev 9659)
@@ -191,6 +191,9 @@
FCPTransferQuery query = model.getQuery(row);
+ if(query == null)
+ return null;
+
if(!query.isRunning() && !query.isFinished())
cell.setBackground(PENDING);
if(query.isFinished() && query.isSuccessful())