Java 8 code cleanup.

This commit is contained in:
Fabian Becker 2015-12-14 15:45:59 +01:00
parent ded424bb55
commit 02a7b74415
9 changed files with 49 additions and 184 deletions

View File

@ -8,10 +8,7 @@ import eva2.tools.BasicResourceLoader;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* The About dialog used in the EvA2 GUI.
@ -57,17 +54,13 @@ class AboutDialog extends JDialog {
infoEditorPane = new JEditorPane("text/html", infoMessage);
infoEditorPane.setEditable(false);
infoEditorPane.setOpaque(false);
infoEditorPane.addHyperlinkListener(new HyperlinkListener() {
infoEditorPane.addHyperlinkListener(hle -> {
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
Desktop desktop = Desktop.getDesktop();
@Override
public void hyperlinkUpdate(HyperlinkEvent hle) {
if (HyperlinkEvent.EventType.ACTIVATED.equals(hle.getEventType())) {
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
//java.net.URI uri = new java.net.URI(hle.getURL().toString());
//desktop.browse(uri);
}
if (desktop.isSupported(Desktop.Action.BROWSE)) {
//java.net.URI uri = new java.net.URI(hle.getURL().toString());
//desktop.browse(uri);
}
}
});
@ -87,14 +80,7 @@ class AboutDialog extends JDialog {
add(new JScrollPane(aboutTextArea), gbConstraints);
JButton closeButton = new JButton("Close");
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
AboutDialog.this.dispose();
}
});
closeButton.addActionListener(e -> this.dispose());
gbConstraints.gridy++;
gbConstraints.fill = GridBagConstraints.NONE;
gbConstraints.weighty = 0.0;

View File

@ -4,8 +4,6 @@ import com.sun.management.OperatingSystemMXBean;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.management.ManagementFactory;
import java.util.LinkedList;
@ -22,12 +20,9 @@ public class CPUPanel extends JPanel {
private OperatingSystemMXBean osBean;
public CPUPanel(int timeSteps) {
Timer timer = new Timer(500, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
CPUPanel.this.updateLoad();
CPUPanel.this.repaint();
}
Timer timer = new Timer(500, e -> {
this.updateLoad();
this.repaint();
});
timer.start();
maxTimeSteps = timeSteps;

View File

@ -1,17 +1,4 @@
package eva2.gui;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 10 $
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
* $Author: streiche $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import javax.swing.*;
@ -29,7 +16,7 @@ public abstract class ExtAction extends AbstractAction {
*/
private void setValues(String s, String toolTip) {
Mnemonic m = new Mnemonic(s);
putValue(MNEMONIC, new Character(m.getMnemonic()));
putValue(MNEMONIC, m.getMnemonic());
putValue(Action.NAME, m.getText());
putValue(TOOLTIP, toolTip);
}

View File

@ -39,16 +39,12 @@ public class JExtDesktopPane extends JDesktopPane {
desktopManager = new ExtDesktopManager(this);
setDesktopManager(desktopManager);
actMenuFrame = new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
if (!(event.getSource() instanceof JMenuItem)) {
return;
}
JInternalFrame frame = (JInternalFrame) ((JMenuItem) event.getSource()).getClientProperty(ExtDesktopManager.FRAME);
selectFrame(frame);
actMenuFrame = event -> {
if (!(event.getSource() instanceof JMenuItem)) {
return;
}
JInternalFrame frame = (JInternalFrame) ((JMenuItem) event.getSource()).getClientProperty(ExtDesktopManager.FRAME);
selectFrame(frame);
};
actWindowTileVert = new ExtAction("Tile &Vertically", "Tiles all windows vertically",
@ -202,15 +198,9 @@ public class JExtDesktopPane extends JDesktopPane {
}
public int getFrameCount() {
return getComponentCount(new ComponentFilter() {
@Override
public boolean accept(Component c) {
return c instanceof JInternalFrame
|| (c instanceof JInternalFrame.JDesktopIcon
&& ((JInternalFrame.JDesktopIcon) c).getInternalFrame() != null);
}
});
return getComponentCount(c -> c instanceof JInternalFrame
|| (c instanceof JInternalFrame.JDesktopIcon
&& ((JInternalFrame.JDesktopIcon) c).getInternalFrame() != null));
}
public int getComponentCount(ComponentFilter c) {

View File

@ -3,8 +3,6 @@ package eva2.gui;
import eva2.tools.ToolBoxGui;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* @author becker
@ -25,36 +23,15 @@ public class JExtDesktopPaneToolBar extends JToolBar {
/* Add Buttons to tile the desktopPane */
JButton verticalButton = ToolBoxGui.createIconifiedButton("images/TileVertical16.png", "Tile vertically", false);
verticalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
desktopPane.tileWindows(SwingConstants.VERTICAL);
}
});
verticalButton.addActionListener(e -> desktopPane.tileWindows(SwingConstants.VERTICAL));
add(verticalButton);
JButton horizontalButton = ToolBoxGui.createIconifiedButton("images/TileHorizontal16.png", "Tile horizontally", false);
horizontalButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
desktopPane.tileWindows(SwingConstants.HORIZONTAL);
}
});
horizontalButton.addActionListener(e -> desktopPane.tileWindows(SwingConstants.HORIZONTAL));
add(horizontalButton);
JButton cascadeButton = ToolBoxGui.createIconifiedButton("images/Cascade16.png", "Cascade windows", false);
cascadeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
desktopPane.overlapWindows();
}
});
cascadeButton.addActionListener(e -> desktopPane.overlapWindows());
add(cascadeButton);
}
}

View File

@ -1,17 +1,4 @@
package eva2.gui;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 10 $
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
* $Author: streiche $
*/
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import javax.swing.*;
import java.io.File;

View File

@ -1,14 +1,4 @@
package eva2.gui;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 10 $
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
* $Author: streiche $
*/
import javax.swing.*;
import java.beans.PropertyChangeEvent;
@ -24,12 +14,7 @@ public class JExtMenu extends JMenu {
/**
*
*/
public JExtMenu() {
//super();
//Mnemonic m = new Mnemonic(s);
//setText(m.getText());
//setMnemonic(m.getMnemonic());
}
public JExtMenu() { }
/**
*
@ -50,7 +35,7 @@ public class JExtMenu extends JMenu {
Object o;
o = a.getValue(ExtAction.MNEMONIC);
if (o != null) {
item.setMnemonic(((Character) o).charValue());
item.setMnemonic((Character) o);
}
o = a.getValue(ExtAction.TOOLTIP);
if (o != null) {
@ -81,7 +66,7 @@ public class JExtMenu extends JMenu {
menuItem.setText((String) e.getNewValue());
break;
case "enabled":
menuItem.setEnabled(((Boolean) e.getNewValue()).booleanValue());
menuItem.setEnabled((Boolean) e.getNewValue());
break;
case Action.SMALL_ICON:
Icon icon = (Icon) e.getNewValue();
@ -90,7 +75,7 @@ public class JExtMenu extends JMenu {
menuItem.repaint();
break;
case ExtAction.MNEMONIC:
menuItem.setMnemonic(((Character) e.getNewValue()).charValue());
menuItem.setMnemonic((Character) e.getNewValue());
break;
case ExtAction.TOOLTIP:
menuItem.setToolTipText((String) e.getNewValue());

View File

@ -1,14 +1,4 @@
package eva2.gui;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 10 $
* $Date: 2006-01-18 11:02:22 +0100 (Wed, 18 Jan 2006) $
* $Author: streiche $
*/
import javax.swing.*;
import java.awt.*;
@ -63,9 +53,9 @@ public class JExtToolBar extends JToolBar {
String propertyName = e.getPropertyName();
if (propertyName.equals(Action.NAME)) {
/* Nichts tun! */
/* Nichts tun! */
} else if (propertyName.equals("enabled")) {
button.setEnabled(((Boolean) e.getNewValue()).booleanValue());
button.setEnabled((Boolean) e.getNewValue());
button.repaint();
} else if (e.getPropertyName().equals(Action.SMALL_ICON)) {
button.setIcon((Icon) e.getNewValue());

View File

@ -15,7 +15,6 @@ import eva2.tools.Serializer;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyEditor;
import java.io.File;
@ -158,37 +157,14 @@ public class OptimizationJobList extends PropertySelectableList<OptimizationJob>
final ArrayEditor arrayEditor = new ArrayEditor();
arrayEditor.setWithAddButton(false);
arrayEditor.setWithSetButton(false);
ActionListener al = new ActionListener() {
ActionListener al = e -> StatisticalEvaluation.evaluate(jobList, jobList.getObjects(), arrayEditor.getSelectedIndices(),
(StatisticsOnSingleDataSet[]) StatisticalEvaluation.statsParams.getOneSampledStats().getSelectedEnum(StatisticsOnSingleDataSet.values()),
(StatisticsOnTwoSampledData[]) StatisticalEvaluation.statsParams.getTwoSampledStats().getSelectedEnum(StatisticsOnTwoSampledData.values()));
ActionListener sl = e -> arrayEditor.selectDeselectAll();
@Override
public void actionPerformed(ActionEvent e) {
StatisticalEvaluation.evaluate(jobList, jobList.getObjects(), arrayEditor.getSelectedIndices(),
(StatisticsOnSingleDataSet[]) StatisticalEvaluation.statsParams.getOneSampledStats().getSelectedEnum(StatisticsOnSingleDataSet.values()),
(StatisticsOnTwoSampledData[]) StatisticalEvaluation.statsParams.getTwoSampledStats().getSelectedEnum(StatisticsOnTwoSampledData.values()));
}
};
ActionListener sl = new ActionListener() {
ActionListener cliButtonListener = actionEvent -> System.out.println("Generating CLI call");
@Override
public void actionPerformed(ActionEvent e) {
arrayEditor.selectDeselectAll();
}
};
ActionListener cliButtonListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
System.out.println("Generating CLI call");
}
};
ActionListener sal = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jobList.saveSelectedJobs(arrayEditor);
}
};
ActionListener sal = e -> jobList.saveSelectedJobs(arrayEditor);
arrayEditor.addUpperActionButton("Get CLI", cliButtonListener);
arrayEditor.addUpperActionButton("(De-)Sel. all", sl);
@ -209,34 +185,26 @@ public class OptimizationJobList extends PropertySelectableList<OptimizationJob>
}
private static ActionListener getReuseActionListener(final Component parent, final OptimizationJobList jobList) {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<OptimizationJob> jobs = jobList.getSelectedJobs();
if (jobs.size() == 1) {
OptimizationJob job = jobs.get(0);
AbstractOptimizationParameters curParams = (AbstractOptimizationParameters) ((AbstractModuleAdapter) jobList.module).getOptimizationParameters();
curParams.setSameParams((AbstractOptimizationParameters) job.getOptimizationParameters());
((GenericModuleAdapter) jobList.module).setOptimizationParameters(curParams);
((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameters().setMultiRuns(job.getNumRuns());
((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameters().setFieldSelection(job.getFieldSelection(((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameters().getFieldSelection()));
} else {
JOptionPane.showMessageDialog(parent, "Select exactly one job to reuse!", "Error", JOptionPane.ERROR_MESSAGE);
}
return e -> {
List<OptimizationJob> jobs = jobList.getSelectedJobs();
if (jobs.size() == 1) {
OptimizationJob job = jobs.get(0);
AbstractOptimizationParameters curParams = (AbstractOptimizationParameters) ((AbstractModuleAdapter) jobList.module).getOptimizationParameters();
curParams.setSameParams((AbstractOptimizationParameters) job.getOptimizationParameters());
((GenericModuleAdapter) jobList.module).setOptimizationParameters(curParams);
((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameters().setMultiRuns(job.getNumRuns());
((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameters().setFieldSelection(job.getFieldSelection(((GenericModuleAdapter) jobList.module).getStatistics().getStatisticsParameters().getFieldSelection()));
} else {
JOptionPane.showMessageDialog(parent, "Select exactly one job to reuse!", "Error", JOptionPane.ERROR_MESSAGE);
}
};
}
private static ActionListener getClearSelectedActionListener(final Component parent, final OptimizationJobList jobList) {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<OptimizationJob> jobs = jobList.getSelectedJobs();
for (OptimizationJob j : jobs) {
j.resetJob();
}
return e -> {
List<OptimizationJob> jobs = jobList.getSelectedJobs();
for (OptimizationJob j : jobs) {
j.resetJob();
}
};
}