The progressBar is now _really_ visible on the bottom of the GUI. Some code has been beautified. The LoggingPanel does now add it's own log handler to the native logging which makes more sense.

This commit is contained in:
Fabian Becker 2012-04-19 15:11:04 +00:00
parent 0e2db96402
commit dcbb488bb9
6 changed files with 143 additions and 166 deletions

View File

@ -36,8 +36,10 @@ import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.plaf.basic.BasicBorders;
/**
@ -68,7 +70,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
private ExtAction actQuit;
// LogPanel
private LogPanel logPanel;
private LoggingPanel logPanel;
private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
// Module:
@ -385,40 +387,17 @@ public class EvAClient implements RemoteStateListener, Serializable {
} catch (Exception e) {
System.out.println("Error" + e.getMessage());
}
progressBar = new JProgressBar();
progressBar.setBorder(new TitledBorder("Progress"));
progressBar.setValue(0);
progressBar.setStringPainted(true);
evaFrame.getContentPane().add(progressBar, BorderLayout.NORTH);
evaFrame.getContentPane().setLayout(new BorderLayout());
logPanel = new LogPanel();
evaFrame.getContentPane().add(logPanel, BorderLayout.CENTER);
logger.addHandler(new Handler() {
@Override
public void publish(LogRecord record) {
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("[");
sBuilder.append(record.getLevel().toString());
sBuilder.append("] ");
MessageFormat messageFormat = new MessageFormat(record.getMessage());
sBuilder.append(messageFormat.format(record.getParameters()));
// Show message on LogPanel
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 */
}
});
progressBar = new JProgressBar();
evaFrame.getContentPane().add(progressBar, BorderLayout.SOUTH);
logPanel = new LoggingPanel(logger);
evaFrame.getContentPane().add(logPanel, BorderLayout.SOUTH);
if (EvAInfo.propShowModules() != null) {
showLoadModules = true;
@ -927,7 +906,7 @@ public class EvAClient implements RemoteStateListener, Serializable {
try {
newModuleAdapter = comAdapter.getModuleAdapter(selectedModule, goParams, withGUI ? null : "EvA2");
} catch (Exception e) {
logger.log(Level.SEVERE, "Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage(), e);
logger.log(Level.SEVERE, "Error loading module.", e);
EVAERROR.EXIT("Error while m_ComAdapter.GetModuleAdapter Host: " + e.getMessage());
}
if (newModuleAdapter == null) {

View File

@ -17,7 +17,7 @@ package eva2.client;
import java.rmi.RemoteException;
import eva2.EvAInfo;
import eva2.gui.LogPanel;
import eva2.gui.LoggingPanel;
import eva2.server.EvAMainAdapter;
import eva2.server.EvAMainAdapterImpl;
import eva2.server.go.InterfaceGOParameters;
@ -35,14 +35,14 @@ import eva2.tools.jproxy.RMIInvocationHandler;
*
*/
public class EvAComAdapter extends ComAdapter {
private LogPanel m_LogPanel;
private LoggingPanel m_LogPanel;
private EvAMainAdapterImpl localMainAdapter;
private boolean runLocally = false;
/**
*
*/
public void setLogPanel(LogPanel OutputFrame) {
public void setLogPanel(LoggingPanel OutputFrame) {
m_LogPanel = OutputFrame;
}
/**

View File

@ -9,10 +9,6 @@ package eva2.gui;
* $Date: 2007-11-27 14:37:05 +0100 (Tue, 27 Nov 2007) $
* $Author: mkron $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import eva2.EvAInfo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -176,25 +172,25 @@ public class EvAModuleButtonPanelMaker implements RemoteStateListener, Serializa
private void makeHelpButton() {
///////////////////////////////////////////////////////////////
if (helpFileName!=null && (!helpFileName.equals(""))) {
helpButton= new JButton("Description");
if (helpFileName != null && (!helpFileName.equals(""))) {
helpButton = new JButton("Description");
helpButton.setToolTipText("Description of the current optimization algorithm.");
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
public void actionPerformed(ActionEvent e) {
//System.out.println("Run Opt pressed !!!!!!!!!!!!!!!!======================!!");
try {
if (helpFileName!=null) {
if (helpFileName != null) {
HtmlDemo temp = new HtmlDemo(helpFileName);
temp.show();
}
helpButton.setEnabled(true);
} catch (Exception ee) {
ee.printStackTrace();
System.out.print ("Error in run: " +ee +" : " + ee.getMessage() );
System.out.print("Error in run: " + ee + " : " + ee.getMessage());
}
}
}
);
});
toolBar.add(helpButton);
}
}

View File

@ -48,18 +48,18 @@ public class GOEPanel extends JPanel implements ItemListener {
/** The model containing the list of names to select from */
private DefaultComboBoxModel m_ObjectNames;
/** Open object from disk */
private JButton m_OpenBut;
private JButton openButton;
/** Save object to disk */
private JButton m_SaveBut;
private JButton saveButton;
/** ok button */
private JButton m_okBut;
private JButton okayButton;
/** cancel button */
private JButton m_cancelBut;
private JButton cancelButton;
/** edit source button */
// private JButton m_editSourceBut;
/** Creates the GUI editor component */
// private Vector<String> m_ClassesLongName;
private GenericObjectEditor m_goe = null;
private GenericObjectEditor genericObjectEditor = null;
private boolean withComboBoxToolTips = true; // should tool tips for the combo box be created?
private int tipMaxLen = 100; // maximum length of tool tip
@ -77,7 +77,7 @@ public class GOEPanel extends JPanel implements ItemListener {
Object m_Object = target;
m_Backup = backup;
m_Support = support;
m_goe = goe;
genericObjectEditor = goe;
// System.out.println("GOEPanel.Constructor !! " + this);
try {
@ -95,42 +95,42 @@ public class GOEPanel extends JPanel implements ItemListener {
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (TRACE) System.out.println("GOE Property Change Listener: " + evt);
m_Support.firePropertyChange("", m_Backup, m_goe.getValue());
m_Support.firePropertyChange("", m_Backup, genericObjectEditor.getValue());
}
});
m_OpenBut = new JButton("Open");
m_OpenBut.setToolTipText("Load a configured object");
m_OpenBut.setEnabled(true);
m_OpenBut.addActionListener(new ActionListener() {
openButton = new JButton("Open");
openButton.setToolTipText("Load a configured object");
openButton.setEnabled(true);
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object object = FileTools.openObject(m_OpenBut, m_goe.getClassType());
Object object = FileTools.openObject(openButton, genericObjectEditor.getClassType());
// Object object = openObject();
if (object != null) {
// setValue takes care of: Making sure obj is of right type,
// and firing property change.
m_goe.setValue(object);
genericObjectEditor.setValue(object);
// Need a second setValue to get property values filled in OK.
// Not sure why.
m_goe.setValue(object); // <- Hannes ?!?!?
genericObjectEditor.setValue(object); // <- Hannes ?!?!?
}
}
});
m_SaveBut = new JButton("Save");
m_SaveBut.setToolTipText("Save the current configured object");
m_SaveBut.setEnabled(true);
m_SaveBut.addActionListener(new ActionListener() {
saveButton = new JButton("Save");
saveButton.setToolTipText("Save the current configured object");
saveButton.setEnabled(true);
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileTools.saveObjectWithFileChooser(m_SaveBut, m_goe.getValue());
FileTools.saveObjectWithFileChooser(saveButton, genericObjectEditor.getValue());
// saveObject(m_goe.getValue());
}
});
m_okBut = new JButton("OK");
m_okBut.setEnabled(true);
m_okBut.addActionListener(new ActionListener() {
okayButton = new JButton("OK");
okayButton.setEnabled(true);
okayButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
m_Backup = copyObject(m_goe.getValue());
m_Backup = copyObject(genericObjectEditor.getValue());
// System.out.println("Backup is now " + BeanInspector.toString(m_Backup));
if ((getTopLevelAncestor() != null) && (getTopLevelAncestor() instanceof Window)) {
Window w = (Window) getTopLevelAncestor();
@ -139,15 +139,15 @@ public class GOEPanel extends JPanel implements ItemListener {
}
});
m_cancelBut = new JButton("Cancel");
m_cancelBut.setEnabled(true);
m_cancelBut.addActionListener(new ActionListener() {
cancelButton = new JButton("Cancel");
cancelButton.setEnabled(true);
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (m_Backup != null) {
// m_Object = copyObject(m_Backup);
// TODO m_goe.setObject(m_Object);
// System.out.println("Backup was " + BeanInspector.toString(m_Backup));
m_goe.setValue(copyObject(m_Backup));
genericObjectEditor.setValue(copyObject(m_Backup));
updateClassType();
updateChooser();
updateChildPropertySheet();
@ -175,15 +175,15 @@ public class GOEPanel extends JPanel implements ItemListener {
JPanel okcButs = new JPanel();
okcButs.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
okcButs.setLayout(new GridLayout(1, 4, 5, 5));
okcButs.add(m_OpenBut);
okcButs.add(m_SaveBut);
okcButs.add(openButton);
okcButs.add(saveButton);
// okcButs.add(m_editSourceBut);
if (withCancel) okcButs.add(m_cancelBut);
okcButs.add(m_okBut);
if (withCancel) okcButs.add(cancelButton);
okcButs.add(okayButton);
add(okcButs, BorderLayout.SOUTH);
if (m_goe.getClassType() != null) {
if (genericObjectEditor.getClassType() != null) {
updateClassType();
updateChooser();
updateChildPropertySheet();
@ -192,8 +192,8 @@ public class GOEPanel extends JPanel implements ItemListener {
}
public void setEnabledOkCancelButtons(boolean enabled) {
m_okBut.setEnabled(enabled);
m_cancelBut.setEnabled(enabled);
okayButton.setEnabled(enabled);
cancelButton.setEnabled(enabled);
}
/**
@ -221,7 +221,7 @@ public class GOEPanel extends JPanel implements ItemListener {
* @param a The action listener.
*/
public void addOkListener(ActionListener a) {
m_okBut.addActionListener(a);
okayButton.addActionListener(a);
}
/**
@ -229,7 +229,7 @@ public class GOEPanel extends JPanel implements ItemListener {
* @param a The action listener.
*/
public void addCancelListener(ActionListener a) {
m_cancelBut.addActionListener(a);
cancelButton.addActionListener(a);
}
/**
@ -237,7 +237,7 @@ public class GOEPanel extends JPanel implements ItemListener {
* @param a The action listener
*/
public void removeOkListener(ActionListener a) {
m_okBut.removeActionListener(a);
okayButton.removeActionListener(a);
}
/**
@ -245,7 +245,7 @@ public class GOEPanel extends JPanel implements ItemListener {
* @param a The action listener
*/
public void removeCancelListener(ActionListener a) {
m_cancelBut.removeActionListener(a);
cancelButton.removeActionListener(a);
}
public void setTarget(Object o) {
@ -256,21 +256,21 @@ public class GOEPanel extends JPanel implements ItemListener {
*
*/
protected void updateClassType() {
if (TRACE) System.out.println("# updating class "+m_goe.getClassType().getName());
if (TRACE) System.out.println("# updating class "+genericObjectEditor.getClassType().getName());
Vector<String> classesLongNames;
ArrayList<Class<?>> instances = new ArrayList<Class<?>>(5);
if (Proxy.isProxyClass(m_goe.getClassType())) {
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_goe.getValue()))).getOriginalClass().getName());
classesLongNames = new Vector<String>(GenericObjectEditor.getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)m_goe.getValue()))).getOriginalClass().getName(), null));
if (Proxy.isProxyClass(genericObjectEditor.getClassType())) {
if (TRACE) System.out.println("PROXY! original was " + ((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)genericObjectEditor.getValue()))).getOriginalClass().getName());
classesLongNames = new Vector<String>(GenericObjectEditor.getClassesFromProperties(((RMIProxyLocal)Proxy.getInvocationHandler(((Proxy)genericObjectEditor.getValue()))).getOriginalClass().getName(), null));
} else {
classesLongNames = new Vector<String>(GenericObjectEditor.getClassesFromProperties(m_goe.getClassType().getName(), instances));
classesLongNames = new Vector<String>(GenericObjectEditor.getClassesFromProperties(genericObjectEditor.getClassType().getName(), instances));
}
if (classesLongNames.size() > 1) {
m_ObjectChooser.setModel(new DefaultComboBoxModel(classesLongNames));
if (withComboBoxToolTips) m_ObjectChooser.setRenderer(new ToolTipComboBoxRenderer(collectComboToolTips(instances, tipMaxLen) ));
add(m_ObjectChooser, BorderLayout.NORTH);
} else remove(m_ObjectChooser);
if (TRACE) System.out.println("# done updating class "+m_goe.getClassType().getName());
if (TRACE) System.out.println("# done updating class "+genericObjectEditor.getClassType().getName());
}
private String[] collectComboToolTips(List<Class<?>> instances, int maxLen) {
@ -294,7 +294,7 @@ public class GOEPanel extends JPanel implements ItemListener {
}
protected void updateChooser() {
String objectName = /*EVAHELP.cutClassName*/ (m_goe.getValue().getClass().getName());
String objectName = /*EVAHELP.cutClassName*/ (genericObjectEditor.getValue().getClass().getName());
boolean found = false;
for (int i = 0; i < m_ObjectNames.getSize(); i++) {
if (TRACE) System.out.println("in updateChooser: looking at "+(String)m_ObjectNames.getElementAt(i));
@ -313,7 +313,7 @@ public class GOEPanel extends JPanel implements ItemListener {
public void updateChildPropertySheet() {
//System.err.println("GOE::updateChildPropertySheet()");
// Set the object as the target of the propertysheet
m_ChildPropertySheet.setTarget(m_goe.getValue());
m_ChildPropertySheet.setTarget(genericObjectEditor.getValue());
// Adjust size of containing window if possible
if ((getTopLevelAncestor() != null)
&& (getTopLevelAncestor() instanceof Window)) {
@ -338,7 +338,7 @@ public class GOEPanel extends JPanel implements ItemListener {
if (TRACE) System.out.println(className);
// Object n = (Object)Class.forName(className, true, this.getClass().getClassLoader()).newInstance();
Object n = (Object)Class.forName(className).newInstance();
m_goe.setValue(n);
genericObjectEditor.setValue(n);
// TODO ? setObject(n);
} catch (Exception ex) {
System.err.println("Exeption in itemStateChanged "+ex.getMessage());

View File

@ -28,22 +28,39 @@ import javax.swing.event.ChangeListener;
import eva2.EvAInfo;
import eva2.tools.BasicResourceLoader;
import java.awt.FlowLayout;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
import java.text.MessageFormat;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.swing.*;
/**
*
*/
public class LogPanel extends JPanel {
// protected JLabel m_Message = new JLabel("OK");
public class LoggingPanel extends JPanel {
protected static Logger logger;
protected JTextArea loggingTextArea = new JTextArea(10,20);
protected boolean m_first = true;
protected boolean firstMessage = true;
protected Handler loggingHandler;
protected JPopupMenu loggingLevelMenu;
/**
*
*/
public LogPanel() {
public LoggingPanel(Logger logger) {
this.logger = logger;
loggingTextArea.setEditable(false);
loggingTextArea.setBorder(BorderFactory.createEmptyBorder(4,4,4,4));
loggingTextArea.setLineWrap(true);
JPanel mainPanel = new JPanel();
mainPanel.setBorder(BorderFactory.createTitledBorder("Info"));
this.loggingHandler = new LoggingHandler(this);
logger.addHandler(loggingHandler);
mainPanel.setLayout(new BorderLayout());
final JScrollPane scrollpane = new JScrollPane(loggingTextArea);
// scrollpane.setAutoscrolls(false);
@ -63,10 +80,6 @@ public class LogPanel extends JPanel {
});
setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
JPanel panel_2 = new JPanel();
panel_2.setLayout(new BorderLayout());
// panel_2.add(m_Message,BorderLayout.CENTER);
add(panel_2, BorderLayout.SOUTH);
}
/**
*
@ -78,39 +91,41 @@ public class LogPanel extends JPanel {
*
*/
public void logMessage(String message) {
if (m_first)
m_first = false;
loggingTextArea.append(LoggingPanel.getTimestamp() + ' ' + message);
loggingTextArea.append("\n");
loggingTextArea.append(LogPanel.getTimestamp() + ' ' + message);
}
/**
*
*/
public static void main(String [] args) {
try {
final JFrame frame = new JFrame("Log_Panel_Test");
frame.getContentPane().setLayout(new BorderLayout());
BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
LogPanel panel = new LogPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
frame.dispose();
System.exit(0);
}
});
frame.pack();
frame.setVisible(true);
panel.logMessage("HI!");
panel.logMessage("Test ------------------------------------------------------------------------");
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}
class LoggingHandler extends Handler {
protected LoggingPanel loggingPanel;
public LoggingHandler(LoggingPanel loggingPanel) {
this.loggingPanel = loggingPanel;
}
@Override
public void publish(LogRecord record) {
StringBuilder sBuilder = new StringBuilder();
sBuilder.append("[");
sBuilder.append(record.getLevel().toString());
sBuilder.append("] ");
MessageFormat messageFormat = new MessageFormat(record.getMessage());
sBuilder.append(messageFormat.format(record.getParameters()));
// Show message on LogPanel
this.loggingPanel.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
*/
}
}

View File

@ -150,14 +150,14 @@ public class EvAJobList extends PropertySelectableList<EvAJob> implements Serial
* @return
*/
public static PropertyEditor makeEditor(final Component parent, final EvAJobList jobList) {
final GenericArrayEditor edi = new GenericArrayEditor();
edi.setWithAddButton(false);
edi.setWithSetButton(false);
final GenericArrayEditor genericArrayEditor = new GenericArrayEditor();
genericArrayEditor.setWithAddButton(false);
genericArrayEditor.setWithSetButton(false);
ActionListener al=new ActionListener() {
public void actionPerformed(ActionEvent e) {
// System.out.println("PING!");
// System.out.println(BeanInspector.toString(edi.getSelectedIndices()));
EvAStatisticalEvaluation.evaluate((InterfaceTextListener)jobList, jobList.getObjects(), edi.getSelectedIndices(),
EvAStatisticalEvaluation.evaluate((InterfaceTextListener)jobList, jobList.getObjects(), genericArrayEditor.getSelectedIndices(),
(StatsOnSingleDataSetEnum[])EvAStatisticalEvaluation.statsParams.getOneSampledStats().getSelectedEnum(StatsOnSingleDataSetEnum.values()),
(StatsOnTwoSampledDataEnum[])EvAStatisticalEvaluation.statsParams.getTwoSampledStats().getSelectedEnum(StatsOnTwoSampledDataEnum.values()));
// System.out.println(BeanInspector.toString(EvAStatisticalEvaluation.statsParams.getPairedStats().getSelected()));
@ -177,47 +177,34 @@ public class EvAJobList extends PropertySelectableList<EvAJob> implements Serial
};
ActionListener sl=new ActionListener() {
public void actionPerformed(ActionEvent e) {
edi.selectDeselectAll();
genericArrayEditor.selectDeselectAll();
}
};
ActionListener sal=new ActionListener() {
public void actionPerformed(ActionEvent e) {
jobList.saveSelectedJobs(edi);
jobList.saveSelectedJobs(genericArrayEditor);
}
};
edi.addUpperActionButton("(De-)Sel. all", sl);
edi.addUpperActionButton("Test Stats", al);
edi.addLowerActionButton("Save selected", sal);
genericArrayEditor.addUpperActionButton("(De-)Sel. all", sl);
genericArrayEditor.addUpperActionButton("Test Stats", al);
genericArrayEditor.addLowerActionButton("Save selected", sal);
// edi.addPopupItem("Reset selected", getClearSelectedActionListener(parent, jobList)); // this option does not make much sense - instead of deleting data, taking over the settings for a new run is more plausible
edi.addPopupItem("Reuse as current settings", getReuseActionListener(parent, jobList));
edi.setAdditionalCenterPane(createStatsPanel(jobList, edi));
edi.setValue(jobList);
return edi;
genericArrayEditor.addPopupItem("Reuse as current settings", getReuseActionListener(parent, jobList));
genericArrayEditor.setAdditionalCenterPane(createStatsPanel(jobList, genericArrayEditor));
genericArrayEditor.setValue(jobList);
return genericArrayEditor;
}
private static JPanel createStatsPanel(final EvAJobList jobList, final GenericArrayEditor edi) {
// if (logPanel != null) System.err.println("Error: logPanel should be null!!!");
// logPanel = new LogPanel();
// EvAStatisticalEvaluation.statsParams.setGenericAdditionalButtons(getActionButtons(lPan, jobList, edi));
JParaPanel pan = new JParaPanel(EvAStatisticalEvaluation.statsParams, "Statistics");
// GOEPanel pan = new GOEPanel(EvAStatisticalEvaluation.selectedSingleStats, jobList, null, new GenericObjectEditor());
JComponent paraPan = pan.makePanel();
JPanel tmpPan = new JPanel();
// tmpPan.setPreferredSize(new Dimension(1200,1200));
tmpPan.add(paraPan);
// tmpPan.add(logPanel);
return tmpPan;
}
// public static void main(String[] args) {
// JEFrame frm = new JEFrame("Test", true);
// EvAJobList jl = new EvAJobList(new EvAJob[]{});
// frm.add((GenericArrayEditor)makeEditor(null, jl));
// frm.pack();
// frm.setVisible(true);
// }
private static ActionListener getReuseActionListener(final Component parent, final EvAJobList jobList) {
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {