/** * Paints this Figure's children. The caller must save the state of the graphics prior to calling * this method, such that <code>graphics.restoreState()</code> may be called safely, and doing so * will return the graphics to its original state when the method was entered. * * <p>This method must leave the Graphics in its original state upon return. * * @param graphics the graphics used to paint * @since 2.0 */ protected void paintChildren(Graphics graphics) { IFigure child; Rectangle clip = Rectangle.SINGLETON; for (int i = 0; i < children.size(); i++) { child = (IFigure) children.get(i); if (child.isVisible() && child.intersects(graphics.getClip(clip))) { graphics.clipRect(child.getBounds()); child.paint(graphics); graphics.restoreState(); } } }
/** * Searches this Figure's children for the deepest descendant for which {@link * #isMouseEventTarget()} returns <code>true</code> and returns that descendant or <code>null * </code> if none found. * * @see #findMouseEventTargetAt(int, int) * @param x The X coordinate * @param y The Y coordinate * @return The deepest descendant for which isMouseEventTarget() returns true */ protected IFigure findMouseEventTargetInDescendantsAt(int x, int y) { PRIVATE_POINT.setLocation(x, y); translateFromParent(PRIVATE_POINT); if (!getClientArea(Rectangle.SINGLETON).contains(PRIVATE_POINT)) return null; IFigure fig; for (int i = children.size(); i > 0; ) { i--; fig = (IFigure) children.get(i); if (fig.isVisible() && fig.isEnabled()) { if (fig.containsPoint(PRIVATE_POINT.x, PRIVATE_POINT.y)) { fig = fig.findMouseEventTargetAt(PRIVATE_POINT.x, PRIVATE_POINT.y); return fig; } } } return null; }
/** * Returns a descendant of this Figure such that the Figure returned contains the point (x, y), * and is accepted by the given TreeSearch. Returns <code>null</code> if none found. * * @param x The X coordinate * @param y The Y coordinate * @param search the TreeSearch * @return The descendant Figure at (x,y) */ protected IFigure findDescendantAtExcluding(int x, int y, TreeSearch search) { PRIVATE_POINT.setLocation(x, y); translateFromParent(PRIVATE_POINT); if (!getClientArea(Rectangle.SINGLETON).contains(PRIVATE_POINT)) return null; x = PRIVATE_POINT.x; y = PRIVATE_POINT.y; IFigure fig; for (int i = children.size(); i > 0; ) { i--; fig = (IFigure) children.get(i); if (fig.isVisible()) { fig = fig.findFigureAt(x, y, search); if (fig != null) return fig; } } // No descendants were found return null; }