Browse Source

path grapg curve stuff

Kevin Trometer 8 years ago
parent
commit
3e0e47dcdc
2 changed files with 12 additions and 8 deletions
  1. 2 3
      src/ui/view/GUI.java
  2. 10 5
      src/ui/view/UnitGraph.java

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

@@ -175,9 +175,8 @@ public class GUI implements CategoryListener {
 		this.controller = control;
 		this.model = control.getModel();
 		this.canvas = new MyCanvas(model, control);
-		this.unitGraph = new UnitGraph(model, control); // for testing, remove
-
-		// later
+		this.unitGraph = new UnitGraph(model, control);
+		
 		control.initListener(this);
 		initialize();
 		updateCategories(model.getCategories());

+ 10 - 5
src/ui/view/UnitGraph.java

@@ -11,6 +11,7 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.awt.geom.CubicCurve2D;
+import java.awt.geom.GeneralPath;
 import java.awt.geom.Line2D;
 import java.util.LinkedList;
 import java.awt.Point;
@@ -44,6 +45,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private HolonElement tempElement;
 	private Model model;
 	private Control controller;
+	GeneralPath graphCurve = new GeneralPath();  
 
 	private boolean pointDrag = false;
 	private boolean init = false;
@@ -56,9 +58,9 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		this.controller = control;
 		this.model = model;
 		this.ITERATIONS = model.getIterations();
-
+		
 		this.pointList = new LinkedList<>();
-
+		
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
@@ -77,6 +79,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		g2.setRenderingHints(rh);
 		g2.setStroke(new BasicStroke(1));
 		
+		graphCurve.reset();
+		
 		if (arrayOfValue != null) {
 			for (int i = 0; i < arrayOfValue.length; i++) {
 				arrayOfValue[i] = convertToValueY(getYValueAt((int) (i * width / (ITERATIONS - 1))));
@@ -94,14 +98,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			g2.drawLine(0, (i) * this.getHeight() / (ITERATIONS - 1), this.getWidth(),
 					(i) * this.getHeight() / (ITERATIONS - 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));
-			g2.draw(c);
+			graphCurve.append(c, true);
 		}
-
+		g2.draw(graphCurve);
+		
 		// Draw the Points
 		g2.setColor(Color.BLUE);
 		for (int i = 0; i < pointList.size() - 0; i++) {