|
@@ -13,11 +13,14 @@ import java.awt.event.MouseMotionListener;
|
|
import java.awt.geom.CubicCurve2D;
|
|
import java.awt.geom.CubicCurve2D;
|
|
import java.awt.geom.GeneralPath;
|
|
import java.awt.geom.GeneralPath;
|
|
import java.awt.geom.Line2D;
|
|
import java.awt.geom.Line2D;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
import java.awt.Point;
|
|
import java.awt.Point;
|
|
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
+import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;
|
|
|
|
+
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
@@ -48,7 +51,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
private boolean isElement = false;
|
|
private boolean isElement = false;
|
|
private boolean isSwitch = false;
|
|
private boolean isSwitch = false;
|
|
|
|
|
|
- private HolonElement tempElement;
|
|
|
|
|
|
+ private ArrayList<HolonElement> tempElements = new ArrayList<>();
|
|
private HolonSwitch tempSwitch;
|
|
private HolonSwitch tempSwitch;
|
|
private Model model;
|
|
private Model model;
|
|
private Control controller;
|
|
private Control controller;
|
|
@@ -101,9 +104,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
if (isElement) {
|
|
if (isElement) {
|
|
if (arrayOfFloats != null) {
|
|
if (arrayOfFloats != null) {
|
|
- // array fillen
|
|
|
|
- fillArrayofValue();
|
|
|
|
-
|
|
|
|
// Draw the Lines
|
|
// Draw the Lines
|
|
g2.setStroke(new BasicStroke(2));
|
|
g2.setStroke(new BasicStroke(2));
|
|
g2.setColor(Color.BLACK);
|
|
g2.setColor(Color.BLACK);
|
|
@@ -338,7 +338,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
tempP = null;
|
|
tempP = null;
|
|
if (pointList != null) {
|
|
if (pointList != null) {
|
|
for (Point p : pointList) {
|
|
for (Point p : pointList) {
|
|
- if (x >= p.getX() - dist && x <= p.getX() + dist) {
|
|
|
|
|
|
+ if (x >= p.getX() - dist * 2 && x <= p.getX() + dist * 2) {
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
tempP = p;
|
|
tempP = p;
|
|
deletePoint = true;
|
|
deletePoint = true;
|
|
@@ -352,21 +352,21 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
|
|
if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
|
|
for (int i = 0; i < pointList.size() && !added; i++) {
|
|
for (int i = 0; i < pointList.size() && !added; i++) {
|
|
if (x < pointList.get(i).getX() - dist) {
|
|
if (x < pointList.get(i).getX() - dist) {
|
|
- // Punkt hinzufügen, je nachdem ob es oberhalb oder
|
|
|
|
- // unterhalb der hälfte ist
|
|
|
|
- if (y < height / 2 && (pointList.get(i - 1).getY() == height - 1
|
|
|
|
- && pointList.get(i).getY() == height - 1)) {
|
|
|
|
- pointList.add(i, new Point((int) (x + dist), (int) height - 1));
|
|
|
|
- pointList.add(i, new Point((int) (x + dist), 0));
|
|
|
|
- pointList.add(i, new Point((int) (x - dist), 0));
|
|
|
|
- pointList.add(i, new Point((int) (x - dist), (int) height - 1));
|
|
|
|
|
|
+ // double p1, p2 um location der points zu bestimmen
|
|
|
|
+ double p1 = pointList.get(i - 1).getX();
|
|
|
|
+ double p2 = pointList.get(i).getX();
|
|
|
|
+ // Punkte hinzufügen, je nachdem ob true oder false
|
|
|
|
+ if (pointList.get(i - 1).getY() != 0 && pointList.get(i).getY() != 0) {
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) height - 1));
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p2) / 2 + dist), 0));
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p1) / 2 - dist), 0));
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) height - 1));
|
|
added = true;
|
|
added = true;
|
|
- } else if (y >= height / 2 && (pointList.get(i - 1).getY() != height - 1
|
|
|
|
- && pointList.get(i).getY() != height - 1)) {
|
|
|
|
- pointList.add(i, new Point((int) (x + dist), 0));
|
|
|
|
- pointList.add(i, new Point((int) (x + dist), (int) height - 1));
|
|
|
|
- pointList.add(i, new Point((int) (x - dist), (int) height - 1));
|
|
|
|
- pointList.add(i, new Point((int) (x - dist), 0));
|
|
|
|
|
|
+ } else if (pointList.get(i - 1).getY() == 0 && pointList.get(i).getY() == 0) {
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p2) / 2 + dist), 0));
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p2) / 2 + dist), (int) height - 1));
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p1) / 2 - dist), (int) height - 1));
|
|
|
|
+ pointList.add(i, new Point((int) ((x + p1) / 2 - dist), 0));
|
|
added = true;
|
|
added = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -376,15 +376,20 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
// Delete a Point
|
|
// Delete a Point
|
|
if (deletePoint && tempP.getX() != 0
|
|
if (deletePoint && tempP.getX() != 0
|
|
&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
|
|
&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
|
|
- System.out.println("x: " + tempP.getY());
|
|
|
|
- // pointList.remove(tempP);
|
|
|
|
|
|
+ int i = pointList.indexOf(tempP);
|
|
|
|
+ if (tempP.getY() == 0) {
|
|
|
|
+ pointList.remove(i);
|
|
|
|
+ pointList.remove(i - 1);
|
|
|
|
+ pointList.remove(i - 2);
|
|
|
|
+ pointList.remove(i - 3);
|
|
|
|
+ }
|
|
|
|
+ if (tempP.getY() == height - 1) {
|
|
|
|
+ pointList.remove(i + 2);
|
|
|
|
+ pointList.remove(i + 1);
|
|
|
|
+ pointList.remove(i);
|
|
|
|
+ pointList.remove(i - 1);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- // Delete This for
|
|
|
|
- /*
|
|
|
|
- * for (int i = 0; i < pointList.size(); i++) {
|
|
|
|
- * System.out.println(pointList.get(i).getX() + ", " +
|
|
|
|
- * pointList.get(i).getY()); }
|
|
|
|
- */
|
|
|
|
|
|
|
|
repaint();
|
|
repaint();
|
|
}
|
|
}
|
|
@@ -397,6 +402,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
pointDrag = false;
|
|
pointDrag = false;
|
|
tempP = null;
|
|
tempP = null;
|
|
}
|
|
}
|
|
|
|
+ if (isElement) {
|
|
|
|
+ // array fillen
|
|
|
|
+ fillArrayofValue();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void componentResized(ComponentEvent e) {
|
|
public void componentResized(ComponentEvent e) {
|
|
@@ -437,7 +446,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
*/
|
|
*/
|
|
public void empty() {
|
|
public void empty() {
|
|
pointList = null;
|
|
pointList = null;
|
|
- tempElement = null;
|
|
|
|
|
|
+ tempElements = null;
|
|
tempSwitch = null;
|
|
tempSwitch = null;
|
|
arrayOfFloats = null;
|
|
arrayOfFloats = null;
|
|
arrayOfBooleans = null;
|
|
arrayOfBooleans = null;
|
|
@@ -484,13 +493,13 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
* @param HolonElement
|
|
* @param HolonElement
|
|
* ele, which should be visualized
|
|
* ele, which should be visualized
|
|
*/
|
|
*/
|
|
- public void repaintWithNewElement(HolonElement ele) {
|
|
|
|
- arrayOfFloats = ele.getEnergyAt();
|
|
|
|
- tempElement = ele;
|
|
|
|
- pointList = ele.getGraphPoints();
|
|
|
|
|
|
+ public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
|
|
|
|
+ arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getEnergyAt();
|
|
|
|
+ tempElements = selectedElement;
|
|
|
|
+ pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
|
|
isSwitch = false;
|
|
isSwitch = false;
|
|
isElement = true;
|
|
isElement = true;
|
|
- MAXIMUM = tempElement.getEnergy();
|
|
|
|
|
|
+ MAXIMUM = selectedElement.get(selectedElement.size() - 1).getEnergy();
|
|
// First time clicked on the Element
|
|
// First time clicked on the Element
|
|
if (pointList.isEmpty()) {
|
|
if (pointList.isEmpty()) {
|
|
pointList.addFirst(new Point(0, 0));
|
|
pointList.addFirst(new Point(0, 0));
|
|
@@ -568,9 +577,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
/**
|
|
/**
|
|
* Fills the Arrays of each HolonElement
|
|
* Fills the Arrays of each HolonElement
|
|
*/
|
|
*/
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
public void fillArrayofValue() {
|
|
public void fillArrayofValue() {
|
|
- for (int i = 0; i < arrayOfFloats.length; i++) {
|
|
|
|
- arrayOfFloats[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
|
|
|
|
|
|
+ for (HolonElement he : tempElements) {
|
|
|
|
+ MAXIMUM = he.getEnergy();
|
|
|
|
+ he.setGraphPoints((LinkedList<Point>) pointList.clone());
|
|
|
|
+ for (int i = 0; i < arrayOfFloats.length; i++) {
|
|
|
|
+ he.getEnergyAt()[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
|
|
|
|
+ }
|
|
|
|
+ arrayOfFloats = he.getEnergyAt();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|