protected void drawConnections(Graphics g, Collection<Connection> cons) {
    if (selectedDotA != null && overDotB != null) {
      Color c = g.getColor();
      g.setColor(Color.GRAY);
      Connection tmpCon = new Connection();
      tmpCon.src = selectedDotA;
      tmpCon.dst = overDotB;
      tmpCon.paint(g);
      g.setColor(c);
    }

    for (Connection con : cons) {
      if (selectedDotA != null
          && overDotB != null
          && con.src.distance(selectedDotA) == 0
          && con.dst.distance(overDotB) != 0) {
        // ignore
      } else if ((overDotA != null && con.src.distance(overDotA) == 0)
          || (overDotB != null && con.dst.distance(overDotB) == 0)) {
        Color c = g.getColor();
        g.setColor(Color.CYAN);
        con.paint(g);
        g.setColor(c);
      } else con.paint(g);
    }
  }
 public void addSurjectivConnections() {
   Iterator<Point> j = dotsB.iterator();
   for (Point aDotsA : dotsA) {
     Connection con = new Connection();
     con.src = aDotsA;
     if (!j.hasNext()) j = dotsB.iterator();
     con.dst = j.next();
     connections.add(con);
   }
 }
  public void mouseClicked(MouseEvent e) {
    if (!editable) return;

    mouseMoved(e); // just a HACK to get sure that vars are correct
    Point p = getPointByPos(dotsA, e.getPoint());
    if (p != null) {
      selectedDotA = p;
    } else if (selectedDotA != null) {
      p = getPointByPos(dotsB, e.getPoint());
      if (p != null) {
        Connection con = getConnectionBySrc(selectedDotA, connections);
        if (con != null) connections.remove(con);
        con = new Connection();
        con.src = selectedDotA;
        con.dst = p;
        connections.add(con);

        onChange();
      }
    }

    this.applet.repaint();
  }