|
@@ -5,6 +5,7 @@ import java.awt.Dimension;
|
|
|
import java.awt.FlowLayout;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.swing.BoxLayout;
|
|
|
import javax.swing.DefaultListModel;
|
|
@@ -13,7 +14,6 @@ import javax.swing.JDialog;
|
|
|
import javax.swing.JList;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.border.EmptyBorder;
|
|
|
-import javax.swing.border.TitledBorder;
|
|
|
|
|
|
import eu.tankernn.grid.model.sensor.Sensor;
|
|
|
|
|
@@ -25,7 +25,7 @@ public class SensorConfig extends JDialog {
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
private final JPanel contentPanel = new JPanel(), buttonPanel = new JPanel(), zonePanel = new JPanel();
|
|
|
- private JList<String> availableList = new JList<>(), cpuList = new JList<>(), gpuList = new JList<>();
|
|
|
+ private SensorZone availableList, cpuList , gpuList;
|
|
|
private JButton cpuAdd = new JButton("->"), cpuRem = new JButton("<-"), gpuAdd = new JButton("->"),
|
|
|
gpuRem = new JButton("<-");
|
|
|
|
|
@@ -37,30 +37,11 @@ public class SensorConfig extends JDialog {
|
|
|
getContentPane().setLayout(new BorderLayout());
|
|
|
contentPanel.setLayout(new FlowLayout());
|
|
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
|
|
-
|
|
|
- {
|
|
|
- DefaultListModel<String> model = new DefaultListModel<>();
|
|
|
- for (String s : sensor.getCpuSensors())
|
|
|
- model.addElement(s);
|
|
|
- cpuList.setModel(model);
|
|
|
- }
|
|
|
- {
|
|
|
- DefaultListModel<String> model = new DefaultListModel<>();
|
|
|
- for (String s : sensor.getGpuSensors())
|
|
|
- model.addElement(s);
|
|
|
- gpuList.setModel(model);
|
|
|
- }
|
|
|
- {
|
|
|
- DefaultListModel<String> model = new DefaultListModel<>();
|
|
|
- for (String s : sensor.getSensorNames().stream().filter(s -> !sensor.getCpuSensors().contains(s))
|
|
|
- .filter(s -> !sensor.getGpuSensors().contains(s)).toArray(String[]::new))
|
|
|
- model.addElement(s);
|
|
|
- availableList.setModel(model);
|
|
|
- }
|
|
|
-
|
|
|
- availableList.setBorder(new TitledBorder("Available sensors:"));
|
|
|
- cpuList.setBorder(new TitledBorder("CPU sensors:"));
|
|
|
- gpuList.setBorder(new TitledBorder("GPU sensors:"));
|
|
|
+
|
|
|
+ availableList = new SensorZone("Available sensors", sensor.getSensorNames().stream().filter(s -> !sensor.getCpuSensors().contains(s))
|
|
|
+ .filter(s -> !sensor.getGpuSensors().contains(s)).collect(Collectors.toList()));
|
|
|
+ cpuList = new SensorZone("CPU sensors", sensor.getCpuSensors());
|
|
|
+ gpuList = new SensorZone("GPU sensors", sensor.getGpuSensors());
|
|
|
|
|
|
availableList.setPreferredSize(new Dimension(150, 400));
|
|
|
cpuList.setPreferredSize(new Dimension(150, 200));
|
|
@@ -93,8 +74,8 @@ public class SensorConfig extends JDialog {
|
|
|
{
|
|
|
JButton okButton = new JButton("OK");
|
|
|
okButton.addActionListener(a -> {
|
|
|
- sensor.setCpuSensors(toList(cpuList));
|
|
|
- sensor.setGpuSensors(toList(gpuList));
|
|
|
+ sensor.setCpuSensors(toList(cpuList.getSensors()));
|
|
|
+ sensor.setGpuSensors(toList(gpuList.getSensors()));
|
|
|
dispose();
|
|
|
});
|
|
|
buttonPane.add(okButton);
|
|
@@ -118,11 +99,11 @@ public class SensorConfig extends JDialog {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
- private void move(JList<String> origin, JList<String> target) {
|
|
|
- if (origin.getSelectedIndex() < 0)
|
|
|
+ private void move(SensorZone origin, SensorZone target) {
|
|
|
+ if (origin.getSensors().getSelectedIndex() < 0)
|
|
|
return;
|
|
|
- String name = origin.getSelectedValue();
|
|
|
- ((DefaultListModel<String>) origin.getModel()).remove(origin.getSelectedIndex());
|
|
|
- ((DefaultListModel<String>) target.getModel()).addElement(name);
|
|
|
+ String name = origin.getSensors().getSelectedValue();
|
|
|
+ ((DefaultListModel<String>) origin.getSensors().getModel()).remove(origin.getSensors().getSelectedIndex());
|
|
|
+ ((DefaultListModel<String>) target.getSensors().getModel()).addElement(name);
|
|
|
}
|
|
|
}
|