|
@@ -22,6 +22,8 @@ import javax.swing.JPanel;
|
|
|
import javax.swing.JPopupMenu;
|
|
|
import javax.swing.JToolTip;
|
|
|
|
|
|
+import com.sun.javafx.geom.Line2D;
|
|
|
+
|
|
|
import classes.CpsEdge;
|
|
|
import classes.CpsNode;
|
|
|
import classes.CpsObject;
|
|
@@ -102,29 +104,32 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
if (drawEdge)
|
|
|
g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
|
|
|
tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
|
|
|
-
|
|
|
- for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
- for (Pair<CpsObject, CpsEdge> con : cps.getConnectedTo()) {
|
|
|
- if (con.getKey().getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
|
|
|
- g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
|
|
|
- cps.getPosition().y + controller.getScaleDiv2(),
|
|
|
- con.getKey().getPosition().x + controller.getScaleDiv2(),
|
|
|
- con.getKey().getPosition().y + controller.getScaleDiv2());
|
|
|
- g2.drawString(con.getValue().getFlow() + "/" + con.getValue().getCapacity(),
|
|
|
- (cps.getPosition().x + con.getKey().getPosition().x) / 2 + controller.getScaleDiv2(),
|
|
|
- (cps.getPosition().y + con.getKey().getPosition().y) / 2 + controller.getScaleDiv2());
|
|
|
- }
|
|
|
+
|
|
|
+ for (CpsEdge con : model.getEdgesOnCanvas()) {
|
|
|
+ if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID())
|
|
|
+ g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
|
|
|
+ con.getA().getPosition().y + controller.getScaleDiv2(),
|
|
|
+ con.getB().getPosition().x + controller.getScaleDiv2(),
|
|
|
+ con.getB().getPosition().y + controller.getScaleDiv2());
|
|
|
+ g2.drawString(con.getFlow() + "/" + con.getCapacity(),
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
|
|
|
}
|
|
|
|
|
|
|
|
|
g2.setColor(Color.GREEN);
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
- for (Pair<CpsObject, CpsEdge> con : cps.getConnectedTo()) {
|
|
|
- if (con.getKey().getID() == model.getSelectedObjectID())
|
|
|
+ for (CpsEdge con : cps.getConnectedTo()) {
|
|
|
+ if (con.getA().getID() == model.getSelectedObjectID()) {
|
|
|
+ g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
|
|
|
+ cps.getPosition().y + controller.getScaleDiv2(),
|
|
|
+ con.getA().getPosition().x + controller.getScaleDiv2(),
|
|
|
+ con.getA().getPosition().y + controller.getScaleDiv2());
|
|
|
+ } else if (con.getB().getID() == model.getSelectedObjectID())
|
|
|
g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
|
|
|
cps.getPosition().y + controller.getScaleDiv2(),
|
|
|
- con.getKey().getPosition().x + controller.getScaleDiv2(),
|
|
|
- con.getKey().getPosition().y + controller.getScaleDiv2());
|
|
|
+ con.getB().getPosition().x + controller.getScaleDiv2(),
|
|
|
+ con.getB().getPosition().y + controller.getScaleDiv2());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -185,6 +190,15 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ if (tempCps == null){
|
|
|
+ for (CpsEdge p : model.getEdgesOnCanvas()) {
|
|
|
+ Line2D l = new Line2D(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x, p.getB().getPosition().y);
|
|
|
+
|
|
|
+ if(l.intersects(x, y, 102, 102)){
|
|
|
+ System.out.println("lineclick");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
objectSelectionHighlighting();
|
|
|
|
|
@@ -299,16 +313,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
private void drawDeleteEdge() {
|
|
|
boolean node = true;
|
|
|
boolean newEdge = true;
|
|
|
- CpsEdge e;
|
|
|
- CpsNode n = null;
|
|
|
- Pair<CpsObject, CpsEdge> tempPair = null;
|
|
|
- Pair<CpsObject, CpsEdge> cpsPair = null;
|
|
|
-
|
|
|
- for (Pair<CpsObject, CpsEdge> p : tempCps.getConnections()) {
|
|
|
- if (p.getKey() == tempCps) {
|
|
|
- cpsPair = p;
|
|
|
- }
|
|
|
- }
|
|
|
+ CpsEdge e = null;
|
|
|
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
cx = cps.getPosition().x;
|
|
@@ -316,41 +321,33 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
|
|
|
&& cps != tempCps) {
|
|
|
node = false;
|
|
|
- for (Pair<CpsObject, CpsEdge> p : tempCps.getConnections()) {
|
|
|
- if (p.getKey() == cps) {
|
|
|
+ for (CpsEdge p : tempCps.getConnections()) {
|
|
|
+ if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
|
|
|
newEdge = false;
|
|
|
- cpsPair = p;
|
|
|
- for (Pair<CpsObject, CpsEdge> pp : cps.getConnections()) {
|
|
|
- if (pp.getKey() == tempCps) {
|
|
|
- tempPair = pp;
|
|
|
- }
|
|
|
- }
|
|
|
+ e = p;
|
|
|
}
|
|
|
}
|
|
|
- tempCps.getConnections().remove(cpsPair);
|
|
|
- cps.getConnections().remove(tempPair);
|
|
|
+ controller.removeEdgesOnCanvas(e);
|
|
|
+ tempCps.getConnections().remove(e);
|
|
|
+ cps.getConnections().remove(e);
|
|
|
if (newEdge) {
|
|
|
e = new CpsEdge(cps, tempCps);
|
|
|
- tempPair = new Pair<CpsObject, CpsEdge>(tempCps, e);
|
|
|
- cpsPair = new Pair<CpsObject, CpsEdge>(cps, e);
|
|
|
-
|
|
|
- cps.AddConnection(tempPair);
|
|
|
- tempCps.AddConnection(cpsPair);
|
|
|
-
|
|
|
+ cps.AddConnection(e);
|
|
|
+ tempCps.AddConnection(e);
|
|
|
+ controller.AddEdgeOnCanvas(e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (node) {
|
|
|
- n = new CpsNode("Node");
|
|
|
+ CpsNode n = new CpsNode("Node");
|
|
|
n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
|
|
|
controller.addObjectCanvas(n);
|
|
|
|
|
|
e = new CpsEdge(n, tempCps);
|
|
|
- tempPair = new Pair<CpsObject, CpsEdge>(tempCps, e);
|
|
|
- cpsPair = new Pair<CpsObject, CpsEdge>(n, e);
|
|
|
|
|
|
- n.AddConnection(tempPair);
|
|
|
- tempCps.AddConnection(cpsPair);
|
|
|
+ n.AddConnection(e);
|
|
|
+ tempCps.AddConnection(e);
|
|
|
+ controller.AddEdgeOnCanvas(e);
|
|
|
System.out.println("node ID: " + n.getID());
|
|
|
}
|
|
|
}
|