/** * Defines how to draw element * * @param graphics */ @Override public void draw(Graphics2D graphics) { content.draw(graphics, offset); }
/** * Calculates the offset of content to make it in the center of the shape * @return offset */ protected Point2D getShapeOffset() { Rectangle2D shapeBounds = getShape().getBounds(); return new Point2D.Double( (shapeBounds.getWidth() - content.getWidth()) / 2, (shapeBounds.getHeight() - content.getHeight()) / 2 ); }
/** * @return minimal bounds of this element */ @Override public Rectangle2D getMinimalBounds() { return content.getMinimalBounds(); }
/** * set new content for shape * @param content */ protected final void setContent(Content content) { if(null != this.content) { this.content.removeParent(this); } if(null == content) { content = new EmptyContent(); } content.addParent(this); this.content = content; refreshUp(); }
/** * @return ellipse described on content */ private Ellipse2D createEllipse() { Rectangle2D contentBounds = getContent().getBounds(); double width = Math.sqrt(contentBounds.getWidth() * contentBounds.getWidth() + aspectRatio * aspectRatio * contentBounds.getHeight() * contentBounds.getHeight()); double height = width / aspectRatio; return new Ellipse2D.Double(0,0,width, height); }
public RelativeContent(Content content, Point2D position) { content.addParent(this); this.content = content; this.position = position; refreshUp(); }
/** * removes "Content" from the collection of objects listening * @param parent the listener */ protected final void removeParent(Content parent) { parents.remove(parent); refresh(); }
/** * @see Layout#getNextOffset(Point2D, Content) */ @Override protected Point2D getNextOffset(Point2D beforeOffset, Content content) { return new Point2D.Double(beforeOffset.getX(),beforeOffset.getY() + content.getHeight()); }
/** * @see Layout#getNextOffset(Point2D, Content) */ @Override protected Point2D getNextOffset(Point2D beforeOffset, Content content) { return new Point2D.Double(beforeOffset.getX() + content.getWidth(),beforeOffset.getY()); }
public boolean contains(Point2D p) { if(null != getBackground()) { return getBackground().contains(p); } return getContent().contains(p); }
/** * @return minimal bounds of this element */ @Override public Rectangle2D getMinimalBounds() { Rectangle2D contentMinimalBounds = content.getMinimalBounds(); Rectangle2D selfMinimalBounds = super.getMinimalBounds(); return new Rectangle2D.Double( position.getX(), position.getY(), Math.max(selfMinimalBounds.getWidth(), contentMinimalBounds.getWidth()), Math.max(selfMinimalBounds.getHeight(), contentMinimalBounds.getHeight()) ); }
private void updateOffsetPoint() { Rectangle2D selfBounds = getBounds(); Rectangle2D contentBounds = content.getBounds(); offset = new Point2D.Double( selfBounds.getX() + (selfBounds.getWidth() - contentBounds.getWidth())/2, selfBounds.getY() + (selfBounds.getHeight() - contentBounds.getHeight())/2 ); }
/** * add a content to layout * @param content */ public void add(Content content) { if(null == content) { throw new NullPointerException("Content can't be null"); } content.addParent(this); contents.add(content); refresh(); }
protected void afterReconstruction() { getContent().refresh(); }
/** * @see Content#draw(Graphics2D) */ @Override public void draw(Graphics2D graphics) { content.draw(graphics, position); }