|
@@ -27,7 +27,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
private int ITERATIONS = 50;
|
|
|
- private int MAXIMUM = 1;
|
|
|
+ private float MAXIMUM = 0;
|
|
|
|
|
|
private Point recSize = new Point(8, 8); // Point Size
|
|
|
private Graphics2D g2;
|
|
@@ -72,23 +72,21 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
*/
|
|
|
public void paintComponent(Graphics g) {
|
|
|
super.paintComponent(g);
|
|
|
-
|
|
|
- if (arrayOfValue != null) {
|
|
|
- for (int i = 0; i < arrayOfValue.length; i++) {
|
|
|
- System.out.println(""+arrayOfValue[i]);
|
|
|
- arrayOfValue[i] = getYValueAt((int) (i * width / (ITERATIONS - 1)));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
g2 = (Graphics2D) g;
|
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2.setRenderingHints(rh);
|
|
|
g2.setStroke(new BasicStroke(1));
|
|
|
-
|
|
|
+
|
|
|
+ if (arrayOfValue != null) {
|
|
|
+ for (int i = 0; i < arrayOfValue.length; i++) {
|
|
|
+ arrayOfValue[i] = convertToValueY(getYValueAt((int) (i * width / (ITERATIONS - 1))));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*
|
|
|
// Draw the Vertical Lines
|
|
|
g2.setColor(new Color(240, 240, 240));
|
|
|
for (int i = 0; i < ITERATIONS; i++) {
|
|
|
- g2.drawLine((i) * this.getWidth() / (ITERATIONS - 1), MAXIMUM, (i) * this.getWidth() / (ITERATIONS - 1),
|
|
|
+ g2.drawLine((i) * this.getWidth() / (ITERATIONS - 1), 0, (i) * this.getWidth() / (ITERATIONS - 1),
|
|
|
this.getHeight());
|
|
|
}
|
|
|
|
|
@@ -96,7 +94,7 @@ 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++) {
|
|
@@ -111,9 +109,21 @@ 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), MAXIMUM,
|
|
|
+ g2.drawLine((model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), 0,
|
|
|
(model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), this.getHeight());
|
|
|
|
|
|
+ //Actual Iteration Point Visualization
|
|
|
+ /*
|
|
|
+ g2.setColor(Color.RED);
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -124,8 +134,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
x = e.getX() / scaleX;
|
|
|
y = e.getY() / scaleY;
|
|
|
// y
|
|
|
- if (e.getY() <= MAXIMUM) {
|
|
|
- y = MAXIMUM / scaleY;
|
|
|
+ if (e.getY() <= 0) {
|
|
|
+ y = 0 / scaleY;
|
|
|
} else if (this.getHeight() <= e.getY()) {
|
|
|
y = this.getHeight() / scaleY;
|
|
|
}
|
|
@@ -186,8 +196,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
&& e.getX() != this.getWidth() / scaleX) {
|
|
|
for (int i = 0; i < pointList.size(); i++) {
|
|
|
if (x < pointList.get(i).getX() && !added) {
|
|
|
- if (e.getY() <= MAXIMUM) {
|
|
|
- pointList.add(i, new Point((int) (x), (int) (MAXIMUM / scaleY)));
|
|
|
+ if (e.getY() <= 0) {
|
|
|
+ pointList.add(i, new Point((int) (x), (int) (0 / scaleY)));
|
|
|
} else {
|
|
|
pointList.add(i, new Point((int) (x), (int) y));
|
|
|
}
|
|
@@ -215,7 +225,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
if (init) {
|
|
|
- MAXIMUM = (int) convertToCanvasY(MAXIMUM);
|
|
|
+ MAXIMUM = tempElement.getEnergy();
|
|
|
init = false;
|
|
|
// for scale
|
|
|
if (width == -1 && height == -1) {
|
|
@@ -227,8 +237,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
scaleY = this.getHeight() / height;
|
|
|
|
|
|
if (pointList.isEmpty()) {
|
|
|
- pointList.addFirst(new Point(0, MAXIMUM));
|
|
|
- pointList.addLast(new Point((int) (this.getWidth() / scaleX), MAXIMUM));
|
|
|
+ pointList.addFirst(new Point(0, 0));
|
|
|
+ pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
}
|
|
|
}
|
|
|
scaleX = this.getWidth() / width;
|
|
@@ -254,8 +264,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
*/
|
|
|
public void reset() {
|
|
|
pointList.removeAll(pointList);
|
|
|
- pointList.addFirst(new Point(0, (int) (MAXIMUM / scaleY)));
|
|
|
- pointList.addLast(new Point((int) (this.getWidth() / scaleX), (int) (MAXIMUM / scaleY)));
|
|
|
+ pointList.addFirst(new Point(0,0));
|
|
|
+ pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
@@ -264,18 +274,26 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
*
|
|
|
* @param double
|
|
|
* d, the number to convert
|
|
|
- * @return the convertet number
|
|
|
+ * @return the converted number
|
|
|
*/
|
|
|
- public double convertToCanvasY(int d) {
|
|
|
- if ((this.getHeight() - (((((double) this.getHeight() * 3) / 4) / MAXIMUM) * d)) <= 0) {
|
|
|
- return 1;
|
|
|
- } else {
|
|
|
- return (this.getHeight() - (((((double) this.getHeight())) / MAXIMUM) * d));
|
|
|
- }
|
|
|
+ public double convertToCanvasY(float d) {
|
|
|
+ System.out.println(""+(height + (d*(height/MAXIMUM))));
|
|
|
+ return (height -(d*(height/MAXIMUM)));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * converts the number to fit the value
|
|
|
+ *
|
|
|
+ * @param double
|
|
|
+ * d, the number to convert
|
|
|
+ * @return the converted number
|
|
|
+ */
|
|
|
+ public float convertToValueY(double d){
|
|
|
+ return (float)((height - ( height * (d/height)))/(height/MAXIMUM));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Viusalise the HolonElement on the Graph
|
|
|
+ * Visualize the HolonElement on the Graph
|
|
|
*
|
|
|
* @param HolonElement
|
|
|
* ele, which should be visualized
|
|
@@ -326,12 +344,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
public int getYValueAt(int xVal) {
|
|
|
for (int i = 0; i < pointList.size() - 1; i++) {
|
|
|
// get the Points
|
|
|
- if (xVal > pointList.get(i + 1).getX()) {
|
|
|
- x = pointList.get(i + 1).getX();
|
|
|
- y = pointList.get(i).getX();
|
|
|
-
|
|
|
+ if (xVal < pointList.get(i + 1).getX()) {
|
|
|
// Curve erstellen
|
|
|
- c = buildCurve(pointList.get(i), pointList.get(i + 1));
|
|
|
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);
|
|
@@ -353,8 +367,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
return null;
|
|
|
} else {
|
|
|
double z = (sx * (qy - py) + sy * (px - qx)) / det;
|
|
|
- if (z == 0 || z == 1)
|
|
|
- return null; // intersection at end point!
|
|
|
+ if (z < 0 || z > 1)
|
|
|
+ return new Point(0,0); // intersection at end point!
|
|
|
return new Point((int) (px + z * rx), (int) (py + z * ry));
|
|
|
}
|
|
|
} // end intersection line-line
|