|
@@ -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();
|