List of usage examples for java.awt.geom Rectangle2D getWidth
public abstract double getWidth();
From source file:org.uva.itast.blended.omr.scanners.BarcodeScanner.java
/** * Generates an expanded boundingbox in milimeters * /*w w w. j a v a 2 s . c o m*/ * @see {@link #BARCODE_AREA_PERCENT} * @see {@value #BARCODE_AREA_PERCENT} * @param rect * @return milimeteres */ protected Rectangle2D getExpandedArea(Rectangle2D rect, double percent) { Rectangle expandedRect = new Rectangle(); expandedRect.setFrame((rect.getX() - rect.getWidth() * (percent) / 2), (rect.getY() - rect.getHeight() * (percent) / 2), (rect.getWidth() * (1 + percent)), (rect.getHeight() * (1 + percent))); return expandedRect; }
From source file:WeatherWizard.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension size = getSize();/*ww w . jav a2 s. c om*/ Composite origComposite; setupWeatherReport(); origComposite = g2.getComposite(); if (alpha0 != null) g2.setComposite(alpha0); g2.drawImage(img0, 0, 0, size.width, size.height, 0, 0, img0.getWidth(null), img0.getHeight(null), null); if (img1 != null) { if (alpha1 != null) g2.setComposite(alpha1); g2.drawImage(img1, 0, 0, size.width, size.height, 0, 0, img1.getWidth(null), img1.getHeight(null), null); } g2.setComposite(origComposite); // Freezing, Cold, Cool, Warm, Hot, // Blue, Green, Yellow, Orange, Red Font font = new Font("Serif", Font.PLAIN, 36); g.setFont(font); String tempString = feels + " " + temperature + "F"; FontRenderContext frc = ((Graphics2D) g).getFontRenderContext(); Rectangle2D boundsTemp = font.getStringBounds(tempString, frc); Rectangle2D boundsCond = font.getStringBounds(condStr, frc); int wText = Math.max((int) boundsTemp.getWidth(), (int) boundsCond.getWidth()); int hText = (int) boundsTemp.getHeight() + (int) boundsCond.getHeight(); int rX = (size.width - wText) / 2; int rY = (size.height - hText) / 2; g.setColor(Color.LIGHT_GRAY); g2.fillRect(rX, rY, wText, hText); g.setColor(textColor); int xTextTemp = rX - (int) boundsTemp.getX(); int yTextTemp = rY - (int) boundsTemp.getY(); g.drawString(tempString, xTextTemp, yTextTemp); int xTextCond = rX - (int) boundsCond.getX(); int yTextCond = rY - (int) boundsCond.getY() + (int) boundsTemp.getHeight(); g.drawString(condStr, xTextCond, yTextCond); }
From source file:com.projity.pm.graphic.xbs.XbsLayout.java
private void setShape(GraphicNode node, Rectangle2D ref, double centerX, double centerY) { TexturedShape texturedShape = findShape(node); if (texturedShape == null) return;// w w w. j a v a 2 s. co m GeneralPath shape = texturedShape.toGeneralPath(ref.getWidth(), ref.getHeight(), centerX - ref.getWidth() / 2, centerY, null); node.setXbsShape(shape, centerX, centerY); Rectangle.union(bounds, network.scale(shape.getBounds()), bounds); }
From source file:Bouncer.java
protected void setClip(Graphics2D g2) { if (mClip == false) return;// w w w. j a v a 2 s . c om if (mClipShape == null) { Dimension d = getSize(); FontRenderContext frc = g2.getFontRenderContext(); Font font = new Font("Serif", Font.PLAIN, 144); String s = "Java Source and Support!"; GlyphVector gv = font.createGlyphVector(frc, s); Rectangle2D bounds = font.getStringBounds(s, frc); mClipShape = gv.getOutline((d.width - (float) bounds.getWidth()) / 2, (d.height + (float) bounds.getHeight()) / 2); } g2.clip(mClipShape); }
From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java
protected void drawMessageBox(Graphics2D g2d, String message, int x, int y, int w, int h) { drawEdgedBox(g2d, x, y, w, h);// w ww . j a va 2 s. c o m if (message == null) { message = "null"; } /* * Padding... */ x += KBConfiguration.OHD_padding; y += KBConfiguration.OHD_padding; w -= KBConfiguration.OHD_padding; h -= KBConfiguration.OHD_padding; g2d.setFont(KBConfiguration.OHD_messageBoxFont); g2d.setColor(KBConfiguration.OHD_fontBoxColor); FontMetrics fm = g2d.getFontMetrics(); int fontHeight = KBConfiguration.OHD_messageBoxFont.getSize(); int yOffset = y; String[] lines = message.split("\n"); for (int j = 0; j < lines.length; j++) { String[] words = lines[j].split(" "); String line = ""; for (int i = 0; i < words.length; i++) { String testLine = new String(line + " " + words[i]); Rectangle2D testRectangle = fm.getStringBounds(testLine, g2d); if (testRectangle.getWidth() > w) { conditionalWrite(g2d, line, x, yOffset + fontHeight, y + h); line = words[i]; yOffset += fontHeight; } else { line = testLine; } } conditionalWrite(g2d, line, x, yOffset + fontHeight, y + h); yOffset += (fontHeight + KBConfiguration.OHD_lineSpacing); } }
From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java
protected void drawTitledMessageBox(Graphics2D g2d, String title, String message, int x, int y, int w, int h) { /* Do some calculations and init variables. */ g2d.setFont(KBConfiguration.OHD_messageBoxFont); FontMetrics fm = g2d.getFontMetrics(); int labelHeight = KBConfiguration.OHD_messageBoxFont.getSize() + (KBConfiguration.OHD_padding * 2); int angling = labelHeight; Rectangle2D testRectangle = fm.getStringBounds(title, g2d); int labelWidth = (int) testRectangle.getWidth(); if (w < labelWidth + (2 * angling)) { w = labelWidth + (2 * angling);/*w w w .j a va2 s. c o m*/ } y += labelHeight; /* Now draw the box... */ drawMessageBox(g2d, message, x, y, w, h); /* Draw the label background */ g2d.setColor(KBConfiguration.OHD_labelBoxColor); GeneralPath label = new GeneralPath(); label.moveTo(x, y); label.lineTo(x + angling, y - labelHeight); label.lineTo(x + angling + labelWidth, y - labelHeight); label.lineTo(x + (angling * 2) + labelWidth, y); label.closePath(); g2d.fill(label); /* Draw the label Lines.. */ g2d.setColor(KBConfiguration.OHD_borderBoxTopLeft); g2d.drawLine(x, y, x + angling, y - labelHeight); g2d.drawLine(x + angling, y - labelHeight, x + angling + labelWidth, y - labelHeight); g2d.setColor(KBConfiguration.OHD_borderBoxBottomRight); g2d.drawLine(x + angling + labelWidth, y - labelHeight, x + (angling * 2) + labelWidth, y); g2d.setColor(KBConfiguration.OHD_borderBoxBackground); g2d.drawLine(x + (angling * 2) + labelWidth, y, x, y); /*Then add the title... */ g2d.setColor(KBConfiguration.OHD_labelFontBoxColor); g2d.drawString(title, x + angling, y - KBConfiguration.OHD_padding); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.ColoredBlockContainer.java
/** * Disclaimer: this is a "works for me" implementation, and probably only works as long as the * items are arranged horizontally in exactly one line, since it brutally enforces the items to * be aligned vertically centered.//from w w w .j a va 2 s . c om */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { area = drawFill(g2, area); // check if we need to collect chart entities from the container EntityBlockParams ebp = null; StandardEntityCollection sec = null; if (params instanceof EntityBlockParams) { ebp = (EntityBlockParams) params; if (ebp.getGenerateEntities()) { sec = new StandardEntityCollection(); } } Rectangle2D contentArea = (Rectangle2D) area.clone(); contentArea = trimMargin(contentArea); drawBorder(g2, contentArea); contentArea = trimBorder(contentArea); contentArea = trimPadding(contentArea); Iterator iterator = getBlocks().iterator(); while (iterator.hasNext()) { Block block = (Block) iterator.next(); Rectangle2D bounds = block.getBounds(); // enforce vertically centered alignment double y = area.getY() + (area.getHeight() - bounds.getHeight()) / 2.0; Rectangle2D drawArea = new Rectangle2D.Double(bounds.getX() + area.getX(), y, bounds.getWidth(), bounds.getHeight()); Object r = block.draw(g2, drawArea, params); if (sec != null) { if (r instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) r; EntityCollection ec = ebr.getEntityCollection(); sec.addAll(ec); } } } BlockResult result = null; if (sec != null) { result = new BlockResult(); result.setEntityCollection(sec); } return result; }
From source file:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java
/** * Override this method because it gets called after the graphics clip * has been reset.//from w w w . j ava2s .c o m * TODO: We end up drawing the annotations twice. Figure something out to * only draw once. * * @param g2 the graphics * @param dataArea the data area */ public void drawOutline(Graphics2D g2, Rectangle2D dataArea) { super.drawOutline(g2, dataArea); Shape originalClip = g2.getClip(); double y = dataArea.getY(); Rectangle2D.Double newClip = new Rectangle2D.Double(dataArea.getX(), 0, dataArea.getWidth(), dataArea.getHeight() + y); g2.clip(newClip); drawAnnotations(g2, dataArea, null); g2.clip(originalClip); }
From source file:haven.Utils.java
static Coord textsz(Graphics g, String text) { java.awt.FontMetrics m = g.getFontMetrics(); java.awt.geom.Rectangle2D ts = m.getStringBounds(text, g); return (new Coord((int) ts.getWidth(), (int) ts.getHeight())); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.sbarcodes.BarcodeWrapper.java
public void draw(final Graphics2D g2, final Rectangle2D bounds) { final Graphics2D gr2 = (Graphics2D) g2.create(); try {/*from w ww .j a va 2 s. c om*/ gr2.clip(bounds); if (scale) { final Dimension size = barcode.getPreferredSize(); final double horzScale = bounds.getWidth() / size.getWidth(); final double vertScale = bounds.getHeight() / size.getHeight(); if (keepAspectRatio) { final double scale = Math.min(horzScale, vertScale); gr2.scale(scale, scale); } else { gr2.scale(horzScale, vertScale); } } barcode.draw(gr2, (int) bounds.getX(), (int) bounds.getY()); } catch (OutputException e) { logger.error("Unable to draw barcode element", e); } finally { gr2.dispose(); } }