|
@@ -98,17 +98,26 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
//Selection
|
|
|
if(selectRect != null){
|
|
|
- g2.setColor(new Color(100, 255, 100));
|
|
|
+ g2.setColor(Color.GREEN);
|
|
|
g2.fillRect((int)selectRect.getX(), (int)selectRect.getY(), (int)selectRect.getWidth(), (int)selectRect.getHeight());
|
|
|
}
|
|
|
|
|
|
//drawEdges
|
|
|
- g.setColor(Color.BLACK);
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
if(drawEdge)g2.drawLine(tempCps.getPos().x+GlobalVariables.SCALE_DIVIDED2, tempCps.getPos().y+GlobalVariables.SCALE_DIVIDED2, x, y);
|
|
|
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
|
- g.drawLine(cps.getPos().x+GlobalVariables.SCALE_DIVIDED2, cps.getPos().y+GlobalVariables.SCALE_DIVIDED2, con.getPos().x+GlobalVariables.SCALE_DIVIDED2, con.getPos().y+GlobalVariables.SCALE_DIVIDED2);
|
|
|
+ if(con.getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
|
|
|
+ g2.drawLine(cps.getPos().x+GlobalVariables.SCALE_DIVIDED2, cps.getPos().y+GlobalVariables.SCALE_DIVIDED2, con.getPos().x+GlobalVariables.SCALE_DIVIDED2, con.getPos().y+GlobalVariables.SCALE_DIVIDED2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ g2.setColor(Color.GREEN);
|
|
|
+ for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
+ for (CpsObject con : cps.getConnectedTo()) {
|
|
|
+ if(con.getID() == model.getSelectedObjectID())
|
|
|
+ g2.drawLine(cps.getPos().x+GlobalVariables.SCALE_DIVIDED2, cps.getPos().y+GlobalVariables.SCALE_DIVIDED2, con.getPos().x+GlobalVariables.SCALE_DIVIDED2, con.getPos().y+GlobalVariables.SCALE_DIVIDED2);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -163,14 +172,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
if(drawEdge){
|
|
|
drawEdge = false;
|
|
|
- for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
- cx = cps.getPos().x;
|
|
|
- cy = cps.getPos().y;
|
|
|
- if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
|
|
|
- cps.AddConnection(tempCps);
|
|
|
- tempCps.AddConnection(cps);
|
|
|
- }
|
|
|
- }
|
|
|
+ drawDeleteEdge();
|
|
|
}
|
|
|
|
|
|
if (dragging) {
|
|
@@ -244,11 +246,28 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
if(tempCps != null){
|
|
|
selectRect.setBounds(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20), GlobalVariables.SCALE+GlobalVariables.SCALE/10, GlobalVariables.SCALE+GlobalVariables.SCALE/10);
|
|
|
controller.setSelectedObjectID(tempCps.getID());
|
|
|
- System.out.println("Select");
|
|
|
}else {
|
|
|
controller.setSelectedObjectID(0);
|
|
|
selectRect.setRect(0, 0, 0, 0);
|
|
|
- System.out.println("Unselect");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Draws or Deletes an Edge
|
|
|
+ */
|
|
|
+ private void drawDeleteEdge() {
|
|
|
+ for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
+ cx = cps.getPos().x;
|
|
|
+ cy = cps.getPos().y;
|
|
|
+ if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
|
|
|
+ if (!cps.getConnectedTo().contains(tempCps)) {
|
|
|
+ cps.AddConnection(tempCps);
|
|
|
+ tempCps.AddConnection(cps);
|
|
|
+ } else {
|
|
|
+ cps.getConnectedTo().remove(tempCps);
|
|
|
+ tempCps.getConnectedTo().remove(cps);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|