fixes #9

GOE does now log all messages using internal logging.
EvAClient log handler has been fixed.
This commit is contained in:
Fabian Becker 2012-04-17 14:40:41 +00:00
parent 7f373e99ca
commit c62db5f36f
2 changed files with 199 additions and 204 deletions

View File

@ -15,6 +15,7 @@ import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Event; import java.awt.Event;
import java.awt.Frame; import java.awt.Frame;
import java.awt.Graphics;
import java.awt.HeadlessException; import java.awt.HeadlessException;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Window; import java.awt.Window;
@ -24,12 +25,19 @@ import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.awt.event.WindowListener; import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Serializable; import java.io.Serializable;
import java.net.URL; import java.net.URL;
import java.text.MessageFormat;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
import java.util.logging.*; import java.util.logging.*;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -89,36 +97,39 @@ public class EvAClient implements RemoteStateListener, Serializable {
private boolean clientInited = false; private boolean clientInited = false;
private JEFrame evaFrame; private JEFrame evaFrame;
private Runnable initRnbl = null; private Runnable initRnbl = null;
private EvAComAdapter m_ComAdapter;
private transient JMenuBar m_barMenu; private EvAComAdapter comAdapter;
private transient JExtMenu m_mnuAbout; private transient JMenuBar menuBar;
private transient JExtMenu m_mnuSelHosts; private transient JExtMenu menuAbout;
private transient JExtMenu m_mnuModule; private transient JExtMenu menuSelHosts;
private transient JExtMenu m_mnuWindow; private transient JExtMenu menuModule;
private transient JExtMenu m_mnuOptions; private transient JExtMenu menuWindow;
private transient JProgressBar m_ProgressBar; private transient JExtMenu menuOptions;
private transient JProgressBar progressBar;
// LogPanel // LogPanel
private LogPanel logPanel; private LogPanel logPanel;
private static final Logger logger = Logger.getLogger("EvAClient"); private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
// Module: // Module:
private ExtAction m_actModuleLoad; private ExtAction actModuleLoad;
// GUI:
// Hosts: // Hosts:
private ExtAction m_actHost;
private ExtAction m_actAvailableHost; private ExtAction actHost;
private ExtAction m_actKillHost; private ExtAction actAvailableHost;
private ExtAction m_actKillAllHosts; private ExtAction actKillHost;
private ExtAction actKillAllHosts;
private ModuleAdapter currentModuleAdapter = null; private ModuleAdapter currentModuleAdapter = null;
// About: // About:
private ExtAction m_actAbout; private ExtAction actAbout;
private ExtAction m_actLicense; private ExtAction actLicense;
// private JPanel m_panelTool;
// private FrameCloseListener m_frameCloseListener; // if not null, the module is loaded automatically and no other can be selected
// private JFileChooser m_FileChooser; private String useDefaultModule = null; //"Genetic_Optimization";
// if not null, the module is loaded automatically and no other can be selected
private String useDefaultModule = null;//"Genetic_Optimization";
private boolean showLoadModules = false; private boolean showLoadModules = false;
private boolean localMode = false; private boolean localMode = false;
// This variable says whether, if running locally, a local server should be addressed by RMI. // This variable says whether, if running locally, a local server should be addressed by RMI.
// False should be preferred here to avoid overhead // False should be preferred here to avoid overhead
private boolean useLocalRMI = false; private boolean useLocalRMI = false;
@ -273,7 +284,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
currentModule = null; currentModule = null;
m_ComAdapter = EvAComAdapter.getInstance(); comAdapter = EvAComAdapter.getInstance();
SwingUtilities.invokeLater(initRnbl = new Runnable() { SwingUtilities.invokeLater(initRnbl = new Runnable() {
@ -426,7 +437,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
sBuilder.append("["); sBuilder.append("[");
sBuilder.append(record.getLevel().toString()); sBuilder.append(record.getLevel().toString());
sBuilder.append("] "); sBuilder.append("] ");
sBuilder.append(record.getMessage()); MessageFormat messageFormat = new MessageFormat(record.getMessage());
sBuilder.append(messageFormat.format(record.getParameters()));
// Show message on LogPanel // Show message on LogPanel
EvAClient.this.logPanel.logMessage(sBuilder.toString()); EvAClient.this.logPanel.logMessage(sBuilder.toString());
} }
@ -443,8 +455,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
}); });
m_ProgressBar = new JProgressBar(); progressBar = new JProgressBar();
evaFrame.getContentPane().add(m_ProgressBar, BorderLayout.SOUTH); evaFrame.getContentPane().add(progressBar, BorderLayout.SOUTH);
if (EvAInfo.propShowModules() != null) { if (EvAInfo.propShowModules() != null) {
showLoadModules = true; showLoadModules = true;
@ -481,12 +493,12 @@ public class EvAClient implements RemoteStateListener, Serializable {
}); });
} }
if (m_ComAdapter != null) { if (comAdapter != null) {
if (hostName != null) { if (hostName != null) {
selectHost(hostName); selectHost(hostName);
} }
m_ComAdapter.setLogPanel(logPanel); comAdapter.setLogPanel(logPanel);
logger.log(Level.INFO, "Selected Host: {0}", m_ComAdapter.getHostName()); logger.log(Level.INFO, "Selected Host: {0}", comAdapter.getHostName());
} }
// m_mnuModule.setText("Select module"); // m_mnuModule.setText("Select module");
// m_mnuModule.repaint(); // m_mnuModule.repaint();
@ -621,7 +633,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// Module: // Module:
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
m_actModuleLoad = new ExtAction("&Load", "Load Module", actModuleLoad = new ExtAction("&Load", "Load Module",
KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -632,7 +644,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
}; };
m_actAbout = new ExtAction("&About...", "Product Information", actAbout = new ExtAction("&About...", "Product Information",
KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -643,7 +655,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
showAboutDialog(); showAboutDialog();
} }
}; };
m_actLicense = new ExtAction("&License...", "View License", actLicense = new ExtAction("&License...", "View License",
KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -654,7 +666,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
showLicense(); showLicense();
} }
}; };
m_actHost = new ExtAction("&List of all servers", "All servers in list", actHost = new ExtAction("&List of all servers", "All servers in list",
KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -662,10 +674,10 @@ public class EvAClient implements RemoteStateListener, Serializable {
*/ */
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
logger.info(e.getActionCommand()); logger.info(e.getActionCommand());
selectAvailableHost(m_ComAdapter.getHostNameList()); selectAvailableHost(comAdapter.getHostNameList());
} }
}; };
m_actAvailableHost = new ExtAction("Available &Server", "Available server", actAvailableHost = new ExtAction("Available &Server", "Available server",
KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -678,13 +690,13 @@ public class EvAClient implements RemoteStateListener, Serializable {
@Override @Override
public void run() { public void run() {
selectAvailableHost(m_ComAdapter.getAvailableHostNameList()); selectAvailableHost(comAdapter.getAvailableHostNameList());
} }
}; };
xx.start(); xx.start();
} }
}; };
m_actKillHost = new ExtAction("&Kill server", "Kill server process on selected host", actKillHost = new ExtAction("&Kill server", "Kill server process on selected host",
KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -696,13 +708,13 @@ public class EvAClient implements RemoteStateListener, Serializable {
Thread xx = new Thread() { Thread xx = new Thread() {
public void run() { public void run() {
selectAvailableHostToKill(m_ComAdapter.getAvailableHostNameList()); selectAvailableHostToKill(comAdapter.getAvailableHostNameList());
} }
}; };
xx.start(); xx.start();
} }
}; };
m_actKillAllHosts = new ExtAction("Kill &all servers", "Kill all servers", actKillAllHosts = new ExtAction("Kill &all servers", "Kill all servers",
KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) { KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK)) {
/* (non-Javadoc) /* (non-Javadoc)
@ -714,7 +726,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
Thread xx = new Thread() { Thread xx = new Thread() {
public void run() { public void run() {
selectAllAvailableHostToKill(m_ComAdapter.getAvailableHostNameList()); selectAllAvailableHostToKill(comAdapter.getAvailableHostNameList());
} }
}; };
xx.start(); xx.start();
@ -730,20 +742,20 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
private void buildMenu() { private void buildMenu() {
m_barMenu = new JMenuBar(); menuBar = new JMenuBar();
evaFrame.setJMenuBar(m_barMenu); evaFrame.setJMenuBar(menuBar);
m_mnuModule = new JExtMenu("&Module"); menuModule = new JExtMenu("&Module");
m_mnuModule.add(m_actModuleLoad); menuModule.add(actModuleLoad);
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
m_mnuWindow = new JExtMenu("&Window"); menuWindow = new JExtMenu("&Window");
m_mnuWindow.addMenuListener(new MenuListener() { menuWindow.addMenuListener(new MenuListener() {
public void menuSelected(MenuEvent e) { public void menuSelected(MenuEvent e) {
// System.out.println("Selected"); // System.out.println("Selected");
m_mnuWindow.removeAll(); menuWindow.removeAll();
JExtMenu curMenu = m_mnuWindow; JExtMenu curMenu = menuWindow;
// JScrollPane jsp = new JScrollPane(); // JScrollPane jsp = new JScrollPane();
Object[] framelist = JEFrameRegister.getFrameList(); Object[] framelist = JEFrameRegister.getFrameList();
for (int i = 0; i < framelist.length; i++) { for (int i = 0; i < framelist.length; i++) {
@ -772,7 +784,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
String[] commonPrefixes = JEFrameRegister.getCommonPrefixes(10); String[] commonPrefixes = JEFrameRegister.getCommonPrefixes(10);
if (commonPrefixes.length > 0) { if (commonPrefixes.length > 0) {
m_mnuWindow.add(new JSeparator()); menuWindow.add(new JSeparator());
} }
for (int i = 0; i < commonPrefixes.length; i++) { for (int i = 0; i < commonPrefixes.length; i++) {
final String prefix = commonPrefixes[i]; final String prefix = commonPrefixes[i];
@ -783,7 +795,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
JEFrameRegister.closeAllByPrefix(prefix); JEFrameRegister.closeAllByPrefix(prefix);
} }
})); }));
m_mnuWindow.add(act); menuWindow.add(act);
} }
} }
@ -796,33 +808,33 @@ public class EvAClient implements RemoteStateListener, Serializable {
}); });
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
m_mnuSelHosts = new JExtMenu("&Select Hosts"); menuSelHosts = new JExtMenu("&Select Hosts");
m_mnuSelHosts.setToolTipText("Select a host for the server application"); menuSelHosts.setToolTipText("Select a host for the server application");
//if (EvAClient.LITE_VERSION == false) //if (EvAClient.LITE_VERSION == false)
m_mnuSelHosts.add(m_actHost); menuSelHosts.add(actHost);
m_mnuSelHosts.add(m_actAvailableHost); menuSelHosts.add(actAvailableHost);
m_mnuSelHosts.addSeparator(); menuSelHosts.addSeparator();
m_mnuSelHosts.add(m_actKillHost); menuSelHosts.add(actKillHost);
m_mnuSelHosts.add(m_actKillAllHosts); menuSelHosts.add(actKillAllHosts);
// m_mnuOptions.add(m_actStartServerManager); // m_mnuOptions.add(m_actStartServerManager);
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
m_mnuAbout = new JExtMenu("&About"); menuAbout = new JExtMenu("&About");
m_mnuAbout.add(m_actAbout); menuAbout.add(actAbout);
m_mnuAbout.add(m_actLicense); menuAbout.add(actLicense);
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// m_barMenu.add(m_Desktop.getWindowMenu()); // m_barMenu.add(m_Desktop.getWindowMenu());
m_mnuOptions = new JExtMenu("&Options"); menuOptions = new JExtMenu("&Options");
m_mnuOptions.add(m_mnuSelHosts); menuOptions.add(menuSelHosts);
//m_barMenu.add(m_mnuSelHosts); //m_barMenu.add(m_mnuSelHosts);
// this is accessible if no default module is given // this is accessible if no default module is given
if (showLoadModules) { if (showLoadModules) {
m_barMenu.add(m_mnuModule); menuBar.add(menuModule);
} }
m_barMenu.add(m_mnuOptions); menuBar.add(menuOptions);
m_barMenu.add(m_mnuWindow); menuBar.add(menuWindow);
m_barMenu.add(m_mnuAbout); menuBar.add(menuAbout);
} }
@ -840,37 +852,37 @@ public class EvAClient implements RemoteStateListener, Serializable {
* *
*/ */
private void loadModuleFromServer(String selectedModule, InterfaceGOParameters goParams) { private void loadModuleFromServer(String selectedModule, InterfaceGOParameters goParams) {
if (m_ComAdapter.getHostName() == null) { if (comAdapter.getHostName() == null) {
System.err.println("error in loadModuleFromServer!"); System.err.println("error in loadModuleFromServer!");
return; return;
} }
if (m_ComAdapter.getHostName().equals("localhost")) { if (comAdapter.getHostName().equals("localhost")) {
localMode = true; localMode = true;
if (useLocalRMI) { if (useLocalRMI) {
EvAServer Server = new EvAServer(true, false); EvAServer Server = new EvAServer(true, false);
m_ComAdapter.setLocalRMIServer(Server.getRMIServer()); comAdapter.setLocalRMIServer(Server.getRMIServer());
logger.info("Local EvAServer started"); logger.info("Local EvAServer started");
m_ComAdapter.setRunLocally(false); // this is not quite true but should have the desired effect comAdapter.setRunLocally(false); // this is not quite true but should have the desired effect
} else { } else {
logger.info("Working locally"); logger.info("Working locally");
m_ComAdapter.setLocalRMIServer(null); comAdapter.setLocalRMIServer(null);
m_ComAdapter.setRunLocally(true); comAdapter.setRunLocally(true);
} }
} else { } else {
localMode = false; localMode = false;
m_ComAdapter.setRunLocally(false); comAdapter.setRunLocally(false);
} }
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 = comAdapter.getModuleNameList();
if (ModuleNameList == null) { if (ModuleNameList == null) {
JOptionPane.showMessageDialog(evaFrame.getContentPane(), "No modules available on " + m_ComAdapter.getHostName(), EvAInfo.infoTitle, 1); JOptionPane.showMessageDialog(evaFrame.getContentPane(), "No modules available on " + 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(evaFrame.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: " + comAdapter.getHostName() + " ?", "Load optimization module on host",
JOptionPane.QUESTION_MESSAGE, JOptionPane.QUESTION_MESSAGE,
null, null,
ModuleNameList, ModuleNameList,
@ -885,8 +897,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
loadSpecificModule(selectedModule, goParams); loadSpecificModule(selectedModule, goParams);
if (withGUI) { if (withGUI) {
m_actHost.setEnabled(true); actHost.setEnabled(true);
m_actAvailableHost.setEnabled(true); actAvailableHost.setEnabled(true);
} }
logger.info("Selected Module: " + selectedModule); logger.info("Selected Module: " + selectedModule);
// m_LogPanel.statusMessage("Selected Module: " + selectedModule); // m_LogPanel.statusMessage("Selected Module: " + selectedModule);
@ -933,7 +945,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
ModuleAdapter newModuleAdapter = null; ModuleAdapter newModuleAdapter = null;
// //
try { try {
newModuleAdapter = m_ComAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2"); newModuleAdapter = comAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2");
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage(), e); logger.log(Level.SEVERE, "Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage(), e);
EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage()); EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage());
@ -953,14 +965,14 @@ public class EvAClient implements RemoteStateListener, Serializable {
System.err.println("adding base dir and trying again..."); System.err.println("adding base dir and trying again...");
System.setProperty("java.class.path", cp + System.getProperty("path.separator") + dir); System.setProperty("java.class.path", cp + System.getProperty("path.separator") + dir);
ReflectPackage.resetDynCP(); ReflectPackage.resetDynCP();
m_ComAdapter.updateLocalMainAdapter(); comAdapter.updateLocalMainAdapter();
loadSpecificModule(selectedModule, goParams); // end recursive call! handle with care! loadSpecificModule(selectedModule, goParams); // end recursive call! handle with care!
return; return;
} }
showLoadModules = true; showLoadModules = true;
} else { } else {
newModuleAdapter.setConnection(!localMode); newModuleAdapter.setConnection(!localMode);
if (m_ComAdapter.isRunLocally()) { if (comAdapter.isRunLocally()) {
// TODO in rmi-mode this doesnt work yet! meaning e.g. that theres no content in the info log // TODO in rmi-mode this doesnt work yet! meaning e.g. that theres no content in the info log
newModuleAdapter.addRemoteStateListener((RemoteStateListener) this); newModuleAdapter.addRemoteStateListener((RemoteStateListener) this);
} }
@ -978,7 +990,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
// 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(progressBar, BorderLayout.SOUTH);
infoPanel.add(logPanel, BorderLayout.NORTH); infoPanel.add(logPanel, BorderLayout.NORTH);
JComponent tree = null; JComponent tree = null;
@ -1048,7 +1060,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
} else { } else {
String hostName = (String) JOptionPane.showInputDialog(evaFrame.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, comAdapter.getHostName());
if (hostName != null) { if (hostName != null) {
selectHost(hostName); selectHost(hostName);
} }
@ -1056,7 +1068,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
private void selectHost(String hostName) { private void selectHost(String hostName) {
m_ComAdapter.setHostName(hostName); comAdapter.setHostName(hostName);
logger.info("Selected Host: " + hostName); logger.info("Selected Host: " + hostName);
if (currentModule != null) { if (currentModule != null) {
logger.info("Reloading module from server..."); logger.info("Reloading module from server...");
@ -1103,12 +1115,12 @@ public class EvAClient implements RemoteStateListener, Serializable {
} }
String HostName = (String) JOptionPane.showInputDialog(evaFrame.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, comAdapter.getHostName());
if (HostName == null) { if (HostName == null) {
return; return;
} }
logger.info("Kill host process on = " + HostName); logger.info("Kill host process on = " + HostName);
m_ComAdapter.killServer(HostName); comAdapter.killServer(HostName);
// m_LogPanel.statusMessage(""); // m_LogPanel.statusMessage("");
} }
@ -1118,7 +1130,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
System.out.println("no host is running"); System.out.println("no host is running");
return; return;
} }
m_ComAdapter.killAllServers(); comAdapter.killAllServers();
} }
public void performedRestart(String infoString) { public void performedRestart(String infoString) {
@ -1168,11 +1180,11 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (msg != null) { if (msg != null) {
logger.info(msg); logger.info(msg);
} }
if (this.m_ProgressBar != null) { if (this.progressBar != null) {
Runnable doSetProgressBarValue = new Runnable() { Runnable doSetProgressBarValue = new Runnable() {
public void run() { public void run() {
m_ProgressBar.setValue(percent); progressBar.setValue(percent);
} }
}; };
SwingUtilities.invokeLater(doSetProgressBarValue); SwingUtilities.invokeLater(doSetProgressBarValue);
@ -1204,6 +1216,7 @@ final class SplashScreen extends Frame {
byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true); byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true);
ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)); ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes));
JLabel splashLabel = new JLabel(ii); JLabel splashLabel = new JLabel(ii);
splashWindow.add(splashLabel); splashWindow.add(splashLabel);
splashWindow.pack(); splashWindow.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

View File

@ -2,9 +2,9 @@ package eva2.gui;
/* /*
* Title: EvA2 * Title: EvA2
* Description: * Description:
* Copyright: Copyright (c) 2003 * Copyright: Copyright (c) 2012
* Company: University of Tuebingen, Computer Architecture * Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher * @author Holger Ulmer, Felix Streichert, Hannes Planatscher, Fabian Becker
* @version: $Revision: 266 $ * @version: $Revision: 266 $
* $Date: 2007-11-20 14:33:48 +0100 (Tue, 20 Nov 2007) $ * $Date: 2007-11-20 14:33:48 +0100 (Tue, 20 Nov 2007) $
* $Author: mkron $ * $Author: mkron $
@ -29,32 +29,30 @@ import java.lang.reflect.Proxy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Vector; import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import eva2.EvAInfo; import eva2.EvAInfo;
import eva2.client.EvAClient;
import eva2.tools.ReflectPackage; import eva2.tools.ReflectPackage;
import eva2.tools.jproxy.RMIProxyLocal; import eva2.tools.jproxy.RMIProxyLocal;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
public class GenericObjectEditor implements PropertyEditor { public class GenericObjectEditor implements PropertyEditor {
static final public boolean TRACE = false; private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
private Object m_Object; private Object m_Object;
private Object m_Backup; private Object m_Backup;
private PropertyChangeSupport m_Support = new PropertyChangeSupport(this); private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
private Class<?> m_ClassType; private Class<?> classType;
private GOEPanel m_EditorComponent; private GOEPanel editorComponent;
private boolean m_Enabled = true; private boolean isEnabled = true;
/** /**
* Read the classes available for user selection from the properties or the classpath respectively * Read the classes available for user selection from the properties or the classpath respectively
*/ */
public static ArrayList<String> getClassesFromProperties(String className, ArrayList<Class<?>> instances) { public static ArrayList<String> getClassesFromProperties(String className, ArrayList<Class<?>> instances) {
if (TRACE) System.out.println("getClassesFromProperties - requesting className: "+className); logger.log(Level.FINEST, "Requesting className: {0}", className);
// Try to read the predefined classes from the props file. // Try to read the predefined classes from the props file.
String typeOptions = EvAInfo.getProperty(className); String typeOptions = EvAInfo.getProperty(className);
@ -66,15 +64,15 @@ public class GenericObjectEditor implements PropertyEditor {
ArrayList<String> classes = new ArrayList<String>(); ArrayList<String> classes = new ArrayList<String>();
while (st.hasMoreTokens()) { while (st.hasMoreTokens()) {
String current = st.nextToken().trim(); String current = st.nextToken().trim();
//System.out.println("current ="+current);
try { try {
Class<?> clz = Class.forName(current); // test for instantiability Class<?> clz = Class.forName(current); // test for instantiability
if (instances!=null) instances.add(clz); if (instances != null) {
instances.add(clz);
}
classes.add(current); classes.add(current);
} catch (Exception ex) { } catch (ClassNotFoundException ex) {
System.err.println("Couldn't load class with name: " + current); logger.log(Level.WARNING,
System.err.println("ex:"+ex.getMessage()); String.format("Requesting className: %1$s, Couldn't load: %2%s", className, current), ex);
ex.printStackTrace();
} }
} }
return classes; return classes;
@ -93,37 +91,42 @@ public class GenericObjectEditor implements PropertyEditor {
*/ */
public static ArrayList<String> getClassesFromClassPath(String className, ArrayList<Class<?>> instances) { public static ArrayList<String> getClassesFromClassPath(String className, ArrayList<Class<?>> instances) {
ArrayList<String> classes = new ArrayList<String>(); ArrayList<String> classes = new ArrayList<String>();
Class<?>[] clsArr; Class<?>[] classArray;
clsArr=ReflectPackage.getAssignableClasses(className, true, true); classArray=ReflectPackage.getAssignableClasses(className, true, true);
if (clsArr == null) { if (classArray == null) {
System.err.println("Warning: No assignable classes found in property file or on classpath: " logger.log(Level.WARNING, String.format("No assignable classes found in property file or on classpath: %1$s for %2$s", EvAInfo.propertyFile, className));
+EvAInfo.propertyFile + " for "+className);
classes.add(className); classes.add(className);
} else { } else {
for (Class<?> class1 : clsArr) { for (Class<?> clazz : classArray) {
int m = class1.getModifiers(); int m = clazz.getModifiers();
try { try {
// a field allowing a class to indicate it doesnt want to be displayed // a field allowing a class to indicate it doesnt want to be displayed
Field f = class1.getDeclaredField("hideFromGOE"); Field f = clazz.getDeclaredField("hideFromGOE");
if (f.getBoolean(class1) == true) { if (f.getBoolean(clazz) == true) {
if (TRACE) System.out.println("Class " + class1 + " wants to be hidden from GOE, skipping..."); logger.log(Level.FINEST, "Class {0} wants to be hidden from GOE.", clazz);
continue; continue;
} }
} catch (Exception e) { } catch (NoSuchFieldException e) {
/*
} catch (Error e) { * We are just logging this exception here. It is expected that
System.err.println("Error on checking fields of " + class1 + ": " + e); * most classes do not have this field.
continue; */
logger.log(Level.FINER, String.format("%1$s does not have a hideFromGOE field", clazz.toString()), e);
} catch (IllegalArgumentException e) {
logger.log(Level.FINER, e.getMessage(), e);
} catch (IllegalAccessException e) {
logger.log(Level.FINER, e.getMessage(), e);
} }
// if (f)
if (!Modifier.isAbstract(m) && !class1.isInterface()) { // dont take abstract classes or interfaces
if (!Modifier.isAbstract(m) && !clazz.isInterface()) { // dont take abstract classes or interfaces
try { try {
Class<?>[] params = new Class[0]; Class<?>[] params = new Class[0];
class1.getConstructor(params); clazz.getConstructor(params);
if (instances!=null) instances.add(class1); if (instances!=null) instances.add(clazz);
classes.add(class1.getName()); classes.add(clazz.getName());
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
System.err.println("GOE warning: Class " + class1.getName() + " has no default constructor, skipping..."); logger.log(Level.WARNING, String.format("GOE warning: Class %1$s has no default constructor", clazz.getName()), e);
} }
} }
} }
@ -155,7 +158,7 @@ public class GenericObjectEditor implements PropertyEditor {
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
System.err.println("exception in setHideProperty for " + cls.getName() + "/" + property + " : " + e.getMessage()); logger.log(Level.WARNING, String.format("Couldn't set expert property for %1$s/%2$s", cls.getName(), property), e);
return false; return false;
} }
} }
@ -175,7 +178,7 @@ public class GenericObjectEditor implements PropertyEditor {
*/ */
public static boolean setHideProperty(Class<?> cls, String property, boolean hide) { public static boolean setHideProperty(Class<?> cls, String property, boolean hide) {
try { try {
BeanInfo bi = Introspector.getBeanInfo(cls); BeanInfo bi = Introspector.getBeanInfo(cls);
PropertyDescriptor[] props = bi.getPropertyDescriptors(); PropertyDescriptor[] props = bi.getPropertyDescriptors();
for (int i=0; i<props.length; i++) { for (int i=0; i<props.length; i++) {
if ((props[i].getName().equals(property))) { if ((props[i].getName().equals(property))) {
@ -185,10 +188,11 @@ public class GenericObjectEditor implements PropertyEditor {
return true; return true;
} }
} }
System.err.println("Error: property " + property + " not found!");
logger.log(Level.WARNING, "Property {0} not found", property);
return false; return false;
} catch (Exception e) { } catch (IntrospectionException e) {
System.err.println("exception in setHideProperty for " + cls.getName() + "/" + property + " : " + e.getMessage()); logger.log(Level.WARNING, String.format("Couldn't set hide property for %1$s/%2$s", cls.getName(), property), e);
return false; return false;
} }
} }
@ -211,8 +215,8 @@ public class GenericObjectEditor implements PropertyEditor {
props[i].setHidden(hide); props[i].setHidden(hide);
} }
return orig; return orig;
} catch (Exception e) { } catch (IntrospectionException e) {
System.err.println("exception in setHideProperty for " + cls.getName() + "/all : " + e.getMessage()); logger.log(Level.WARNING, String.format("Couldn't hide all properties for %1$s/all", cls.getName()), e);
return null; return null;
} }
} }
@ -223,8 +227,7 @@ public class GenericObjectEditor implements PropertyEditor {
try { try {
bi = Introspector.getBeanInfo(cls); bi = Introspector.getBeanInfo(cls);
} catch (IntrospectionException e) { } catch (IntrospectionException e) {
System.err.println("Error on introspection of " + cls.getName() + ", " + e.getMessage()); logger.log(Level.WARNING, String.format("Error on introspection of %1$s", cls.getName()), e);
e.printStackTrace();
return; return;
} }
PropertyDescriptor[] props = bi.getPropertyDescriptors(); PropertyDescriptor[] props = bi.getPropertyDescriptors();
@ -257,8 +260,8 @@ public class GenericObjectEditor implements PropertyEditor {
* @param newVal a value of type 'boolean' * @param newVal a value of type 'boolean'
*/ */
public void setEnabled(boolean newVal) { public void setEnabled(boolean newVal) {
if (newVal != m_Enabled) { if (newVal != isEnabled) {
m_Enabled = newVal; isEnabled = newVal;
} }
} }
@ -268,15 +271,15 @@ 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()) + ")"); //if (TRACE) System.out.println("GOE setClassType("+ (type == null? "<null>" : type.getName()) + ")");
m_ClassType = type; classType = type;
if (m_EditorComponent != null) if (editorComponent != null)
m_EditorComponent.updateClassType(); editorComponent.updateClassType();
} }
public Class<?> getClassType() { public Class<?> getClassType() {
return m_ClassType; return classType;
} }
/** /**
@ -284,17 +287,17 @@ public class GenericObjectEditor implements PropertyEditor {
* the chooser * the chooser
*/ */
public void setDefaultValue() { public void setDefaultValue() {
if (m_ClassType == null) { if (classType == null) {
System.err.println("No ClassType set up for GenericObjectEditor!!"); logger.log(Level.WARNING, "No ClassType set up for GenericObjectEditor!");
return; return;
} }
Vector<String> v=null; Vector<String> v=null;
if (Proxy.isProxyClass(m_ClassType)) { if (Proxy.isProxyClass(classType)) {
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName()); //if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName());
v = new Vector<String>(getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName(), null)); v = new Vector<String>(getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_Object))).getOriginalClass().getName(), null));
} else { } else {
v = new Vector<String>(getClassesFromProperties(m_ClassType.getName(), null)); v = new Vector<String>(getClassesFromProperties(classType.getName(), null));
} }
// v = new Vector<String>(getClassesFromProperties(m_ClassType.getName())); // v = new Vector<String>(getClassesFromProperties(m_ClassType.getName()));
@ -316,25 +319,25 @@ public class GenericObjectEditor implements PropertyEditor {
public void setValue(Object o) { public void setValue(Object o) {
//System.err.println("setValue()" + m_ClassType.toString()); //System.err.println("setValue()" + m_ClassType.toString());
if (o==null || m_ClassType == null) { if (o==null || classType == null) {
System.err.println("No ClassType set up for GenericObjectEditor!!"); logger.log(Level.WARNING, "No ClassType set up for GenericObjectEditor!");
return; return;
} }
if (!m_ClassType.isAssignableFrom(o.getClass())) { if (!classType.isAssignableFrom(o.getClass())) {
if (m_ClassType.isPrimitive()) { if (classType.isPrimitive()) {
System.err.println("setValue object not of correct type! Expected "+m_ClassType.getName()+", got " + o.getClass().getName()); System.err.println("setValue object not of correct type! Expected "+classType.getName()+", got " + o.getClass().getName());
System.err.println("setting primitive type"); System.err.println("setting primitive type");
setObject((Object)o); setObject((Object)o);
//throw new NullPointerException("ASDF"); //throw new NullPointerException("ASDF");
} else { } else {
System.err.println("setValue object not of correct type! Expected "+m_ClassType.getName()+", got " + o.getClass().getName()); System.err.println("setValue object not of correct type! Expected "+classType.getName()+", got " + o.getClass().getName());
} }
return; return;
} }
setObject((Object)o); setObject((Object)o);
if (m_EditorComponent != null) if (editorComponent != null)
m_EditorComponent.updateChooser(); editorComponent.updateChooser();
} }
@ -346,16 +349,16 @@ 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); //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;
m_Object = c; m_Object = c;
if (m_EditorComponent != null) { if (editorComponent != null) {
m_EditorComponent.updateChildPropertySheet(); editorComponent.updateChildPropertySheet();
if (trueChange) if (trueChange)
m_Support.firePropertyChange("", m_Backup, m_Object); propertyChangeSupport.firePropertyChange("", m_Backup, m_Object);
} }
} }
@ -397,7 +400,7 @@ public class GenericObjectEditor implements PropertyEditor {
* @param box the area we are allowed to paint into * @param box the area we are allowed to paint into
*/ */
public void paintValue(Graphics gfx,Rectangle box) { public void paintValue(Graphics gfx,Rectangle box) {
if (m_Enabled && m_Object != null) { if (isEnabled && m_Object != null) {
int getNameMethod = -1; int getNameMethod = -1;
MethodDescriptor[] methods; MethodDescriptor[] methods;
String rep = ""; String rep = "";
@ -478,50 +481,29 @@ public class GenericObjectEditor implements PropertyEditor {
* @return a value of type 'java.awt.Component' * @return a value of type 'java.awt.Component'
*/ */
public Component getCustomEditor() { public Component getCustomEditor() {
if (m_EditorComponent == null) if (editorComponent == null)
m_EditorComponent = new GOEPanel(m_Object, m_Backup, m_Support, this); editorComponent = new GOEPanel(m_Object, m_Backup, propertyChangeSupport, this);
return m_EditorComponent; return editorComponent;
} }
/** /**
* *
*/ */
public void disableOKCancel() { public void disableOKCancel() {
if (m_EditorComponent == null) if (editorComponent == null)
m_EditorComponent = new GOEPanel(m_Object, m_Backup, m_Support, this); editorComponent = new GOEPanel(m_Object, m_Backup,
m_EditorComponent.setEnabledOkCancelButtons(false); propertyChangeSupport, this);
editorComponent.setEnabledOkCancelButtons(false);
} }
public void addPropertyChangeListener(PropertyChangeListener l) {
if (m_Support == null) m_Support = new PropertyChangeSupport(this);
m_Support.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) { public void addPropertyChangeListener(PropertyChangeListener l) {
if (m_Support == null) m_Support = new PropertyChangeSupport(this); if (propertyChangeSupport == null)
m_Support.removePropertyChangeListener(l); propertyChangeSupport = new PropertyChangeSupport(this);
} propertyChangeSupport.addPropertyChangeListener(l);
/** }
*
*/ public void removePropertyChangeListener(PropertyChangeListener l) {
// public static void main(String [] args) { if (propertyChangeSupport == null)
// try { propertyChangeSupport = new PropertyChangeSupport(this);
// PropertyEditorManager.registerEditor(SelectedTag.class,TagEditor.class); propertyChangeSupport.removePropertyChangeListener(l);
// PropertyEditorManager.registerEditor(double[].class,GenericArrayEditor.class); }
// GenericObjectEditor editor = new GenericObjectEditor();
// editor.setClassType(StatisticsParameter.class);
// editor.setValue(new StatisticsParameterImpl());
// PropertyDialog pd = new PropertyDialog(editor,EVAHELP.cutClassName(editor.getClass().getName()),110, 120);
// pd.addWindowListener(new WindowAdapter() {
// public void windowClosing(WindowEvent e) {
// PropertyEditor pe = ((PropertyDialog)e.getSource()).getEditor();
// Object c = (Object)pe.getValue();
// String options = "";
// if (TRACE) System.out.println(c.getClass().getName() + " " + options);
// System.exit(0);
// }
// });
// } catch (Exception ex) {
// ex.printStackTrace();
// System.out.println(ex.getMessage());
// }
// }
} }