|
@@ -99,6 +99,19 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
|
|
|
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.
|
|
|
*
|
|
@@ -151,16 +164,121 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
itemGroup.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
|
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() {
|
|
|
@Override
|
|
|
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);
|
|
|
- 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;
|
|
|
if (controller.getTrackingObj() != null) {
|
|
|
for (AbstractCpsObject obj : controller.getTrackingObj()) {
|
|
|
- if(obj instanceof HolonObject){
|
|
|
+ if (obj instanceof HolonObject) {
|
|
|
if (obj.getID() == o.getID()) {
|
|
|
found = true;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -201,7 +319,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
boolean found = false;
|
|
|
if (controller.getTrackingObj() != null) {
|
|
|
for (AbstractCpsObject obj : controller.getTrackingObj()) {
|
|
|
- if(obj instanceof HolonObject){
|
|
|
+ if (obj instanceof HolonObject) {
|
|
|
if (obj.getID() == o.getID()) {
|
|
|
found = true;
|
|
|
}
|
|
@@ -229,6 +347,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
|
|
|
if (upperNode.getNodes().contains(cps)) {
|
|
|
controller.delObjUpperNode(cps, upperNode);
|
|
|
+ // Removes the object from the tracked objects, in case it was tracked
|
|
|
+ controller.removeTrackingObj(cps);
|
|
|
// Remove UpperNodeTab if UpperNode deleted
|
|
|
if (cps instanceof CpsUpperNode) {
|
|
|
JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
|
|
@@ -431,11 +551,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
// Objects in upper node
|
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
|
// 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
|
|
@@ -516,12 +638,14 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
}
|
|
|
|
|
|
// 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]){
|
|
|
+ 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
|
|
@@ -1222,6 +1346,14 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
showedInformation[0] = connection;
|
|
|
showedInformation[1] = object;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * copies a set of given informations
|
|
|
+ * @param informations
|
|
|
+ */
|
|
|
+ public void setShowedInformation(boolean[] informations){
|
|
|
+ showedInformation = informations;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Returns if Information should be shown.
|