|
@@ -99,6 +99,19 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
|
|
|
private UpdateController updCon;
|
|
private UpdateController updCon;
|
|
|
|
|
|
|
|
+ javax.swing.Timer animT; // animation Timer
|
|
|
|
+ private final int ANIMTIME = 500; // animation Time
|
|
|
|
+
|
|
|
|
+ private ArrayList<AbstractCpsObject> animCps = null;
|
|
|
|
+ private int animFPS = 60;
|
|
|
|
+ private int animDuration = ANIMTIME; // animation Duration
|
|
|
|
+ private int animDelay = 1000 / animFPS; // animation Delay
|
|
|
|
+ private int animSteps = animDuration / animDelay; // animation Steps;
|
|
|
|
+ private long start = 0; // for time
|
|
|
|
+ private long elapsedTime = 0; // outprint
|
|
|
|
+ private Position unPos;
|
|
|
|
+ private ArrayList<Position> savePos;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Constructor.
|
|
* Constructor.
|
|
*
|
|
*
|
|
@@ -108,7 +121,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
* the Controller
|
|
* the Controller
|
|
*/
|
|
*/
|
|
public UpperNodeCanvas(Model mod, Control control, CpsUpperNode UpperNode, String parentPath) {
|
|
public UpperNodeCanvas(Model mod, Control control, CpsUpperNode UpperNode, String parentPath) {
|
|
- this.add(objectTT);
|
|
|
|
|
|
+ //this.add(objectTT);
|
|
this.controller = control;
|
|
this.controller = control;
|
|
this.model = mod;
|
|
this.model = mod;
|
|
this.upperNode = UpperNode;
|
|
this.upperNode = UpperNode;
|
|
@@ -147,20 +160,125 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
itemTrack.setEnabled(false);
|
|
itemTrack.setEnabled(false);
|
|
itemUntrack.setEnabled(false);
|
|
itemUntrack.setEnabled(false);
|
|
updCon = new UpdateController(model, controller);
|
|
updCon = new UpdateController(model, controller);
|
|
-
|
|
|
|
|
|
+
|
|
itemGroup.addActionListener(new ActionListener() {
|
|
itemGroup.addActionListener(new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
- controller.addUpperNode("NodeOfNode", upperNode, model.getSelectedCpsObjects());
|
|
|
|
- repaint();
|
|
|
|
|
|
+ // calculate uppernode pos (taken from the controller)
|
|
|
|
+ unPos = new Position(0, 0);
|
|
|
|
+ animCps = new ArrayList<>();
|
|
|
|
+ for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
|
|
|
|
+ animCps.add(cps); // add to animation Cps ArrayList
|
|
|
|
+ unPos.x += cps.getPosition().x;
|
|
|
|
+ unPos.y += cps.getPosition().y;
|
|
|
|
+ }
|
|
|
|
+ unPos.x /= animCps.size();
|
|
|
|
+ unPos.y /= animCps.size();
|
|
|
|
+
|
|
|
|
+ // save old Position
|
|
|
|
+ savePos = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
|
+ savePos.add(new Position(0, 0));
|
|
|
|
+ savePos.get(i).x = animCps.get(i).getPosition().x;
|
|
|
|
+ savePos.get(i).y = animCps.get(i).getPosition().y;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ animT = new javax.swing.Timer(animDelay, new ActionListener() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ if (animDuration - animDelay > 0 && animCps.size() > 1) {
|
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
|
+ double x1 = animCps.get(i).getPosition().x - unPos.x;
|
|
|
|
+ double y1 = animCps.get(i).getPosition().y - unPos.y;
|
|
|
|
+ animCps.get(i).getPosition().x -= x1 / animSteps;
|
|
|
|
+ animCps.get(i).getPosition().y -= y1 / animSteps;
|
|
|
|
+ }
|
|
|
|
+ repaint();
|
|
|
|
+ animDuration -= animDelay;
|
|
|
|
+ animSteps--;
|
|
|
|
+ } else {
|
|
|
|
+ animDuration = ANIMTIME;
|
|
|
|
+ animSteps = animDuration / animDelay;
|
|
|
|
+ animT.stop();
|
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
|
+ animCps.get(i).getPosition().x = savePos.get(i).x;
|
|
|
|
+ animCps.get(i).getPosition().y = savePos.get(i).y;
|
|
|
|
+ }
|
|
|
|
+ controller.addUpperNode("NodeOfNode", upperNode, model.getSelectedCpsObjects());
|
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
|
+ repaint();
|
|
|
|
+ elapsedTime = System.currentTimeMillis() - start;
|
|
|
|
+ controller.addTextToConsole(elapsedTime + "");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ start = System.currentTimeMillis();
|
|
|
|
+ animT.start();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
itemUngroup.addActionListener(new ActionListener() {
|
|
itemUngroup.addActionListener(new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
+ // save old Position
|
|
|
|
+ JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
|
|
|
|
+ for (int i = 3; i < tabbedPane.getTabCount(); i++) {
|
|
|
|
+ if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
|
|
|
|
+ .getComponent(0)).upperNode.getID() == ((CpsUpperNode) tempCps).getID()) {
|
|
|
|
+ tabbedPane.remove(i);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ savePos = new ArrayList<>();
|
|
|
|
+ animCps = ((CpsUpperNode) tempCps).getNodes();
|
|
controller.delUpperNode((CpsUpperNode) tempCps, upperNode);
|
|
controller.delUpperNode((CpsUpperNode) tempCps, upperNode);
|
|
- repaint();
|
|
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
|
+ savePos.add(new Position(0, 0));
|
|
|
|
+ savePos.get(i).x = animCps.get(i).getPosition().x;
|
|
|
|
+ savePos.get(i).y = animCps.get(i).getPosition().y;
|
|
|
|
+ }
|
|
|
|
+ for (AbstractCpsObject cps : animCps) {
|
|
|
|
+ int x = ((CpsUpperNode) tempCps).getPosition().x;
|
|
|
|
+ int y = ((CpsUpperNode) tempCps).getPosition().y;
|
|
|
|
+
|
|
|
|
+ cps.setPosition(new Position(x, y));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ animT = new javax.swing.Timer(animDelay, new ActionListener() {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ if (animDuration - animDelay >= 0) {
|
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
|
+ double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
|
|
|
|
+ double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
|
|
|
|
+ animCps.get(i).getPosition().x -= x1 / animSteps;
|
|
|
|
+ animCps.get(i).getPosition().y -= y1 / animSteps;
|
|
|
|
+ }
|
|
|
|
+ repaint();
|
|
|
|
+ animDuration -= animDelay;
|
|
|
|
+ animSteps--;
|
|
|
|
+ } else {
|
|
|
|
+ animDuration = ANIMTIME;
|
|
|
|
+ animSteps = animDuration / animDelay;
|
|
|
|
+ animT.stop();
|
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
|
+ animCps.get(i).getPosition().x = savePos.get(i).x;
|
|
|
|
+ animCps.get(i).getPosition().y = savePos.get(i).y;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
|
+ repaint();
|
|
|
|
+ elapsedTime = System.currentTimeMillis() - start;
|
|
|
|
+ controller.addTextToConsole(elapsedTime + "");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ start = System.currentTimeMillis();
|
|
|
|
+ animT.start();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
@@ -172,10 +290,10 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
boolean found = false;
|
|
boolean found = false;
|
|
if (controller.getTrackingObj() != null) {
|
|
if (controller.getTrackingObj() != null) {
|
|
for (AbstractCpsObject obj : controller.getTrackingObj()) {
|
|
for (AbstractCpsObject obj : controller.getTrackingObj()) {
|
|
- if(obj instanceof HolonObject){
|
|
|
|
|
|
+ if (obj instanceof HolonObject) {
|
|
if (obj.getID() == o.getID()) {
|
|
if (obj.getID() == o.getID()) {
|
|
found = true;
|
|
found = true;
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -201,7 +319,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
boolean found = false;
|
|
boolean found = false;
|
|
if (controller.getTrackingObj() != null) {
|
|
if (controller.getTrackingObj() != null) {
|
|
for (AbstractCpsObject obj : controller.getTrackingObj()) {
|
|
for (AbstractCpsObject obj : controller.getTrackingObj()) {
|
|
- if(obj instanceof HolonObject){
|
|
|
|
|
|
+ if (obj instanceof HolonObject) {
|
|
if (obj.getID() == o.getID()) {
|
|
if (obj.getID() == o.getID()) {
|
|
found = true;
|
|
found = true;
|
|
}
|
|
}
|
|
@@ -229,6 +347,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
|
|
for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
|
|
if (upperNode.getNodes().contains(cps)) {
|
|
if (upperNode.getNodes().contains(cps)) {
|
|
controller.delObjUpperNode(cps, upperNode);
|
|
controller.delObjUpperNode(cps, upperNode);
|
|
|
|
+ // Removes the object from the tracked objects, in case it was tracked
|
|
|
|
+ controller.removeTrackingObj(cps);
|
|
// Remove UpperNodeTab if UpperNode deleted
|
|
// Remove UpperNodeTab if UpperNode deleted
|
|
if (cps instanceof CpsUpperNode) {
|
|
if (cps instanceof CpsUpperNode) {
|
|
JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
|
|
JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
|
|
@@ -342,13 +462,18 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
for (CpsEdge con : upperNode.getNodeEdges()) {
|
|
for (CpsEdge con : upperNode.getNodeEdges()) {
|
|
if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
|
|
if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
|
|
&& con != edgeHighlight) {
|
|
&& con != edgeHighlight) {
|
|
- if (con.getState()) {
|
|
|
|
- g2.setColor(Color.GREEN);
|
|
|
|
- if (con.getCapacity() != -1) {
|
|
|
|
- g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));
|
|
|
|
|
|
+ if(con.getConnected()){
|
|
|
|
+ if (con.getState()) {
|
|
|
|
+ g2.setColor(Color.GREEN);
|
|
|
|
+ if (con.getCapacity() != -1) {
|
|
|
|
+ g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 4), 4)));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ g2.setColor(Color.RED);
|
|
|
|
+ g2.setStroke(new BasicStroke(2));
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- g2.setColor(Color.RED);
|
|
|
|
|
|
+ }else{
|
|
|
|
+ g2.setColor(Color.DARK_GRAY);
|
|
g2.setStroke(new BasicStroke(2));
|
|
g2.setStroke(new BasicStroke(2));
|
|
}
|
|
}
|
|
g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
|
|
g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
|
|
@@ -362,9 +487,15 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
maxCap = String.valueOf(con.getCapacity());
|
|
maxCap = String.valueOf(con.getCapacity());
|
|
}
|
|
}
|
|
if (showedInformation[0]) {
|
|
if (showedInformation[0]) {
|
|
- g2.drawString(con.getFlow() + "/" + maxCap,
|
|
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
|
|
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
|
|
|
|
|
|
+ if(con.getConnected()){
|
|
|
|
+ g2.drawString(con.getFlow() + "/" + maxCap,
|
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
|
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
|
|
|
|
+ }else{
|
|
|
|
+ g2.drawString("not connected",
|
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
|
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -394,11 +525,19 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
maxCap = String.valueOf(con.getCapacity());
|
|
maxCap = String.valueOf(con.getCapacity());
|
|
}
|
|
}
|
|
if (showedInformation[0]) {
|
|
if (showedInformation[0]) {
|
|
- g2.drawString(con.getFlow() + "/" + maxCap,
|
|
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
|
|
|
|
+ if(con.getConnected()){
|
|
|
|
+ g2.drawString(con.getFlow() + "/" + maxCap,
|
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
+ controller.getScaleDiv2(),
|
|
+ controller.getScaleDiv2(),
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
|
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
+ controller.getScaleDiv2());
|
|
+ controller.getScaleDiv2());
|
|
|
|
+ }else{
|
|
|
|
+ g2.drawString("not connected",
|
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
|
|
+ + controller.getScaleDiv2(),
|
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
|
|
+ + controller.getScaleDiv2());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -431,11 +570,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
// Objects in upper node
|
|
// Objects in upper node
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
// Border Highlighting
|
|
// Border Highlighting
|
|
- g2.setColor(cps.getBorderColor());
|
|
|
|
- if (g2.getColor() != Color.WHITE) {
|
|
|
|
- g2.fillRect((int) (cps.getPosition().x - scalediv20 - 3), (int) (cps.getPosition().y - scalediv20 - 3),
|
|
|
|
- (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
|
|
- (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
|
|
|
|
+ if(showedInformation[3]){
|
|
|
|
+ g2.setColor(cps.getBorderColor());
|
|
|
|
+ if (g2.getColor() != Color.WHITE) {
|
|
|
|
+ g2.fillRect((int) (cps.getPosition().x - scalediv20 - 3), (int) (cps.getPosition().y - scalediv20 - 3),
|
|
|
|
+ (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
|
|
+ (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// node image
|
|
// node image
|
|
@@ -516,12 +657,15 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
}
|
|
}
|
|
|
|
|
|
// Border Highlighting
|
|
// Border Highlighting
|
|
- g2.setColor(cps.getBorderColor());
|
|
|
|
- if (g2.getColor() != Color.WHITE) {
|
|
|
|
- g2.fillRect((int) ((borderPos >> 1) - model.getScaleDiv2() - scalediv20) - 3,
|
|
|
|
- (int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count - scalediv20) - 3,
|
|
|
|
- (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
|
|
- (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
|
|
|
|
+ if(showedInformation[3]){
|
|
|
|
+ System.out.println("here");
|
|
|
|
+ g2.setColor(cps.getBorderColor());
|
|
|
|
+ if (g2.getColor() != Color.WHITE) {
|
|
|
|
+ g2.fillRect((int) ((borderPos >> 1) - model.getScaleDiv2() - scalediv20) - 3,
|
|
|
|
+ (int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count - scalediv20) - 3,
|
|
|
|
+ (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
|
|
+ (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// node image
|
|
// node image
|
|
@@ -1222,6 +1366,14 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
showedInformation[0] = connection;
|
|
showedInformation[0] = connection;
|
|
showedInformation[1] = object;
|
|
showedInformation[1] = object;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * copies a set of given informations
|
|
|
|
+ * @param informations
|
|
|
|
+ */
|
|
|
|
+ public void setShowedInformation(boolean[] informations){
|
|
|
|
+ showedInformation = informations;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Returns if Information should be shown.
|
|
* Returns if Information should be shown.
|