Explorar el Código

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

Edgardo Palza hace 8 años
padre
commit
234bb31017
Se han modificado 2 ficheros con 68 adiciones y 50 borrados
  1. 3 0
      src/ui/view/GUI.java
  2. 65 50
      src/ui/view/UnitGraph.java

+ 3 - 0
src/ui/view/GUI.java

@@ -729,6 +729,9 @@ public class GUI<E> implements CategoryListener {
 					tableModelProperties.setCellEditable(2, 1, true);
 				} else if (getActualCps() == null) {
 					deleteRows();
+				} 
+				if(model.getSelectedObjectID() == 0){
+					unitGraph.empty();
 				}
 			}
 

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

@@ -81,10 +81,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 		graphCurve.reset();
 
-		if (arrayOfValue != null) {
-			fillArrayofValue();
-		}
-
 		// Draw the Vertical Lines
 		g2.setColor(new Color(240, 240, 240));
 		for (int i = 0; i < model.getIterations(); i++) {
@@ -97,22 +93,28 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					(i) * this.getHeight() / (model.getIterations() - 1));
 		}
 
-		// Draw the Lines
-		g2.setColor(Color.BLACK);
-		for (int i = 0; i < pointList.size() - 1; i++) {
-			c = buildCurve(pointList.get(i), pointList.get(i + 1));
-			graphCurve.append(c, true);
-		}
-		g2.draw(graphCurve);
+		if (arrayOfValue != null) {
+			//array fillen
+			fillArrayofValue();
 
-		// Draw the Points
-		g2.setColor(Color.BLUE);
-		for (int i = 0; i < pointList.size() - 0; i++) {
-			g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
-					(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
-					(int) recSize.getY());
+			// Draw the Lines
+			g2.setColor(Color.BLACK);
+			for (int i = 0; i < pointList.size() - 1; i++) {
+				c = buildCurve(pointList.get(i), pointList.get(i + 1));
+				graphCurve.append(c, true);
+			}
+			g2.draw(graphCurve);
+
+			// Draw the Points
+			g2.setColor(Color.BLUE);
+			for (int i = 0; i < pointList.size() - 0; i++) {
+				g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
+						(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
+						(int) recSize.getY());
+			}
 		}
 		// Iteration Line
+		g2.setColor(Color.BLUE);
 		g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
 				(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
 		// Iteration Value
@@ -158,9 +160,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				x = tempP.getX();
 			}
 			tempP.setLocation(x, y);
+			repaint();
 		}
 
-		repaint();
+		
 	}
 
 	@Override
@@ -193,39 +196,41 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 		// Click on Point
 		tempP = null;
-		for (Point p : pointList) {
-			if (x >= p.getX() - recSize.getX() / 2 && y >= p.getY() - recSize.getY() / 2
-					&& x <= p.getX() + recSize.getX() / 2 && y <= p.getY() * scaleY + recSize.getY() / 2) {
-				if (e.getButton() == MouseEvent.BUTTON3) {
-					tempP = p;
-					deletePoint = true;
-				} else {
-					pointDrag = true;
-					tempP = p;
+		if (pointList != null) {
+			for (Point p : pointList) {
+				if (x >= p.getX() - recSize.getX() / 2 && y >= p.getY() - recSize.getY() / 2
+						&& x <= p.getX() + recSize.getX() / 2 && y <= p.getY() * scaleY + recSize.getY() / 2) {
+					if (e.getButton() == MouseEvent.BUTTON3) {
+						tempP = p;
+						deletePoint = true;
+					} else {
+						pointDrag = true;
+						tempP = p;
+					}
 				}
 			}
-		}
-		if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
-				&& e.getX() != this.getWidth() / scaleX) {
-			for (int i = 0; i < pointList.size(); i++) {
-				if (x < pointList.get(i).getX() && !added) {
-					if (e.getY() <= 0) {
-						pointList.add(i, new Point((int) (x), (int) (0 / scaleY)));
-					} else {
-						pointList.add(i, new Point((int) (x), (int) y));
+			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
+					&& e.getX() != this.getWidth() / scaleX) {
+				for (int i = 0; i < pointList.size(); i++) {
+					if (x < pointList.get(i).getX() && !added) {
+						if (e.getY() <= 0) {
+							pointList.add(i, new Point((int) (x), (int) (0 / scaleY)));
+						} else {
+							pointList.add(i, new Point((int) (x), (int) y));
+						}
+						added = true;
+						pointDrag = true;
+						tempP = pointList.get(i);
 					}
-					added = true;
-					pointDrag = true;
-					tempP = pointList.get(i);
 				}
 			}
-		}
-		if (deletePoint && tempP.getX() != 0
-				&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
-			pointList.remove(tempP);
-		}
+			if (deletePoint && tempP.getX() != 0
+					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
+				pointList.remove(tempP);
+			}
 
-		repaint();
+			repaint();
+		}
 	}
 
 	@Override
@@ -273,7 +278,17 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	}
 
 	/*
-	 * Resets the Graph
+	 * Emptys the Graph
+	 */
+	public void empty() {
+		pointList = null;
+		tempElement = null;
+		arrayOfValue = null;
+		repaint();
+	}
+
+	/*
+	 * Resets the Points for the Element
 	 */
 	public void reset() {
 		pointList.removeAll(pointList);
@@ -390,14 +405,14 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				// Teil der Kurve aussuchen
 				if (cl.getX1() <= xVal * scaleX && cl.getX2() > xVal * scaleX) {
 					c = cl;
-					//Kurve Links von "unten"
+					// Kurve Links von "unten"
 					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
 						for (int j = (int) (height - 1); j >= 0; j--) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
 							}
 						}
-					} else {//Kurve Links von "oben"
+					} else {// Kurve Links von "oben"
 						for (int j = 0; j < height; j++) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
@@ -406,14 +421,14 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					}
 				} else {
 					c = cr;
-					//Kurve Links von "unten"
+					// Kurve Links von "unten"
 					if (pointList.get(i).getY() >= pointList.get(i + 1).getY()) {
 						for (int j = 0; j < height; j++) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);
 							}
 						}
-					} else {//Kurve Links von "oben"
+					} else {// Kurve Links von "oben"
 						for (int j = (int) (height - 1); j >= 0; j--) {
 							if (c.contains(xVal * scaleX, j * scaleY)) {
 								return (float) (j);