package ui.view; import javax.swing.JPanel; import javax.swing.JScrollPane; import classes.HolonObject; import classes.SubNet; import ui.controller.Control; import java.awt.Color; import java.awt.Dimension; import javax.swing.BoxLayout; public class FlexiblePane extends JScrollPane { private JPanel flexPanel; private Control controller; public FlexiblePane(Control controller) { this.controller = controller; flexPanel = new JPanel(); flexPanel.setLayout(new BoxLayout(flexPanel, BoxLayout.Y_AXIS)); setViewportView(flexPanel); } public void recalculate(){ flexPanel.removeAll(); flexPanel.add(new FlexibleData("Main Grid", 0,0)); float gridProd = 0; float gridCons = 0; int counter = 1; for(SubNet sn: controller.getSimManager().getSubNets()){ float subProd = 0; float subCons = 0; for(HolonObject hl: sn.getObjects()){ subProd += hl.getFlexProd(); subCons += hl.getFlexCons(); flexPanel.add(new FlexibleData(hl.getName()+" "+hl.getId(), hl.getFlexProd(), hl.getFlexCons())); } gridProd += subProd; gridCons += subCons; flexPanel.add(new FlexibleData("Subnet "+ counter, subProd, subCons)); counter++; } if (flexPanel.getComponent(0) instanceof FlexibleData){ ((FlexibleData)flexPanel.getComponent(0)).setProd(gridProd); ((FlexibleData)flexPanel.getComponent(0)).setCons(gridCons); ((FlexibleData)flexPanel.getComponent(0)).setProdConsVal(gridProd, gridCons); } } }