public Rectangle2D.Double layout( CompositeFigure compositeFigure, Point2D.Double anchor, Point2D.Double lead) { Rectangle2D.Double bounds = null; for (Figure child : compositeFigure.getChildren()) { Locator locator = getLocator(child); Rectangle2D.Double r; if (locator == null) { r = child.getBounds(); } else { Point2D.Double p = locator.locate(compositeFigure, child); Dimension2DDouble d = child.getPreferredSize(); r = new Rectangle2D.Double(p.x, p.y, d.width, d.height); } child.willChange(); child.setBounds( new Point2D.Double(r.getMinX(), r.getMinY()), new Point2D.Double(r.getMaxX(), r.getMaxY())); child.changed(); if (!r.isEmpty()) { if (bounds == null) { bounds = r; } else { bounds.add(r); } } } return (bounds == null) ? new Rectangle2D.Double() : bounds; }
public Rectangle2D.Double calculateLayout( CompositeFigure compositeFigure, Point2D.Double anchor, Point2D.Double lead) { Rectangle2D.Double bounds = null; for (Figure child : compositeFigure.getChildren()) { Locator locator = getLocator(child); Rectangle2D.Double r; if (locator == null) { r = child.getBounds(); } else { Point2D.Double p = locator.locate(compositeFigure); Dimension2DDouble d = child.getPreferredSize(); r = new Rectangle2D.Double(p.x, p.y, d.width, d.height); } if (!r.isEmpty()) { if (bounds == null) { bounds = r; } else { bounds.add(r); } } } return (bounds == null) ? new Rectangle2D.Double() : bounds; }
@Override public Rectangle2D.Double getDrawingArea() { Rectangle2D.Double r = super.getDrawingArea(); if (getNodeCount() > 1) { if (get(START_DECORATION) != null) { Point2D.Double p1 = getPoint(0, 0); Point2D.Double p2 = getPoint(1, 0); r.add(get(START_DECORATION).getDrawingArea(this, p1, p2)); } if (get(END_DECORATION) != null) { Point2D.Double p1 = getPoint(getNodeCount() - 1, 0); Point2D.Double p2 = getPoint(getNodeCount() - 2, 0); r.add(get(END_DECORATION).getDrawingArea(this, p1, p2)); } } return r; }
/** * Updates the list of connectors that we draw when the user moves or drags the mouse over a * figure to which can connect. */ public void repaintConnectors() { Rectangle2D.Double invalidArea = null; for (Connector c : connectors) { if (invalidArea == null) { invalidArea = c.getDrawingArea(); } else { invalidArea.add(c.getDrawingArea()); } } connectors = (connectableFigure == null) ? new java.util.LinkedList<Connector>() : connectableFigure.getConnectors(getOwner()); for (Connector c : connectors) { if (invalidArea == null) { invalidArea = c.getDrawingArea(); } else { invalidArea.add(c.getDrawingArea()); } } if (invalidArea != null) { view.getComponent().repaint(view.drawingToView(invalidArea)); } }
/** Gets the drawing area without taking the decorator into account. */ @Override protected Rectangle2D.Double getFigureDrawingArea() { if (getText() == null) { return getBounds(); } else { TextLayout layout = getTextLayout(); Rectangle2D.Double r = new Rectangle2D.Double(origin.x, origin.y, layout.getAdvance(), layout.getAscent()); Rectangle2D lBounds = layout.getBounds(); if (!lBounds.isEmpty() && !Double.isNaN(lBounds.getX())) { r.add( new Rectangle2D.Double( lBounds.getX() + origin.x, (lBounds.getY() + origin.y + layout.getAscent()), lBounds.getWidth(), lBounds.getHeight())); } // grow by two pixels to take antialiasing into account Geom.grow(r, 2d, 2d); return r; } }
/** * All other write methods delegate their work to here. */ public void write(OutputStream out, java.util.List<Figure> figures) throws IOException { Rectangle2D.Double drawingRect = null; for (Figure f : figures) { if (drawingRect == null) { drawingRect = f.getBounds(); } else { drawingRect.add(f.getBounds()); } } AffineTransform drawingTransform = new AffineTransform(); drawingTransform.translate( -Math.min(0, drawingRect.x), -Math.min(0, drawingRect.y) ); write(out, figures, drawingTransform, new Dimension( (int) (Math.abs(drawingRect.x) + drawingRect.width), (int) (Math.abs(drawingRect.y) + drawingRect.height)) ); }
public Rectangle2D layoutImplicitHydrogens( IAtom atom, int implicitHydrogenCount, LabelManager.AnnotationPosition pos, Graphics2D g) { String text = atom.getSymbol(); Point2d p = atom.getPoint2d(); g.setFont(this.atomSymbolFont); Point2f pc = this.getTextPoint(g, text, p.x, p.y); Rectangle2D hBounds = this.getTextBounds(g, "H"); double atomSymbolWidth = this.getTextBounds(g, text).getWidth(); double hWidth = hBounds.getWidth(); double hHeight = hBounds.getHeight(); double subscriptWidth = 0.0; Rectangle2D.Double totalHBounds = null; if (pos == LabelManager.AnnotationPosition.E) { double cx = p.x + atomSymbolWidth / 2.0 + hWidth / 2.0; double cy = p.y; totalHBounds = new Rectangle2D.Double(cx - hWidth / 2.0, cy - hHeight / 2.0, hWidth, hHeight); if (implicitHydrogenCount > 1) { g.setFont(this.subscriptFont); String hCount = String.valueOf(implicitHydrogenCount); Rectangle2D subscriptBounds = this.getTextBounds(g, hCount); subscriptWidth = subscriptBounds.getWidth(); g.setFont(this.atomSymbolFont); double subscriptHeight = subscriptBounds.getHeight(); totalHBounds.add( new Rectangle2D.Double( (cx += hWidth / 2.0 + subscriptWidth / 2.0) - subscriptWidth / 2.0, (cy += (double) this.params.subscriptHeight) - subscriptHeight / 2.0, subscriptWidth, subscriptHeight)); } } else if (pos == LabelManager.AnnotationPosition.W) { float y; float x; if (implicitHydrogenCount > 1) { String hCount = String.valueOf(implicitHydrogenCount); g.setFont(this.subscriptFont); Rectangle2D subscriptBounds = this.getTextBounds(g, hCount); subscriptWidth = subscriptBounds.getWidth(); x = (float) ((double) pc.x - subscriptWidth); y = pc.y + (float) this.params.subscriptHeight; g.setFont(this.atomSymbolFont); double subscriptHeight = subscriptBounds.getHeight(); totalHBounds = new Rectangle2D.Double( (double) x - subscriptWidth / 2.0, (double) y - subscriptHeight / 2.0, subscriptWidth, subscriptHeight); } x = (float) ((double) pc.x - atomSymbolWidth / 2.0 - subscriptWidth - hWidth / 2.0); y = pc.y; Rectangle2D.Double hDrawnBounds = new Rectangle2D.Double( (double) x - hWidth / 2.0, (double) y - hHeight / 2.0, hWidth, hHeight); if (totalHBounds == null) { totalHBounds = hDrawnBounds; } else { totalHBounds.add(hDrawnBounds); } } return totalHBounds; }