public Rectangle2D apply(Rectangle2D rect) { return new Rectangle2D.Double(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight()); }
private void drawProgessBar(Graphics g, int intValue, int totalValue) { if (totalValue == 0) { return; } g.setFont(font); final String label = "" + intValue + "/" + totalValue; final Rectangle2D rect = getUsed(g, label); final int x = 10; final int y = 33; final int barWidth = 170; final int barHeight = (int) (rect.getHeight() + 2); final int grey = 230; g.setColor(new Color(grey, grey, grey)); final int value = barWidth * intValue / totalValue; g.fillRect(x, y, value, barHeight); g.setColor(Color.BLACK); g.drawRect(x, y, barWidth, barHeight); final double xLabel = x + (barWidth - rect.getWidth()) / 2; final double yLabel = y - rect.getY() + (barHeight - rect.getHeight()) / 2; g.drawString(label, (int) xLabel, (int) yLabel); }
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); }
/** Closes a path for area charts if one is available. */ void closePath( Graphics2D g, Path2D.Double path, double previousX, Rectangle2D bounds, double yTopMargin) { if (path != null) { double yBottomOfArea = getBounds().getY() + getBounds().getHeight() - yTopMargin; path.lineTo(previousX, yBottomOfArea); path.closePath(); g.fill(path); } } }
/** * 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)); }
static Rectangle2D move(Rectangle2D rect, double dx, double dy) { return new Rectangle2D.Double(rect.getX() + dx, rect.getY() + dy, rect.getWidth(), rect.getHeight()); }
final double yy = bounds.getHeight() + bounds.getY(); double y = 0; if (ta.getOrientationAngle() == 0) { x = -0.5 * ta.getHorizontalAnchor().getFactor() * bounds.getWidth(); y = 0.5 * ta.getVerticalAnchor().getFactor() * bounds.getHeight() - yy; x = pos.x + x; y = pos.y + y; } else { x = 0.5 * ta.getVerticalAnchor().getFactor() * bounds.getHeight(); y = 0.5 * ta.getHorizontalAnchor().getFactor() * bounds.getWidth();
@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());