|
@@ -2,6 +2,7 @@ package ui.view;
|
|
|
|
|
|
import classes.*;
|
|
import classes.*;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
|
|
+import ui.controller.SingletonControl;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
@@ -23,6 +24,7 @@ import java.util.LinkedList;
|
|
public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
|
|
public class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
+ public static final int STANDARD_GRAPH_ACCURACY = 100;
|
|
private GeneralPath graphCurve = new GeneralPath();
|
|
private GeneralPath graphCurve = new GeneralPath();
|
|
private float maximum = 0;
|
|
private float maximum = 0;
|
|
// Information shown when a Point is Dragged
|
|
// Information shown when a Point is Dragged
|
|
@@ -37,8 +39,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
// Scale for the Graph
|
|
// Scale for the Graph
|
|
private double scaleX;
|
|
private double scaleX;
|
|
private double scaleY;
|
|
private double scaleY;
|
|
- private float[] arrayOfFloats = null;
|
|
|
|
- private boolean[] arrayOfBooleans = null;
|
|
|
|
|
|
+ //private float[] arrayOfFloats = null;
|
|
|
|
+ //private boolean[] arrayOfBooleans = null;
|
|
private double width = -1;
|
|
private double width = -1;
|
|
private double height = -1;
|
|
private double height = -1;
|
|
private boolean isElement = false;
|
|
private boolean isElement = false;
|
|
@@ -52,11 +54,10 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
private Point tempP = null;
|
|
private Point tempP = null;
|
|
private double x = 0, y = 0;
|
|
private double x = 0, y = 0;
|
|
private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
|
|
private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
|
|
-
|
|
|
|
private int border = 4;
|
|
private int border = 4;
|
|
private int textWidth = 0;
|
|
private int textWidth = 0;
|
|
|
|
|
|
- private int localPeriod = 100;
|
|
|
|
|
|
+ private IGraphedElement current;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Constructor.
|
|
* Constructor.
|
|
@@ -83,6 +84,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
* @param g Graphics
|
|
* @param g Graphics
|
|
*/
|
|
*/
|
|
public void paintComponent(Graphics g) {
|
|
public void paintComponent(Graphics g) {
|
|
|
|
+
|
|
super.paintComponent(g);
|
|
super.paintComponent(g);
|
|
g2 = (Graphics2D) g;
|
|
g2 = (Graphics2D) g;
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
@@ -104,11 +106,15 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
}
|
|
}
|
|
g2.drawLine(border, this.getHeight() - border, this.getWidth() - border, this.getHeight() - border);
|
|
g2.drawLine(border, this.getHeight() - border, this.getWidth() - border, this.getHeight() - border);
|
|
|
|
|
|
|
|
+ int effectiveX;
|
|
|
|
+ if(current!=null)effectiveX=getEffectiveIndex(model, current, model.getCurIteration());
|
|
|
|
+ else effectiveX=0;
|
|
|
|
+
|
|
if (isElement) {
|
|
if (isElement) {
|
|
// fill array with values from the pointList in a HolonElement
|
|
// fill array with values from the pointList in a HolonElement
|
|
fillArrayofValue();
|
|
fillArrayofValue();
|
|
|
|
|
|
- if (arrayOfFloats != null) {
|
|
|
|
|
|
+ if (current != null) {
|
|
// Draw the Lines
|
|
// Draw the Lines
|
|
g2.setStroke(new BasicStroke(2));
|
|
g2.setStroke(new BasicStroke(2));
|
|
g2.setColor(Color.BLACK);
|
|
g2.setColor(Color.BLACK);
|
|
@@ -131,17 +137,17 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
// Iteration Value
|
|
// Iteration Value
|
|
//TODO: added function getGraphIterations see if it works
|
|
//TODO: added function getGraphIterations see if it works
|
|
- textWidth = g.getFontMetrics().stringWidth("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()]) + 2;
|
|
|
|
|
|
+ textWidth = g.getFontMetrics().stringWidth("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration())/*arrayOfFloats[effectiveX]*/) + 2;
|
|
if (textWidth
|
|
if (textWidth
|
|
- + (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1) + 2
|
|
|
|
|
|
+ + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
|
|
+ border <= this.getWidth()) {
|
|
+ border <= this.getWidth()) {
|
|
- g2.drawString("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()],
|
|
|
|
- (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
|
|
|
|
|
|
+ g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
|
|
|
|
+ (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
|
|
+ 2 + border,
|
|
+ 2 + border,
|
|
this.getHeight() - 10);
|
|
this.getHeight() - 10);
|
|
} else {
|
|
} else {
|
|
- g2.drawString("" + arrayOfFloats[model.getCurIteration()%model.getGraphIterations()],
|
|
|
|
- (model.getCurIteration()%model.getGraphIterations()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
|
|
|
|
|
|
+ g2.drawString("" + ((HolonElement)current).getAvailableEnergyAt(model.getCurIteration()),
|
|
|
|
+ (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
|
|
+ border - textWidth,
|
|
+ border - textWidth,
|
|
this.getHeight() - 10);
|
|
this.getHeight() - 10);
|
|
}
|
|
}
|
|
@@ -171,7 +177,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
*/
|
|
*/
|
|
|
|
|
|
} else if (isSwitch) {
|
|
} else if (isSwitch) {
|
|
- if (arrayOfBooleans != null) {
|
|
|
|
|
|
+ if (/*arrayOfBooleans*/current != null) {//Technically this test should be unnecessary
|
|
// array fillen
|
|
// array fillen
|
|
fillArrayofBooleans();
|
|
fillArrayofBooleans();
|
|
|
|
|
|
@@ -215,17 +221,17 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
|
|
|
|
// Iteration Value
|
|
// Iteration Value
|
|
g2.setColor(Color.BLUE);
|
|
g2.setColor(Color.BLUE);
|
|
- textWidth = g.getFontMetrics().stringWidth("" + arrayOfBooleans[model.getCurIteration()]) + 2;
|
|
|
|
|
|
+ textWidth = g.getFontMetrics().stringWidth("" + ((HolonSwitch)current).getState(model.getCurIteration())/*arrayOfBooleans[effectiveX]*/) + 2;
|
|
if (textWidth
|
|
if (textWidth
|
|
- + (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1) + 2
|
|
|
|
|
|
+ + (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1) + 2
|
|
+ border <= this.getWidth()) {
|
|
+ border <= this.getWidth()) {
|
|
- g2.drawString("" + arrayOfBooleans[model.getCurIteration()],
|
|
|
|
- (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
|
|
|
|
|
|
+ g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
|
|
|
|
+ (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
|
|
+ 2 + border,
|
|
+ 2 + border,
|
|
this.getHeight() - 10);
|
|
this.getHeight() - 10);
|
|
} else {
|
|
} else {
|
|
- g2.drawString("" + arrayOfBooleans[model.getCurIteration()],
|
|
|
|
- (model.getCurIteration()) * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
|
|
|
|
|
|
+ g2.drawString("" + ((HolonSwitch)current).getState(model.getCurIteration()),
|
|
|
|
+ (effectiveX) * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
|
|
+ border - textWidth,
|
|
+ border - textWidth,
|
|
this.getHeight() - 10);
|
|
this.getHeight() - 10);
|
|
}
|
|
}
|
|
@@ -237,7 +243,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
{
|
|
{
|
|
try {
|
|
try {
|
|
int i;
|
|
int i;
|
|
- for (i = 0; (i * (this.getWidth() - (border * 2)) / (model.getIterations() - 1)
|
|
|
|
|
|
+ for (i = 0; (i * (this.getWidth() - (border * 2)) / (/*model.getIterations()*/100 - 1)
|
|
+ border < getMousePosition().getX()); i++) {
|
|
+ border < getMousePosition().getX()); i++) {
|
|
}
|
|
}
|
|
dragInformation = "" + i;
|
|
dragInformation = "" + i;
|
|
@@ -255,11 +261,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // Iteration Line
|
|
|
|
|
|
+ // Iteration Line TODO: repeat
|
|
g2.setColor(Color.BLUE);
|
|
g2.setColor(Color.BLUE);
|
|
g2.setStroke(new BasicStroke(1));
|
|
g2.setStroke(new BasicStroke(1));
|
|
- g2.drawLine(border + (model.getCurIteration()) * (this.getWidth() - border * 2) / (model.getIterations() - 1),
|
|
|
|
- 0, border + (model.getCurIteration()) * (this.getWidth() - border * 2) / (model.getIterations() - 1),
|
|
|
|
|
|
+ g2.drawLine(border + (effectiveX) * (this.getWidth() - border * 2) / /*(model.getIterations() - 1)*/100-1,
|
|
|
|
+ 0, border + (effectiveX) * (this.getWidth() - border * 2) / /*(model.getIterations() - 1)*/100-1,
|
|
this.getHeight());
|
|
this.getHeight());
|
|
|
|
|
|
// algorithmus
|
|
// algorithmus
|
|
@@ -553,8 +559,7 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
public void empty() {
|
|
public void empty() {
|
|
pointList = null;
|
|
pointList = null;
|
|
tempElements = null;
|
|
tempElements = null;
|
|
- arrayOfFloats = null;
|
|
|
|
- arrayOfBooleans = null;
|
|
|
|
|
|
+ current = null;
|
|
isSwitch = false;
|
|
isSwitch = false;
|
|
isElement = false;
|
|
isElement = false;
|
|
repaint();
|
|
repaint();
|
|
@@ -601,8 +606,9 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
* @param selectedElement which should be visualized
|
|
* @param selectedElement which should be visualized
|
|
*/
|
|
*/
|
|
public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
|
|
public void repaintWithNewElement(ArrayList<HolonElement> selectedElement) {
|
|
- arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getAvailableEnergyPerElementAt();
|
|
|
|
- tempElements = selectedElement;
|
|
|
|
|
|
+ //arrayOfFloats = selectedElement.get(selectedElement.size() - 1).getAvailableEnergyPerElementAt();
|
|
|
|
+ current = selectedElement.get(selectedElement.size()-1);
|
|
|
|
+ tempElements=selectedElement;
|
|
pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
|
|
pointList = selectedElement.get(selectedElement.size() - 1).getGraphPoints();
|
|
isSwitch = false;
|
|
isSwitch = false;
|
|
isElement = true;
|
|
isElement = true;
|
|
@@ -621,7 +627,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
* @param s which should be visualized
|
|
* @param s which should be visualized
|
|
*/
|
|
*/
|
|
public void repaintWithNewSwitch(HolonSwitch s) {
|
|
public void repaintWithNewSwitch(HolonSwitch s) {
|
|
- arrayOfBooleans = s.getActiveAt();
|
|
|
|
|
|
+ current=s;
|
|
|
|
+ //arrayOfBooleans = s.getValueArray();
|
|
pointList = s.getGraphPoints();
|
|
pointList = s.getGraphPoints();
|
|
isSwitch = true;
|
|
isSwitch = true;
|
|
isElement = false;
|
|
isElement = false;
|
|
@@ -667,14 +674,13 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
* Fills the Arrays with booleans.
|
|
* Fills the Arrays with booleans.
|
|
*/
|
|
*/
|
|
public void fillArrayofBooleans() {
|
|
public void fillArrayofBooleans() {
|
|
- for (int i = 0; i < arrayOfBooleans.length; i++) {
|
|
|
|
- int t = (int) getYValueAt((int) (i * width / (model.getIterations() - 1)));
|
|
|
|
|
|
+ for (int i = 0; i < STANDARD_GRAPH_ACCURACY; i++) {
|
|
|
|
+ int t = (int) getYValueAt((int) (i * width / (STANDARD_GRAPH_ACCURACY - 1)));
|
|
if (t <= height / 2) {
|
|
if (t <= height / 2) {
|
|
- arrayOfBooleans[i] = true;
|
|
|
|
|
|
+ ((HolonSwitch)current).setActiveAt(i, true);
|
|
} else {
|
|
} else {
|
|
- arrayOfBooleans[i] = false;
|
|
|
|
|
|
+ ((HolonSwitch)current).setActiveAt(i, false);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -686,10 +692,11 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
for (HolonElement he : tempElements) {
|
|
for (HolonElement he : tempElements) {
|
|
maximum = getMaximum(he);
|
|
maximum = getMaximum(he);
|
|
he.setGraphPoints((LinkedList<Point>) pointList.clone());
|
|
he.setGraphPoints((LinkedList<Point>) pointList.clone());
|
|
- for (int i = 0; i < arrayOfFloats.length; i++) {
|
|
|
|
- he.getAvailableEnergyPerElementAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (model.getIterations() - 1))));
|
|
|
|
|
|
+ for (int i = 0; i < STANDARD_GRAPH_ACCURACY; i++) {//!!!!!
|
|
|
|
+ he.setAvailableEnergyPerElementAt(i, convertToValueY(getYValueAt2((int) (i * width / (100 - 1)))));
|
|
|
|
+ //he.getAvailableEnergyPerElementAt()[i] = convertToValueY(getYValueAt2((int) (i * width / (100 - 1))));
|
|
}
|
|
}
|
|
- arrayOfFloats = he.getAvailableEnergyPerElementAt();
|
|
|
|
|
|
+ //arrayOfFloats = he.getAvailableEnergyPerElementAt();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -843,7 +850,8 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
*/
|
|
*/
|
|
public void setLocalPeriod(int localPeriod){
|
|
public void setLocalPeriod(int localPeriod){
|
|
//TODO: local Graph length for each HolonElelemt
|
|
//TODO: local Graph length for each HolonElelemt
|
|
- this.localPeriod = localPeriod;
|
|
|
|
|
|
+ this.current.setLocalPeriod(localPeriod);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -851,6 +859,25 @@ public class UnitGraph extends JPanel implements MouseListener, MouseMotionListe
|
|
* @return localPeriod of the current Element or Switch
|
|
* @return localPeriod of the current Element or Switch
|
|
*/
|
|
*/
|
|
public int getLocalPeriod(){
|
|
public int getLocalPeriod(){
|
|
- return localPeriod;
|
|
|
|
|
|
+ if(current!=null)return current.getLocalPeriod();
|
|
|
|
+ else return model.getGraphIterations();//TODO: maybe rename
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ static int lv=0;
|
|
|
|
+
|
|
|
|
+ public static int getEffectiveIndex(Model m, IGraphedElement e, int timeStep){
|
|
|
|
+ int o;
|
|
|
|
+ if(e.isStretching())o= timeStep*100/m.getIterations();
|
|
|
|
+ else o= timeStep%e.getLocalPeriod()*100/e.getLocalPeriod();
|
|
|
|
+ return o;//TODO
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int getEffectiveIndex(IGraphedElement e, int timeStep){
|
|
|
|
+ return getEffectiveIndex(SingletonControl.getInstance().getControl().getModel(),e,timeStep);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static int getEffectiveIndex(IGraphedElement e){
|
|
|
|
+ return getEffectiveIndex(e,SingletonControl.getInstance().getControl().getModel().getCurIteration());
|
|
}
|
|
}
|
|
}
|
|
}
|