|
@@ -26,10 +26,16 @@ import classes.HolonSwitch;
|
|
|
|
|
|
import java.awt.Cursor;
|
|
|
|
|
|
+
|
|
|
+ * This Class represents a Graph where the User can model the behavior of
|
|
|
+ * elements and switches over time.
|
|
|
+ *
|
|
|
+ * @author Gruppe14
|
|
|
+ */
|
|
|
public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
- private float MAXIMUM = 0;
|
|
|
+ private float maximum = 0;
|
|
|
|
|
|
|
|
|
private String dragInformation = "";
|
|
@@ -66,6 +72,14 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
private double x = 0, y = 0;
|
|
|
private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
|
|
|
|
|
|
+
|
|
|
+ * Constructor.
|
|
|
+ *
|
|
|
+ * @param model
|
|
|
+ * the Model
|
|
|
+ * @param control
|
|
|
+ * the Controller
|
|
|
+ */
|
|
|
public UnitGraph(final Model model, Control control) {
|
|
|
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
|
|
this.controller = control;
|
|
@@ -80,9 +94,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Paints all Components on the Canvas
|
|
|
+ * Paints all Components on the Canvas.
|
|
|
*
|
|
|
- * @param Graphics
|
|
|
+ * @param g
|
|
|
+ * Graphics
|
|
|
*
|
|
|
*/
|
|
|
public void paintComponent(Graphics g) {
|
|
@@ -213,9 +228,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Wenn ein Punkt bei einem HolonElement gedragged wird
|
|
|
+ * When a Point of a Holon Element is dragged.
|
|
|
*
|
|
|
* @param e
|
|
|
+ * MouseEvent
|
|
|
*/
|
|
|
public void elementDragged(MouseEvent e) {
|
|
|
if (pointDrag && tempP != null) {
|
|
@@ -241,9 +257,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Wenn ein Punkt bei einem CpsSwitch gedragged wird
|
|
|
+ * When a Point of a switch is dragged.
|
|
|
*
|
|
|
* @param e
|
|
|
+ * MouseEvent
|
|
|
*/
|
|
|
public void switchDragged(MouseEvent e) {
|
|
|
if (pointDrag && tempP != null && tempP != pointList.getFirst() && tempP != pointList.getLast()) {
|
|
@@ -295,9 +312,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Wenn ein Punkt von einem Element gedrueckt wird
|
|
|
+ * When a point of a Holon Element is pressed.
|
|
|
*
|
|
|
* @param e
|
|
|
+ * MouseEvent
|
|
|
*/
|
|
|
public void elementPressed(MouseEvent e) {
|
|
|
boolean added = false;
|
|
@@ -349,9 +367,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Wenn ein Punkt von einem Switch gedr�ck wird
|
|
|
+ * When a point of a Switch is pressed.
|
|
|
*
|
|
|
* @param e
|
|
|
+ * MouseEvent
|
|
|
*/
|
|
|
public void switchPressed(MouseEvent e) {
|
|
|
boolean added = false;
|
|
@@ -431,10 +450,19 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
pointDrag = false;
|
|
|
tempP = null;
|
|
|
}
|
|
|
+
|
|
|
+ * reset the dragInformation.
|
|
|
+ */
|
|
|
dragInformation = "";
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * When the Component is Resized.
|
|
|
+ *
|
|
|
+ * @param e
|
|
|
+ * ComponentEvent
|
|
|
+ */
|
|
|
public void componentResized(ComponentEvent e) {
|
|
|
|
|
|
if (init) {
|
|
@@ -468,8 +496,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
public void componentShown(ComponentEvent e) {
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Empty the Graph
|
|
|
+
|
|
|
+ * Empty the Graph.
|
|
|
*/
|
|
|
public void empty() {
|
|
|
pointList = null;
|
|
@@ -481,8 +509,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Resets the Points for the Element
|
|
|
+
|
|
|
+ * Resets the Points for the Element.
|
|
|
*/
|
|
|
public void reset() {
|
|
|
pointList.removeAll(pointList);
|
|
@@ -492,32 +520,32 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * converts the number to fit the canvas
|
|
|
+ * converts the number to fit the canvas.
|
|
|
*
|
|
|
- * @param double
|
|
|
- * d, the number to convert
|
|
|
+ * @param d
|
|
|
+ * the number to convert
|
|
|
* @return the converted number
|
|
|
*/
|
|
|
public double convertToCanvasY(float d) {
|
|
|
- return (height - (d * (height / MAXIMUM)));
|
|
|
+ return (height - (d * (height / maximum)));
|
|
|
}
|
|
|
|
|
|
|
|
|
- * converts the number to fit the value
|
|
|
+ * converts the number to fit the value.
|
|
|
*
|
|
|
- * @param double
|
|
|
- * d, the number to convert
|
|
|
+ * @param d
|
|
|
+ * the number to convert
|
|
|
* @return the converted number
|
|
|
*/
|
|
|
public float convertToValueY(double d) {
|
|
|
- return (float) Math.round(((height - (height * (d / height))) / (height / MAXIMUM)) * 10) / 10;
|
|
|
+ return (float) Math.round(((height - (height * (d / height))) / (height / maximum)) * 10) / 10;
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Visualize the HolonElement on the Graph
|
|
|
+ * Visualize the HolonElement on the Graph.
|
|
|
*
|
|
|
- * @param HolonElement
|
|
|
- * ele, which should be visualized
|
|
|
+ * @param selectedElement
|
|
|
+ * which should be visualized
|
|
|
*/
|
|
|
public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
|
|
|
arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getEnergyAt();
|
|
@@ -525,7 +553,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
|
|
|
isSwitch = false;
|
|
|
isElement = true;
|
|
|
- MAXIMUM = selectedElement.get(selectedElement.size() - 1).getEnergy();
|
|
|
+ maximum = selectedElement.get(selectedElement.size() - 1).getEnergy();
|
|
|
|
|
|
if (pointList.isEmpty()) {
|
|
|
pointList.addFirst(new Point(0, 0));
|
|
@@ -535,10 +563,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Visualize the HolonElement on the Graph
|
|
|
+ * Visualize the Switch on the Graph.
|
|
|
*
|
|
|
- * @param HolonElement
|
|
|
- * ele, which should be visualized
|
|
|
+ * @param s
|
|
|
+ * which should be visualized
|
|
|
*/
|
|
|
public void repaintWithNewSwitch(HolonSwitch s) {
|
|
|
arrayOfBooleans = s.getActiveAt();
|
|
@@ -554,12 +582,14 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Build a Curve for the Graph
|
|
|
+ * Build a Curve for the Graph.
|
|
|
*
|
|
|
- * @param Point,Point
|
|
|
- * ,startpoint p1 and endpoint p2
|
|
|
+ * @param p1
|
|
|
+ * startpoint
|
|
|
+ * @param p2
|
|
|
+ * endpoint
|
|
|
*
|
|
|
- * @return CubicCurve2D, c, the CubicCurve2D for the Graph
|
|
|
+ * @return the CubicCurve2D for the Graph
|
|
|
*/
|
|
|
public CubicCurve2D buildCurve(Point p1, Point p2) {
|
|
|
x1 = (int) p1.getX();
|
|
@@ -585,11 +615,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Fills the Arrays with booleans
|
|
|
+ * Fills the Arrays with booleans.
|
|
|
*/
|
|
|
public void fillArrayofBooleans() {
|
|
|
for (int i = 0; i < arrayOfBooleans.length; i++) {
|
|
|
- int t = (int) getYValueAt_2((int) (i * width / (model.getIterations() - 1)));
|
|
|
+ int t = (int) getYValueAt2((int) (i * width / (model.getIterations() - 1)));
|
|
|
if (t == 0) {
|
|
|
arrayOfBooleans[i] = true;
|
|
|
} else {
|
|
@@ -600,23 +630,24 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
- * Fills the Arrays of each HolonElement
|
|
|
+ * Fills the Arrays of each HolonElement.
|
|
|
*/
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public void fillArrayofValue() {
|
|
|
for (HolonElement he : tempElements) {
|
|
|
- MAXIMUM = he.getEnergy();
|
|
|
+ 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))));
|
|
|
+ he.getEnergyAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (model.getIterations() - 1))));
|
|
|
}
|
|
|
arrayOfFloats = he.getEnergyAt();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+ * Get the Y Value at the x Coordination.
|
|
|
*
|
|
|
- * @param xVal,
|
|
|
+ * @param xVal
|
|
|
* the x value for the y value
|
|
|
* @return y, the value at x
|
|
|
*/
|
|
@@ -635,12 +666,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
+ * Get y value at the x Coordination via curves.
|
|
|
*
|
|
|
- * @param xVal,
|
|
|
+ * @param xVal
|
|
|
* the x value for the y value
|
|
|
- * @return y, the value at x
|
|
|
+ * @return y value at x
|
|
|
*/
|
|
|
- public float getYValueAt_2(int xVal) {
|
|
|
+ public float getYValueAt2(int xVal) {
|
|
|
for (int i = 0; i < pointList.size() - 1; i++) {
|
|
|
|
|
|
if (xVal >= pointList.get(i).getX()) {
|
|
@@ -687,10 +719,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
}
|
|
|
|
|
|
|
|
|
+ * Get the Intersection Point of 2 Lines.
|
|
|
*
|
|
|
- * @param l1,
|
|
|
+ * @param l1
|
|
|
* the first Line
|
|
|
- * @param l2,
|
|
|
+ * @param l2
|
|
|
* the second Line
|
|
|
*
|
|
|
* @return The Intersection Point
|