|
@@ -53,6 +53,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
private int sx, sy; // Mark Coords
|
|
|
|
|
|
ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
|
|
|
+ ArrayList<CpsObject> TempSelected = new ArrayList<CpsObject>();
|
|
|
|
|
|
private boolean dragging = false; // for dragging
|
|
|
private boolean drawEdge = false; // for drawing edges
|
|
@@ -182,8 +183,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
((HolonSwitch) cps).setState(false);
|
|
|
}
|
|
|
}
|
|
|
- if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0)
|
|
|
- || model.getSelectedCpsObjects().contains(cps)) {
|
|
|
+ if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && TempSelected.size() == 0)
|
|
|
+ || model.getSelectedCpsObjects().contains(cps) || TempSelected.contains(cps)) {
|
|
|
g2.setColor(Color.BLUE);
|
|
|
g2.fillRect(cps.getPosition().x - (controller.getScale() / 20),
|
|
|
cps.getPosition().y - (controller.getScale() / 20),
|
|
@@ -233,15 +234,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
g2.drawRect(sx, y, x - sx, sy - y);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- * // Testing for (CpsObject cps : markSelect) {
|
|
|
- * g2.setColor(Color.BLUE); g2.fillRect(cps.getPosition().x -
|
|
|
- * (controller.getScale() / 20), cps.getPosition().y -
|
|
|
- * (controller.getScale() / 20), controller.getScale() +
|
|
|
- * ((controller.getScale() / 20) * 2), controller.getScale() +
|
|
|
- * ((controller.getScale() / 20) * 2)); }
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -249,6 +241,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
// clear SelectedObjects
|
|
|
if (!e.isControlDown() && dragging == false) {
|
|
|
model.getSelectedCpsObjects().clear();
|
|
|
+ TempSelected.clear();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -325,9 +318,19 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
popmenu.show(e.getComponent(), e.getX(), e.getY());
|
|
|
}
|
|
|
|
|
|
- doMark = false;
|
|
|
+ if (doMark) {
|
|
|
+ doMark = false;
|
|
|
+ for (CpsObject cps : TempSelected) {
|
|
|
+ if (!model.getSelectedCpsObjects().contains(cps)) {
|
|
|
+ controller.addSelectedObject(cps);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
controller.calculateStateForTimeStep(model.getCurIteration());
|
|
|
+
|
|
|
repaint();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -335,56 +338,57 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
// If Edge is drawn
|
|
|
x = e.getX();
|
|
|
y = e.getY();
|
|
|
+ if (!model.getSelectedCpsObjects().contains(tempCps)) {
|
|
|
+ model.getSelectedCpsObjects().clear();
|
|
|
+ TempSelected.clear();
|
|
|
+ }
|
|
|
+
|
|
|
if (dragging) {
|
|
|
try {
|
|
|
- if (model.getSelectedCpsObjects().size() > 0) {
|
|
|
- for (CpsObject cps : model.getSelectedCpsObjects()) {
|
|
|
- // Au�erhalb des Randes gedragged?
|
|
|
- if (cps == tempCps) {
|
|
|
- x = e.getX() - controller.getScaleDiv2();
|
|
|
- y = e.getY() - controller.getScaleDiv2();
|
|
|
- } else {
|
|
|
- x = e.getX() + (cps.getPosition().x - e.getX()) ;
|
|
|
- y = e.getY() + (cps.getPosition().y - e.getY()) ;
|
|
|
- }
|
|
|
-
|
|
|
- if (x < controller.getScaleDiv2())
|
|
|
+ float xDist, yDist; //Distance
|
|
|
+
|
|
|
+ x = e.getX() - controller.getScaleDiv2();
|
|
|
+ y = e.getY() - controller.getScaleDiv2();
|
|
|
+
|
|
|
+ //Make sure its in bounds
|
|
|
+ if (e.getX() < controller.getScaleDiv2())
|
|
|
+ x = 0;
|
|
|
+ else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
+ x = this.getWidth() - controller.getScale();
|
|
|
+ if (e.getY() < controller.getScaleDiv2())
|
|
|
+ y = 0;
|
|
|
+ else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
+ y = this.getHeight() - controller.getScale();
|
|
|
+
|
|
|
+ //Distance
|
|
|
+ xDist = x-tempCps.getPosition().x;
|
|
|
+ yDist = y-tempCps.getPosition().y;
|
|
|
+
|
|
|
+ tempCps.setPosition(x, y); // Drag Position
|
|
|
+ selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20)); // Highlighting-Position
|
|
|
+
|
|
|
+ // TipText Position and name
|
|
|
+ objectTT.setTipText(tempCps.getName());
|
|
|
+ objectTT.setLocation(x, y + controller.getScale());
|
|
|
+
|
|
|
+ //All Selected Objects
|
|
|
+ for (CpsObject cps : model.getSelectedCpsObjects()) {
|
|
|
+ if (cps != tempCps) {
|
|
|
+ x = (int) (cps.getPosition().x+xDist);
|
|
|
+ y = (int) (cps.getPosition().y+yDist);
|
|
|
+
|
|
|
+ //Make sure its in bounds
|
|
|
+ if (x < 0)
|
|
|
x = 0;
|
|
|
- else if (x > this.getWidth() - controller.getScaleDiv2())
|
|
|
+ else if (x > this.getWidth())
|
|
|
x = this.getWidth() - controller.getScale();
|
|
|
if (y < controller.getScaleDiv2())
|
|
|
y = 0;
|
|
|
- else if (y > this.getHeight() - controller.getScaleDiv2())
|
|
|
+ else if (y > this.getHeight())
|
|
|
y = this.getHeight() - controller.getScale();
|
|
|
-
|
|
|
- System.out.println(x + ", " + y);
|
|
|
- // Drag Position
|
|
|
+
|
|
|
cps.setPosition(x, y);
|
|
|
- // TipText Position and name
|
|
|
- objectTT.setTipText(tempCps.getName());
|
|
|
- objectTT.setLocation(e.getX() - controller.getScaleDiv2(),
|
|
|
- e.getY() - controller.getScaleDiv2() + controller.getScale());
|
|
|
}
|
|
|
- } else {
|
|
|
- // Au�erhalb des Randes gedragged?
|
|
|
- x = e.getX() - controller.getScaleDiv2();
|
|
|
- y = e.getY() - controller.getScaleDiv2();
|
|
|
-
|
|
|
- if (e.getX() < controller.getScaleDiv2())
|
|
|
- x = 0;
|
|
|
- else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
- x = this.getWidth() - controller.getScale();
|
|
|
- if (e.getY() < controller.getScaleDiv2())
|
|
|
- y = 0;
|
|
|
- else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
- y = this.getHeight() - controller.getScale();
|
|
|
- // Drag Position
|
|
|
- tempCps.setPosition(x, y);
|
|
|
- // Highlighting Position
|
|
|
- selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20));
|
|
|
- // TipText Position and name
|
|
|
- objectTT.setTipText(tempCps.getName());
|
|
|
- objectTT.setLocation(x, y + controller.getScale());
|
|
|
}
|
|
|
repaint();
|
|
|
} catch (Exception e2) {
|
|
@@ -393,24 +397,25 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
}
|
|
|
|
|
|
// Mark Objects
|
|
|
- if (doMark) {
|
|
|
+ TempSelected.clear();
|
|
|
+ if (doMark)
|
|
|
+
|
|
|
+ {
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
- if (!model.getSelectedCpsObjects().contains(cps)) {
|
|
|
+ int x1 = sx, x2 = x, y1 = sy, y2 = y;
|
|
|
|
|
|
- int x1 = sx, x2 = x, y1 = sy, y2 = y;
|
|
|
+ if (sx >= x) {
|
|
|
+ x1 = x;
|
|
|
+ x2 = sx;
|
|
|
+ }
|
|
|
+ if (sy >= y) {
|
|
|
+ y1 = y;
|
|
|
+ y2 = sy;
|
|
|
+ }
|
|
|
+ if (x1 <= cps.getPosition().x && y1 <= cps.getPosition().y && x2 >= cps.getPosition().x
|
|
|
+ && y2 >= cps.getPosition().y) {
|
|
|
+ TempSelected.add(cps);
|
|
|
|
|
|
- if (sx >= x) {
|
|
|
- x1 = x;
|
|
|
- x2 = sx;
|
|
|
- }
|
|
|
- if (sy >= y) {
|
|
|
- y1 = y;
|
|
|
- y2 = sy;
|
|
|
- }
|
|
|
- if (x1 <= cps.getPosition().x && y1 <= cps.getPosition().y && x2 >= cps.getPosition().x
|
|
|
- && y2 >= cps.getPosition().y) {
|
|
|
- controller.addSelectedObject(cps);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -485,8 +490,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
}
|
|
|
if (!newEdge) {
|
|
|
controller.removeEdgesOnCanvas(e);
|
|
|
- tempCps.getConnections().remove(e);
|
|
|
- cps.getConnections().remove(e);
|
|
|
// Node ohne Edge?
|
|
|
if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
|
|
|
tempCps = e.getA();
|
|
@@ -507,7 +510,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
if (onEdge) {
|
|
|
CpsEdge p = mousePositionOnEdge(x, y);
|
|
|
if (p != null) {
|
|
|
- CpsEdge temp = null;
|
|
|
CpsEdge e1 = null;
|
|
|
CpsEdge e2 = null;
|
|
|
|
|
@@ -528,11 +530,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
|
|
|
|
e2 = new CpsEdge(n, k, edgeCapacity);
|
|
|
|
|
|
- p.getA().getConnections().remove(p);
|
|
|
- p.getB().getConnections().remove(p);
|
|
|
-
|
|
|
- temp = p;
|
|
|
- controller.removeEdgesOnCanvas(temp);
|
|
|
+ controller.removeEdgesOnCanvas(p);
|
|
|
controller.AddEdgeOnCanvas(e);
|
|
|
controller.AddEdgeOnCanvas(e1);
|
|
|
controller.AddEdgeOnCanvas(e2);
|