Pārlūkot izejas kodu

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

Kevin Trometer 7 gadi atpakaļ
vecāks
revīzija
02cd127a93

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

@@ -686,6 +686,10 @@ public class Control {
 	public void setCanvasY(int canvasY) {
 		globalController.setCanvasY(canvasY);
 	}
+	
+	public void setMaxCapacity(float cap) {
+		globalController.setMaxCapacity(cap);
+	}
 
 	/**
 	 * Set the Algorithm.
@@ -755,4 +759,8 @@ public class Control {
 	public void delEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
 		nodeController.deleteEdge(edge, upperNode);
 	}
+	
+	public void connectNodes(AbstractCpsObject a, AbstractCpsObject b, CpsUpperNode node) {
+		nodeController.connectNodes(a, b, node);
+	}
 }

+ 4 - 0
src/ui/controller/GlobalController.java

@@ -128,5 +128,9 @@ public class GlobalController {
 	public void addSubNetColor(Color c) {
 		model.addSubNetColor(c);
 	}
+	
+	public void setMaxCapacity(float cap) {
+		model.setMaxCapacity(cap);
+	}
 
 }

+ 37 - 3
src/ui/controller/NodeController.java

@@ -28,6 +28,7 @@ public class NodeController {
 	 * Add a CpsUpperNode into Canvas
 	 * 
 	 * @param nodeName
+	 * @param upperNode
 	 */
 	public void doUpperNode(String nodeName, CpsUpperNode upperNode) {
 
@@ -47,6 +48,7 @@ public class NodeController {
 	 * Delete a CpsUpperNode from the Canvas
 	 * 
 	 * @param node
+	 * @param upperNode
 	 */
 	public void undoUpperNode(CpsUpperNode node, CpsUpperNode upperNode) {
 		restoreOldEdges(node, upperNode);
@@ -62,11 +64,12 @@ public class NodeController {
 	 * Put selected Nodes inside the Upper Node
 	 * 
 	 * @param node
+	 * @param upperNode
 	 */
 	private void makeNodeOfNodes(CpsUpperNode node, CpsUpperNode upperNode) {
 
 		ArrayList<AbstractCpsObject> nodes = node.getNodes();
-		//ArrayList<CpsEdge> nodeEdges = node.getNodeEdges();
+		// ArrayList<CpsEdge> nodeEdges = node.getNodeEdges();
 
 		// Put all selected Nodes into the Upper Node
 		for (Iterator<AbstractCpsObject> it = model.getSelectedCpsObjects().iterator(); it.hasNext();) {
@@ -101,23 +104,35 @@ public class NodeController {
 
 	}
 
+	/**
+	 * Transfer all relevant data from Node into the next higher layer of Node
+	 * (upperNode)
+	 * 
+	 * @param node
+	 * @param upperNode
+	 */
 	private void unmakeNodesOfNodes(CpsUpperNode node, CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
+		// add all nodes into upperNode
 		(upperNode == null ? model.getObjectsOnCanvas() : upperNode.getNodes()).addAll(node.getNodes());
+		// add all indices of nodes into upperNode
 		(upperNode == null ? model.getCvsObjIdx() : upperNode.getNodesIdx()).putAll(node.getNodesIdx());
+		// add all Edges of node into upperNode
 		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).addAll(node.getNodeEdges());
 	}
 
 	/**
+	 * Look for adjacent Nodes connected with the new CpsUpperNode and make Connections
 	 * 
-	 * @return
+	 * @param node
+	 * @param upperNode
 	 */
 	private void makeAdjacent(CpsUpperNode node, CpsUpperNode upperNode) {
 
 		ArrayList<AbstractCpsObject> adj = new ArrayList<>();
 		ArrayList<Float> maxCapacity = new ArrayList<>();
+		
 		ArrayList<CpsEdge> oldEdges = node.getOldEdges();
-
 		ArrayList<CpsEdge> toDelete = new ArrayList<>();
 
 		// für alle Edges auf dem Canvas
@@ -175,6 +190,7 @@ public class NodeController {
 	}
 
 	/**
+	 * Restore the Old Connections from the adjacent Object
 	 * 
 	 * @param node
 	 * @param upperNode
@@ -183,6 +199,7 @@ public class NodeController {
 		// TODO Auto-generated method stub
 		ArrayList<CpsEdge> toDelete = new ArrayList<>();
 
+		//für jede Edge aus upperNode die Node enthält tu sie in toDelete
 		for (Iterator<CpsEdge> it = (upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges())
 				.iterator(); it.hasNext();) {
 
@@ -191,6 +208,7 @@ public class NodeController {
 				toDelete.add(edge);
 
 		}
+		//lösch alle Edges die in toDelete sind und wiederherstell alte Edges
 		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).removeAll(toDelete);
 		(upperNode == null ? model.getEdgesOnCanvas() : upperNode.getNodeEdges()).addAll(node.getOldEdges());
 	}
@@ -361,4 +379,20 @@ public class NodeController {
 		upperNode.getNodeEdges().remove(edge);
 	}
 
+	/**
+	 * Adds a Edge into Connections of AbstactCpsObjects
+	 * 
+	 * @param a
+	 * @param b
+	 */
+	public void connectNodes(AbstractCpsObject a, AbstractCpsObject b, CpsUpperNode node) {
+		// mache hier Connections in A und B rein
+		// mache diese Edge auch in OldEdges rein des aktuellen CpsUpperNodes
+		
+		 CpsEdge edge = new CpsEdge(a, b, model.getMaxCapacity());
+		 edge.getA().getConnections().add(edge);
+		 edge.getB().getConnections().add(edge);
+		 node.getOldEdges().add(edge);
+	}
+
 }

+ 1 - 5
src/ui/controller/StatsController.java

@@ -26,16 +26,12 @@ public class StatsController {
 	public void addTrackingObj(HolonObject obj) {
 		model.getTrackingObj().add(obj);
 		model.addObjectsToGraphListeners();
-		/*
-		for(int i = 0; i < model.getTrackingObj().size(); i++){
-			System.out.println(model.getTrackingObj().get(i).getName() + " " + model.getTrackingObj().get(i).getID());
-		}
-		*/
 	}
 
 	public void removeTrackingObj(HolonObject obj) {
 		ArrayList<HolonObject> objArr = model.getTrackingObj();
 		objArr.remove(obj);
 		model.setTrackingObj(objArr);
+		model.addObjectsToGraphListeners();
 	}
 }

+ 17 - 0
src/ui/model/Model.java

@@ -41,6 +41,8 @@ public class Model{
 	private ArrayList<AbstractCpsObject> selectedObjects = new ArrayList<AbstractCpsObject>();
 	private ArrayList<AbstractCpsObject> clipboardObjects = new ArrayList<AbstractCpsObject>();
 	private Console console;
+	//Capacity for Edge
+	private float maxCapacity;
 
 	private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
 	// Iteration Speed
@@ -517,6 +519,20 @@ public class Model{
 		return console;
 	}
 
+	/**
+	 * @return the maxCapacity
+	 */
+	public float getMaxCapacity() {
+		return maxCapacity;
+	}
+
+	/**
+	 * @param maxCapacity the maxCapacity to set
+	 */
+	public void setMaxCapacity(float maxCapacity) {
+		this.maxCapacity = maxCapacity;
+	}
+
 	/**
 	 * Sets the Interval in ms between each Iteration.
 	 * 
@@ -647,6 +663,7 @@ public class Model{
 	public void addObjectsToGraphListeners(){
 		for(GraphListener gl : graphListeners){
 			gl.addTrackedObject(trackingObj);
+			gl.repaintGraph();
 		}
 	}
 

+ 1 - 1
src/ui/view/EditEdgesPopUp.java

@@ -182,7 +182,7 @@ public class EditEdgesPopUp extends JDialog {
 	 *            the capacity
 	 */
 	public void changeForNew(float cap) {
-		canvas.setEdgeCapacity(cap);
+		controller.setMaxCapacity(cap);
 	}
 
 	/**

+ 8 - 16
src/ui/view/MyCanvas.java

@@ -85,7 +85,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 												// rightclicked
 
 	// contains the value of the Capacity for new created Edges
-	private float edgeCapacity;
+
 
 	/**
 	 * Constructor.
@@ -104,7 +104,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 		showedInformation[0] = true;
 		showedInformation[1] = true;
-		edgeCapacity = 10000;
+		control.setMaxCapacity(10000);
 
 		popmenu.add(itemCut);
 		popmenu.add(itemCopy);
@@ -741,7 +741,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					}
 				}
 				if (newEdge) {
-					e = new CpsEdge(cps, tempCps, edgeCapacity);
+					e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
 					controller.addEdgeOnCanvas(e);
 				}
 			}
@@ -764,11 +764,11 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				r = p.getA();
 				k = p.getB();
 
-				e = new CpsEdge(n, tempCps, edgeCapacity);
+				e = new CpsEdge(n, tempCps, model.getMaxCapacity());
 
-				e1 = new CpsEdge(n, r, edgeCapacity);
+				e1 = new CpsEdge(n, r, model.getMaxCapacity());
 
-				e2 = new CpsEdge(n, k, edgeCapacity);
+				e2 = new CpsEdge(n, k, model.getMaxCapacity());
 
 				controller.removeEdgesOnCanvas(p);
 				controller.addEdgeOnCanvas(e);
@@ -784,7 +784,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
 			controller.addObjectCanvas(n);
 
-			e = new CpsEdge(n, tempCps, edgeCapacity);
+			e = new CpsEdge(n, tempCps, model.getMaxCapacity());
 
 			controller.addEdgeOnCanvas(e);
 		}
@@ -859,15 +859,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		return false;
 	}
 
-	/**
-	 * sets the Edge Capacity.
-	 * 
-	 * @param cap
-	 *            capacity
-	 */
-	public void setEdgeCapacity(float cap) {
-		edgeCapacity = cap;
-	}
+
 
 	/**
 	 * Set if Information should be shown.

+ 7 - 8
src/ui/view/UpperNodeCanvas.java

@@ -95,7 +95,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 												// rightclicked
 
 	// contains the value of the Capacity for new created Edges
-	private float edgeCapacity;
 
 	/**
 	 * Constructor.
@@ -123,7 +122,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 
 		showedInformation[0] = true;
 		showedInformation[1] = true;
-		edgeCapacity = 10000;
+		control.setMaxCapacity(10000);
 
 		popmenu.add(itemCut);
 		popmenu.add(itemCopy);
@@ -876,7 +875,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					}
 				}
 				if (newEdge) {
-					e = new CpsEdge(cps, tempCps, edgeCapacity);
+					e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
 					controller.addEdgeUpperNode(e, upperNode);
 				}
 			}
@@ -899,11 +898,11 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				r = p.getA();
 				k = p.getB();
 
-				e = new CpsEdge(n, tempCps, edgeCapacity);
+				e = new CpsEdge(n, tempCps, model.getMaxCapacity());
 
-				e1 = new CpsEdge(n, r, edgeCapacity);
+				e1 = new CpsEdge(n, r, model.getMaxCapacity());
 
-				e2 = new CpsEdge(n, k, edgeCapacity);
+				e2 = new CpsEdge(n, k, model.getMaxCapacity());
 
 				controller.delEdgeUpperNode(p, upperNode);
 				controller.addEdgeUpperNode(e, upperNode);
@@ -919,7 +918,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 			n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
 			controller.addObjUpperNode(n, upperNode);
 
-			e = new CpsEdge(n, tempCps, edgeCapacity);
+			e = new CpsEdge(n, tempCps, model.getMaxCapacity());
 
 			controller.addEdgeUpperNode(e, upperNode);
 		}
@@ -999,7 +998,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 	 *            capacity
 	 */
 	public void setEdgeCapacity(float cap) {
-		edgeCapacity = cap;
+		controller.setMaxCapacity(cap);
 	}
 
 	/**

+ 42 - 33
src/ui/view/splitPane.java

@@ -24,6 +24,7 @@ import javax.swing.JTextField;
 import javax.swing.JComboBox;
 import javax.swing.JButton;
 import javax.swing.JTree;
+import java.awt.Color;
 
 public class splitPane extends JSplitPane implements GraphListener {
 	private JTextField graphNrTxtField;
@@ -76,40 +77,47 @@ public class splitPane extends JSplitPane implements GraphListener {
 		JLabel lblG = new JLabel("G:");
 		
 		JButton btnAdd = new JButton("Add");
+		
+		JPanel colorPanel = new JPanel();
+		colorPanel.setBackground(Color.GRAY);
 		GroupLayout gl_panel = new GroupLayout(panel);
 		gl_panel.setHorizontalGroup(
 			gl_panel.createParallelGroup(Alignment.LEADING)
 				.addGroup(gl_panel.createSequentialGroup()
-					.addContainerGap()
-					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
-						.addComponent(treeScrollPane, Alignment.LEADING)
-						.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
+					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
+						.addGroup(gl_panel.createSequentialGroup()
+							.addContainerGap()
 							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
-								.addComponent(lblGraph)
-								.addComponent(lblObject)
-								.addComponent(lblProperty)
-								.addComponent(lblColor)
+								.addComponent(treeScrollPane, GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
 								.addGroup(gl_panel.createSequentialGroup()
-									.addComponent(lblR)
+									.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
+										.addComponent(lblGraph)
+										.addComponent(lblObject)
+										.addComponent(lblProperty)
+										.addComponent(lblColor)
+										.addGroup(gl_panel.createSequentialGroup()
+											.addComponent(lblR)
+											.addPreferredGap(ComponentPlacement.RELATED)
+											.addComponent(redField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
 									.addPreferredGap(ComponentPlacement.RELATED)
-									.addComponent(redField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
-							.addPreferredGap(ComponentPlacement.RELATED)
-							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
-								.addComponent(showObjectlbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-								.addComponent(showPropertylbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-								.addComponent(graphNrTxtField)
-								.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
-									.addComponent(colorComboBox, Alignment.LEADING, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-									.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
-										.addComponent(lblB)
-										.addPreferredGap(ComponentPlacement.RELATED)
-										.addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
-										.addPreferredGap(ComponentPlacement.RELATED)
-										.addComponent(lblG)
-										.addPreferredGap(ComponentPlacement.RELATED)
-										.addComponent(greenField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
-									.addComponent(btnAdd, Alignment.LEADING)))))
-					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+									.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
+										.addComponent(showObjectlbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+										.addComponent(showPropertylbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+										.addComponent(graphNrTxtField)
+										.addComponent(colorComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+										.addGroup(gl_panel.createSequentialGroup()
+											.addComponent(lblB)
+											.addPreferredGap(ComponentPlacement.RELATED)
+											.addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)
+											.addPreferredGap(ComponentPlacement.RELATED)
+											.addComponent(lblG)
+											.addPreferredGap(ComponentPlacement.RELATED)
+											.addComponent(greenField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))))
+								.addComponent(colorPanel, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)))
+						.addGroup(gl_panel.createSequentialGroup()
+							.addGap(67)
+							.addComponent(btnAdd)))
+					.addContainerGap())
 		);
 		gl_panel.setVerticalGroup(
 			gl_panel.createParallelGroup(Alignment.LEADING)
@@ -140,13 +148,15 @@ public class splitPane extends JSplitPane implements GraphListener {
 						.addComponent(blueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
 						.addComponent(lblG)
 						.addComponent(greenField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
-					.addPreferredGap(ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
+					.addPreferredGap(ComponentPlacement.UNRELATED)
+					.addComponent(colorPanel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
+					.addPreferredGap(ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
 					.addComponent(btnAdd)
-					.addContainerGap())
+					.addGap(34))
 		);
 		
 		objectTree = new JTree();
-		treeModel = new DefaultTreeModel(null);
+		treeModel = (DefaultTreeModel)objectTree.getModel();
 		DefaultMutableTreeNode root = new DefaultMutableTreeNode("Statistics");
 		wholeHolon = new DefaultMutableTreeNode("whole Holon");
 		wholeHolon.add(new DefaultMutableTreeNode("total Production"));
@@ -199,11 +209,11 @@ public class splitPane extends JSplitPane implements GraphListener {
 		
 		JScrollPane graphScrollPane = new JScrollPane();
 		setRightComponent(graphScrollPane);
+		repaintGraph();
 	}
 	@Override
 	public void repaintGraph() {
-		// TODO Auto-generated method stub
-		
+		treeModel.reload();
 	}
 	@Override
 	public void addTrackedObject(ArrayList<HolonObject> hlList) {
@@ -219,7 +229,6 @@ public class splitPane extends JSplitPane implements GraphListener {
 		}else{
 			objectsNode.add(new DefaultMutableTreeNode("empty"));
 		}
-		objectTree.repaint();
 		
 	}
 }