|
@@ -111,6 +111,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
this.add(objectTT);
|
|
|
this.controller = control;
|
|
|
this.model = mod;
|
|
|
+ System.setProperty("sun.java2d.opengl","True");
|
|
|
|
|
|
scalediv20 = model.getScale() / 20;
|
|
|
|
|
@@ -142,34 +143,35 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
// calculate uppernode pos (taken from the controller)
|
|
|
unPos = new Position(0, 0);
|
|
|
-
|
|
|
- for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
|
|
|
- unPos.x += abs.getPosition().x;
|
|
|
- unPos.y += abs.getPosition().y;
|
|
|
+ animCps = new ArrayList<>();
|
|
|
+ for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
|
|
|
+ animCps.add(cps); //add to animation Cps
|
|
|
+ unPos.x += cps.getPosition().x;
|
|
|
+ unPos.y += cps.getPosition().y;
|
|
|
}
|
|
|
- unPos.x /= model.getSelectedCpsObjects().size();
|
|
|
- unPos.y /= model.getSelectedCpsObjects().size();
|
|
|
+ unPos.x /= animCps.size();
|
|
|
+ unPos.y /= animCps.size();
|
|
|
|
|
|
// save old Position
|
|
|
savePos = new ArrayList<>();
|
|
|
- for (int i = 0; i < model.getSelectedCpsObjects().size(); i++) {
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
savePos.add(new Position(0, 0));
|
|
|
- savePos.get(i).x = model.getSelectedCpsObjects().get(i).getPosition().x;
|
|
|
- savePos.get(i).y = model.getSelectedCpsObjects().get(i).getPosition().y;
|
|
|
+ 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 && model.getSelectedCpsObjects().size() > 1) {
|
|
|
- for (int i = 0; i < model.getSelectedCpsObjects().size(); i++) {
|
|
|
- double x1 = model.getSelectedCpsObjects().get(i).getPosition().x;
|
|
|
- double y1 = model.getSelectedCpsObjects().get(i).getPosition().y;
|
|
|
+ if (animDuration - animDelay >= 0 && animCps.size() > 1) {
|
|
|
+ for (int i = 0; i < animCps.size(); i++) {
|
|
|
+ double x1 = animCps.get(i).getPosition().x;
|
|
|
+ double y1 = animCps.get(i).getPosition().y;
|
|
|
x1 = x1 - unPos.x;
|
|
|
y1 = y1 - unPos.y;
|
|
|
- model.getSelectedCpsObjects().get(i).getPosition().x -= x1 / animSteps;
|
|
|
- model.getSelectedCpsObjects().get(i).getPosition().y -= y1 / animSteps;
|
|
|
+ animCps.get(i).getPosition().x -= x1 / animSteps;
|
|
|
+ animCps.get(i).getPosition().y -= y1 / animSteps;
|
|
|
}
|
|
|
repaint();
|
|
|
animDuration -= animDelay;
|
|
@@ -178,11 +180,11 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
animDuration = 500;
|
|
|
animSteps = animDuration / animDelay;
|
|
|
animT.stop();
|
|
|
- for (int i = 0; i < model.getSelectedCpsObjects().size(); i++) {
|
|
|
- model.getSelectedCpsObjects().get(i).getPosition().x = savePos.get(i).x;
|
|
|
- model.getSelectedCpsObjects().get(i).getPosition().y = savePos.get(i).y;
|
|
|
+ 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", null);
|
|
|
+ controller.addUpperNode("NodeOfNode", null, animCps);
|
|
|
controller.calculateStateForCurrentTimeStep();
|
|
|
repaint();
|
|
|
elapsedTime = System.currentTimeMillis() - start;
|