private Rectangle fieldBounds(Figure figure) { Rectangle box = figure.displayBox(); int nChars = Math.max(20, getURL(figure).length()); Dimension d = fTextField.getPreferredSize(nChars); box.x = Math.max(0, box.x + (box.width - d.width) / 2); box.y = Math.max(0, box.y + (box.height - d.height) / 2); return new Rectangle(box.x, box.y, d.width, d.height); }
public void drawingInvalidated(DrawingChangeEvent e) { Rectangle r = e.getInvalidatedRectangle(); if (getDamage() == null) { setDamage(r); } else { // don't manipulate rectangle returned by getDamage() directly // because it could be a cloned rectangle. Rectangle damagedR = getDamage(); damagedR.add(r); setDamage(damagedR); } }
/** Finds a top level Figure that intersects the given rectangle. */ public Figure findFigure(Rectangle r) { FigureEnumeration k = figuresReverse(); while (k.hasMoreElements()) { Figure figure = k.nextFigure(); Rectangle fr = figure.displayBox(); if (r.intersects(fr)) return figure; } return null; }
/** * 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; }
public void basicMoveBy(int x, int y) { fDisplayBox.translate(x, y); }
public void basicDisplayBox(Point origin, Point corner) { fDisplayBox = new Rectangle(origin); fDisplayBox.add(corner); }