Added basic logging handler that logs to the LogPanel on the client.
This commit is contained in:
Fabian Becker 2012-04-14 16:46:50 +00:00
parent b8ca6891d2
commit af1fae181e
3 changed files with 106 additions and 88 deletions

View File

@ -1,11 +1,15 @@
package eva2.client; package eva2.client;
/* /*
* Title: EvA2 Description: The main client class of the EvA framework. * Title: EvA2
* Copyright: Copyright (c) 2008 Company: University of Tuebingen, Computer * Description: The main client class of the EvA framework.
* Architecture @author Holger Ulmer, Felix Streichert, Hannes Planatscher * Copyright: Copyright (c) 2008
* @version: $Revision: 322 $ $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec * Company: University of Tuebingen, Computer
* 2007) $ $Author: mkron $ * Architecture
*
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 322 $ $Date: 2007-12-11 17:24:07 +0100 (Tue, 11 Dec 2007)$
* $Author: mkron $
*/ */
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
@ -24,6 +28,7 @@ import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
import java.util.logging.*;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JComponent; import javax.swing.JComponent;
@ -44,7 +49,6 @@ import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener; import javax.swing.event.MenuListener;
import eva2.EvAInfo; import eva2.EvAInfo;
import eva2.gui.BeanInspector;
import eva2.gui.EvATabbedFrameMaker; import eva2.gui.EvATabbedFrameMaker;
import eva2.gui.EvATreeNode; import eva2.gui.EvATreeNode;
import eva2.gui.EvATreeSelectionListener; import eva2.gui.EvATreeSelectionListener;
@ -66,7 +70,6 @@ import eva2.server.stat.InterfaceStatisticsListener;
import eva2.server.stat.InterfaceStatisticsParameter; import eva2.server.stat.InterfaceStatisticsParameter;
import eva2.tools.BasicResourceLoader; import eva2.tools.BasicResourceLoader;
import eva2.tools.EVAERROR; import eva2.tools.EVAERROR;
import eva2.tools.EVAHELP;
import eva2.tools.ReflectPackage; import eva2.tools.ReflectPackage;
import eva2.tools.Serializer; import eva2.tools.Serializer;
import eva2.tools.StringTools; import eva2.tools.StringTools;
@ -84,7 +87,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
private final int splashScreenTime = 1500; private final int splashScreenTime = 1500;
private final int maxWindowMenuLength = 30; private final int maxWindowMenuLength = 30;
private boolean clientInited = false; private boolean clientInited = false;
public JEFrame m_Frame; private JEFrame evaFrame;
private Runnable initRnbl = null; private Runnable initRnbl = null;
private EvAComAdapter m_ComAdapter; private EvAComAdapter m_ComAdapter;
private transient JMenuBar m_barMenu; private transient JMenuBar m_barMenu;
@ -94,9 +97,9 @@ public class EvAClient implements RemoteStateListener, Serializable {
private transient JExtMenu m_mnuWindow; private transient JExtMenu m_mnuWindow;
private transient JExtMenu m_mnuOptions; private transient JExtMenu m_mnuOptions;
private transient JProgressBar m_ProgressBar; private transient JProgressBar m_ProgressBar;
// public ArrayList m_ModulGUIContainer = new ArrayList();
// LogPanel // LogPanel
private LogPanel m_LogPanel; private LogPanel logPanel;
private Logger logger;
// Module: // Module:
private ExtAction m_actModuleLoad; private ExtAction m_actModuleLoad;
// GUI: // GUI:
@ -358,8 +361,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
* @param l * @param l
*/ */
public void addWindowListener(WindowListener l) { public void addWindowListener(WindowListener l) {
if (m_Frame != null) { if (evaFrame != null) {
m_Frame.addWindowListener(l); evaFrame.addWindowListener(l);
} else { } else {
System.err.println("Error, no JFrame existent in " System.err.println("Error, no JFrame existent in "
+ this.getClass().getSimpleName()); + this.getClass().getSimpleName());
@ -372,8 +375,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
* @param l * @param l
*/ */
public void removeWindowListener(WindowListener l) { public void removeWindowListener(WindowListener l) {
if (m_Frame != null) { if (evaFrame != null) {
m_Frame.removeWindowListener(l); evaFrame.removeWindowListener(l);
} else { } else {
System.err.println("Error, no JFrame existent in " System.err.println("Error, no JFrame existent in "
+ this.getClass().getSimpleName()); + this.getClass().getSimpleName());
@ -385,7 +388,6 @@ public class EvAClient implements RemoteStateListener, Serializable {
* null. * null.
*/ */
private void init(String hostName, String paramsFile, InterfaceGOParameters goParams, final Window parent) { private void init(String hostName, String paramsFile, InterfaceGOParameters goParams, final Window parent) {
//EVA_EDITOR_PROPERTIES
useDefaultModule = EvAInfo.propDefaultModule(); useDefaultModule = EvAInfo.propDefaultModule();
if (useDefaultModule != null) { if (useDefaultModule != null) {
@ -396,14 +398,13 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
if (withGUI) { if (withGUI) {
m_Frame = new JEFrame(EvAInfo.productName + " workbench"); evaFrame = new JEFrame(EvAInfo.productName + " workbench");
m_Frame.setCloseAllOnClosed(true); evaFrame.setCloseAllOnClosed(true);
m_Frame.setName(this.getClass().getSimpleName()); // the name is set to recognize the client window evaFrame.setName(this.getClass().getSimpleName()); // the name is set to recognize the client window
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); evaFrame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
// m_Frame.setTitle(EvAInfo.productName + " workbench");
try { try {
Thread.sleep(200); Thread.sleep(200);
@ -411,11 +412,40 @@ public class EvAClient implements RemoteStateListener, Serializable {
System.out.println("Error" + e.getMessage()); System.out.println("Error" + e.getMessage());
} }
m_Frame.getContentPane().setLayout(new BorderLayout()); evaFrame.getContentPane().setLayout(new BorderLayout());
m_LogPanel = new LogPanel(); logPanel = new LogPanel();
m_Frame.getContentPane().add(m_LogPanel, BorderLayout.CENTER); evaFrame.getContentPane().add(logPanel, BorderLayout.CENTER);
logger = Logger.getLogger("EvAClient");
logger.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("[");
sBuilder.append(record.getLevel().toString());
sBuilder.append("] ");
sBuilder.append(record.getMessage());
EvAClient.this.logPanel.logMessage(sBuilder.toString());
}
@Override
public void flush() {
/* We do nothing here as we don't buffer the entries */
}
@Override
public void close() throws SecurityException {
/* Nothing to close */
}
});
logger.info("EvAClient Loggin enabled");
logger.warning("Logging could still die.");
m_ProgressBar = new JProgressBar(); m_ProgressBar = new JProgressBar();
m_Frame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH); evaFrame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH);
if (EvAInfo.propShowModules() != null) { if (EvAInfo.propShowModules() != null) {
showLoadModules = true; showLoadModules = true;
@ -435,11 +465,11 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (withGUI) { if (withGUI) {
buildMenu(); buildMenu();
m_Frame.addWindowListener(new WindowAdapter() { evaFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
System.out.println("Closing EvA2 Client. Bye!"); System.out.println("Closing EvA2 Client. Bye!");
m_Frame.dispose(); evaFrame.dispose();
Set<String> keys = System.getenv().keySet(); Set<String> keys = System.getenv().keySet();
if (keys.contains("MATLAB")) { if (keys.contains("MATLAB")) {
System.out.println("Seems like Ive been started from Matlab: not killing JVM"); System.out.println("Seems like Ive been started from Matlab: not killing JVM");
@ -456,23 +486,23 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (hostName != null) { if (hostName != null) {
selectHost(hostName); selectHost(hostName);
} }
m_ComAdapter.setLogPanel(m_LogPanel); m_ComAdapter.setLogPanel(logPanel);
logMessage("Selected Host: " + m_ComAdapter.getHostName()); logMessage("Selected Host: " + m_ComAdapter.getHostName());
} }
// m_mnuModule.setText("Select module"); // m_mnuModule.setText("Select module");
// m_mnuModule.repaint(); // m_mnuModule.repaint();
if (withGUI) { if (withGUI) {
m_LogPanel.logMessage("Working directory is: " + System.getProperty("user.dir")); logPanel.logMessage("Working directory is: " + System.getProperty("user.dir"));
m_LogPanel.logMessage("Class path is: " + System.getProperty("java.class.path", ".")); logPanel.logMessage("Class path is: " + System.getProperty("java.class.path", "."));
if (!(m_Frame.isVisible())) { if (!(evaFrame.isVisible())) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
m_Frame.setLocation((int) ((screenSize.width - m_Frame.getWidth()) / 2), (int) ((screenSize.height - m_Frame.getHeight()) / 2.5)); evaFrame.setLocation((int) ((screenSize.width - evaFrame.getWidth()) / 2), (int) ((screenSize.height - evaFrame.getHeight()) / 2.5));
m_Frame.pack(); evaFrame.pack();
m_Frame.setVisible(true); evaFrame.setVisible(true);
} }
m_LogPanel.logMessage("EvA2 ready"); // if this message is omitted, the stupid scroll pane runs to the end of the last line which is ugly for a long class path logPanel.logMessage("EvA2 ready"); // if this message is omitted, the stupid scroll pane runs to the end of the last line which is ugly for a long class path
} }
} }
@ -678,7 +708,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
private void buildMenu() { private void buildMenu() {
m_barMenu = new JMenuBar(); m_barMenu = new JMenuBar();
m_Frame.setJMenuBar(m_barMenu); evaFrame.setJMenuBar(m_barMenu);
m_mnuModule = new JExtMenu("&Module"); m_mnuModule = new JExtMenu("&Module");
m_mnuModule.add(m_actModuleLoad); m_mnuModule.add(m_actModuleLoad);
@ -778,8 +808,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
protected void logMessage(String msg) { protected void logMessage(String msg) {
if (m_LogPanel != null) { if (logPanel != null) {
m_LogPanel.logMessage(msg); logPanel.logMessage(msg);
} }
} }
@ -810,13 +840,13 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (selectedModule == null) { // show a dialog and ask for a module if (selectedModule == null) { // show a dialog and ask for a module
String[] ModuleNameList = m_ComAdapter.getModuleNameList(); String[] ModuleNameList = m_ComAdapter.getModuleNameList();
if (ModuleNameList == null) { if (ModuleNameList == null) {
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No modules available on " + m_ComAdapter.getHostName(), EvAInfo.infoTitle, 1); JOptionPane.showMessageDialog(evaFrame.getContentPane(), "No modules available on " + m_ComAdapter.getHostName(), EvAInfo.infoTitle, 1);
} else { } else {
String LastModuleName = Serializer.loadString("lastmodule.ser"); String LastModuleName = Serializer.loadString("lastmodule.ser");
if (LastModuleName == null) { if (LastModuleName == null) {
LastModuleName = ModuleNameList[0]; LastModuleName = ModuleNameList[0];
} }
selectedModule = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), selectedModule = (String) JOptionPane.showInputDialog(evaFrame.getContentPane(),
"Which module do you want \n to load on host: " + m_ComAdapter.getHostName() + " ?", "Load optimization module on host", "Which module do you want \n to load on host: " + m_ComAdapter.getHostName() + " ?", "Load optimization module on host",
JOptionPane.QUESTION_MESSAGE, JOptionPane.QUESTION_MESSAGE,
null, null,
@ -919,29 +949,29 @@ public class EvAClient implements RemoteStateListener, Serializable {
// newModuleAdapter.setLogPanel(m_LogPanel); // newModuleAdapter.setLogPanel(m_LogPanel);
JPanel moduleContainer = frameMaker.makePanel(); // MK the main frame is actually painted in here JPanel moduleContainer = frameMaker.makePanel(); // MK the main frame is actually painted in here
boolean wasVisible = m_Frame.isVisible(); boolean wasVisible = evaFrame.isVisible();
m_Frame.setVisible(false); evaFrame.setVisible(false);
m_Frame.getContentPane().removeAll(); evaFrame.getContentPane().removeAll();
// nested info-panel so that we can stay with simple borderlayouts // nested info-panel so that we can stay with simple borderlayouts
JPanel infoPanel = new JPanel(); JPanel infoPanel = new JPanel();
infoPanel.setLayout(new BorderLayout()); infoPanel.setLayout(new BorderLayout());
infoPanel.add(m_ProgressBar, BorderLayout.SOUTH); infoPanel.add(m_ProgressBar, BorderLayout.SOUTH);
infoPanel.add(m_LogPanel, BorderLayout.NORTH); infoPanel.add(logPanel, BorderLayout.NORTH);
JComponent tree = null; JComponent tree = null;
if (withTreeView && (newModuleAdapter instanceof AbstractModuleAdapter)) { if (withTreeView && (newModuleAdapter instanceof AbstractModuleAdapter)) {
tree = getEvATreeView(frameMaker.getGOPanel(), "GOParameters", ((AbstractModuleAdapter) newModuleAdapter).getGOParameters()); tree = getEvATreeView(frameMaker.getGOPanel(), "GOParameters", ((AbstractModuleAdapter) newModuleAdapter).getGOParameters());
m_Frame.add(tree, BorderLayout.WEST); evaFrame.add(tree, BorderLayout.WEST);
} }
m_Frame.add(frameMaker.getToolBar(), BorderLayout.NORTH); evaFrame.add(frameMaker.getToolBar(), BorderLayout.NORTH);
m_Frame.add(moduleContainer, BorderLayout.CENTER); evaFrame.add(moduleContainer, BorderLayout.CENTER);
//m_Frame.add(m_ProgressBar, BorderLayout.CENTER); //m_Frame.add(m_ProgressBar, BorderLayout.CENTER);
//m_Frame.add(m_LogPanel, BorderLayout.SOUTH); //m_Frame.add(m_LogPanel, BorderLayout.SOUTH);
m_Frame.add(infoPanel, BorderLayout.SOUTH); evaFrame.add(infoPanel, BorderLayout.SOUTH);
m_Frame.pack(); evaFrame.pack();
m_Frame.setVisible(wasVisible); evaFrame.setVisible(wasVisible);
} }
currentModule = selectedModule; currentModule = selectedModule;
@ -995,7 +1025,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (HostNames == null || HostNames.length == 0) { if (HostNames == null || HostNames.length == 0) {
showNoHostFoundDialog(); showNoHostFoundDialog();
} else { } else {
String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), String HostName = (String) JOptionPane.showInputDialog(evaFrame.getContentPane(),
"Which active host do you want to connect to?", "Host", JOptionPane.QUESTION_MESSAGE, null, "Which active host do you want to connect to?", "Host", JOptionPane.QUESTION_MESSAGE, null,
HostNames, m_ComAdapter.getHostName()); HostNames, m_ComAdapter.getHostName());
if (HostName != null) { if (HostName != null) {
@ -1014,11 +1044,11 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
private void showPleaseWaitDialog() { private void showPleaseWaitDialog() {
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "Please wait one moment.", EvAInfo.infoTitle, 1); JOptionPane.showMessageDialog(evaFrame.getContentPane(), "Please wait one moment.", EvAInfo.infoTitle, 1);
} }
private void showAboutDialog() { private void showAboutDialog() {
JOptionPane.showMessageDialog(m_Frame, JOptionPane.showMessageDialog(evaFrame,
EvAInfo.productName + " - " + EvAInfo.productLongName EvAInfo.productName + " - " + EvAInfo.productLongName
+ "\nUniversity of Tuebingen, T\u00FCbingen, Germany\nChair for Cognitive Systems\n" + "\nUniversity of Tuebingen, T\u00FCbingen, Germany\nChair for Cognitive Systems\n"
+ "Dr. M. Kronfeld, H. Planatscher, M. de Paly, Dr. A. Dr\u00E4ger,\n" + "Dr. M. Kronfeld, H. Planatscher, M. de Paly, Dr. A. Dr\u00E4ger,\n"
@ -1035,7 +1065,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
private void showNoHostFoundDialog() { private void showNoHostFoundDialog() {
JOptionPane.showMessageDialog(m_Frame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", EvAInfo.infoTitle, 1); JOptionPane.showMessageDialog(evaFrame.getContentPane(), "No host with running EVASERVER found. Please start one or \nadd the correct address to the properties list.", EvAInfo.infoTitle, 1);
} }
private void selectAvailableHostToKill(String[] HostNames) { private void selectAvailableHostToKill(String[] HostNames) {
@ -1043,7 +1073,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
showNoHostFoundDialog(); showNoHostFoundDialog();
return; return;
} }
String HostName = (String) JOptionPane.showInputDialog(m_Frame.getContentPane(), String HostName = (String) JOptionPane.showInputDialog(evaFrame.getContentPane(),
"Which server do you want to be killed ?", "Host", JOptionPane.QUESTION_MESSAGE, null, "Which server do you want to be killed ?", "Host", JOptionPane.QUESTION_MESSAGE, null,
HostNames, m_ComAdapter.getHostName()); HostNames, m_ComAdapter.getHostName());
if (HostName == null) { if (HostName == null) {

View File

@ -49,11 +49,11 @@ public class EvAModuleButtonPanelMaker implements RemoteStateListener, Serializa
/** /**
* *
*/ */
public EvAModuleButtonPanelMaker(ModuleAdapter Adapter, boolean state) { public EvAModuleButtonPanelMaker(ModuleAdapter adapter, boolean state) {
m_Name = "GENERAL"; m_Name = "GENERAL";
m_StateRunning = state; m_StateRunning = state;
if (TRACE) System.out.println("Constructor EvAModuleButtonPanelMaker:"); if (TRACE) System.out.println("Constructor EvAModuleButtonPanelMaker:");
m_Adapter = Adapter; m_Adapter = adapter;
} }
public JComponent makePanel() { public JComponent makePanel() {

View File

@ -9,9 +9,6 @@ package eva2.gui;
* $Date: 2007-10-23 12:56:51 +0200 (Tue, 23 Oct 2007) $ * $Date: 2007-10-23 12:56:51 +0200 (Tue, 23 Oct 2007) $
* $Author: mkron $ * $Author: mkron $
*/ */
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Point; import java.awt.Point;
import java.awt.Toolkit; import java.awt.Toolkit;
@ -31,46 +28,41 @@ import javax.swing.event.ChangeListener;
import eva2.EvAInfo; import eva2.EvAInfo;
import eva2.tools.BasicResourceLoader; import eva2.tools.BasicResourceLoader;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
/** /**
* *
*/ */
public class LogPanel extends JPanel { public class LogPanel extends JPanel {
// protected JLabel m_Message = new JLabel("OK"); // protected JLabel m_Message = new JLabel("OK");
protected JTextArea m_LogText = new JTextArea(10,20); protected JTextArea loggingTextArea = new JTextArea(10,20);
protected boolean m_first = true; protected boolean m_first = true;
/** /**
* *
*/ */
public LogPanel() { public LogPanel() {
m_LogText.setEditable(false); loggingTextArea.setEditable(false);
m_LogText.setBorder(BorderFactory.createEmptyBorder(4,4,4,4)); loggingTextArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
// m_Message.setBorder(BorderFactory.createCompoundBorder(
// BorderFactory.createTitledBorder("Message"), JPanel mainPanel = new JPanel();
// BorderFactory.createEmptyBorder(0,4,4,4))); mainPanel.setBorder(BorderFactory.createTitledBorder("Info"));
JPanel panel_1 = new JPanel(); mainPanel.setLayout(new BorderLayout());
panel_1.setBorder(BorderFactory.createTitledBorder("Info")); final JScrollPane scrollpane = new JScrollPane(loggingTextArea);
panel_1.setLayout(new BorderLayout());
final JScrollPane scrollpane = new JScrollPane(m_LogText);
// scrollpane.setAutoscrolls(false); // scrollpane.setAutoscrolls(false);
panel_1.add(scrollpane, BorderLayout.CENTER); mainPanel.add(scrollpane, BorderLayout.CENTER);
scrollpane.getViewport().addChangeListener(new ChangeListener() { scrollpane.getViewport().addChangeListener(new ChangeListener() {
private int lastHeight; private int lastHeight;
// //
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
JViewport viewport = (JViewport)e.getSource(); JViewport viewport = (JViewport)e.getSource();
int Height = viewport.getViewSize().height; int height = viewport.getViewSize().height;
if (Height != lastHeight) { if (height != lastHeight) {
lastHeight = Height; lastHeight = height;
int x = Height - viewport.getExtentSize().height; int x = height - viewport.getExtentSize().height;
viewport.setViewPosition(new Point(0, x)); viewport.setViewPosition(new Point(0, x));
} }
} }
}); });
setLayout(new BorderLayout()); setLayout(new BorderLayout());
add(panel_1, BorderLayout.CENTER); add(mainPanel, BorderLayout.CENTER);
JPanel panel_2 = new JPanel(); JPanel panel_2 = new JPanel();
panel_2.setLayout(new BorderLayout()); panel_2.setLayout(new BorderLayout());
// panel_2.add(m_Message,BorderLayout.CENTER); // panel_2.add(m_Message,BorderLayout.CENTER);
@ -88,15 +80,11 @@ public class LogPanel extends JPanel {
public void logMessage(String message) { public void logMessage(String message) {
if (m_first) if (m_first)
m_first = false; m_first = false;
m_LogText.append("\n"); loggingTextArea.append("\n");
m_LogText.append(LogPanel.getTimestamp() + ' ' + message); loggingTextArea.append(LogPanel.getTimestamp() + ' ' + message);
} }
// /**
// *
// */
// public void statusMessage(String message) {
// m_Message.setText(message);
// }
/** /**
* *
*/ */