瀏覽代碼

little working flexibility

dominik.rieder 7 年之前
父節點
當前提交
ea0a891fb3

+ 26 - 0
src/classes/HolonObject.java

@@ -407,6 +407,32 @@ public class HolonObject extends AbstractCpsObject {
 		}
 		this.totalFlex = tempFlex;
 	}
+	
+	/**
+	 * calculates total flexible Production
+	 */
+	public float getFlexProd(){
+		float tempFlex = 0;
+		for (HolonElement e : getElements()) {
+			if (e.getFlexibility() > 0) {
+				tempFlex += e.getFlexibility();
+			}
+		}
+		return tempFlex;
+	}
+	
+	/**
+	 * calculates total flexible Concumption
+	 */
+	public float getFlexCons(){
+		float tempFlex = 0;
+		for (HolonElement e : getElements()) {
+			if (e.getFlexibility() < 0) {
+				tempFlex += e.getFlexibility();
+			}
+		}
+		return tempFlex;
+	}
 
 	/**
 	 * If the user track any HolonObject the tracking information will be

+ 5 - 0
src/ui/controller/Control.java

@@ -22,6 +22,7 @@ import classes.HolonObject;
 import cpsAlgorithm.CpsAlgorithm;
 import interfaces.CategoryListener;
 import ui.model.Model;
+import ui.view.FlexiblePane;
 import ui.view.MyCanvas;
 
 /**
@@ -902,5 +903,9 @@ public class Control {
 	public void setBackgroundImage(String imagePath, int mode, int width, int height) {
 	canvasController.setBackgroundImage(imagePath, mode, width, height);
 	}
+	
+	public void setFlexiblePane(FlexiblePane fp){
+		simulationManager.setFlexiblePane(fp);
+	}
 
 }

+ 8 - 0
src/ui/controller/SimulationManager.java

@@ -12,6 +12,7 @@ import classes.HolonObject;
 import classes.HolonSwitch;
 import classes.SubNet;
 import ui.model.Model;
+import ui.view.FlexiblePane;
 import ui.view.MyCanvas;
 
 /**
@@ -28,6 +29,7 @@ public class SimulationManager {
 	private MyCanvas canvas;
 	private int timeStep;
 	private HashMap<Integer, Float> tagTable = new HashMap<Integer, Float>();
+	private FlexiblePane flexPane;
 	/**
 	 * Constructor.
 	 * 
@@ -90,6 +92,7 @@ public class SimulationManager {
 		}
 		canvas.repaint();
 		//printNet();
+		flexPane.recalculate();
 	}
 
 	/**
@@ -591,4 +594,9 @@ public class SimulationManager {
 		}
 	}
 
+	public void setFlexiblePane(FlexiblePane fp) {
+		flexPane = fp;
+		
+	}
+
 }

+ 73 - 0
src/ui/view/FlexibleData.java

@@ -0,0 +1,73 @@
+package ui.view;
+
+import javax.swing.JPanel;
+import javax.swing.JLabel;
+import java.awt.Font;
+import java.awt.Dimension;
+
+public class FlexibleData extends JPanel {
+	private JLabel name_lbl;
+	private JLabel lblProdVal;
+	private JLabel lblConsVal;
+	private JLabel lblProdConsVal;
+	public FlexibleData(String name, float prod, float cons) {
+		setPreferredSize(new Dimension(400, 150));
+		setMinimumSize(new Dimension(300, 200));
+		setLayout(null);
+		
+		name_lbl = new JLabel();
+		name_lbl.setFont(new Font("Tahoma", Font.PLAIN, 13));
+		name_lbl.setBounds(10, 11, 125, 27);
+		setlblName(name);
+		add(name_lbl);
+		
+		JLabel lblFlProd = new JLabel("Flex. Prod.  :");
+		lblFlProd.setBounds(31, 46, 65, 27);
+		add(lblFlProd);
+		
+		JLabel lblFlexCons = new JLabel("Flex. Cons.  :\r\n");
+		lblFlexCons.setBounds(31, 72, 65, 27);
+		add(lblFlexCons);
+		
+		JLabel lblProdCons = new JLabel("Prod./Cons. :");
+		lblProdCons.setBounds(31, 95, 65, 27);
+		add(lblProdCons);
+		
+		lblProdVal = new JLabel();
+		setProd(prod);
+		lblProdVal.setBounds(100, 47, 125, 24);
+		add(lblProdVal);
+		
+		lblConsVal = new JLabel();
+		setCons(cons);
+		lblConsVal.setBounds(100, 73, 125, 24);
+		add(lblConsVal);
+		
+		lblProdConsVal = new JLabel();
+		if(cons != 0 && prod != 0){
+		lblProdConsVal.setText(Float.toString(prod/cons));
+		}else if(prod == 0){
+			lblProdConsVal.setText("only consuming...");
+		}else if(cons == 0){
+			lblProdConsVal.setText("only producing...");
+		}
+		lblProdConsVal.setBounds(100, 96, 125, 24);
+		add(lblProdConsVal);
+	}
+	
+	public void setProd(float p){
+		lblProdVal.setText(Float.toString(p));
+	}
+	
+	public void setCons(float c){
+		lblConsVal.setText(Float.toString(c));
+	}
+	
+	public void setProdConsVal(float pc){
+		lblProdConsVal.setText(Float.toString(pc));
+	}
+	
+	public void setlblName(String name){
+		name_lbl.setText(name);
+	}
+}

+ 38 - 2
src/ui/view/FlexiblePane.java

@@ -1,9 +1,45 @@
 package ui.view;
 
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 
-public class FlexiblePane extends JPanel {
-	public FlexiblePane() {
+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.X_AXIS));
+		setViewportView(flexPanel);
+		flexPanel.add(new FlexibleData("MainGrid" ,0 ,0));
+		flexPanel.add(new FlexibleData("SubNet", 1, 1));
+	}
+	
+	public void recalculate(){
+		flexPanel.removeAll();
+		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()));
+			}
+			flexPanel.add(new FlexibleData("Subnet "+ counter, subProd, subCons));
+			counter++;
+		}
 	}
 
 }

+ 2 - 1
src/ui/view/GUI.java

@@ -302,7 +302,6 @@ public class GUI<E> implements CategoryListener {
 		initialize();
 		updateCategories(model.getCategories());
 		updCon = new UpdateController(model, controller);
-		flexPane = new FlexiblePane();
 	}
 
 	/**
@@ -1799,6 +1798,8 @@ public class GUI<E> implements CategoryListener {
 		tabbedPane.addTab("View", canvasSP);
 		tabbedPane.addTab("Statistics", statScrollPane);
 		tabbedPane.addTab("Holon", holonCanvas);
+		flexPane = new FlexiblePane(controller);
+		controller.setFlexiblePane(flexPane);
 		tabbedPane.addTab("Flexibility", flexPane);
 
 		splitPaneCanvasConsole.setRightComponent(console);

+ 16 - 16
src/ui/view/StatPanel2.java

@@ -621,67 +621,67 @@ public class StatPanel2 extends JSplitPane implements GraphListener {
 		editPanel.setLayout(null);
 		
 		JLabel lblObject = new JLabel("Object(s):");
-		lblObject.setBounds(10, 11, 49, 14);
+		lblObject.setBounds(10, 11, 59, 20);
 		editPanel.add(lblObject);
 		
 		showObjectlbl = new JLabel("...");
-		showObjectlbl.setBounds(69, 11, 86, 14);
+		showObjectlbl.setBounds(69, 11, 101, 20);
 		editPanel.add(showObjectlbl);
 		
 		JLabel lblProperty = new JLabel("Property:");
-		lblProperty.setBounds(10, 36, 46, 14);
+		lblProperty.setBounds(10, 36, 59, 20);
 		editPanel.add(lblProperty);
 		
 		showPropertylbl = new JLabel("...");
-		showPropertylbl.setBounds(69, 36, 86, 14);
+		showPropertylbl.setBounds(69, 36, 101, 20);
 		editPanel.add(showPropertylbl);
 		
 		JLabel lblGraph = new JLabel("Graph:");
-		lblGraph.setBounds(10, 61, 33, 14);
+		lblGraph.setBounds(10, 61, 49, 23);
 		editPanel.add(lblGraph);
 		
 		graphNrTxtField.setColumns(10);
-		graphNrTxtField.setBounds(69, 61, 86, 20);
+		graphNrTxtField.setBounds(69, 61, 101, 23);
 		editPanel.add(graphNrTxtField);
 		
 		JLabel lblColor = new JLabel("Color:");
-		lblColor.setBounds(10, 86, 29, 14);
+		lblColor.setBounds(10, 95, 49, 23);
 		editPanel.add(lblColor);
 		
-		colorComboBox.setBounds(69, 83, 86, 20);
+		colorComboBox.setBounds(69, 95, 101, 23);
 		editPanel.add(colorComboBox);
 		
 		JLabel lblR = new JLabel("R");
-		lblR.setBounds(10, 111, 11, 14);
+		lblR.setBounds(10, 139, 11, 14);
 		editPanel.add(lblR);
 		
 		redField.setColumns(10);
-		redField.setBounds(20, 108, 37, 20);
+		redField.setBounds(22, 136, 37, 20);
 		editPanel.add(redField);
 		
 		JLabel lblG = new JLabel("G");
-		lblG.setBounds(58, 111, 11, 14);
+		lblG.setBounds(68, 139, 11, 14);
 		editPanel.add(lblG);
 		
 		greenField.setColumns(10);
-		greenField.setBounds(69, 108, 37, 20);
+		greenField.setBounds(79, 136, 37, 20);
 		editPanel.add(greenField);
 		
 		JLabel lblB = new JLabel("B");
-		lblB.setBounds(108, 111, 10, 14);
+		lblB.setBounds(126, 139, 10, 14);
 		editPanel.add(lblB);
 		
 		blueField.setColumns(10);
-		blueField.setBounds(116, 108, 39, 20);
+		blueField.setBounds(133, 136, 37, 20);
 		editPanel.add(blueField);
 		
 		colorPanel = new JPanel();
 		colorPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
 		colorPanel.setBackground(Color.WHITE);
-		colorPanel.setBounds(10, 136, 49, 36);
+		colorPanel.setBounds(10, 164, 59, 38);
 		editPanel.add(colorPanel);
 
-		btnAdd.setBounds(10, 175, 51, 23);
+		btnAdd.setBounds(10, 213, 59, 23);
 		editPanel.add(btnAdd);
 		splitPane.setDividerLocation(220);