|
@@ -27,7 +27,6 @@ import java.awt.Cursor;
|
|
|
class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
- private int ITERATIONS = 50;
|
|
|
private float MAXIMUM = 0;
|
|
|
|
|
|
private Point recSize = new Point(8, 8);
|
|
@@ -45,7 +44,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
private HolonElement tempElement;
|
|
|
private Model model;
|
|
|
private Control controller;
|
|
|
- GeneralPath graphCurve = new GeneralPath();
|
|
|
+ GeneralPath graphCurve = new GeneralPath();
|
|
|
|
|
|
private boolean pointDrag = false;
|
|
|
private boolean init = false;
|
|
@@ -57,10 +56,9 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
|
|
this.controller = control;
|
|
|
this.model = model;
|
|
|
- this.ITERATIONS = model.getIterations();
|
|
|
-
|
|
|
+
|
|
|
this.pointList = new LinkedList<>();
|
|
|
-
|
|
|
+
|
|
|
this.addMouseListener(this);
|
|
|
this.addMouseMotionListener(this);
|
|
|
this.addComponentListener(this);
|
|
@@ -78,27 +76,27 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
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))));
|
|
|
+ arrayOfValue[i] = convertToValueY(getYValueAt((int) (i * width / (model.getIterations() - 1))));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
g2.setColor(new Color(240, 240, 240));
|
|
|
- for (int i = 0; i < ITERATIONS; i++) {
|
|
|
- g2.drawLine((i) * this.getWidth() / (ITERATIONS - 1), 0, (i) * this.getWidth() / (ITERATIONS - 1),
|
|
|
- this.getHeight());
|
|
|
+ for (int i = 0; i < model.getIterations(); i++) {
|
|
|
+ g2.drawLine((i) * this.getWidth() / (model.getIterations() - 1), 0,
|
|
|
+ (i) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
|
|
|
}
|
|
|
|
|
|
- for (int i = 0; i < ITERATIONS; i++) {
|
|
|
- g2.drawLine(0, (i) * this.getHeight() / (ITERATIONS - 1), this.getWidth(),
|
|
|
- (i) * this.getHeight() / (ITERATIONS - 1));
|
|
|
+ for (int i = 0; i < model.getIterations(); i++) {
|
|
|
+ g2.drawLine(0, (i) * this.getHeight() / (model.getIterations() - 1), this.getWidth(),
|
|
|
+ (i) * this.getHeight() / (model.getIterations() - 1));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
g2.setColor(Color.BLACK);
|
|
|
for (int i = 0; i < pointList.size() - 1; i++) {
|
|
@@ -106,7 +104,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
graphCurve.append(c, true);
|
|
|
}
|
|
|
g2.draw(graphCurve);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
g2.setColor(Color.BLUE);
|
|
|
for (int i = 0; i < pointList.size() - 0; i++) {
|
|
@@ -114,21 +112,30 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
|
|
|
(int) recSize.getY());
|
|
|
}
|
|
|
- g2.drawLine((model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), 0,
|
|
|
- (model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), this.getHeight());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- g2.setColor(Color.RED);
|
|
|
+
|
|
|
+ g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
|
|
|
+ (model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
|
|
|
+
|
|
|
if (arrayOfValue != null) {
|
|
|
- for (int i = 0; i < arrayOfValue.length; i++) {
|
|
|
- g2.fillOval((int) (i * width / (ITERATIONS - 1) * scaleX - recSize.getX() / 2),
|
|
|
- (int) (convertToCanvasY((int) arrayOfValue[i]) * scaleY - recSize.getY() / 2), (int) recSize.getX(),
|
|
|
- (int) recSize.getY());
|
|
|
+ if (model.getCurIteration() > model.getIterations() / 2) {
|
|
|
+ g2.drawString("" + arrayOfValue[model.getCurIteration()],
|
|
|
+ (model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) - 30,
|
|
|
+ this.getHeight() / 2);
|
|
|
+ } else {
|
|
|
+ g2.drawString("" + arrayOfValue[model.getCurIteration()],
|
|
|
+ (model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
|
|
|
+ this.getHeight() / 2);
|
|
|
}
|
|
|
}
|
|
|
- */
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ * g2.setColor(Color.RED); if (arrayOfValue != null) { for (int i = 0; i
|
|
|
+ * < arrayOfValue.length; i++) { g2.fillOval((int) (i * width /
|
|
|
+ * (model.getIterations() - 1) * scaleX - recSize.getX() / 2), (int)
|
|
|
+ * (convertToCanvasY((int) arrayOfValue[i]) * scaleY - recSize.getY() /
|
|
|
+ * 2), (int) recSize.getX(), (int) recSize.getY()); } }
|
|
|
+ */
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -269,7 +276,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
*/
|
|
|
public void reset() {
|
|
|
pointList.removeAll(pointList);
|
|
|
- pointList.addFirst(new Point(0,0));
|
|
|
+ pointList.addFirst(new Point(0, 0));
|
|
|
pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
repaint();
|
|
|
}
|
|
@@ -282,10 +289,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* @return the converted number
|
|
|
*/
|
|
|
public double convertToCanvasY(float d) {
|
|
|
- System.out.println(""+(height + (d*(height/MAXIMUM))));
|
|
|
- return (height -(d*(height/MAXIMUM)));
|
|
|
+ System.out.println("" + (height + (d * (height / MAXIMUM))));
|
|
|
+ return (height - (d * (height / MAXIMUM)));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
* converts the number to fit the value
|
|
|
*
|
|
@@ -293,8 +300,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* d, the number to convert
|
|
|
* @return the converted number
|
|
|
*/
|
|
|
- public float convertToValueY(double d){
|
|
|
- return (float)((height - ( height * (d/height)))/(height/MAXIMUM));
|
|
|
+ public float convertToValueY(double d) {
|
|
|
+ return Math.round(((float) ((height - (height * (d / height))) / (height / MAXIMUM)) * 10)) / 10;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -354,7 +361,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
Line2D l1 = new Line2D.Double(pointList.get(i).getX(), pointList.get(i).getY(),
|
|
|
pointList.get(i + 1).getX(), pointList.get(i + 1).getY());
|
|
|
Line2D l2 = new Line2D.Double(xVal, 0, xVal, height);
|
|
|
-
|
|
|
+
|
|
|
return (int) getIntersectionPoint(l1, l2).getY();
|
|
|
}
|
|
|
}
|
|
@@ -373,7 +380,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
} else {
|
|
|
double z = (sx * (qy - py) + sy * (px - qx)) / det;
|
|
|
if (z < 0 || z > 1)
|
|
|
- return new Point(0,0);
|
|
|
+ return new Point(0, 0);
|
|
|
return new Point((int) (px + z * rx), (int) (py + z * ry));
|
|
|
}
|
|
|
}
|