HolonInformationPanel.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. package holeg.ui.view.information;
  2. import holeg.model.*;
  3. import holeg.model.HolonObject.HolonObjectState;
  4. import holeg.preferences.ColorPreference;
  5. import holeg.preferences.ImagePreference;
  6. import holeg.ui.controller.Control;
  7. import holeg.ui.model.GuiSettings;
  8. import holeg.ui.view.image.Import;
  9. import holeg.utility.math.decimal.Format;
  10. import org.knowm.xchart.PieChart;
  11. import org.knowm.xchart.PieChartBuilder;
  12. import org.knowm.xchart.PieSeries.PieSeriesRenderStyle;
  13. import org.knowm.xchart.XChartPanel;
  14. import org.knowm.xchart.style.PieStyler;
  15. import org.knowm.xchart.style.PieStyler.LabelType;
  16. import javax.swing.*;
  17. import javax.swing.event.PopupMenuEvent;
  18. import javax.swing.event.PopupMenuListener;
  19. import java.awt.*;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.logging.Logger;
  23. import java.util.stream.Collectors;
  24. public class HolonInformationPanel extends JPanel {
  25. private static final Logger log = Logger.getLogger(HolonInformationPanel.class.getName());
  26. private final int defaultWidth = 50;
  27. private final int defaultHeight = 200;
  28. private static final Color[] supplyStateColors = new Color[] { ColorPreference.HolonObject.Producer,
  29. ColorPreference.HolonObject.OverSupplied, ColorPreference.HolonObject.Supplied,
  30. ColorPreference.HolonObject.PartiallySupplied, ColorPreference.HolonObject.NotSupplied,
  31. ColorPreference.HolonObject.NoEnergy, ColorPreference.InformationPanel.NoData };
  32. private static final Color[] productionColors = new Color[] { ColorPreference.Energy.Production,
  33. ColorPreference.Energy.Consumption, ColorPreference.InformationPanel.NoData };
  34. private static final Color[] activeColors = new Color[] { ColorPreference.Element.Active,
  35. ColorPreference.Element.Inactive, ColorPreference.InformationPanel.NoData };
  36. private static final Color[] flexibilityColors = new Color[] { ColorPreference.Flexibility.Offered,
  37. ColorPreference.Flexibility.InUse, ColorPreference.Flexibility.OnCooldown,
  38. ColorPreference.Flexibility.NotOffered, ColorPreference.Flexibility.Unavailable, ColorPreference.Flexibility.NoFlexibility,
  39. ColorPreference.InformationPanel.NoData };
  40. private static final Color[] priorityColors = new Color[] { ColorPreference.Element.Priority.Essential,
  41. ColorPreference.Element.Priority.High, ColorPreference.Element.Priority.Medium,
  42. ColorPreference.Element.Priority.Low, ColorPreference.InformationPanel.NoData };
  43. private final PieChart supplyChart = createSupplyStateChart();
  44. private final PieChart priorityChart = createPriorityChart();
  45. private final PieChart flexibilityChart = createFlexibilityChart();
  46. private final PieChart energyChart = createProductionChart();
  47. private final PieChart activeChart = createActiveChart();
  48. private final JPanel graphPanel = new JPanel(new GridLayout(0, 2));
  49. private final JCheckBoxMenuItem producerCheckBox = new JCheckBoxMenuItem("Producer", true);
  50. private final JCheckBoxMenuItem overSuppliedCheckBox = new JCheckBoxMenuItem("Over supplied", true);
  51. private final JCheckBoxMenuItem suppliedCheckBox = new JCheckBoxMenuItem("Supplied", true);
  52. private final JCheckBoxMenuItem partiallySuppliedCheckBox = new JCheckBoxMenuItem("Partial supplied", true);
  53. private final JCheckBoxMenuItem notSuppliedCheckBox = new JCheckBoxMenuItem("Not supplied", true);
  54. private final JCheckBoxMenuItem noEnergyCheckBox = new JCheckBoxMenuItem("No energy", true);
  55. private final JCheckBoxMenuItem essentialCheckBox = new JCheckBoxMenuItem("Essential", true);
  56. private final JCheckBoxMenuItem highCheckBox = new JCheckBoxMenuItem("High", true);
  57. private final JCheckBoxMenuItem mediumBox = new JCheckBoxMenuItem("Medium", true);
  58. private final JCheckBoxMenuItem lowCheckBox = new JCheckBoxMenuItem("Low", true);
  59. private final JCheckBoxMenuItem activeCheckBox = new JCheckBoxMenuItem("Active", true);
  60. private final JCheckBoxMenuItem inactiveCheckBox = new JCheckBoxMenuItem("Inactive", true);
  61. private final JCheckBoxMenuItem noFlexibilityCheckBox = new JCheckBoxMenuItem("No Flexibility", true);
  62. private final JCheckBoxMenuItem inUseCheckBox = new JCheckBoxMenuItem("In use", true);
  63. private final JCheckBoxMenuItem offeredCheckBox = new JCheckBoxMenuItem("Offered", true);
  64. private final JCheckBoxMenuItem notOfferedCheckBox = new JCheckBoxMenuItem("Not offered", true);
  65. private final JCheckBoxMenuItem onCooldownCheckBox = new JCheckBoxMenuItem("On cooldown", true);
  66. private final JCheckBoxMenuItem unavailableCheckBox = new JCheckBoxMenuItem("Unavailable", true);
  67. private final Control control;
  68. private final JLabel differenceEnergyLabelAmount = new JLabel("");
  69. public HolonInformationPanel(Control control) {
  70. control.OnSelectionChanged.addListener(this::updateCharts);
  71. control.OnCanvasUpdate.addListener(this::updateCharts);
  72. this.control = control;
  73. this.setLayout(new BorderLayout());
  74. initGraphPanel();
  75. this.setBackground(ColorPreference.Panel.Background);
  76. this.add(graphPanel, BorderLayout.CENTER);
  77. }
  78. public void updateCharts() {
  79. TempGroupNode tempGroupNode = new TempGroupNode();
  80. if(GuiSettings.getSelectedObjects().isEmpty()){
  81. tempGroupNode.add(control.getModel().getCanvas());
  82. }else{
  83. tempGroupNode.addAll(GuiSettings.getSelectedObjects());
  84. }
  85. List<HolonObject> filteredHolonObjectList = tempGroupNode.getAllHolonObjectsRecursive().filter(this::stateFilter).toList();
  86. Map<HolonObjectState, Long> stateMap = filteredHolonObjectList.stream().collect(Collectors.groupingBy(HolonObject::getState, Collectors.counting()));
  87. // UPDATE SUPPLY STATE
  88. int producerAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.PRODUCER, 0L));
  89. int overSuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.OVER_SUPPLIED, 0L));
  90. int suppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.SUPPLIED, 0L));
  91. int partiallySuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.PARTIALLY_SUPPLIED, 0L));
  92. int notSuppliedAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.NOT_SUPPLIED, 0L));
  93. int noEnergyAmount = Math.toIntExact(stateMap.getOrDefault(HolonObjectState.NO_ENERGY, 0L));
  94. supplyChart.updatePieSeries("Producer", producerAmount);
  95. supplyChart.updatePieSeries("Over supplied", overSuppliedAmount);
  96. supplyChart.updatePieSeries("Supplied", suppliedAmount);
  97. supplyChart.updatePieSeries("Partial supplied", partiallySuppliedAmount);
  98. supplyChart.updatePieSeries("Not supplied", notSuppliedAmount);
  99. supplyChart.updatePieSeries("No energy", noEnergyAmount);
  100. supplyChart.updatePieSeries("No Data", filteredHolonObjectList.isEmpty() ? 1 : 0);
  101. //UPDATE PRIORITIES
  102. List<HolonElement> filteredHolonElements = filteredHolonObjectList.stream().flatMap(HolonObject::elementsStream)
  103. .filter(ele -> priorityFilter(ele) && activeFilter(ele) && flexibilityFilter(ele)).toList();
  104. Map<HolonElement.Priority, Long> priorityCounts = filteredHolonElements.stream()
  105. .collect(Collectors.groupingBy(HolonElement::getPriority, Collectors.counting()));
  106. long essential = priorityCounts.getOrDefault(HolonElement.Priority.Essential, 0L);
  107. long high = priorityCounts.getOrDefault(HolonElement.Priority.High, 0L);
  108. long medium = priorityCounts.getOrDefault(HolonElement.Priority.Medium, 0L);
  109. long low = priorityCounts.getOrDefault(HolonElement.Priority.Low, 0L);
  110. priorityChart.updatePieSeries("Essential", essential);
  111. priorityChart.updatePieSeries("High", high);
  112. priorityChart.updatePieSeries("Medium", medium);
  113. priorityChart.updatePieSeries("Low", low);
  114. boolean hasPriority = essential + high + medium + low > 0;
  115. priorityChart.updatePieSeries("No Data", hasPriority ? 0 : 1);
  116. // UPDATE PRODUCTION
  117. float consumption = filteredHolonElements.stream().filter(element -> element.getActualEnergy() < 0)
  118. .map(element -> -element.getActualEnergy()).reduce(0.0f, Float::sum);
  119. float production = filteredHolonElements.stream()
  120. .map(HolonElement::getActualEnergy).filter(energy -> energy > 0).reduce(0.0f, Float::sum);
  121. float difference = Math.abs(production - consumption);
  122. energyChart.updatePieSeries("Production", production);
  123. energyChart.updatePieSeries("Consumption", consumption);
  124. energyChart.updatePieSeries("No Data", production + consumption == 0 ? 1 : 0);
  125. differenceEnergyLabelAmount.setText(Format.doubleFixedPlaces(1, difference));
  126. // UPDATE FLEXIBILITIES
  127. int inUse = 0;
  128. int offered = 0;
  129. int onCooldown = 0;
  130. int notOffered = 0;
  131. int unavailable = 0;
  132. List<Flexibility> flexList = filteredHolonElements.stream().flatMap(ele -> ele.flexList.stream()).toList();
  133. for (Flexibility flex : flexList) {
  134. switch (flex.getState()) {
  135. case IN_USE -> inUse++;
  136. case NOT_OFFERED -> notOffered++;
  137. case OFFERED -> offered++;
  138. case ON_COOLDOWN -> onCooldown++;
  139. case UNAVAILABLE -> unavailable++;
  140. default -> {
  141. }
  142. }
  143. }
  144. int noFlexibility = (int)filteredHolonElements.stream().filter(ele -> ele.flexList.isEmpty()).count();
  145. flexibilityChart.updatePieSeries("No flexibility", noFlexibility);
  146. flexibilityChart.updatePieSeries("Offered", offered);
  147. flexibilityChart.updatePieSeries("In use", inUse);
  148. flexibilityChart.updatePieSeries("On cooldown", onCooldown);
  149. flexibilityChart.updatePieSeries("Not offered", notOffered);
  150. flexibilityChart.updatePieSeries("Unavailable", unavailable);
  151. boolean hasFlex = noFlexibility + offered + inUse + onCooldown + notOffered + unavailable > 0;
  152. flexibilityChart.updatePieSeries("No Data", hasFlex ? 0 : 1);
  153. Map<Boolean, Long> activeCounts = filteredHolonElements.stream()
  154. .collect(Collectors.groupingBy(HolonElement::isOn, Collectors.counting()));
  155. // UPDATE ActiveInActive
  156. int activeAmount = Math.toIntExact(activeCounts.getOrDefault(true, 0L));
  157. int inactiveAmounts = Math.toIntExact(activeCounts.getOrDefault(false, 0L));
  158. activeChart.updatePieSeries("Active", activeAmount);
  159. activeChart.updatePieSeries("Inactive", inactiveAmounts);
  160. activeChart.updatePieSeries("No Data", activeAmount + inactiveAmounts == 0 ? 1 : 0);
  161. this.revalidate();
  162. this.repaint();
  163. }
  164. private JPopupMenu createHolonStateSelection(){
  165. JPopupMenu menu = new JPopupMenu();
  166. producerCheckBox.addActionListener(clicked -> updateCharts());
  167. overSuppliedCheckBox.addActionListener(clicked -> updateCharts());
  168. suppliedCheckBox.addActionListener(clicked -> updateCharts());
  169. partiallySuppliedCheckBox.addActionListener(clicked -> updateCharts());
  170. notSuppliedCheckBox.addActionListener(clicked -> updateCharts());
  171. noEnergyCheckBox.addActionListener(clicked -> updateCharts());
  172. menu.add(producerCheckBox);
  173. menu.add(overSuppliedCheckBox);
  174. menu.add(suppliedCheckBox);
  175. menu.add(partiallySuppliedCheckBox);
  176. menu.add(notSuppliedCheckBox);
  177. menu.add(noEnergyCheckBox);
  178. return menu;
  179. }
  180. private JPopupMenu createPrioritySelection(){
  181. JPopupMenu menu = new JPopupMenu();
  182. essentialCheckBox.addActionListener(clicked -> updateCharts());
  183. highCheckBox.addActionListener(clicked -> updateCharts());
  184. mediumBox.addActionListener(clicked -> updateCharts());
  185. lowCheckBox.addActionListener(clicked -> updateCharts());
  186. menu.add(essentialCheckBox);
  187. menu.add(highCheckBox);
  188. menu.add(mediumBox);
  189. menu.add(lowCheckBox);
  190. return menu;
  191. }
  192. private JPopupMenu createActiveSelection(){
  193. JPopupMenu menu = new JPopupMenu();
  194. activeCheckBox.addActionListener(clicked -> updateCharts());
  195. inactiveCheckBox.addActionListener(clicked -> updateCharts());
  196. menu.add(activeCheckBox);
  197. menu.add(inactiveCheckBox);
  198. return menu;
  199. }
  200. private JPopupMenu createFlexibilitySelection(){
  201. JPopupMenu menu = new JPopupMenu();
  202. noFlexibilityCheckBox.addActionListener(clicked -> updateCharts());
  203. offeredCheckBox.addActionListener(clicked -> updateCharts());
  204. notOfferedCheckBox.addActionListener(clicked -> updateCharts());
  205. unavailableCheckBox.addActionListener(clicked -> updateCharts());
  206. inUseCheckBox.addActionListener(clicked -> updateCharts());
  207. onCooldownCheckBox.addActionListener(clicked -> updateCharts());
  208. menu.add(noFlexibilityCheckBox);
  209. menu.add(offeredCheckBox);
  210. menu.add(notOfferedCheckBox);
  211. menu.add(unavailableCheckBox);
  212. menu.add(inUseCheckBox);
  213. menu.add(onCooldownCheckBox);
  214. return menu;
  215. }
  216. private JPanel initMenuButtonPanel(JPopupMenu menu){
  217. JPanel buttonPanel = new JPanel(new BorderLayout());
  218. MenuButton button = new MenuButton(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.Filter, 20, 20)), menu);
  219. buttonPanel.add(button, BorderLayout.LINE_END);
  220. buttonPanel.setOpaque(false);
  221. button.setPressedIcon(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.FilterHovered, 20, 20)));
  222. button.setRolloverIcon(new ImageIcon(Import.loadImage(ImagePreference.HolonInformationPanel.FilterHovered, 20, 20)));
  223. button.setBorderPainted(false);
  224. button.setBorder(null);
  225. button.setFocusable(false);
  226. button.setMargin(new Insets(0, 0, 0, 0));
  227. button.setContentAreaFilled(false);
  228. return buttonPanel;
  229. }
  230. private boolean stateFilter(HolonObject holonObject){
  231. return switch (holonObject.getState()) {
  232. case PRODUCER -> producerCheckBox.isSelected();
  233. case OVER_SUPPLIED -> overSuppliedCheckBox.isSelected();
  234. case SUPPLIED -> suppliedCheckBox.isSelected();
  235. case PARTIALLY_SUPPLIED -> partiallySuppliedCheckBox.isSelected();
  236. case NOT_SUPPLIED -> notSuppliedCheckBox.isSelected();
  237. case NO_ENERGY -> noEnergyCheckBox.isSelected();
  238. };
  239. }
  240. private boolean priorityFilter(HolonElement ele){
  241. return switch (ele.priority) {
  242. case Essential -> essentialCheckBox.isSelected();
  243. case High -> highCheckBox.isSelected();
  244. case Medium -> mediumBox.isSelected();
  245. case Low -> lowCheckBox.isSelected();
  246. };
  247. }
  248. private boolean activeFilter(HolonElement ele){
  249. return ele.active ? activeCheckBox.isSelected(): inactiveCheckBox.isSelected();
  250. }
  251. private boolean flexibilityFilter(HolonElement ele){
  252. if(ele.flexList.isEmpty()){
  253. return noFlexibilityCheckBox.isSelected();
  254. }
  255. Map<Flexibility.FlexState,Long> flexes = ele.flexList.stream().collect(Collectors.groupingBy(Flexibility::getState, Collectors.counting()));
  256. return flexes.keySet().stream().anyMatch(flexState -> switch (flexState) {
  257. case IN_USE -> inUseCheckBox.isSelected();
  258. case UNAVAILABLE -> unavailableCheckBox.isSelected();
  259. case OFFERED -> offeredCheckBox.isSelected();
  260. case NOT_OFFERED -> notOfferedCheckBox.isSelected();
  261. case ON_COOLDOWN -> onCooldownCheckBox.isSelected();
  262. });
  263. }
  264. public static class MenuButton extends JToggleButton {
  265. JPopupMenu popup;
  266. public MenuButton(Icon icon, JPopupMenu menu) {
  267. super(icon);
  268. this.popup = menu;
  269. addActionListener(clicked -> {
  270. if (MenuButton.this.isSelected()) {
  271. popup.show(MenuButton.this, 0, MenuButton.this.getBounds().height);
  272. } else {
  273. popup.setVisible(false);
  274. }
  275. });
  276. popup.addPopupMenuListener(new PopupMenuListener() {
  277. @Override
  278. public void popupMenuWillBecomeVisible(PopupMenuEvent e) {}
  279. @Override
  280. public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
  281. MenuButton.this.setSelected(false);
  282. }
  283. @Override
  284. public void popupMenuCanceled(PopupMenuEvent e) {}
  285. });
  286. }
  287. }
  288. private void initGraphPanel() {
  289. graphPanel.setBackground(ColorPreference.Panel.Background);
  290. XChartPanel<PieChart> panelHolonObject = new XChartPanel<>(supplyChart);
  291. panelHolonObject.setLayout(new BorderLayout());
  292. panelHolonObject.add(initMenuButtonPanel(createHolonStateSelection()), BorderLayout.PAGE_START);
  293. panelHolonObject.setBackground(ColorPreference.Panel.Background);
  294. graphPanel.add(panelHolonObject);
  295. XChartPanel<PieChart> panelPriority = new XChartPanel<>(priorityChart);
  296. panelPriority.setLayout(new BorderLayout());
  297. panelPriority.add(initMenuButtonPanel(createPrioritySelection()), BorderLayout.PAGE_START);
  298. panelPriority.setBackground(ColorPreference.Panel.Background);
  299. graphPanel.add(panelPriority);
  300. XChartPanel<PieChart> panelFlexibility = new XChartPanel<>(flexibilityChart);
  301. panelFlexibility.setLayout(new BorderLayout());
  302. panelFlexibility.add(initMenuButtonPanel(createFlexibilitySelection()), BorderLayout.PAGE_START);
  303. panelFlexibility.setBackground(ColorPreference.Panel.Background);
  304. graphPanel.add(panelFlexibility);
  305. Component panel = initEnergyChart();
  306. graphPanel.add(panel);
  307. XChartPanel<PieChart> panelActive = new XChartPanel<>(activeChart);
  308. panelActive.setLayout(new BorderLayout());
  309. panelActive.add(initMenuButtonPanel(createActiveSelection()), BorderLayout.PAGE_START);
  310. panelActive.setBackground(ColorPreference.Panel.Background);
  311. graphPanel.add(panelActive);
  312. graphPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray));
  313. }
  314. private JLayeredPane initEnergyChart() {
  315. JLayeredPane panel = new JLayeredPane();
  316. JPanel panelMiddle = new JPanel(new GridBagLayout());
  317. XChartPanel<PieChart> panelEnergy = new XChartPanel<>(energyChart);
  318. panelEnergy.setBackground(ColorPreference.Panel.Background);
  319. GridBagConstraints c = new GridBagConstraints();
  320. c.gridx = 0;
  321. c.gridy = 0;
  322. c.insets = new Insets(15, 0, 0, 0); // top padding
  323. JLabel difference = new JLabel("Difference:");
  324. difference.setHorizontalAlignment(JLabel.CENTER);
  325. difference.setAlignmentX(Component.CENTER_ALIGNMENT);
  326. difference.setForeground(ColorPreference.Panel.Title);
  327. difference.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 10));
  328. panelMiddle.add(difference, c);
  329. differenceEnergyLabelAmount.setHorizontalAlignment(JLabel.CENTER);
  330. differenceEnergyLabelAmount.setForeground(Color.red);
  331. differenceEnergyLabelAmount.setAlignmentX(Component.CENTER_ALIGNMENT);
  332. differenceEnergyLabelAmount.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 12));
  333. c.insets = new Insets(0, 0, 0, 0);
  334. c.gridy = 1;
  335. panelMiddle.add(differenceEnergyLabelAmount, c);
  336. panel.setLayout(new OverlayLayout(panel));
  337. panelEnergy.setOpaque(false);
  338. panelMiddle.setOpaque(false);
  339. panel.add(panelMiddle, Integer.valueOf(0));
  340. panel.add(panelEnergy, Integer.valueOf(1));
  341. return panel;
  342. }
  343. public void setDefaultPieChartSettings(PieChart chart) {
  344. PieStyler styler = chart.getStyler();
  345. styler.setChartTitleVisible(true);
  346. styler.setDefaultSeriesRenderStyle(PieSeriesRenderStyle.Donut);
  347. styler.setLabelsFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 14));
  348. styler.setLabelType(LabelType.Percentage);
  349. styler.setLabelsFontColor(Color.black);
  350. styler.setLabelsFontColorAutomaticEnabled(false);
  351. styler.setLabelsDistance(0.8);
  352. styler.setChartFontColor(ColorPreference.Panel.Title);
  353. styler.setToolTipsEnabled(true);
  354. styler.setPlotContentSize(0.9);
  355. styler.setPlotBackgroundColor(ColorPreference.Panel.Transparent);
  356. styler.setPlotBorderColor(ColorPreference.Panel.Transparent);
  357. styler.setLegendVisible(false);
  358. styler.setChartBackgroundColor(ColorPreference.Panel.Transparent);
  359. }
  360. public PieChart createSupplyStateChart() {
  361. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("HolonObjects").build();
  362. setDefaultPieChartSettings(chart);
  363. chart.getStyler().setSeriesColors(supplyStateColors);
  364. // Series
  365. chart.addSeries("Producer", 0);
  366. chart.addSeries("Over supplied", 0);
  367. chart.addSeries("Supplied", 0);
  368. chart.addSeries("Partial supplied", 0);
  369. chart.addSeries("Not supplied", 0);
  370. chart.addSeries("No energy", 0);
  371. chart.addSeries("No Data", 0);
  372. return chart;
  373. }
  374. public PieChart createPriorityChart() {
  375. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Priorities").build();
  376. setDefaultPieChartSettings(chart);
  377. // Customize Chart
  378. chart.getStyler().setSeriesColors(priorityColors);
  379. // Series
  380. chart.addSeries("Essential", 0);
  381. chart.addSeries("High", 0);
  382. chart.addSeries("Medium", 0);
  383. chart.addSeries("Low", 0);
  384. chart.addSeries("No Data", 0);
  385. return chart;
  386. }
  387. public PieChart createFlexibilityChart() {
  388. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Flexibilities").build();
  389. setDefaultPieChartSettings(chart);
  390. // Customize Chart
  391. chart.getStyler().setSeriesColors(flexibilityColors);
  392. // Series
  393. chart.addSeries("Offered", 0);
  394. chart.addSeries("In use", 0);
  395. chart.addSeries("On cooldown", 0);
  396. chart.addSeries("Not offered", 0);
  397. chart.addSeries("Unavailable", 0);
  398. chart.addSeries("No flexibility", 0);
  399. chart.addSeries("No Data", 0);
  400. return chart;
  401. }
  402. public PieChart createProductionChart() {
  403. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight)
  404. .title("Production vs. Consumption").build();
  405. setDefaultPieChartSettings(chart);
  406. // Customize Chart
  407. // Customize Chart
  408. chart.getStyler().setSeriesColors(productionColors);
  409. // Series
  410. chart.addSeries("Production", 0);
  411. chart.addSeries("Consumption", 0);
  412. chart.addSeries("No Data", 0);
  413. return chart;
  414. }
  415. public PieChart createActiveChart() {
  416. PieChart chart = new PieChartBuilder().width(defaultWidth).height(defaultHeight).title("Active").build();
  417. setDefaultPieChartSettings(chart);
  418. // Customize Chart
  419. // Customize Chart
  420. chart.getStyler().setSeriesColors(activeColors);
  421. // Series
  422. chart.addSeries("Active", 0);
  423. chart.addSeries("Inactive", 0);
  424. chart.addSeries("No Data", 0);
  425. return chart;
  426. }
  427. private static class TempGroupNode extends GroupNode {
  428. public TempGroupNode() {
  429. super("temp");
  430. }
  431. public void add(AbstractCanvasObject object) {
  432. if (object instanceof HolonObject hObject) {
  433. objectList.add(hObject);
  434. }else if(object instanceof HolonSwitch hSwitch) {
  435. switchList.add(hSwitch);
  436. }else if(object instanceof Node node) {
  437. nodeList.add(node);
  438. }else if(object instanceof GroupNode groupNode) {
  439. groupNodeList.add(groupNode);
  440. }
  441. }
  442. public void remove(AbstractCanvasObject object) {
  443. if (object instanceof HolonObject hObject) {
  444. objectList.remove(hObject);
  445. }else if(object instanceof HolonSwitch hSwitch) {
  446. switchList.remove(hSwitch);
  447. }else if(object instanceof Node node) {
  448. nodeList.remove(node);
  449. }else if(object instanceof GroupNode groupNode) {
  450. groupNodeList.remove(groupNode);
  451. }
  452. }
  453. }
  454. }