public Connector getConnector(int x, int y) {
        for (Connector connector : connectors) {
            double ax = connector.getFrom().getLocation().getX();
            double ay = connector.getFrom().getLocation().getY();
            double bx = connector.getTo().getLocation().getX();
            double by = connector.getTo().getLocation().getY();
            double rn = ((double) x - ax) * (bx - ax) + ((double) y - ay) * (by - ay);
            double rd = (bx - ax) * (bx - ax) + (by - ay) * (by - ay);
            double r = rn / rd;
            double s = ((ay - (double) y) * (bx - ax) - (ax - (double) x) * (by - ay) ) / rd;
            double distanceLine = Math.abs(s) * Math.sqrt(rd);
            double distanceSegment;
            if ((r >= 0) && (r <= 1)) {
                distanceSegment = distanceLine;
            } else {
                double dist1 = ((double) x - ax) * ((double) x - ax) + ((double) y - ay) * ((double) y - ay);
                double dist2 = ((double) x - bx) * ((double) x - bx) + ((double) y - by) * ((double) y - by);
                if (dist1 < dist2) {
                    distanceSegment = Math.sqrt(dist1);
                } else {
                    distanceSegment = Math.sqrt(dist2);
                }
            }
            if (distanceSegment <= 1) return connector;
        }
        return null;
    }