12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package ui.view;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.event.ComponentAdapter;
- import java.awt.event.ComponentEvent;
- import javax.swing.BoxLayout;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import classes.HolonObject;
- import classes.SubNet;
- import ui.controller.Control;
- 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();
- FlexibleData maingrid = new FlexibleData("Main Grid", 0,0);
- maingrid.getColorPanel().setVisible(false);
- maingrid.getNamelbl().setFont(new Font("Tahoma", Font.BOLD, 11));
- flexPanel.add(maingrid);
- float gridProd = 0;
- float gridCons = 0;
- int counter = 1;
- for(SubNet sn: controller.getSimManager().getSubNets()){
- JPanel objects = new JPanel();
- objects.setLayout(new BoxLayout(objects, BoxLayout.Y_AXIS));
- int index = flexPanel.getComponentCount();
- float subProd = 0;
- float subCons = 0;
- Color subColor = sn.getObjects().get(0).getBorderColor();
- for(HolonObject hl: sn.getObjects()){
- subProd += hl.getFlexProd();
- subCons += hl.getFlexCons();
- FlexibleData tmp = new FlexibleData(hl.getName()+" "+hl.getId(),
- hl.getFlexProd(), hl.getFlexCons());
- tmp.getColorPanel().setBackground(subColor);
- objects.add(tmp);
- }
- gridProd += subProd;
- gridCons += subCons;
- FlexibleData subnet = new FlexibleData("Subnet "+ counter, subProd, subCons);
- subnet.getNamelbl().setFont(new Font("Tahoma", Font.BOLD, 11));
- subnet.getColorPanel().setBackground(subColor);
- FlexSubData wholeSubnet = new FlexSubData(subnet);
- wholeSubnet.setObjects(objects);
- wholeSubnet.setListener(this);
- flexPanel.add(wholeSubnet, index);
- //flexPanel.add(new FlexibleData("Subnet "+ counter, subProd, subCons), index);
- 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);
- }
-
- class ResizeListener extends ComponentAdapter{
- public void componentResized(ComponentEvent e){
- flexPanel.requestFocusInWindow();
- }
- }
- this.addComponentListener(new ResizeListener());
- }
-
- public JPanel getPanel(){
- return flexPanel;
- }
- }
|