|
@@ -1,89 +1,93 @@
|
|
package holeg.ui.view.information;
|
|
package holeg.ui.view.information;
|
|
|
|
|
|
-import java.awt.BorderLayout;
|
|
|
|
-import java.awt.Color;
|
|
|
|
-import java.awt.Component;
|
|
|
|
-import java.awt.GridBagConstraints;
|
|
|
|
-import java.awt.GridBagLayout;
|
|
|
|
-import java.awt.GridLayout;
|
|
|
|
-import java.awt.Insets;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Optional;
|
|
|
|
-import java.util.function.Predicate;
|
|
|
|
-import java.util.logging.Logger;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-import java.util.stream.Stream;
|
|
|
|
-
|
|
|
|
-import javax.swing.BorderFactory;
|
|
|
|
-import javax.swing.JLabel;
|
|
|
|
-import javax.swing.JLayeredPane;
|
|
|
|
-import javax.swing.JPanel;
|
|
|
|
-import javax.swing.OverlayLayout;
|
|
|
|
-import javax.swing.border.EmptyBorder;
|
|
|
|
-
|
|
|
|
-import org.knowm.xchart.PieChart;
|
|
|
|
-import org.knowm.xchart.PieChartBuilder;
|
|
|
|
-import org.knowm.xchart.PieSeries.PieSeriesRenderStyle;
|
|
|
|
-import org.knowm.xchart.XChartPanel;
|
|
|
|
-import org.knowm.xchart.style.PieStyler;
|
|
|
|
-import org.knowm.xchart.style.PieStyler.LabelType;
|
|
|
|
-
|
|
|
|
import holeg.model.Flexibility;
|
|
import holeg.model.Flexibility;
|
|
-import holeg.model.GroupNode;
|
|
|
|
import holeg.model.HolonElement;
|
|
import holeg.model.HolonElement;
|
|
import holeg.model.HolonObject;
|
|
import holeg.model.HolonObject;
|
|
import holeg.model.HolonObject.HolonObjectState;
|
|
import holeg.model.HolonObject.HolonObjectState;
|
|
import holeg.preferences.ColorPreference;
|
|
import holeg.preferences.ColorPreference;
|
|
|
|
+import holeg.preferences.ImagePreference;
|
|
import holeg.ui.controller.Control;
|
|
import holeg.ui.controller.Control;
|
|
-import holeg.utility.math.decimal.Format;
|
|
|
|
import holeg.ui.model.GuiSettings;
|
|
import holeg.ui.model.GuiSettings;
|
|
|
|
+import holeg.ui.view.image.Import;
|
|
|
|
+import holeg.utility.math.decimal.Format;
|
|
|
|
+import org.knowm.xchart.PieChart;
|
|
|
|
+import org.knowm.xchart.PieChartBuilder;
|
|
|
|
+import org.knowm.xchart.PieSeries.PieSeriesRenderStyle;
|
|
|
|
+import org.knowm.xchart.XChartPanel;
|
|
|
|
+import org.knowm.xchart.style.PieStyler;
|
|
|
|
+import org.knowm.xchart.style.PieStyler.LabelType;
|
|
|
|
+
|
|
|
|
+import javax.swing.*;
|
|
|
|
+import javax.swing.border.EmptyBorder;
|
|
|
|
+import javax.swing.event.PopupMenuEvent;
|
|
|
|
+import javax.swing.event.PopupMenuListener;
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.logging.Logger;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
-//TODO(Tom2022-01-13): Fix;
|
|
|
|
public class HolonInformationPanel extends JPanel {
|
|
public class HolonInformationPanel extends JPanel {
|
|
- private static final Logger log = Logger.getLogger(JPanel.class.getName());
|
|
|
|
|
|
+ private static final Logger log = Logger.getLogger(HolonInformationPanel.class.getName());
|
|
//private Predicate<DecoratedHolonObject> stateFilter = (object) -> true;// = (object) -> object.getState() ==
|
|
//private Predicate<DecoratedHolonObject> stateFilter = (object) -> true;// = (object) -> object.getState() ==
|
|
// HolonObjectState.PRODUCER;
|
|
// HolonObjectState.PRODUCER;
|
|
- private Predicate<HolonElement> priorityFilter = (ele) -> true;
|
|
|
|
private final int defaultWidth = 50;
|
|
private final int defaultWidth = 50;
|
|
private final int defaultHeight = 200;
|
|
private final int defaultHeight = 200;
|
|
|
|
|
|
private static final Color[] supplyStateColors = new Color[] { ColorPreference.HolonObject.Producer,
|
|
private static final Color[] supplyStateColors = new Color[] { ColorPreference.HolonObject.Producer,
|
|
ColorPreference.HolonObject.OverSupplied, ColorPreference.HolonObject.Supplied,
|
|
ColorPreference.HolonObject.OverSupplied, ColorPreference.HolonObject.Supplied,
|
|
ColorPreference.HolonObject.PartiallySupplied, ColorPreference.HolonObject.NotSupplied,
|
|
ColorPreference.HolonObject.PartiallySupplied, ColorPreference.HolonObject.NotSupplied,
|
|
- ColorPreference.HolonObject.NoEnergy };
|
|
|
|
|
|
+ ColorPreference.HolonObject.NoEnergy, ColorPreference.InformationPanel.NoData };
|
|
private static final Color[] productionColors = new Color[] { ColorPreference.Energy.Production,
|
|
private static final Color[] productionColors = new Color[] { ColorPreference.Energy.Production,
|
|
- ColorPreference.Energy.Consumption };
|
|
|
|
|
|
+ ColorPreference.Energy.Consumption, ColorPreference.InformationPanel.NoData };
|
|
private static final Color[] activeColors = new Color[] { ColorPreference.Element.Active,
|
|
private static final Color[] activeColors = new Color[] { ColorPreference.Element.Active,
|
|
- ColorPreference.Element.Inactive };
|
|
|
|
|
|
+ ColorPreference.Element.Inactive, ColorPreference.InformationPanel.NoData };
|
|
private static final Color[] flexibilityColors = new Color[] { ColorPreference.Flexibility.Offered,
|
|
private static final Color[] flexibilityColors = new Color[] { ColorPreference.Flexibility.Offered,
|
|
ColorPreference.Flexibility.InUse, ColorPreference.Flexibility.OnCooldown,
|
|
ColorPreference.Flexibility.InUse, ColorPreference.Flexibility.OnCooldown,
|
|
- ColorPreference.Flexibility.NotOffered, ColorPreference.Flexibility.Unavailable,
|
|
|
|
- ColorPreference.Element.Priority.NoData };
|
|
|
|
|
|
+ ColorPreference.Flexibility.NotOffered, ColorPreference.Flexibility.Unavailable, ColorPreference.Flexibility.NoFlexibility,
|
|
|
|
+ ColorPreference.InformationPanel.NoData };
|
|
private static final Color[] priorityColors = new Color[] { ColorPreference.Element.Priority.Essential,
|
|
private static final Color[] priorityColors = new Color[] { ColorPreference.Element.Priority.Essential,
|
|
ColorPreference.Element.Priority.High, ColorPreference.Element.Priority.Medium,
|
|
ColorPreference.Element.Priority.High, ColorPreference.Element.Priority.Medium,
|
|
- ColorPreference.Element.Priority.Low, ColorPreference.Element.Priority.NoData };
|
|
|
|
|
|
+ ColorPreference.Element.Priority.Low, ColorPreference.InformationPanel.NoData };
|
|
|
|
|
|
- private PieChart supplyChart = createSupplyStateChart();
|
|
|
|
- private PieChart priorityChart = createPriorityChart();
|
|
|
|
- private PieChart flexibilityChart = createFlexibilityChart();
|
|
|
|
- private PieChart energyChart = createProductionChart();
|
|
|
|
- private PieChart activeChart = createActiveChart();
|
|
|
|
|
|
+ private final PieChart supplyChart = createSupplyStateChart();
|
|
|
|
+ private final PieChart priorityChart = createPriorityChart();
|
|
|
|
+ private final PieChart flexibilityChart = createFlexibilityChart();
|
|
|
|
+ private final PieChart energyChart = createProductionChart();
|
|
|
|
+ private final PieChart activeChart = createActiveChart();
|
|
|
|
+
|
|
|
|
+ private final JPanel graphPanel = new JPanel(new GridLayout(0, 2));
|
|
|
|
+ private final JPanel titlePanel = new JPanel(new BorderLayout(0, 0));
|
|
|
|
+
|
|
|
|
+ private final JCheckBoxMenuItem producerCheckBox = new JCheckBoxMenuItem("Producer", true);
|
|
|
|
+ private final JCheckBoxMenuItem overSuppliedCheckBox = new JCheckBoxMenuItem("Over supplied", true);
|
|
|
|
+ private final JCheckBoxMenuItem suppliedCheckBox = new JCheckBoxMenuItem("Supplied", true);
|
|
|
|
+ private final JCheckBoxMenuItem partiallySuppliedCheckBox = new JCheckBoxMenuItem("Partial supplied", true);
|
|
|
|
+ private final JCheckBoxMenuItem notSuppliedCheckBox = new JCheckBoxMenuItem("Not supplied", true);
|
|
|
|
+ private final JCheckBoxMenuItem noEnergyCheckBox = new JCheckBoxMenuItem("No energy", true);
|
|
|
|
|
|
- private XChartPanel<PieChart> panelHolonObject;
|
|
|
|
- private XChartPanel<PieChart> panelPriority;
|
|
|
|
- private XChartPanel<PieChart> panelFlexibility;
|
|
|
|
- private XChartPanel<PieChart> panelEnergy;
|
|
|
|
- private XChartPanel<PieChart> panelActive;
|
|
|
|
|
|
+ private final JCheckBoxMenuItem essentialCheckBox = new JCheckBoxMenuItem("Essential", true);
|
|
|
|
+ private final JCheckBoxMenuItem highCheckBox = new JCheckBoxMenuItem("High", true);
|
|
|
|
+ private final JCheckBoxMenuItem mediumBox = new JCheckBoxMenuItem("Medium", true);
|
|
|
|
+ private final JCheckBoxMenuItem lowCheckBox = new JCheckBoxMenuItem("Low", true);
|
|
|
|
|
|
- private JPanel graphPanel = new JPanel(new GridLayout(0, 2));
|
|
|
|
- private JPanel titlePanel = new JPanel(new BorderLayout(0, 0));
|
|
|
|
|
|
+ private final JCheckBoxMenuItem activeCheckBox = new JCheckBoxMenuItem("Active", true);
|
|
|
|
+ private final JCheckBoxMenuItem inactiveCheckBox = new JCheckBoxMenuItem("Inactive", true);
|
|
|
|
|
|
- private Control control;
|
|
|
|
- private JLabel differenceEnergyLabelAmount = new JLabel("");
|
|
|
|
|
|
+ private final JCheckBoxMenuItem noFlexibilityCheckBox = new JCheckBoxMenuItem("No Flexibility", true);
|
|
|
|
+ private final JCheckBoxMenuItem inUseCheckBox = new JCheckBoxMenuItem("In use", true);
|
|
|
|
+ private final JCheckBoxMenuItem offeredCheckBox = new JCheckBoxMenuItem("Offered", true);
|
|
|
|
+ private final JCheckBoxMenuItem notOfferedCheckBox = new JCheckBoxMenuItem("Not offered", true);
|
|
|
|
+ private final JCheckBoxMenuItem onCooldownCheckBox = new JCheckBoxMenuItem("On cooldown", true);
|
|
|
|
+ private final JCheckBoxMenuItem unavailableCheckBox = new JCheckBoxMenuItem("Unavailable", true);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private final Control control;
|
|
|
|
+ private final JLabel differenceEnergyLabelAmount = new JLabel("");
|
|
|
|
|
|
public HolonInformationPanel(Control control) {
|
|
public HolonInformationPanel(Control control) {
|
|
- control.OnSelectionChanged.addListener(() -> updateCharts());
|
|
|
|
|
|
+ control.OnSelectionChanged.addListener(this::updateCharts);
|
|
|
|
+ control.OnCanvasUpdate.addListener(this::updateCharts);
|
|
this.control = control;
|
|
this.control = control;
|
|
this.setLayout(new BorderLayout());
|
|
this.setLayout(new BorderLayout());
|
|
initGraphPanel();
|
|
initGraphPanel();
|
|
@@ -94,163 +98,271 @@ public class HolonInformationPanel extends JPanel {
|
|
}
|
|
}
|
|
|
|
|
|
public void updateCharts() {
|
|
public void updateCharts() {
|
|
- if (GuiSettings.getSelectedObjects().isEmpty()) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- Optional<FilterableGroupNode> filteredGroupNode = multiSelectionToFilterableGroupNode();
|
|
|
|
- if(filteredGroupNode.isEmpty()) {
|
|
|
|
- return;
|
|
|
|
|
|
+ FilterableGroupNode tempGroupNode = new FilterableGroupNode();
|
|
|
|
+ if(GuiSettings.getSelectedObjects().isEmpty()){
|
|
|
|
+ tempGroupNode.add(control.getModel().getCanvas());
|
|
|
|
+ }else{
|
|
|
|
+ tempGroupNode.addAll(GuiSettings.getSelectedObjects());
|
|
}
|
|
}
|
|
-
|
|
|
|
- FilterableGroupNode decoratedGroupNode = filteredGroupNode.get();
|
|
|
|
|
|
+
|
|
|
|
+ List<HolonObject> filteredHolonObjectList = tempGroupNode.getAllHolonObjectsRecursive().filter(this::stateFilter).toList();
|
|
|
|
+ Map<HolonObjectState, Long> stateMap = filteredHolonObjectList.stream().collect(Collectors.groupingBy(HolonObject::getState, Collectors.counting()));
|
|
// UPDATE SUPPLY STATE
|
|
// UPDATE SUPPLY STATE
|
|
-// int producerAmount = decoratedGroupNode.getAmountOfSupplier(stateFilter);
|
|
|
|
-// int overSuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
|
|
|
|
-// HolonObjectState.OVER_SUPPLIED);
|
|
|
|
-// int suppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter, HolonObjectState.SUPPLIED);
|
|
|
|
-// int partiallySuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
|
|
|
|
-// HolonObjectState.PARTIALLY_SUPPLIED);
|
|
|
|
-// int notSuppliedAmount = decoratedGroupNode.getAmountOfConsumerWithState(stateFilter,
|
|
|
|
-// HolonObjectState.NOT_SUPPLIED);
|
|
|
|
-// int noEnergyAmount = decoratedGroupNode.getAmountOfPassiv(stateFilter);
|
|
|
|
-//
|
|
|
|
-// supplyChart.updatePieSeries("Producer", producerAmount);
|
|
|
|
-// supplyChart.updatePieSeries("Over supplied", overSuppliedAmount);
|
|
|
|
-// supplyChart.updatePieSeries("Supplied", suppliedAmount);
|
|
|
|
-// supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
|
|
|
|
-// supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
|
|
|
|
-// supplyChart.updatePieSeries("No energy", noEnergyAmount);
|
|
|
|
-
|
|
|
|
- // UPDATE PRIORITYS
|
|
|
|
-// holeg.ui.view.information.FilterableGroupNode.PriorityCounts priorityCounts = decoratedGroupNode
|
|
|
|
-// .getPriorityCounts(stateFilter);
|
|
|
|
-//
|
|
|
|
-// priorityChart.updatePieSeries("Essential", priorityCounts.essential);
|
|
|
|
-// priorityChart.updatePieSeries("High", priorityCounts.high);
|
|
|
|
-// priorityChart.updatePieSeries("Medium", priorityCounts.medium);
|
|
|
|
-// priorityChart.updatePieSeries("Low", priorityCounts.low);
|
|
|
|
-// boolean hasPriority = priorityCounts.essential + priorityCounts.high + priorityCounts.medium
|
|
|
|
-// + priorityCounts.low > 0;
|
|
|
|
-// priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
|
|
|
|
-// updateToolTips(panelPriority);
|
|
|
|
|
|
+ int producerAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.PRODUCER, 0L));
|
|
|
|
+ int overSuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.OVER_SUPPLIED, 0L));
|
|
|
|
+ int suppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.SUPPLIED, 0L));
|
|
|
|
+ int partiallySuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.PARTIALLY_SUPPLIED, 0L));
|
|
|
|
+ int notSuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.NOT_SUPPLIED, 0L));
|
|
|
|
+ int noEnergyAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.NO_ENERGY, 0L));
|
|
|
|
+
|
|
|
|
+ supplyChart.updatePieSeries("Producer", producerAmount);
|
|
|
|
+ supplyChart.updatePieSeries("Over supplied", overSuppliedAmount);
|
|
|
|
+ supplyChart.updatePieSeries("Supplied", suppliedAmount);
|
|
|
|
+ supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
|
|
|
|
+ supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
|
|
|
|
+ supplyChart.updatePieSeries("No energy", noEnergyAmount);
|
|
|
|
+ supplyChart.updatePieSeries("No Data", filteredHolonObjectList.isEmpty() ? 1 : 0);
|
|
|
|
+ //UPDATE PRIORITIES
|
|
|
|
+
|
|
|
|
+ List<HolonElement> filteredHolonElements = filteredHolonObjectList.stream().flatMap(HolonObject::elementsStream)
|
|
|
|
+ .filter(ele -> priorityFilter(ele) && activeFilter(ele) && flexibilityFilter(ele)).toList();
|
|
|
|
+ Map<HolonElement.Priority, Long> priorityCounts = filteredHolonElements.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(HolonElement::getPriority, Collectors.counting()));
|
|
|
|
+
|
|
|
|
+ long essential = priorityCounts.getOrDefault(HolonElement.Priority.Essential, 0L);
|
|
|
|
+ long high = priorityCounts.getOrDefault(HolonElement.Priority.High, 0L);
|
|
|
|
+ long medium = priorityCounts.getOrDefault(HolonElement.Priority.Medium, 0L);
|
|
|
|
+ long low = priorityCounts.getOrDefault(HolonElement.Priority.Low, 0L);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ priorityChart.updatePieSeries("Essential", essential);
|
|
|
|
+ priorityChart.updatePieSeries("High", high);
|
|
|
|
+ priorityChart.updatePieSeries("Medium", medium);
|
|
|
|
+ priorityChart.updatePieSeries("Low", low);
|
|
|
|
+ boolean hasPriority = essential + high + medium + low > 0;
|
|
|
|
+ priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
|
|
|
|
|
|
// UPDATE PRODUCTION
|
|
// UPDATE PRODUCTION
|
|
-// float production = decoratedGroupNode.getProduction(stateFilter, priorityFilter);
|
|
|
|
-// float consumption = decoratedGroupNode.getConsumption(stateFilter, priorityFilter);
|
|
|
|
-// log.info("production" + production + " consumption" + consumption);
|
|
|
|
-// float difference = Math.abs(production - consumption);
|
|
|
|
-// energyChart.updatePieSeries("Production", production);
|
|
|
|
-// energyChart.updatePieSeries("Consumption", consumption);
|
|
|
|
-// differenceEnergyLabelAmount.setText(Format.doubleFixedPlaces(1, difference));
|
|
|
|
-//
|
|
|
|
-// // UPDATE FLEXIBILITIES
|
|
|
|
-// int inUse = 0;
|
|
|
|
-// int offered = 0;
|
|
|
|
-// int onCooldown = 0;
|
|
|
|
-// int notOffered = 0;
|
|
|
|
-// int unavailable = 0;
|
|
|
|
-//
|
|
|
|
-// Stream<Flexibility> flexWrapperStream = decoratedGroupNode.getFlexibilitiesStream(stateFilter, priorityFilter);
|
|
|
|
-// List<Flexibility> flexList = flexWrapperStream.collect(Collectors.toList());
|
|
|
|
-// for (Flexibility flex : flexList) {
|
|
|
|
-// switch (flex.getState()) {
|
|
|
|
-// case IN_USE:
|
|
|
|
-// inUse++;
|
|
|
|
-// break;
|
|
|
|
-// case NOT_OFFERED:
|
|
|
|
-// notOffered++;
|
|
|
|
-// break;
|
|
|
|
-// case OFFERED:
|
|
|
|
-// offered++;
|
|
|
|
-// break;
|
|
|
|
-// case ON_COOLDOWN:
|
|
|
|
-// onCooldown++;
|
|
|
|
-// break;
|
|
|
|
-// case UNAVAILABLE:
|
|
|
|
-// unavailable++;
|
|
|
|
-// break;
|
|
|
|
-// default:
|
|
|
|
-// break;
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// flexibilityChart.updatePieSeries("Offered", offered);
|
|
|
|
-// flexibilityChart.updatePieSeries("In use", inUse);
|
|
|
|
-// flexibilityChart.updatePieSeries("On cooldown", onCooldown);
|
|
|
|
-// flexibilityChart.updatePieSeries("Not offered", notOffered);
|
|
|
|
-// flexibilityChart.updatePieSeries("Unavailable", unavailable);
|
|
|
|
-// boolean hasFlex = offered + inUse + onCooldown + notOffered + unavailable > 0;
|
|
|
|
-// flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
|
|
|
|
-// // UPDATE ActiveInActive
|
|
|
|
-// int activeAmount = decoratedGroupNode.getAmountOfAktiveElementsFromHolonObjects(stateFilter, priorityFilter);
|
|
|
|
-// int inactiveAmounts = decoratedGroupNode.getAmountOfElementsFromHolonObjects(stateFilter, priorityFilter)
|
|
|
|
-// - activeAmount;
|
|
|
|
-// activeChart.updatePieSeries("Active", activeAmount);
|
|
|
|
-// activeChart.updatePieSeries("Inactive", inactiveAmounts);
|
|
|
|
-
|
|
|
|
|
|
+ float consumption = filteredHolonElements.stream().filter(element -> element.getActualEnergy() < 0)
|
|
|
|
+ .map(element -> -element.getActualEnergy()).reduce(0.0f, Float::sum);
|
|
|
|
+ float production = filteredHolonElements.stream()
|
|
|
|
+ .map(HolonElement::getActualEnergy).filter(energy -> energy > 0).reduce(0.0f, Float::sum);
|
|
|
|
+
|
|
|
|
+ float difference = Math.abs(production - consumption);
|
|
|
|
+ energyChart.updatePieSeries("Production", production);
|
|
|
|
+ energyChart.updatePieSeries("Consumption", consumption);
|
|
|
|
+ energyChart.updatePieSeries("No Data", production + consumption == 0 ? 1 : 0);
|
|
|
|
+ differenceEnergyLabelAmount.setText(Format.doubleFixedPlaces(1, difference));
|
|
|
|
+
|
|
|
|
+ // UPDATE FLEXIBILITIES
|
|
|
|
+ int inUse = 0;
|
|
|
|
+ int offered = 0;
|
|
|
|
+ int onCooldown = 0;
|
|
|
|
+ int notOffered = 0;
|
|
|
|
+ int unavailable = 0;
|
|
|
|
+
|
|
|
|
+ List<Flexibility> flexList = filteredHolonElements.stream().flatMap(ele -> ele.flexList.stream()).toList();
|
|
|
|
+ for (Flexibility flex : flexList) {
|
|
|
|
+ switch (flex.getState()) {
|
|
|
|
+ case IN_USE -> inUse++;
|
|
|
|
+ case NOT_OFFERED -> notOffered++;
|
|
|
|
+ case OFFERED -> offered++;
|
|
|
|
+ case ON_COOLDOWN -> onCooldown++;
|
|
|
|
+ case UNAVAILABLE -> unavailable++;
|
|
|
|
+ default -> {
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ int noFlexibility = (int)filteredHolonElements.stream().filter(ele -> ele.flexList.isEmpty()).count();
|
|
|
|
+ flexibilityChart.updatePieSeries("No flexibility", noFlexibility);
|
|
|
|
+ flexibilityChart.updatePieSeries("Offered", offered);
|
|
|
|
+ flexibilityChart.updatePieSeries("In use", inUse);
|
|
|
|
+ flexibilityChart.updatePieSeries("On cooldown", onCooldown);
|
|
|
|
+ flexibilityChart.updatePieSeries("Not offered", notOffered);
|
|
|
|
+ flexibilityChart.updatePieSeries("Unavailable", unavailable);
|
|
|
|
+ boolean hasFlex = noFlexibility + offered + inUse + onCooldown + notOffered + unavailable > 0;
|
|
|
|
+ flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
|
|
|
|
+
|
|
|
|
+ Map<Boolean, Long> activeCounts = filteredHolonElements.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(HolonElement::isOn, Collectors.counting()));
|
|
|
|
+
|
|
|
|
+ // UPDATE ActiveInActive
|
|
|
|
+ int activeAmount = Math.toIntExact(activeCounts.getOrDefault(true, 0L));
|
|
|
|
+ int inactiveAmounts = Math.toIntExact(activeCounts.getOrDefault(false, 0L));
|
|
|
|
+ activeChart.updatePieSeries("Active", activeAmount);
|
|
|
|
+ activeChart.updatePieSeries("Inactive", inactiveAmounts);
|
|
|
|
+ activeChart.updatePieSeries("No Data", activeAmount + inactiveAmounts == 0 ? 1 : 0);
|
|
this.revalidate();
|
|
this.revalidate();
|
|
this.repaint();
|
|
this.repaint();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private Optional<FilterableGroupNode> multiSelectionToFilterableGroupNode() {
|
|
|
|
-// FilterableGroupNode temp = new FilterableGroupNode(new GroupNode("Temp"),
|
|
|
|
-// control.getModel().getCurrentIteration());
|
|
|
|
-
|
|
|
|
-// Optional<VisualRepresentationalState> visState = control.getSimManager().getActualVisualRepresentationalState();
|
|
|
|
-// if(visState.isEmpty()) {
|
|
|
|
-// return Optional.empty();
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// // GroupNodes
|
|
|
|
-// HashMap<GroupNode, DecoratedGroupNode> accessMapGroupNode = visState.get().getCreatedGroupNodes();
|
|
|
|
-// List<FilterableGroupNode> groupNodeList = GuiSettings.getSelectedObjects().stream()
|
|
|
|
-// .filter(object -> object instanceof GroupNode).map(object -> accessMapGroupNode.get(object))
|
|
|
|
-// .map(node -> new FilterableGroupNode(node, control.getModel().getCurrentIteration()))
|
|
|
|
-// .collect(Collectors.toList());
|
|
|
|
-//
|
|
|
|
-// temp.getGroupNodeList().addAll(groupNodeList);
|
|
|
|
-//
|
|
|
|
-// // HolonObjects
|
|
|
|
-// HashMap<HolonObject, DecoratedHolonObject> accessMapHolonObject = visState.get().createdHolonObjects;
|
|
|
|
-// List<DecoratedHolonObject> holonObjectList = GuiSettings.getSelectedObjects().stream()
|
|
|
|
-// .filter(object -> object instanceof HolonObject).map(object -> accessMapHolonObject.get(object))
|
|
|
|
-// .collect(Collectors.toList());
|
|
|
|
-//
|
|
|
|
-// for (DecoratedHolonObject object : holonObjectList) {
|
|
|
|
-// switch (object.getState()) {
|
|
|
|
-// case NO_ENERGY:
|
|
|
|
-// temp.getPassivList().add((Passiv) object);
|
|
|
|
-// break;
|
|
|
|
-// case PRODUCER:
|
|
|
|
-// temp.getSupplierList().add((Supplier) object);
|
|
|
|
-// break;
|
|
|
|
-// default:
|
|
|
|
-// temp.getConsumerList().add((Consumer) object);
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// return Optional.of(temp);
|
|
|
|
- return Optional.empty();
|
|
|
|
|
|
+ private JPopupMenu createHolonStateSelection(){
|
|
|
|
+ JPopupMenu menu = new JPopupMenu();
|
|
|
|
+ producerCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ overSuppliedCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ suppliedCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ partiallySuppliedCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ notSuppliedCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ noEnergyCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ menu.add(producerCheckBox);
|
|
|
|
+ menu.add(overSuppliedCheckBox);
|
|
|
|
+ menu.add(suppliedCheckBox);
|
|
|
|
+ menu.add(partiallySuppliedCheckBox);
|
|
|
|
+ menu.add(notSuppliedCheckBox);
|
|
|
|
+ menu.add(noEnergyCheckBox);
|
|
|
|
+ return menu;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JPopupMenu createPrioritySelection(){
|
|
|
|
+ JPopupMenu menu = new JPopupMenu();
|
|
|
|
+ essentialCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ highCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ mediumBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ lowCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ menu.add(essentialCheckBox);
|
|
|
|
+ menu.add(highCheckBox);
|
|
|
|
+ menu.add(mediumBox);
|
|
|
|
+ menu.add(lowCheckBox);
|
|
|
|
+ return menu;
|
|
|
|
+ }
|
|
|
|
+ private JPopupMenu createActiveSelection(){
|
|
|
|
+ JPopupMenu menu = new JPopupMenu();
|
|
|
|
+ activeCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ inactiveCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ menu.add(activeCheckBox);
|
|
|
|
+ menu.add(inactiveCheckBox);
|
|
|
|
+ return menu;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JPopupMenu createFlexibilitySelection(){
|
|
|
|
+ JPopupMenu menu = new JPopupMenu();
|
|
|
|
+ noFlexibilityCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ offeredCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ notOfferedCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ unavailableCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ inUseCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ onCooldownCheckBox.addActionListener(clicked -> updateCharts());
|
|
|
|
+ menu.add(noFlexibilityCheckBox);
|
|
|
|
+ menu.add(offeredCheckBox);
|
|
|
|
+ menu.add(notOfferedCheckBox);
|
|
|
|
+ menu.add(unavailableCheckBox);
|
|
|
|
+ menu.add(inUseCheckBox);
|
|
|
|
+ menu.add(onCooldownCheckBox);
|
|
|
|
+ return menu;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private JPanel initMenuButtonPanel(JPopupMenu menu){
|
|
|
|
+ JPanel buttonPanel = new JPanel(new BorderLayout());
|
|
|
|
+ MenuButton button = new MenuButton(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.Filter, 20, 20)), menu);
|
|
|
|
+ buttonPanel.add(button, BorderLayout.LINE_END);
|
|
|
|
+ buttonPanel.setOpaque(false);
|
|
|
|
+ button.setPressedIcon(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.FilterHovered, 20, 20)));
|
|
|
|
+ button.setRolloverIcon(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.FilterHovered, 20, 20)));
|
|
|
|
+ button.setBorderPainted(false);
|
|
|
|
+ button.setBorder(null);
|
|
|
|
+ button.setFocusable(false);
|
|
|
|
+ button.setMargin(new Insets(0, 0, 0, 0));
|
|
|
|
+ button.setContentAreaFilled(false);
|
|
|
|
+ return buttonPanel;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private boolean stateFilter(HolonObject holonObject){
|
|
|
|
+ return switch (holonObject.getState()) {
|
|
|
|
+ case PRODUCER -> producerCheckBox.isSelected();
|
|
|
|
+ case OVER_SUPPLIED -> overSuppliedCheckBox.isSelected();
|
|
|
|
+ case SUPPLIED -> suppliedCheckBox.isSelected();
|
|
|
|
+ case PARTIALLY_SUPPLIED -> partiallySuppliedCheckBox.isSelected();
|
|
|
|
+ case NOT_SUPPLIED -> notSuppliedCheckBox.isSelected();
|
|
|
|
+ case NO_ENERGY -> noEnergyCheckBox.isSelected();
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean priorityFilter(HolonElement ele){
|
|
|
|
+ return switch (ele.priority) {
|
|
|
|
+ case Essential -> essentialCheckBox.isSelected();
|
|
|
|
+ case High -> highCheckBox.isSelected();
|
|
|
|
+ case Medium -> mediumBox.isSelected();
|
|
|
|
+ case Low -> lowCheckBox.isSelected();
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean activeFilter(HolonElement ele){
|
|
|
|
+ return ele.active ? activeCheckBox.isSelected(): inactiveCheckBox.isSelected();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean flexibilityFilter(HolonElement ele){
|
|
|
|
+ if(ele.flexList.isEmpty()){
|
|
|
|
+ return noFlexibilityCheckBox.isSelected();
|
|
|
|
+ }
|
|
|
|
+ Map<Flexibility.FlexState,Long> flexes = ele.flexList.stream().collect(Collectors.groupingBy(Flexibility::getState, Collectors.counting()));
|
|
|
|
+ return flexes.keySet().stream().anyMatch(flexState -> switch (flexState) {
|
|
|
|
+ case IN_USE -> inUseCheckBox.isSelected();
|
|
|
|
+ case UNAVAILABLE -> unavailableCheckBox.isSelected();
|
|
|
|
+ case OFFERED -> offeredCheckBox.isSelected();
|
|
|
|
+ case NOT_OFFERED -> notOfferedCheckBox.isSelected();
|
|
|
|
+ case ON_COOLDOWN -> onCooldownCheckBox.isSelected();
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void initGraphPanel() {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static class MenuButton extends JToggleButton {
|
|
|
|
+
|
|
|
|
+ JPopupMenu popup;
|
|
|
|
+
|
|
|
|
+ public MenuButton(Icon icon, JPopupMenu menu) {
|
|
|
|
+ super(icon);
|
|
|
|
+ this.popup = menu;
|
|
|
|
+ addActionListener(clicked -> {
|
|
|
|
+ if (MenuButton.this.isSelected()) {
|
|
|
|
+ popup.show(MenuButton.this, 0, MenuButton.this.getBounds().height);
|
|
|
|
+ } else {
|
|
|
|
+ popup.setVisible(false);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ popup.addPopupMenuListener(new PopupMenuListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
|
|
|
|
+ @Override
|
|
|
|
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
|
|
|
+ MenuButton.this.setSelected(false);
|
|
|
|
+ }
|
|
|
|
+ @Override
|
|
|
|
+ public void popupMenuCanceled(PopupMenuEvent e) {}
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private void initGraphPanel() {
|
|
graphPanel.setBackground(ColorPreference.Panel.Background);
|
|
graphPanel.setBackground(ColorPreference.Panel.Background);
|
|
- panelHolonObject = new XChartPanel<PieChart>(supplyChart);
|
|
|
|
|
|
+ XChartPanel<PieChart> panelHolonObject = new XChartPanel<>(supplyChart);
|
|
|
|
+ panelHolonObject.setLayout(new BorderLayout());
|
|
|
|
+ panelHolonObject.add(initMenuButtonPanel(createHolonStateSelection()), BorderLayout.PAGE_START);
|
|
panelHolonObject.setBackground(ColorPreference.Panel.Background);
|
|
panelHolonObject.setBackground(ColorPreference.Panel.Background);
|
|
graphPanel.add(panelHolonObject);
|
|
graphPanel.add(panelHolonObject);
|
|
- panelPriority = new XChartPanel<PieChart>(priorityChart);
|
|
|
|
|
|
+ XChartPanel<PieChart> panelPriority = new XChartPanel<>(priorityChart);
|
|
|
|
+ panelPriority.setLayout(new BorderLayout());
|
|
|
|
+ panelPriority.add(initMenuButtonPanel(createPrioritySelection()), BorderLayout.PAGE_START);
|
|
panelPriority.setBackground(ColorPreference.Panel.Background);
|
|
panelPriority.setBackground(ColorPreference.Panel.Background);
|
|
graphPanel.add(panelPriority);
|
|
graphPanel.add(panelPriority);
|
|
- panelFlexibility = new XChartPanel<PieChart>(flexibilityChart);
|
|
|
|
|
|
+ XChartPanel<PieChart> panelFlexibility = new XChartPanel<>(flexibilityChart);
|
|
|
|
+ panelFlexibility.setLayout(new BorderLayout());
|
|
|
|
+ panelFlexibility.add(initMenuButtonPanel(createFlexibilitySelection()), BorderLayout.PAGE_START);
|
|
panelFlexibility.setBackground(ColorPreference.Panel.Background);
|
|
panelFlexibility.setBackground(ColorPreference.Panel.Background);
|
|
graphPanel.add(panelFlexibility);
|
|
graphPanel.add(panelFlexibility);
|
|
Component panel = initEnergyChart();
|
|
Component panel = initEnergyChart();
|
|
graphPanel.add(panel);
|
|
graphPanel.add(panel);
|
|
- panelActive = new XChartPanel<PieChart>(activeChart);
|
|
|
|
|
|
+ XChartPanel<PieChart> panelActive = new XChartPanel<>(activeChart);
|
|
|
|
+ panelActive.setLayout(new BorderLayout());
|
|
|
|
+ panelActive.add(initMenuButtonPanel(createActiveSelection()), BorderLayout.PAGE_START);
|
|
panelActive.setBackground(ColorPreference.Panel.Background);
|
|
panelActive.setBackground(ColorPreference.Panel.Background);
|
|
- panelActive.setLayout(new GridBagLayout());
|
|
|
|
graphPanel.add(panelActive);
|
|
graphPanel.add(panelActive);
|
|
graphPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
|
|
graphPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
|
|
}
|
|
}
|
|
@@ -258,7 +370,7 @@ public class HolonInformationPanel extends JPanel {
|
|
private JLayeredPane initEnergyChart() {
|
|
private JLayeredPane initEnergyChart() {
|
|
JLayeredPane panel = new JLayeredPane();
|
|
JLayeredPane panel = new JLayeredPane();
|
|
JPanel panelMiddle = new JPanel(new GridBagLayout());
|
|
JPanel panelMiddle = new JPanel(new GridBagLayout());
|
|
- panelEnergy = new XChartPanel<PieChart>(energyChart);
|
|
|
|
|
|
+ XChartPanel<PieChart> panelEnergy = new XChartPanel<>(energyChart);
|
|
panelEnergy.setBackground(ColorPreference.Panel.Background);
|
|
panelEnergy.setBackground(ColorPreference.Panel.Background);
|
|
GridBagConstraints c = new GridBagConstraints();
|
|
GridBagConstraints c = new GridBagConstraints();
|
|
c.gridx = 0;
|
|
c.gridx = 0;
|
|
@@ -310,7 +422,7 @@ public class HolonInformationPanel extends JPanel {
|
|
}
|
|
}
|
|
|
|
|
|
public PieChart createSupplyStateChart() {
|
|
public PieChart createSupplyStateChart() {
|
|
- PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Holon Objects").build();
|
|
|
|
|
|
+ PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("HolonObjects").build();
|
|
setDefaultPieChartSettings(chart);
|
|
setDefaultPieChartSettings(chart);
|
|
|
|
|
|
chart.getStyler().setSeriesColors(supplyStateColors);
|
|
chart.getStyler().setSeriesColors(supplyStateColors);
|
|
@@ -322,11 +434,12 @@ public class HolonInformationPanel extends JPanel {
|
|
chart.addSeries("Partial supplied", 0);
|
|
chart.addSeries("Partial supplied", 0);
|
|
chart.addSeries("Not supplied", 0);
|
|
chart.addSeries("Not supplied", 0);
|
|
chart.addSeries("No energy", 0);
|
|
chart.addSeries("No energy", 0);
|
|
|
|
+ chart.addSeries("No Data", 0);
|
|
return chart;
|
|
return chart;
|
|
}
|
|
}
|
|
|
|
|
|
public PieChart createPriorityChart() {
|
|
public PieChart createPriorityChart() {
|
|
- PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Priotities").build();
|
|
|
|
|
|
+ PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Priorities").build();
|
|
setDefaultPieChartSettings(chart);
|
|
setDefaultPieChartSettings(chart);
|
|
// Customize Chart
|
|
// Customize Chart
|
|
|
|
|
|
@@ -352,6 +465,7 @@ public class HolonInformationPanel extends JPanel {
|
|
chart.addSeries("On cooldown", 0);
|
|
chart.addSeries("On cooldown", 0);
|
|
chart.addSeries("Not offered", 0);
|
|
chart.addSeries("Not offered", 0);
|
|
chart.addSeries("Unavailable", 0);
|
|
chart.addSeries("Unavailable", 0);
|
|
|
|
+ chart.addSeries("No flexibility", 0);
|
|
chart.addSeries("No Data", 0);
|
|
chart.addSeries("No Data", 0);
|
|
return chart;
|
|
return chart;
|
|
}
|
|
}
|
|
@@ -368,6 +482,7 @@ public class HolonInformationPanel extends JPanel {
|
|
// Series
|
|
// Series
|
|
chart.addSeries("Production", 0);
|
|
chart.addSeries("Production", 0);
|
|
chart.addSeries("Consumption", 0);
|
|
chart.addSeries("Consumption", 0);
|
|
|
|
+ chart.addSeries("No Data", 0);
|
|
return chart;
|
|
return chart;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -381,6 +496,7 @@ public class HolonInformationPanel extends JPanel {
|
|
// Series
|
|
// Series
|
|
chart.addSeries("Active", 0);
|
|
chart.addSeries("Active", 0);
|
|
chart.addSeries("Inactive", 0);
|
|
chart.addSeries("Inactive", 0);
|
|
|
|
+ chart.addSeries("No Data", 0);
|
|
return chart;
|
|
return chart;
|
|
}
|
|
}
|
|
}
|
|
}
|