fixes #22
Implemented LoggingLevelLabel as viewable component in the status bar. A click onto the label will open a popup menu that allows the user to set the logging level for the current process. The Version number of EvA2 has now increased to 3.0-rc1. Due to the major changes in the GUI and server implementation I think the version number 2.x should be dropped to reflect the size of changes.
This commit is contained in:
@@ -11,7 +11,6 @@ import java.util.Properties;
|
||||
public class EvAInfo {
|
||||
public static final String productName = "EvA2";
|
||||
public static final String productLongName = "Evolutionary Algorithms Workbench 2";
|
||||
// public static final String fullVersion = "2.043"; // moved to EvA2.props!
|
||||
public static final String url = "http://www.cogsys.cs.uni-tuebingen.de/software/EvA2";
|
||||
|
||||
public static final String propertyFile = "META-INF/EvA2.props";
|
||||
@@ -22,8 +21,8 @@ public class EvAInfo {
|
||||
public static final String splashLocation = "images/EvASplashScreen.png";
|
||||
public static final String infoTitle = productName+" Information";
|
||||
public static final String copyrightYear = "2010-2012";
|
||||
|
||||
public static final String defaultLogger = "EvA2";
|
||||
|
||||
public static final String defaultLogger = "EvA2";
|
||||
|
||||
////////////// Property handling...
|
||||
|
||||
|
@@ -39,6 +39,7 @@ import java.util.logging.Logger;
|
||||
import javax.help.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.plaf.SeparatorUI;
|
||||
|
||||
|
||||
/**
|
||||
@@ -458,14 +459,30 @@ public class EvAClient extends JFrame implements RemoteStateListener {
|
||||
add(horizontalSplit, gbConstraints);
|
||||
|
||||
/* StatusBar of the main frame */
|
||||
statusBar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
statusBar.add(new JLabel("Progress"));
|
||||
statusBar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JPanel statusBarControls = new JPanel();
|
||||
statusBarControls.setLayout(new BoxLayout(statusBarControls, BoxLayout.LINE_AXIS));
|
||||
|
||||
statusBarControls.add(Box.createHorizontalGlue());
|
||||
/* Logging settings drop down */
|
||||
LoggingLevelLabel loggingOption = new LoggingLevelLabel(LOGGER);
|
||||
|
||||
statusBarControls.add(loggingOption);
|
||||
|
||||
statusBarControls.add(Box.createHorizontalStrut(5));
|
||||
statusBarControls.add(new JSeparator(JSeparator.VERTICAL));
|
||||
statusBarControls.add(Box.createHorizontalStrut(5));
|
||||
|
||||
/* Create ProgressBar and add it to the status bar */
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setValue(0);
|
||||
statusBarControls.add(new JLabel("Progress"));
|
||||
statusBarControls.add(Box.createHorizontalStrut(5));
|
||||
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setValue(0);
|
||||
progressBar.setStringPainted(true);
|
||||
statusBar.add(progressBar);
|
||||
statusBarControls.add(progressBar);
|
||||
|
||||
statusBar.add(statusBarControls);
|
||||
|
||||
gbConstraints.gridx = 0;
|
||||
gbConstraints.gridy = 2;
|
||||
|
109
src/eva2/gui/LoggingLevelLabel.java
Normal file
109
src/eva2/gui/LoggingLevelLabel.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package eva2.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author becker
|
||||
*/
|
||||
public final class LoggingLevelLabel extends JLabel {
|
||||
private JPopupMenu menu;
|
||||
private String[] options;
|
||||
private String selected;
|
||||
private Logger logger;
|
||||
|
||||
public LoggingLevelLabel(Logger logger) {
|
||||
options = new String[]{"Info", "Warning", "Severe", "Fine", "Finer", "Finest", "All"};
|
||||
|
||||
this.logger = logger;
|
||||
createPopupMenu();
|
||||
updateText();
|
||||
}
|
||||
|
||||
private void createPopupMenu() {
|
||||
this.menu = new JPopupMenu();
|
||||
addMouseListener(new MouseListener() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent ev) {
|
||||
menu.show(ev.getComponent(), ev.getX(), ev.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
for (String option : options) {
|
||||
JMenuItem menuItem = new JMenuItem(option);
|
||||
menuItem.addActionListener(new MenuActionListener());
|
||||
menu.add(menuItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateText() {
|
||||
/* Get the current logging Level */
|
||||
Level lvl = logger.getLevel();
|
||||
/* Level could be null, fetch parent level */
|
||||
if (lvl == null) {
|
||||
lvl = logger.getParent().getLevel();
|
||||
}
|
||||
/* Show the updated text */
|
||||
setText("<html><b>Level</b>: " + lvl.getName());
|
||||
}
|
||||
|
||||
private void setLoggerLevel(Level level) {
|
||||
logger.setLevel(level);
|
||||
logger.log(Level.INFO, "Logging Level changed to {0}", level.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class MenuActionListener implements ActionListener {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent ev) {
|
||||
JMenuItem menuItem = (JMenuItem) ev.getSource();
|
||||
String levelName = menuItem.getText();
|
||||
|
||||
try {
|
||||
Level level = Level.parse(levelName.toUpperCase());
|
||||
LoggingLevelLabel.this.setLoggerLevel(level);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
logger.log(Level.INFO, "Could not determine new logging level!", ex);
|
||||
}
|
||||
|
||||
LoggingLevelLabel.this.updateText();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user