private Figure findConnectableFigure(Point2D.Double p, Drawing drawing) { for (Figure f : drawing.getFiguresFrontToBack()) { if (!f.includes(getOwner()) && f.canConnect() && f.contains(p)) { return f; } } return null; }
/** * Finds a top level Figure, but supresses the passed in figure. Use this method to ignore a * figure that is temporarily inserted into the drawing. * * @param x the x coordinate * @param y the y coordinate * @param without the figure to be ignored during the find. */ public Figure findFigureWithout(int x, int y, Figure without) { if (without == null) return findFigure(x, y); FigureEnumeration k = figuresReverse(); while (k.hasMoreElements()) { Figure figure = k.nextFigure(); if (figure.containsPoint(x, y) && !figure.includes(without)) return figure; } return null; }
/** Checks if the composite figure has the argument as one of its children. */ public boolean includes(Figure figure) { if (super.includes(figure)) return true; FigureEnumeration k = figures(); while (k.hasMoreElements()) { Figure f = k.nextFigure(); if (f.includes(figure)) return true; } return false; }
/** * Finds a top level Figure that intersects the given rectangle. It supresses the passed in * figure. Use this method to ignore a figure that is temporarily inserted into the drawing. */ public Figure findFigure(Rectangle r, Figure without) { if (without == null) return findFigure(r); FigureEnumeration k = figuresReverse(); while (k.hasMoreElements()) { Figure figure = k.nextFigure(); Rectangle fr = figure.displayBox(); if (r.intersects(fr) && !figure.includes(without)) return figure; } return null; }
/** Check existance of figure in the drawing */ public boolean figureExists(Figure inf, FigureEnumeration fe) { while (fe.hasNextFigure()) { Figure figure = fe.nextFigure(); if (figure.includes(inf)) { return true; } } return false; }
private Figure findConnectableFigure(int x, int y, Drawing drawing) { FigureEnumeration k = drawing.figuresReverse(); while (k.hasMoreElements()) { Figure figure = k.nextFigure(); if (!figure.includes(getConnection()) && figure.canConnect()) { if (figure.containsPoint(x, y)) { return figure; } } } return null; }
private Connector findConnectionTarget(int x, int y, Drawing drawing) { Figure target = findConnectableFigure(x, y, drawing); if ((target != null) && target.canConnect() && target != fOriginalTarget && !target.includes(owner()) && getConnection().canConnect(source().owner(), target)) { return findConnector(x, y, target); } return null; }
private Connector findConnectionTarget(Point2D.Double p, Drawing drawing) { Figure targetFigure = findConnectableFigure(p, drawing); if (getSource() == null && targetFigure != null) { return findConnector(p, targetFigure, getOwner()); } else if (targetFigure != null) { Connector target = findConnector(p, targetFigure, getOwner()); if ((targetFigure != null) && targetFigure.canConnect() && targetFigure != savedTarget && !targetFigure.includes(getOwner()) && (canConnect(getSource(), target) || getTarget() != null && getTarget().getOwner() == targetFigure)) { return target; } } return null; }