ソースを参照

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons

Teh-Hai Julian Zheng 8 年 前
コミット
25439b5eea

+ 12 - 2
src/classes/HolonElement.java

@@ -56,6 +56,7 @@ public class HolonElement {
 	 * beginning, it starts with all values at energy
 	 */
 	private float[] energyAt;
+
 	// Points on the UnitGraph
 	LinkedList<Point> graphPoints;
 
@@ -228,7 +229,11 @@ public class HolonElement {
 	 * @return totalEnergy (actual)
 	 */
 	public float getTotalEnergy() {
-		totalEnergy = ((float) amount) * energy;
+		if (activeFlex) {
+			totalEnergy = ((float) amount) * (energy + flexibility);
+		} else {
+			totalEnergy = ((float) amount) * energy;
+		}
 		return totalEnergy;
 	}
 
@@ -240,7 +245,12 @@ public class HolonElement {
 	 * @return energy value
 	 */
 	public float getTotalEnergyAtTimeStep(int x) {
-		float result = ((float) amount) * energyAt[x];
+		float result = 0;
+		if (activeFlex) {
+			result = ((float) amount) * (energyAt[x] + flexibility);
+		} else {
+			result = ((float) amount) * energyAt[x];
+		}
 		return result;
 	}
 

+ 16 - 19
src/ui/view/EditEdgesPopUp.java

@@ -193,37 +193,34 @@ public class EditEdgesPopUp extends JDialog {
 	 */
 	public void changeForExisting(float cap) {
 		/*
-		for(SubNet sn: controller.getSimManager().getSubNets()){
-			for(CpsEdge edge: sn.getEdges()){
-				edge.setCapacity(cap);
-			}
-		}
-		for(CpsEdge edge: controller.getSimManager().getBrokenEdges()){
-			edge.setCapacity(cap);
-		}
-		*/
+		 * for(SubNet sn: controller.getSimManager().getSubNets()){ for(CpsEdge
+		 * edge: sn.getEdges()){ edge.setCapacity(cap); } } for(CpsEdge edge:
+		 * controller.getSimManager().getBrokenEdges()){ edge.setCapacity(cap);
+		 * }
+		 */
 		for (CpsEdge edge : controller.getModel().getEdgesOnCanvas()) {
 			edge.setCapacity(cap);
+			edge.setState(true);
 		}
-		for(AbstractCpsObject abs: controller.getModel().getObjectsOnCanvas()){
-			if(abs instanceof CpsUpperNode){
-				changeInUpperNode((CpsUpperNode)abs, cap);
+		for (AbstractCpsObject abs : controller.getModel().getObjectsOnCanvas()) {
+			if (abs instanceof CpsUpperNode) {
+				changeInUpperNode((CpsUpperNode) abs, cap);
 			}
 		}
 		controller.calculateStateForCurrentTimeStep();
 		canvas.repaint();
 	}
-	
-	public void changeInUpperNode(CpsUpperNode uN, float cap){
-		for(CpsEdge e: uN.getNodeEdges()){
+
+	public void changeInUpperNode(CpsUpperNode uN, float cap) {
+		for (CpsEdge e : uN.getNodeEdges()) {
 			e.setCapacity(cap);
 		}
-		for(CpsEdge e: uN.getOldEdges()){
+		for (CpsEdge e : uN.getOldEdges()) {
 			e.setCapacity(cap);
 		}
-		for(AbstractCpsObject abs: uN.getNodes()){
-			if(abs instanceof CpsUpperNode){
-				changeInUpperNode((CpsUpperNode)abs, cap);
+		for (AbstractCpsObject abs : uN.getNodes()) {
+			if (abs instanceof CpsUpperNode) {
+				changeInUpperNode((CpsUpperNode) abs, cap);
 			}
 		}
 	}

+ 11 - 11
src/ui/view/FlexibleData.java

@@ -22,42 +22,42 @@ public class FlexibleData extends JPanel {
 		setlblName(name);
 		add(name_lbl);
 		
-		JLabel lblFlProd = new JLabel("Flex. Prod.  :");
+		JLabel lblFlProd = new JLabel("Flex. Prod.:");
 		lblFlProd.setForeground(new Color(0, 128, 0));
-		lblFlProd.setBounds(31, 46, 65, 27);
+		lblFlProd.setBounds(31, 46, 85, 27);
 		add(lblFlProd);
 		
-		JLabel lblFlexCons = new JLabel("Flex. Cons.  :\r\n");
+		JLabel lblFlexCons = new JLabel("Flex. Cons.:\r\n");
 		lblFlexCons.setForeground(new Color(255, 0, 0));
-		lblFlexCons.setBounds(181, 46, 65, 27);
+		lblFlexCons.setBounds(160, 46, 85, 27);
 		add(lblFlexCons);
 		
-		JLabel lblProdCons = new JLabel("Prod./Cons. :");
+		JLabel lblProdCons = new JLabel("Prod./Cons.:");
 		lblProdCons.setForeground(new Color(218, 165, 32));
-		lblProdCons.setBounds(327, 46, 65, 27);
+		lblProdCons.setBounds(300, 46, 85, 27);
 		add(lblProdCons);
 		
 		lblProdVal = new JLabel();
 		setProd(prod);
-		lblProdVal.setBounds(100, 47, 72, 24);
+		lblProdVal.setBounds(106, 47, 72, 24);
 		add(lblProdVal);
 		
 		lblConsVal = new JLabel();
 		setCons(cons);
-		lblConsVal.setBounds(252, 47, 72, 24);
+		lblConsVal.setBounds(240, 47, 72, 24);
 		add(lblConsVal);
 		
 		lblProdConsVal = new JLabel();
 		if(cons != 0 && prod != 0){
 		lblProdConsVal.setText(Float.toString((prod/cons)*(-1)));
 		}else if(prod == 0 && cons == 0){
-			lblProdConsVal.setText("not producing or consuming...");
+			lblProdConsVal.setText("neither producing nor consuming...");
 		}else if(prod == 0){
 			lblProdConsVal.setText("only consuming...");
 		}else if(cons == 0){
 			lblProdConsVal.setText("only producing...");
 		}
-		lblProdConsVal.setBounds(402, 46, 173, 24);
+		lblProdConsVal.setBounds(380, 46, 240, 24);
 		add(lblProdConsVal);
 	}
 	
@@ -73,7 +73,7 @@ public class FlexibleData extends JPanel {
 		if(cons != 0 && prod != 0){
 		lblProdConsVal.setText(Float.toString((prod/cons)*(-1)));
 		}else if(prod == 0 && cons == 0){
-			lblProdConsVal.setText("not producing or consuming...");
+			lblProdConsVal.setText("neither producing nor consuming...");
 		}else if(prod == 0){
 			lblProdConsVal.setText("only consuming...");
 		}else if(cons == 0){

+ 13 - 6
src/ui/view/GUI.java

@@ -255,6 +255,8 @@ public class GUI<E> implements CategoryListener {
 	// Coord for the Edit-Modus in the PropertieTable
 	private int yProThis;
 	private int xProThis;
+	private int yProThisOneClick;
+	private int xProThisOneClick;
 	private AbstractCpsObject temp = null;
 	private final JMenuItem mntmUndo = new JMenuItem("Undo");
 	private final JMenuItem mntmRedo = new JMenuItem("Redo");
@@ -1157,6 +1159,9 @@ public class GUI<E> implements CategoryListener {
 				if (e.getClickCount() == 2) {
 					yProThis = e.getY();
 					xProThis = e.getX();
+				} else {
+					yProThisOneClick = e.getY();
+					xProThisOneClick = e.getX();
 				}
 			}
 		});
@@ -1213,6 +1218,8 @@ public class GUI<E> implements CategoryListener {
 							updCon.getActualCps().setName(temp.toString());
 						}
 					} else {
+						selValueY = (int) Math.floor(yProThisOneClick / 16);
+						selValueX = (int) Math.floor(xProThisOneClick / (tableProperties.getWidth() / 2));
 						temp = model.getPropertyTable().getValueAt(selValueY, selValueX);
 						btemp = model.getPropertyTable().getValueAt(mousePos.y / tableProperties.getRowHeight(),
 								mousePos.x / (tableProperties.getWidth() / 2));
@@ -1313,8 +1320,8 @@ public class GUI<E> implements CategoryListener {
 							UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent())
 									.getViewport().getComponent(0));
 
-							int x = (int) unc.getMousePosition().getX();
-							int y = (int) unc.getMousePosition().getY();
+							int x = (int) unc.getMousePosition().getX() + 16;
+							int y = (int) unc.getMousePosition().getY() + 16;
 
 							if (x > unc.borderPos) {
 
@@ -1336,8 +1343,8 @@ public class GUI<E> implements CategoryListener {
 								unc.repaint();
 							}
 						} else {
-							int x = (int) canvas.getMousePosition().getX();
-							int y = (int) canvas.getMousePosition().getY();
+							int x = (int) canvas.getMousePosition().getX() + 16;
+							int y = (int) canvas.getMousePosition().getY() + 16;
 
 							AbstractCpsObject h = null;
 							if (tempCps instanceof HolonObject) {
@@ -1410,11 +1417,11 @@ public class GUI<E> implements CategoryListener {
 								if (actualObjectClicked.compareTo(cps.getObjName()) == 0) {
 									File checkPath = new File(cps.getImage());
 									if (checkPath.exists()) {
-										img = new ImageIcon(cps.getImage()).getImage().getScaledInstance(50, 50,
+										img = new ImageIcon(cps.getImage()).getImage().getScaledInstance(32, 32,
 												java.awt.Image.SCALE_SMOOTH);
 									} else {
 										img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
-												.getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
+												.getScaledInstance(32, 32, java.awt.Image.SCALE_SMOOTH);
 									}
 									tempCps = cps;
 									dragging = true;

+ 5 - 2
src/ui/view/MyCanvas.java

@@ -71,7 +71,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
 	ArrayList<AbstractCpsObject> tempSelected = new ArrayList<AbstractCpsObject>();
 
-	private boolean[] showedInformation = new boolean[4];
+	private boolean[] showedInformation = new boolean[5];
 	private boolean dragging = false; // for dragging
 	private boolean dragged = false; // if an object/objects was/were dragged
 	private boolean drawEdge = false; // for drawing edges
@@ -131,6 +131,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		showedInformation[0] = true;
 		showedInformation[1] = true;
 		showedInformation[3] = false;
+		showedInformation[4] = true;
 		control.setMaxCapacity(10000);
 
 		popmenu.add(itemCut);
@@ -1112,11 +1113,13 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 	 *            boolean for conecction
 	 * @param object
 	 *            boolean for objects
+	 * @param nodeOfnode 
 	 */
-	public void setShowedInformation(boolean connection, boolean object, boolean border) {
+	public void setShowedInformation(boolean connection, boolean object, boolean border, boolean nodeOfnode) {
 		showedInformation[0] = connection;
 		showedInformation[1] = object;
 		showedInformation[3] = border;
+		showedInformation[4] = nodeOfnode;
 	}
 
 	/**

+ 14 - 7
src/ui/view/ShowedInformationPopUp.java

@@ -24,6 +24,7 @@ public class ShowedInformationPopUp extends JDialog {
 	private JCheckBox objectEnergyCheckbox;
 	private JCheckBox connectionCheckbox;
 	private JCheckBox colorizedBorderCheckbox;
+	private JCheckBox nodeOfnodeConnectionCheckbox;
 	private JPanel toUpdate;
 
 	/**
@@ -36,7 +37,7 @@ public class ShowedInformationPopUp extends JDialog {
 		super((java.awt.Frame) null, true);
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		this.setTitle(Languages.getLanguage()[31]);
-		setBounds(100, 100, 400, 220);
+		setBounds(100, 100, 400, 254);
 		getContentPane().setLayout(new BorderLayout());
 		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
 		getContentPane().add(contentPanel, BorderLayout.CENTER);
@@ -57,11 +58,11 @@ public class ShowedInformationPopUp extends JDialog {
 		btnOk.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {
 				setInformation(connectionCheckbox.isSelected(), objectEnergyCheckbox.isSelected(),
-						colorizedBorderCheckbox.isSelected());
+						colorizedBorderCheckbox.isSelected(), nodeOfnodeConnectionCheckbox.isSelected());
 				dispose();
 			}
 		});
-		btnOk.setBounds(171, 147, 82, 23);
+		btnOk.setBounds(174, 193, 82, 23);
 		contentPanel.add(btnOk);
 
 		JButton btnCancel = new JButton(Languages.getLanguage()[34]);
@@ -71,13 +72,18 @@ public class ShowedInformationPopUp extends JDialog {
 				dispose();
 			}
 		});
-		btnCancel.setBounds(72, 147, 89, 23);
+		btnCancel.setBounds(69, 193, 89, 23);
 		contentPanel.add(btnCancel);
 		
 		colorizedBorderCheckbox = new JCheckBox("Show colorized Border for Objects");
-		colorizedBorderCheckbox.setBounds(19, 96, 195, 23);
+		colorizedBorderCheckbox.setBounds(19, 96, 369, 23);
 		contentPanel.add(colorizedBorderCheckbox);
 		colorizedBorderCheckbox.setSelected(canvas.getShowedInformation()[3]);
+		
+		nodeOfnodeConnectionCheckbox = new JCheckBox("Show outside Connections in gouped Nodes");
+		nodeOfnodeConnectionCheckbox.setBounds(19, 133, 369, 23);
+		contentPanel.add(nodeOfnodeConnectionCheckbox);
+		nodeOfnodeConnectionCheckbox.setSelected(canvas.getShowedInformation()[4]);
 	}
 
 	/**
@@ -87,9 +93,10 @@ public class ShowedInformationPopUp extends JDialog {
 	 *            conection Information
 	 * @param object
 	 *            Object Information
+	 * @param nodeOfnode 
 	 */
-	private void setInformation(boolean connection, boolean object, boolean borders) {
-		canvas.setShowedInformation(connection, object, borders);
+	private void setInformation(boolean connection, boolean object, boolean borders, boolean nodeOfnode) {
+		canvas.setShowedInformation(connection, object, borders, nodeOfnode);
 		canvas.repaint();
 		toUpdate.updateUI();
 	}

+ 14 - 6
src/ui/view/StatisticGraph.java

@@ -197,7 +197,7 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.CONSUMPTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
 					if (h.getEnergy() < 0) {
-						val += h.getEnergy() * h.getAmount();
+						val += (h.getEnergy() + h.getFlexibility()) * h.getAmount();
 					}
 				}
 				val *= -1;
@@ -205,7 +205,7 @@ public class StatisticGraph extends JPanel {
 			case TrackedDataSet.PRODUCTION:
 				for (HolonElement h : ((HolonObject) set.getCpsObject()).getElements()) {
 					if (h.getEnergy() > 0) {
-						val += h.getEnergy() * h.getAmount();
+						val += (h.getEnergy() + h.getFlexibility()) * h.getAmount();
 					}
 				}
 				break;
@@ -619,7 +619,7 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergy() > 0) {
-						val += ele.getEnergy() * ele.getAmount();
+						val += (ele.getEnergy() + ele.getFlexibility()) * ele.getAmount();
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -642,7 +642,7 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergy() < 0) {
-						val += ele.getEnergy() * ele.getAmount();
+						val += (ele.getEnergy() + ele.getFlexibility()) * ele.getAmount();
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -666,7 +666,11 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergyAt()[tStep] > 0 && ele.getActive()) {
-						val += ele.getEnergyAt()[tStep] * ele.getAmount();
+						if (ele.getActiveFlex()) {
+							val += (ele.getEnergyAt()[tStep]+ele.getFlexibility()) * ele.getAmount();
+						} else {
+							val += ele.getEnergyAt()[tStep] * ele.getAmount();
+						}
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {
@@ -690,7 +694,11 @@ public class StatisticGraph extends JPanel {
 			if (obj instanceof HolonObject) {
 				for (HolonElement ele : ((HolonObject) obj).getElements()) {
 					if (ele.getEnergyAt()[tStep] < 0 && ele.getActive()) {
-						val += ele.getEnergyAt()[tStep] * ele.getAmount();
+						if (ele.getActiveFlex()) {
+							val += (ele.getEnergyAt()[tStep]+ele.getFlexibility()) * ele.getAmount();
+						} else {
+							val += ele.getEnergyAt()[tStep] * ele.getAmount();
+						}
 					}
 				}
 			} else if (obj instanceof CpsUpperNode) {

+ 28 - 17
src/ui/view/UpperNodeCanvas.java

@@ -74,7 +74,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	// The UpperNode
 	public CpsUpperNode upperNode;
 
-	private boolean[] showedInformation = new boolean[3];
+	private boolean[] showedInformation = new boolean[5];
 	private boolean dragging = false; // for dragging
 	private boolean dragged = false; // if an object/objects was/were dragged
 	private boolean drawEdge = false; // for drawing edges
@@ -126,7 +126,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 *            the Model
 	 * @param control
 	 *            the Controller
-	 * @param unitGraph 
+	 * @param unitGraph
 	 */
 	public UpperNodeCanvas(Model mod, Control control, UnitGraph unitGraph, CpsUpperNode UpperNode, String parentPath) {
 		toolTip = false;
@@ -145,12 +145,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 		borderPos = (int) (50 + scalediv20 + scalediv20 + 10);
 		for (AbstractCpsObject cps : upperNode.getNodes()) {
 			if (cps.getPosition().x < model.getScaleDiv2() + borderPos + 5) {
-				cps.setPosition(new Position(borderPos + 5+model.getScaleDiv2(), cps.getPosition().y));
+				cps.setPosition(new Position(borderPos + 5 + model.getScaleDiv2(), cps.getPosition().y));
 			}
 		}
 
 		showedInformation[0] = true;
 		showedInformation[1] = true;
+		showedInformation[4] = true;
 
 		popmenu.add(itemCut);
 		popmenu.add(itemCopy);
@@ -666,7 +667,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				cps = e.getA();
 			}
 			// Show and Highlight
-			if (model.getSelectedCpsObjects().contains(cps)) {
+			if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4] == true) {
 				for (CpsEdge ed : cps.getConnections()) {
 					AbstractCpsObject obj = null;
 					if (upperNode.getNodes().contains(ed.getA())) {
@@ -675,10 +676,23 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 						obj = ed.getB();
 					}
 					if (obj != null) {
-						g2.setColor(Color.BLUE);
+						if (ed.getFlow() == 0)
+							g2.setColor(Color.RED);
+						else
+							g2.setColor(Color.BLUE);
 						g2.drawLine(obj.getPosition().x, obj.getPosition().y, (borderPos >> 1),
-								(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
-										+ 25);
+								(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
+						if (showedInformation[0]) {
+							if (ed.getConnected() == 0 || ed.getConnected() == 1) {
+								g2.drawString(ed.getFlow() + "/" + ed.getCapacity(),
+										(ed.getA().getPosition().x + ed.getB().getPosition().x) / 2,
+										(ed.getA().getPosition().y + ed.getB().getPosition().y) / 2);
+							} else {
+								g2.drawString("not connected",
+										(ed.getA().getPosition().x + ed.getB().getPosition().x) / 2,
+										(ed.getA().getPosition().y + ed.getB().getPosition().y) / 2);
+							}
+						}
 					}
 				}
 			}
@@ -689,8 +703,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				if (g2.getColor() != Color.WHITE) {
 					g2.fillRect((int) ((borderPos >> 1) - 25 - scalediv20) - 3,
 							(int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
-							(int) (50 + ((scalediv20 + 3) * 2)),
-							(int) (50 + ((scalediv20 + 3) * 2)));
+							(int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
 				}
 			}
 
@@ -712,15 +725,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					g2.setColor(Color.BLUE);
 					g2.fillRect((int) ((borderPos >> 1) - 25 - scalediv20),
 							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-							(int) (50 + (scalediv20 * 2)),
-							(int) (50 + (scalediv20 * 2)));
+							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
 				} else if (cps instanceof HolonObject) {
 					g2.setColor(((HolonObject) cps).getColor());
 
 					g2.fillRect((int) ((borderPos >> 1) - 25 - scalediv20),
 							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-							(int) (50 + (scalediv20 * 2)),
-							(int) (50 + (scalediv20 * 2)));
+							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
 				}
 				// draw image
 				File checkPath = new File(cps.getImage());
@@ -730,9 +741,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
 				}
 			}
-			g2.drawImage(img, (borderPos >> 1) - 25,
-					(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50,
-					50, null);
+			g2.drawImage(img, (borderPos >> 1) - 25, (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50,
+					null);
 			count++;
 		}
 
@@ -1414,9 +1424,10 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 * @param object
 	 *            boolean for objects
 	 */
-	public void setShowedInformation(boolean connection, boolean object) {
+	public void setShowedInformation(boolean connection, boolean object, boolean nodeOfnode) {
 		showedInformation[0] = connection;
 		showedInformation[1] = object;
+		showedInformation[4] = nodeOfnode;
 	}
 
 	/**