|
@@ -21,6 +21,7 @@ import javax.swing.JPanel;
|
|
|
import classes.HolonElement;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
+import classes.HolonSwitch;
|
|
|
|
|
|
import java.awt.Cursor;
|
|
|
|
|
@@ -38,21 +39,23 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
private double scaleX;
|
|
|
private double scaleY;
|
|
|
|
|
|
- private float[] arrayOfValue = null;
|
|
|
+ private float[] arrayOfFloats = null;
|
|
|
+ private boolean[] arrayOfBooleans = null;
|
|
|
|
|
|
private double width = -1;
|
|
|
private double height = -1;
|
|
|
|
|
|
- private boolean isElement = true;
|
|
|
- private boolean isSwitch = true;
|
|
|
+ private boolean isElement = false;
|
|
|
+ private boolean isSwitch = false;
|
|
|
|
|
|
private HolonElement tempElement;
|
|
|
+ private HolonSwitch tempSwitch;
|
|
|
private Model model;
|
|
|
private Control controller;
|
|
|
GeneralPath graphCurve = new GeneralPath();
|
|
|
|
|
|
private boolean pointDrag = false;
|
|
|
- private boolean init = false;
|
|
|
+ private boolean init = true;
|
|
|
private Point tempP = null;
|
|
|
private double x = 0, y = 0;
|
|
|
private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
|
|
@@ -85,19 +88,18 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
graphCurve.reset();
|
|
|
|
|
|
- if (isElement) {
|
|
|
-
|
|
|
- // Draw the Vertical Lines
|
|
|
- g2.setColor(Color.BLACK);
|
|
|
- for (int i = 0; i <= this.getWidth(); i += 10) {
|
|
|
- g2.drawLine(i, 0, i, this.getHeight());
|
|
|
- }
|
|
|
+ // Draw the Vertical Lines
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
+ for (int i = 0; i <= this.getWidth(); i += 10) {
|
|
|
+ g2.drawLine(i, 0, i, this.getHeight());
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i <= this.getHeight(); i += 5) {
|
|
|
- g2.drawLine(0, i, this.getWidth(), i);
|
|
|
- }
|
|
|
+ for (int i = 0; i <= this.getHeight(); i += 5) {
|
|
|
+ g2.drawLine(0, i, this.getWidth(), i);
|
|
|
+ }
|
|
|
|
|
|
- if (arrayOfValue != null) {
|
|
|
+ if (isElement) {
|
|
|
+ if (arrayOfFloats != null) {
|
|
|
// array fillen
|
|
|
fillArrayofValue();
|
|
|
|
|
@@ -124,8 +126,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
|
|
|
(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
|
|
|
// Iteration Value
|
|
|
- if (arrayOfValue != null) {
|
|
|
- g2.drawString("" + arrayOfValue[model.getCurIteration()],
|
|
|
+ if (arrayOfFloats != null) {
|
|
|
+ g2.drawString("" + arrayOfFloats[model.getCurIteration()],
|
|
|
(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
|
|
|
this.getHeight() - 10);
|
|
|
}
|
|
@@ -273,7 +275,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* @param e
|
|
|
*/
|
|
|
public void switchPressed(MouseEvent e) {
|
|
|
- //TODO Siwtch pressed zeugs hier hin
|
|
|
+ // TODO Siwtch pressed zeugs hier hin
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -287,7 +289,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
// Wenn ein anderes Element genommen wird
|
|
|
if (init) {
|
|
|
- MAXIMUM = tempElement.getEnergy();
|
|
|
init = false;
|
|
|
// for scale on the first initialisation
|
|
|
if (width == -1 && height == -1) {
|
|
@@ -297,12 +298,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
|
|
|
scaleX = this.getWidth() / width;
|
|
|
scaleY = this.getHeight() / height;
|
|
|
-
|
|
|
- // First time clicked on the Element
|
|
|
- if (pointList.isEmpty()) {
|
|
|
- pointList.addFirst(new Point(0, 0));
|
|
|
- pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
// Scale
|
|
@@ -330,7 +325,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
public void empty() {
|
|
|
pointList = null;
|
|
|
tempElement = null;
|
|
|
- arrayOfValue = null;
|
|
|
+ tempSwitch = null;
|
|
|
+ arrayOfFloats = null;
|
|
|
+ arrayOfBooleans = null;
|
|
|
+ isSwitch = false;
|
|
|
+ isElement = false;
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
@@ -373,11 +372,37 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* ele, which should be visualized
|
|
|
*/
|
|
|
public void repaintWithNewElement(HolonElement ele) {
|
|
|
- arrayOfValue = ele.getEnergyAt();
|
|
|
+ arrayOfFloats = ele.getEnergyAt();
|
|
|
tempElement = ele;
|
|
|
pointList = ele.getGraphPoints();
|
|
|
- init = true;
|
|
|
- componentResized(null);
|
|
|
+ isSwitch = false;
|
|
|
+ isElement = true;
|
|
|
+ MAXIMUM = tempElement.getEnergy();
|
|
|
+ // First time clicked on the Element
|
|
|
+ if (pointList.isEmpty()) {
|
|
|
+ pointList.addFirst(new Point(0, 0));
|
|
|
+ pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
+ }
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Visualize the HolonElement on the Graph
|
|
|
+ *
|
|
|
+ * @param HolonElement
|
|
|
+ * ele, which should be visualized
|
|
|
+ */
|
|
|
+ public void repaintWithNewSwitch(HolonSwitch s) {
|
|
|
+ arrayOfBooleans = s.getActiveAt();
|
|
|
+ tempSwitch = s;
|
|
|
+ pointList = s.getGraphPoints();
|
|
|
+ isSwitch = true;
|
|
|
+ isElement = false;
|
|
|
+ // First time clicked on the Element
|
|
|
+ if (pointList.isEmpty()) {
|
|
|
+ pointList.addFirst(new Point(0, 0));
|
|
|
+ pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
|
|
|
+ }
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
@@ -416,8 +441,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
|
|
|
* Fills the Arrays of each HolonElement
|
|
|
*/
|
|
|
public void fillArrayofValue() {
|
|
|
- for (int i = 0; i < arrayOfValue.length; i++) {
|
|
|
- arrayOfValue[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
|
|
|
+ for (int i = 0; i < arrayOfFloats.length; i++) {
|
|
|
+ arrayOfFloats[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
|
|
|
}
|
|
|
}
|
|
|
|