Forráskód Böngészése

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

Conflicts:
	src/ui/view/GUI.java
Edgardo Palza 8 éve
szülő
commit
6feb361f7e

+ 1 - 1
.classpath

@@ -3,8 +3,8 @@
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="res"/>
 	<classpathentry excluding="src/|res/" kind="src" path=""/>
+	<classpathentry kind="lib" path="jars/json-simple-1.1.1.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
-	<classpathentry kind="lib" path="jars/json-simple-1.1.1.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

BIN
.gradle/2.2.1/taskArtifacts/cache.properties.lock


BIN
.gradle/2.2.1/taskArtifacts/fileHashes.bin


BIN
.gradle/2.2.1/taskArtifacts/fileSnapshots.bin


BIN
.gradle/2.2.1/taskArtifacts/taskArtifacts.bin


+ 2 - 9
build.gradle

@@ -36,15 +36,8 @@ sourceSets {
     }
 }
 
-repositories {
-   flatDir {
-       dirs 'jars'
-   }
-}
-
-
-dependencies {
-   compile name: 'json-simple-1.1.1'
+ dependencies {   
+       compile fileTree(dir: 'jars', include: ['*.jar'])
 }
 /*
 // In this section you declare where to find the dependencies of your project

+ 1 - 0
src/classes/CpsEdge.java

@@ -11,6 +11,7 @@ public class CpsEdge {
 	public CpsEdge(CpsObject A, CpsObject B){
 		setA(A);
 		setB(B);
+		this.flow = 50;
 		this.A.AddConnection(this);
 		this.B.AddConnection(this);
 		this.maxCapacity = 100;

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

@@ -387,12 +387,16 @@ public class GUI<E> implements CategoryListener {
 						} else {
 							holonEleNamesDisplayed = ele.getEleName() + " ";
 						}
+<<<<<<< HEAD
+=======
+						unitGraph.repaintWithNewElement(selectedElements);
+>>>>>>> 6a56b8b4607b7c38c67477e4f5c42a239c6b9a6d
 					}
 				} else if (ele != null) {
 					selectedElements.clear();
 					selectedElements.add(ele);
 					holonEleNamesDisplayed = ele.getEleName() + " ";
-					unitGraph.repaintWithNewElement(ele);
+					unitGraph.repaintWithNewElement(selectedElements);
 				} else {
 					elementGraph.setText("None ");
 					unitGraph.empty();

+ 15 - 3
src/ui/view/MyCanvas.java

@@ -102,7 +102,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		}
 
 		// drawEdges
-		g2.setColor(Color.BLACK);
+		//g2.setColor(Color.BLACK);
 		if (drawEdge) {
 			g2.setStroke(new BasicStroke(2));
 			g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
@@ -112,8 +112,14 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		for (CpsEdge con : model.getEdgesOnCanvas()) {
 			if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
 					&& con != edgeHighlight) {
-				g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));
-				g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
+				if(con.getFlow()<=con.getCapacity()){
+						g2.setColor(Color.BLACK);
+						g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));
+				}else{
+					g2.setColor(Color.RED);
+					g2.setStroke(new BasicStroke(2));
+				}
+						g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
 						con.getA().getPosition().y + controller.getScaleDiv2(),
 						con.getB().getPosition().x + controller.getScaleDiv2(),
 						con.getB().getPosition().y + controller.getScaleDiv2());
@@ -127,6 +133,11 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		if (model.getSelectedObjectID() > 0) {
 			g2.setColor(Color.BLUE);
 			for (CpsEdge con : model.getEdgesOnCanvas()) {
+				if(con.getFlow()<=con.getCapacity()){
+					g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));	
+				}else{
+					g2.setStroke(new BasicStroke(2));
+				}
 				if (con.getA().getID() == model.getSelectedObjectID()
 						|| con.getB().getID() == model.getSelectedObjectID() && con != edgeHighlight) {
 					g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
@@ -140,6 +151,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			}
 		} else if (edgeHighlight != null) {
 			g2.setColor(Color.BLUE);
+			g2.setStroke(new BasicStroke(2));
 			g2.drawLine(edgeHighlight.getA().getPosition().x + controller.getScaleDiv2(),
 					edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),

+ 50 - 35
src/ui/view/UnitGraph.java

@@ -13,11 +13,14 @@ import java.awt.event.MouseMotionListener;
 import java.awt.geom.CubicCurve2D;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Line2D;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.awt.Point;
 
 import javax.swing.JPanel;
 
+import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;
+
 import classes.HolonElement;
 import ui.controller.Control;
 import ui.model.Model;
@@ -48,7 +51,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private boolean isElement = false;
 	private boolean isSwitch = false;
 
-	private HolonElement tempElement;
+	private ArrayList<HolonElement> tempElements = new ArrayList<>();
 	private HolonSwitch tempSwitch;
 	private Model model;
 	private Control controller;
@@ -101,9 +104,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 		if (isElement) {
 			if (arrayOfFloats != null) {
-				// array fillen
-				fillArrayofValue();
-
 				// Draw the Lines
 				g2.setStroke(new BasicStroke(2));
 				g2.setColor(Color.BLACK);
@@ -338,7 +338,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		tempP = null;
 		if (pointList != null) {
 			for (Point p : pointList) {
-				if (x >= p.getX() - dist && x <= p.getX() + dist) {
+				if (x >= p.getX() - dist * 2 && x <= p.getX() + dist * 2) {
 					if (e.getButton() == MouseEvent.BUTTON3) {
 						tempP = p;
 						deletePoint = true;
@@ -352,21 +352,21 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
 				for (int i = 0; i < pointList.size() && !added; i++) {
 					if (x < pointList.get(i).getX() - dist) {
-						// Punkt hinzufügen, je nachdem ob es oberhalb oder
-						// unterhalb der hälfte ist
-						if (y < height / 2 && (pointList.get(i - 1).getY() == height - 1
-								&& pointList.get(i).getY() == height - 1)) {
-							pointList.add(i, new Point((int) (x + dist), (int) height - 1));
-							pointList.add(i, new Point((int) (x + dist), 0));
-							pointList.add(i, new Point((int) (x - dist), 0));
-							pointList.add(i, new Point((int) (x - dist), (int) height - 1));
+						// double p1, p2 um location der points zu bestimmen
+						double p1 = pointList.get(i - 1).getX();
+						double p2 = pointList.get(i).getX();
+						// Punkte hinzufügen, je nachdem ob true oder false
+						if (pointList.get(i - 1).getY() != 0 && pointList.get(i).getY() != 0) {
+							pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) height - 1));
+							pointList.add(i, new Point((int) ((x + p2) / 2 + dist), 0));
+							pointList.add(i, new Point((int) ((x + p1) / 2 - dist), 0));
+							pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) height - 1));
 							added = true;
-						} else if (y >= height / 2 && (pointList.get(i - 1).getY() != height - 1
-								&& pointList.get(i).getY() != height - 1)) {
-							pointList.add(i, new Point((int) (x + dist), 0));
-							pointList.add(i, new Point((int) (x + dist), (int) height - 1));
-							pointList.add(i, new Point((int) (x - dist), (int) height - 1));
-							pointList.add(i, new Point((int) (x - dist), 0));
+						} else if (pointList.get(i - 1).getY() == 0 && pointList.get(i).getY() == 0) {
+							pointList.add(i, new Point((int) ((x + p2) / 2 + dist), 0));
+							pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) height - 1));
+							pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) height - 1));
+							pointList.add(i, new Point((int) ((x + p1) / 2 - dist), 0));
 							added = true;
 						}
 					}
@@ -376,15 +376,20 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			// Delete a Point
 			if (deletePoint && tempP.getX() != 0
 					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
-				System.out.println("x: " + tempP.getY());
-				// pointList.remove(tempP);
+				int i = pointList.indexOf(tempP);
+				if (tempP.getY() == 0) {
+					pointList.remove(i);
+					pointList.remove(i - 1);
+					pointList.remove(i - 2);
+					pointList.remove(i - 3);
+				}
+				if (tempP.getY() == height - 1) {
+					pointList.remove(i + 2);
+					pointList.remove(i + 1);
+					pointList.remove(i);
+					pointList.remove(i - 1);
+				}
 			}
-			// Delete This for
-			/*
-			 * for (int i = 0; i < pointList.size(); i++) {
-			 * System.out.println(pointList.get(i).getX() + ", " +
-			 * pointList.get(i).getY()); }
-			 */
 
 			repaint();
 		}
@@ -397,6 +402,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			pointDrag = false;
 			tempP = null;
 		}
+		if (isElement) {
+			// array fillen
+			fillArrayofValue();
+		}
 	}
 
 	public void componentResized(ComponentEvent e) {
@@ -437,7 +446,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 */
 	public void empty() {
 		pointList = null;
-		tempElement = null;
+		tempElements = null;
 		tempSwitch = null;
 		arrayOfFloats = null;
 		arrayOfBooleans = null;
@@ -484,13 +493,13 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 * @param HolonElement
 	 *            ele, which should be visualized
 	 */
-	public void repaintWithNewElement(HolonElement ele) {
-		arrayOfFloats = ele.getEnergyAt();
-		tempElement = ele;
-		pointList = ele.getGraphPoints();
+	public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
+		arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getEnergyAt();
+		tempElements = selectedElement;
+		pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
 		isSwitch = false;
 		isElement = true;
-		MAXIMUM = tempElement.getEnergy();
+		MAXIMUM = selectedElement.get(selectedElement.size() - 1).getEnergy();
 		// First time clicked on the Element
 		if (pointList.isEmpty()) {
 			pointList.addFirst(new Point(0, 0));
@@ -568,9 +577,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	/**
 	 * Fills the Arrays of each HolonElement
 	 */
+	@SuppressWarnings("unchecked")
 	public void fillArrayofValue() {
-		for (int i = 0; i < arrayOfFloats.length; i++) {
-			arrayOfFloats[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
+		for (HolonElement he : tempElements) {
+			MAXIMUM = he.getEnergy();
+			he.setGraphPoints((LinkedList<Point>) pointList.clone());
+			for (int i = 0; i < arrayOfFloats.length; i++) {
+				he.getEnergyAt()[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
+			}
+			arrayOfFloats = he.getEnergyAt();
 		}
 	}