浏览代码

global Variable ITERATIONS

Kevin Trometer 8 年之前
父节点
当前提交
c3f1b5faab
共有 4 个文件被更改,包括 23 次插入23 次删除
  1. 12 2
      src/ui/model/Model.java
  2. 1 1
      src/ui/view/GUI.java
  3. 0 2
      src/ui/view/MyCanvas.java
  4. 10 18
      src/ui/view/UnitGraph.java

+ 12 - 2
src/ui/model/Model.java

@@ -15,8 +15,9 @@ import ui.controller.*;
 public class Model {
 
 	//Global Variables
-	public static int SCALE = 50;	//Picture Scale
-	public static int SCALE_DIV2 = SCALE/2;
+	private static int SCALE = 50;	//Picture Scale
+	private static int SCALE_DIV2 = SCALE/2;
+	private static final int ITERATIONS = 50;
 	
 	// ID of the Selected Object
 	private int selectedID = 0;
@@ -211,5 +212,14 @@ public class Model {
 		SCALE = scale;
 		SCALE_DIV2 = SCALE/2;
 	}
+	
+	/**
+	 * Returns ITERATIONS
+	 * 
+	 * @return ITERATIONS
+	 */
+	public int getIterations(){
+		return ITERATIONS;
+	}
 
 }

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

@@ -672,7 +672,7 @@ public class GUI implements CategoryListener {
 		timeSlider.setToolTipText("");
 
 		timeSlider.setMinimum(1);
-		timeSlider.setMaximum(50);
+		timeSlider.setMaximum(model.getIterations());
 		timeSlider.setValue(1);
 
 		playBtn.setBorder(BorderFactory.createEmptyBorder());

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

@@ -30,7 +30,6 @@ import classes.CpsObject;
 import classes.HolonElement;
 import classes.HolonObject;
 import classes.HolonSwitch;
-import javafx.util.Pair;
 import ui.controller.Control;
 import ui.model.*;
 
@@ -431,7 +430,6 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			}
 			
 			// distance from a point to a line and between both Objects
-			System.out.println("" + x + " " + y + " , " + hx + " " + lx + " " + hy + " " + ly);
 			if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 14 && x > lx && x < hx && y > ly
 					&& y < hy) {
 				return p;

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

@@ -11,43 +11,35 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.awt.geom.CubicCurve2D;
-import java.awt.geom.QuadCurve2D;
-import java.util.ArrayList;
 import java.awt.Point;
 
-import javax.swing.ImageIcon;
-import javax.swing.JButton;
-import javax.swing.JLabel;
 import javax.swing.JPanel;
 
-import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
-
-import classes.CpsObject;
 import ui.controller.Control;
 import ui.model.Model;
 
 class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
 
-	private final int NUMBER = 50;
 	private static final long serialVersionUID = 1L;
 	private Control controller;
 	private Model model;
 	private Graphics2D g2;
 	private CubicCurve2D c = new CubicCurve2D.Double();
-	Point[] pointList = new Point[NUMBER];
-
+	private Point[] pointList;
+	
 	private boolean pointDrag = false;
 	private int tempP;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
-	private double ratio = this.getHeight();
 
 	public UnitGraph(final Model model, Control control) {
-
 		this.controller = control;
 		this.model = model;
+		
+		this.pointList = new Point[model.getIterations()];
 		for (int i = 0; i < pointList.length; i++) {
 			pointList[i] = new Point(0, 0);
 		}
+		
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
@@ -104,7 +96,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			if(tempP!=0){
 				pointList[tempP-1].setLocation(pointList[tempP-1].getX(), pointList[tempP-1].getY()+(pointList[tempP].getY()-e.getY())/2);
 			}
-			if(tempP!=NUMBER-1){
+			if(tempP!=model.getIterations()-1){
 				pointList[tempP+1].setLocation(pointList[tempP+1].getX(), pointList[tempP+1].getY()+(pointList[tempP].getY()-e.getY())/2);
 			}
 		} else if(tempP != -1){
@@ -136,8 +128,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	@Override
 	public void mousePressed(MouseEvent e) {
 		for (int i = 0; i < pointList.length; i++) {
-			if (e.getX() - this.getWidth() / NUMBER / 2 <= pointList[i].getX()
-					&& e.getX() + this.getWidth() / NUMBER / 2 >= pointList[i].getX()
+			if (e.getX() - this.getWidth() / model.getIterations()/ 2 <= pointList[i].getX()
+					&& e.getX() + this.getWidth() / model.getIterations() / 2 >= pointList[i].getX()
 					&& e.getY() - 10 < pointList[i].getY() && e.getY() + 10 > pointList[i].getY()) {
 				tempP = i;
 				pointDrag = true;
@@ -157,10 +149,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	public void componentResized(ComponentEvent e) {
 		if(pointList[0].getY() != 0)
 		for (int i = 0; i < pointList.length; i++) {
-			pointList[i] = new Point((i) * this.getWidth() / (NUMBER - 1), (int) pointList[i].getY());
+			pointList[i] = new Point((i) * this.getWidth() / (model.getIterations() - 1), (int) pointList[i].getY());
 		} else {
 			for (int i = 0; i < pointList.length; i++) {
-				pointList[i] = new Point((i) * this.getWidth() / (NUMBER - 1), this.getHeight() / 3);
+				pointList[i] = new Point((i) * this.getWidth() / (model.getIterations() - 1), this.getHeight() / 3);
 			}
 		}
 		repaint();