|
@@ -34,6 +34,7 @@ import classes.AbstractCpsObject;
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
import classes.HolonSwitch;
|
|
import classes.HolonSwitch;
|
|
|
|
+import classes.Position;
|
|
import classes.SubNet;
|
|
import classes.SubNet;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
@@ -84,6 +85,12 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
private Point mousePosition = new Point(); // Mouse Position when
|
|
private Point mousePosition = new Point(); // Mouse Position when
|
|
// rightclicked
|
|
// rightclicked
|
|
|
|
|
|
|
|
+ javax.swing.Timer animT; // animation Timer
|
|
|
|
+ int animFPS = 30;
|
|
|
|
+ int animDuration = 500; // animation Duration
|
|
|
|
+ int animDelay = animDuration/animFPS; // animation Delay
|
|
|
|
+ int animSteps = animDuration / animDelay; // animation Steps;
|
|
|
|
+
|
|
// contains the value of the Capacity for new created Edges
|
|
// contains the value of the Capacity for new created Edges
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -127,8 +134,56 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
itemGroup.addActionListener(new ActionListener() {
|
|
itemGroup.addActionListener(new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
- controller.addUpperNode("NodeOfNode", null);
|
|
|
|
- repaint();
|
|
|
|
|
|
+ // calculate uppernode pos (taken from the controller)
|
|
|
|
+ Position unPos = new Position(0, 0);
|
|
|
|
+
|
|
|
|
+ for (AbstractCpsObject abs : model.getSelectedCpsObjects()) {
|
|
|
|
+ unPos.x += abs.getPosition().x;
|
|
|
|
+ unPos.y += abs.getPosition().y;
|
|
|
|
+ }
|
|
|
|
+ unPos.x /= model.getSelectedCpsObjects().size();
|
|
|
|
+ unPos.y /= model.getSelectedCpsObjects().size();
|
|
|
|
+ unPos.x +=model.getScaleDiv2();
|
|
|
|
+ unPos.y +=model.getScaleDiv2();
|
|
|
|
+
|
|
|
|
+ // save old Position
|
|
|
|
+ ArrayList<Position> savePos = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < model.getSelectedCpsObjects().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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 = savePos.get(i).x;
|
|
|
|
+ double y1 = savePos.get(i).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;
|
|
|
|
+ }
|
|
|
|
+ repaint();
|
|
|
|
+ animDuration -= animDelay;
|
|
|
|
+ controller.addTextToConsole("" + animDuration);
|
|
|
|
+ } else {
|
|
|
|
+ animDuration = 500;
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ controller.addUpperNode("NodeOfNode", null);
|
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
|
+ repaint();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ animT.start();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|