public Rectangle2D apply(Rectangle2D rect) { return new Rectangle2D.Double(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight()); }
private void renderProgressWidget(Graphics2D graphics) { Widget bar = client.getWidget(WidgetInfo.PEST_CONTROL_ACTIVITY_BAR).getChild(0); Rectangle2D bounds = bar.getBounds().getBounds2D(); Widget prgs = client.getWidget(WidgetInfo.PEST_CONTROL_ACTIVITY_PROGRESS).getChild(0); int perc = (int) ((prgs.getBounds().getWidth() / bounds.getWidth()) * 100); Color color = Color.GREEN; if (perc < 25) { color = Color.RED; } String text = String.valueOf(perc) + "%"; FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, graphics); int x = (int) (bounds.getX() - textBounds.getWidth()); int y = (int) (bounds.getY() + fm.getHeight() - 2); graphics.setColor(Color.BLACK); graphics.drawString(text, x + 1, y + 1); graphics.setColor(color); graphics.drawString(text, x, y); }
/** * Resize this picture to the default size. * * For PNG and JPEG resizes the image to 100%, * for other types, if the size can't be determined it will be 200x200 pixels. */ public void resize() { PictureShape<?,?> ps = getShape(); Dimension dim = ps.getPictureData().getImageDimension(); Rectangle2D origRect = ps.getAnchor(); double x = origRect.getX(); double y = origRect.getY(); double w = dim.getWidth(); double h = dim.getHeight(); ps.setAnchor(new Rectangle2D.Double(x, y, w, h)); }
width = pageDim.getWidth() - anchor.getX(); break; case VERTICAL: width = pageDim.getHeight() - anchor.getX(); break; case VERTICAL_270: width = anchor.getX(); break; switch (textDir) { default: width = anchor.getWidth() - leftInset - rightInset - leftMargin - rightMargin; break; case VERTICAL: case VERTICAL_270: width = anchor.getHeight() - leftInset - rightInset - leftMargin - rightMargin; break;
static Rectangle2D move(Rectangle2D rect, double dx, double dy) { return new Rectangle2D.Double(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight()); }
Rectangle2D textBounds = textLayout.getBounds(); double xOffset = chart.getPlot().getBounds().getX(); // of plot left edge double yOffset = chart.getStyler().getChartPadding(); double chartTitleBoxWidth = chart.getPlot().getBounds().getWidth(); double chartTitleBoxHeight = textBounds.getHeight() + 2 * chart.getStyler().getChartTitlePadding(); new Rectangle2D.Double(xOffset, yOffset, chartTitleBoxWidth, chartTitleBoxHeight); g.setColor(chart.getStyler().getChartTitleBoxBackgroundColor()); g.fill(rect); chart.getPlot().getBounds().getX() + (chart.getPlot().getBounds().getWidth() - textBounds.getWidth()) / 2.0; yOffset = chart.getStyler().getChartPadding() + textBounds.getHeight() + chart.getStyler().getChartTitlePadding(); double width = 2 * chart.getStyler().getChartTitlePadding() + textBounds.getWidth(); double height = 2 * chart.getStyler().getChartTitlePadding() + textBounds.getHeight(); bounds = new Rectangle2D.Double( xOffset - chart.getStyler().getChartTitlePadding(), yOffset - textBounds.getHeight() - chart.getStyler().getChartTitlePadding(),
@Override public Rectangle2D resizeToFitText(Graphics2D graphics) { Rectangle2D anchor = getAnchor(); if (anchor.getWidth() == 0.) { throw new POIXMLException("Anchor of the shape was not set."); } double height = getTextHeight(graphics); height += 1; // add a pixel to compensate rounding errors Insets2D insets = getInsets(); anchor.setRect(anchor.getX(), anchor.getY(), anchor.getWidth(), height + insets.top + insets.bottom); setAnchor(anchor); return anchor; }
final Rectangle2D xfrm2d = new Rectangle2D.Double (xfrm.getOff().getX(), xfrm.getOff().getY(), xfrm.getExt().getCx(), xfrm.getExt().getCy()); at.translate(bounds.getX()+bounds.getCenterX(), bounds.getY()+bounds.getCenterY()); at.scale(1./Units.EMU_PER_POINT, 1./Units.EMU_PER_POINT); at.translate(-xfrm2d.getCenterX(), -xfrm2d.getCenterY());
Graphics2D g = ...; Point2D loc = ...; Font font = Font.getFont("Helvetica-bold-italic"); FontRenderContext frc = g.getFontRenderContext(); TextLayout layout = new TextLayout("This is a string", font, frc); layout.draw(g, (float)loc.getX(), (float)loc.getY()); Rectangle2D bounds = layout.getBounds(); bounds.setRect(bounds.getX()+loc.getX(), bounds.getY()+loc.getY(), bounds.getWidth(), bounds.getHeight()); g.draw(bounds);
DrawFactory df = DrawFactory.getInstance(null); double newY = tblAnc.getY(); tc.setAnchor(new Rectangle2D.Double(0,0,colWidths[col],0)); DrawTextShape dts = df.getDrawable(tc); maxHeight = Math.max(maxHeight, dts.getTextHeight()); double newX = tblAnc.getX(); for (int col=0; col<cols; col++) { Rectangle2D bounds = new Rectangle2D.Double(newX, newY, colWidths[col], rowHeights[row]); XSLFTableCell tc = getCell(row, col); if (tc != null) {
public Raster getRaster(int xOffset, int yOffset, int w, int h) { ColorModel cm = getColorModel(); if (raster == null) createRaster(); // TODO: eventually use caching here WritableRaster childRaster = cm.createCompatibleWritableRaster(w, h); Rectangle2D childRect = new Rectangle2D.Double(xOffset, yOffset, w, h); if (!childRect.intersects(deviceBounds)) { // usually doesn't happen ... return childRaster; } Rectangle2D destRect = new Rectangle2D.Double(); Rectangle2D.intersect(childRect, deviceBounds, destRect); int dx = (int)(destRect.getX()-deviceBounds.getX()); int dy = (int)(destRect.getY()-deviceBounds.getY()); int dw = (int)destRect.getWidth(); int dh = (int)destRect.getHeight(); Object data = raster.getDataElements(dx, dy, dw, dh, null); dx = (int)(destRect.getX()-childRect.getX()); dy = (int)(destRect.getY()-childRect.getY()); childRaster.setDataElements(dx, dy, dw, dh, data); return childRaster; }
private void renderWidgetOverlay(Graphics2D graphics, Portal portal, String text, Color color) { Widget shield = client.getWidget(portal.getShield()); Widget icon = client.getWidget(portal.getIcon()); Widget hp = client.getWidget(portal.getHitpoints()); Widget bar = client.getWidget(WidgetInfo.PEST_CONTROL_ACTIVITY_BAR).getChild(0); Rectangle2D barBounds = bar.getBounds().getBounds2D(); // create one rectangle from two different widget bounds Rectangle2D bounds = union(shield.getBounds().getBounds2D(), icon.getBounds().getBounds2D()); bounds = union(bounds, hp.getBounds().getBounds2D()); graphics.setColor(color); graphics.draw(new Rectangle2D.Double(bounds.getX(), bounds.getY() - 2, bounds.getWidth(), bounds.getHeight() - 3)); FontMetrics fm = graphics.getFontMetrics(); Rectangle2D textBounds = fm.getStringBounds(text, graphics); int x = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2)); int y = (int) (bounds.getY() + bounds.getHeight() + textBounds.getHeight() + barBounds.getHeight()); graphics.setColor(Color.BLACK); graphics.drawString(text, x + 1, y + 5); graphics.setColor(color); graphics.drawString(text, x, y + 4); }
public void draw(Graphics2D graphics) { // the coordinate system of this group of shape Rectangle2D interior = getShape().getInteriorAnchor(); // anchor of this group relative to the parent shape Rectangle2D exterior = getShape().getAnchor(); AffineTransform tx = (AffineTransform)graphics.getRenderingHint(Drawable.GROUP_TRANSFORM); AffineTransform tx0 = new AffineTransform(tx); double scaleX = interior.getWidth() == 0. ? 1.0 : exterior.getWidth() / interior.getWidth(); double scaleY = interior.getHeight() == 0. ? 1.0 : exterior.getHeight() / interior.getHeight(); tx.translate(exterior.getX(), exterior.getY()); tx.scale(scaleX, scaleY); tx.translate(-interior.getX(), -interior.getY()); DrawFactory drawFact = DrawFactory.getInstance(graphics); AffineTransform at2 = graphics.getTransform(); for (Shape<?,?> child : getShape()) { // remember the initial transform and restore it after we are done with the drawing AffineTransform at = graphics.getTransform(); graphics.setRenderingHint(Drawable.GSAVE, true); Drawable draw = drawFact.getDrawable(child); draw.applyTransform(graphics); draw.draw(graphics); // restore the coordinate system graphics.setTransform(at); graphics.setRenderingHint(Drawable.GRESTORE, true); } graphics.setTransform(at2); graphics.setRenderingHint(Drawable.GROUP_TRANSFORM, tx0); }
if (bounds.getX() <= 0) int orbInnerHeight = (int) bounds.getHeight(); int orbInnerWidth = orbInnerHeight; int orbInnerX = (int) (bounds.getX() + 24);//x pos of the inside of the prayer orb int orbInnerY = (int) (bounds.getY() - 1);//y pos of the inside of the prayer orb graphics.fillRect(orbInnerX + xOffset, orbInnerY + yOffset, 1, indicatorHeight); return new Dimension((int) bounds.getWidth(), (int) bounds.getHeight());