|
@@ -1,5 +1,12 @@
|
|
|
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;
|
|
|
|
|
@@ -7,11 +14,6 @@ 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;
|
|
@@ -25,23 +27,38 @@ public class FlexiblePane extends JScrollPane {
|
|
|
|
|
|
public void recalculate(){
|
|
|
flexPanel.removeAll();
|
|
|
- flexPanel.add(new FlexibleData("Main Grid", 0,0));
|
|
|
+ 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();
|
|
|
- flexPanel.add(new FlexibleData(hl.getName()+" "+hl.getId(),
|
|
|
- hl.getFlexProd(), 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;
|
|
|
- flexPanel.add(new FlexibleData("Subnet "+ counter, subProd, subCons), index);
|
|
|
+ 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);
|
|
|
+
|
|
|
counter++;
|
|
|
}
|
|
|
if (flexPanel.getComponent(0) instanceof FlexibleData){
|
|
@@ -49,6 +66,17 @@ public class FlexiblePane extends JScrollPane {
|
|
|
((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;
|
|
|
}
|
|
|
|
|
|
}
|