private static final void drawShadowedStringCentered( final Graphics2D g2d, final String str, final double x, final double y, final Font font, final Paint paint, final double shadowOffset, final Paint shadowPaint) { g2d.setFont(font); final FontRenderContext frc = g2d.getFontRenderContext(); final Rectangle2D bounds = font.getStringBounds(str, frc); final LineMetrics metrics = font.getLineMetrics(str, frc); final double width = bounds.getWidth(); // The width of our text final float lineHeight = metrics.getHeight(); // Total line height final float ascent = metrics.getAscent(); // Top of text to baseline final double cx = (x + (0 - width) / 2); final double cy = (y + (0 - lineHeight) / 2 + ascent); if (shadowOffset > 0) { drawString(g2d, str, cx + shadowOffset, cy - shadowOffset, shadowPaint); drawString(g2d, str, cx + shadowOffset, cy + shadowOffset, shadowPaint); drawString(g2d, str, cx - shadowOffset, cy - shadowOffset, shadowPaint); drawString(g2d, str, cx - shadowOffset, cy + shadowOffset, shadowPaint); } drawString(g2d, str, cx, cy, paint); }
@Override public void paintEntity(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setFont(Main.getHandlerForElement(this).getFontHandler().getFont()); colorize(g2); // enable colors g2.setColor(fgColor); g2.fillOval(0, 0, getRectangle().width, getRectangle().height); // Measure the font and the message Rectangle2D bounds = Main.getHandlerForElement(this) .getFontHandler() .getFont() .getStringBounds("H", g2.getFontRenderContext()); LineMetrics metrics = Main.getHandlerForElement(this) .getFontHandler() .getFont() .getLineMetrics("H", g2.getFontRenderContext()); float width = (float) bounds.getWidth(); // The width of our text float lineheight = metrics.getHeight(); // Total line height float ascent = metrics.getAscent(); // Top of text to baseline // Now display the message centered horizontally and vertically in this float x0 = (getRectangle().width - width) / 2; float y0 = (getRectangle().height - lineheight) / 2 + ascent; g2.setColor(Color.WHITE); g2.drawString("H", x0, y0); g2.setColor(fgColor); }
/** * @see org.jfree.chart.axis.Axis#refreshTicks(java.awt.Graphics2D, java.awt.geom.Rectangle2D, * java.awt.geom.Rectangle2D, int) */ public void refreshTicks( Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, int location) { // getTicks().clear(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); double size = getTickUnit().getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); if (count <= ValueAxis.MAXIMUM_TICK_COUNT) { for (int i = 0; i < count; i++) { double currentTickValue = lowestTickValue + (i * size); double yy = translateValueToJava2D(currentTickValue, dataArea, RectangleEdge.BOTTOM); String tickLabel; NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue); } else { tickLabel = valueToString(currentTickValue); } FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D tickLabelBounds = tickLabelFont.getStringBounds(longestStr, frc); LineMetrics lm = tickLabelFont.getLineMetrics(tickLabel, frc); float x = (float) (dataArea.getX() - tickLabelBounds.getWidth() - getTickLabelInsets().right); float y = (float) (yy + (lm.getAscent() / 2)); // Tick tick = new Tick(new Double(currentTickValue), tickLabel, x, y); // getTicks().add(tick); } } }
/* * Test method for 'java.awt.FontMetrics.getStringBounds(char[], int, int, Graphics)' */ public final void testGetStringBoundsCharArrayIntIntGraphics() { String str = "toremove-This is a very long string for getting bounds!-toremove"; char[] chars = str.toCharArray(); int width = 237; Rectangle2D rect = fm.getStringBounds(chars, 9, 55, g); LineMetrics lm = fm.getLineMetrics(" ", g); assertNotNull(rect); assertEquals(rect, new Rectangle2D.Float(0, -lm.getAscent(), width, lm.getHeight())); try { rect = fm.getStringBounds(chars, 10, 155, g); fail( "IndexOutOfBoundsException wasn't thrown, when end index is more than count of elements in CharacterIterator"); } catch (IndexOutOfBoundsException e) { // expected } try { rect = fm.getStringBounds(chars, -1, 55, g); fail("IndexOutOfBoundsException wasn't thrown, when initial offset < 0"); } catch (IndexOutOfBoundsException e) { // expected } try { rect = fm.getStringBounds(chars, 45, 40, g); fail("IndexOutOfBoundsException wasn't thrown, when end index is less than start index"); } catch (IndexOutOfBoundsException e) { // expected } }
/* * Test method for 'java.awt.FontMetrics.getStringBounds(String, int, int, Graphics)' */ public final void testGetStringBoundsStringIntIntGraphics() { String str = "toremove-This is a very long string for getting bounds!-toremove"; int width = 237; Rectangle2D rect = fm.getStringBounds(str, 9, 55, g); LineMetrics lm = fm.getLineMetrics(" ", g); assertNotNull(rect); assertEquals(rect, new Rectangle2D.Float(0, -lm.getAscent(), width, lm.getHeight())); try { rect = fm.getStringBounds(str, 10, 65, g); fail( "IndexOutOfBoundsException wasn't thrown, when end index is more than number of chars in string"); } catch (IndexOutOfBoundsException e) { // expected } try { rect = fm.getStringBounds(str, -1, 55, g); fail("IndexOutOfBoundsException wasn't thrown, when initial offset < 0"); } catch (IndexOutOfBoundsException e) { // expected } try { rect = fm.getStringBounds(str, 45, 10, g); fail("IndexOutOfBoundsException wasn't thrown, when end index is less than start index"); } catch (IndexOutOfBoundsException e) { // expected } }
/* * Test method for 'java.awt.FontMetrics.getStringBounds(String, Graphics)' */ public final void testGetStringBoundsStringGraphics() { String str = "This is a very long string for getting bounds!"; int width = 237; Rectangle2D rect = fm.getStringBounds(str, g); LineMetrics lm = fm.getLineMetrics(" ", g); assertNotNull(rect); assertEquals(new Rectangle2D.Float(0, -lm.getAscent(), width, lm.getHeight()), rect); }
void drawCenteredString(Graphics2D g2d, String string, int x0, int y0, float angle) { FontRenderContext frc = g2d.getFontRenderContext(); Rectangle2D bounds = g2d.getFont().getStringBounds(string, frc); LineMetrics metrics = g2d.getFont().getLineMetrics(string, frc); if (angle == 0) { g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2); } else { g2d.rotate(angle, x0, y0); g2d.drawString(string, x0 - (float) bounds.getWidth() / 2, y0 + metrics.getHeight() / 2); g2d.rotate(-angle, x0, y0); } }
/** * A utility method that draws a string inside a rectangle. * * @param g2 the graphics device. * @param bounds the rectangle. * @param font the font. * @param text the text. */ private void drawStringInRect(Graphics2D g2, Rectangle2D bounds, Font font, String text) { g2.setFont(font); FontMetrics fm = g2.getFontMetrics(font); Rectangle2D r = TextUtilities.getTextBounds(text, g2, fm); double x = bounds.getX(); if (r.getWidth() < bounds.getWidth()) { x = x + (bounds.getWidth() - r.getWidth()) / 2; } LineMetrics metrics = font.getLineMetrics(text, g2.getFontRenderContext()); g2.drawString( text, (float) x, (float) (bounds.getMaxY() - this.bottomInnerGap - metrics.getDescent())); }
/** * Returns the height of the band. * * @param g2 the graphics device. * @return The height of the band. */ public double getHeight(Graphics2D g2) { double result = 0.0; if (this.markers.size() > 0) { LineMetrics metrics = this.font.getLineMetrics("123g", g2.getFontRenderContext()); result = this.topOuterGap + this.topInnerGap + metrics.getHeight() + this.bottomInnerGap + this.bottomOuterGap; } return result; }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); // Draw ordinate. g2.draw(new Line2D.Double(Points, Points, Points, h - Points)); // Draw abcissa. g2.draw(new Line2D.Double(Points, h - Points, w - Points, h - Points)); // Draw labels. Font font = g2.getFont(); FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = font.getLineMetrics("0", frc); float sh = lm.getAscent() + lm.getDescent(); // Ordinate label. String s = "Strecke"; float sy = Points + ((h - 2 * Points) - s.length() * sh) / 2 + lm.getAscent(); for (int i = 0; i < s.length(); i++) { String letter = String.valueOf(s.charAt(i)); float sw = (float) font.getStringBounds(letter, frc).getWidth(); float sx = (Points - sw) / 2; g2.drawString(letter, sx, sy); sy += sh; } // Abcissa label. s = "Datum"; sy = h - Points + (Points - sh) / 2 + lm.getAscent(); float sw = (float) font.getStringBounds(s, frc).getWidth(); float sx = (w - sw) / 2; g2.drawString(s, sx, sy); // Draw lines. double xInc = (double) (w - 2 * Points) / (data.length - 1); double scale = (double) (h - 2 * Points) / getMax(); g2.setPaint(Color.green.darker()); for (int i = 0; i < data.length - 1; i++) { double x1 = Points + i * xInc; double y1 = h - Points - scale * data[i]; double x2 = Points + (i + 1) * xInc; double y2 = h - Points - scale * data[i + 1]; g2.draw(new Line2D.Double(x1, y1, x2, y2)); } // Mark data points. g2.setPaint(Color.red); for (int i = 0; i < data.length; i++) { double x = Points + i * xInc; double y = h - Points - scale * data[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } }
/** Method to repaint this ThreeDSideView. */ @Override public void paint(Graphics g) { Dimension dim = getSize(); g.setColor(Color.WHITE); g.fillRect(0, 0, dim.width, dim.height); g.setColor(Color.BLACK); g.drawLine(0, 0, 0, dim.height - 1); g.drawLine(0, dim.height - 1, dim.width - 1, dim.height - 1); g.drawLine(dim.width - 1, dim.height - 1, dim.width - 1, 0); g.drawLine(dim.width - 1, 0, 0, 0); String layerName = (String) dialog.threeDLayerList.getSelectedValue(); Layer selectedLayer = dialog.curTech.findLayer(layerName); for (Iterator<Layer> it = dialog.curTech.getLayers(); it.hasNext(); ) { Layer layer = it.next(); if (layer.isPseudoLayer()) continue; // if (!layer.isVisible()) continue; if (layer == selectedLayer) g.setColor(Color.RED); else g.setColor(Color.BLACK); GenMath.MutableDouble thickness = dialog.threeDThicknessMap.get(layer); GenMath.MutableDouble distance = dialog.threeDDistanceMap.get(layer); double dis = distance.doubleValue() + thickness.doubleValue() / 2; int yValue = dim.height - (int) ((dis - lowHeight) / (highHeight - lowHeight) * dim.height + 0.5); int yHeight = (int) (thickness.doubleValue() / (highHeight - lowHeight) * dim.height + 0.5); if (yHeight == 0) { g.drawLine(0, yValue, dim.width / 3, yValue); } else { // yHeight -= 4; int firstPart = dim.width / 6; int pointPos = dim.width / 4; g.drawLine(0, yValue - yHeight / 2, firstPart, yValue - yHeight / 2); g.drawLine(0, yValue + yHeight / 2, firstPart, yValue + yHeight / 2); g.drawLine(firstPart, yValue - yHeight / 2, pointPos, yValue); g.drawLine(firstPart, yValue + yHeight / 2, pointPos, yValue); g.drawLine(pointPos, yValue, dim.width / 3, yValue); } String string = layer.getName(); Font font = new Font(User.getDefaultFont(), Font.PLAIN, 9); g.setFont(font); FontRenderContext frc = new FontRenderContext(null, true, true); GlyphVector gv = font.createGlyphVector(frc, string); LineMetrics lm = font.getLineMetrics(string, frc); double txtHeight = lm.getHeight(); Graphics2D g2 = (Graphics2D) g; g2.drawGlyphVector( gv, dim.width / 3 + 1, (float) (yValue + txtHeight / 2) - lm.getDescent()); } }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); Font font = g2.getFont(); FontRenderContext frc = g2.getFontRenderContext(); float y = PAD; for (int j = 0; j < data.length; j++) { for (int k = 0; k < data[j].length; k++) { String s = data[j][k]; LineMetrics lm = font.getLineMetrics(s, frc); float x = PAD + offsets[j][k]; y += lm.getAscent(); g2.drawString(s, x, y); y += lm.getDescent(); } } }
/** * Draws a watermark that shows the version number if it is < 1.0 * * @param g2 the graphics context */ private void drawWatermark(Graphics2D g2) { if ("hide".equals(System.getProperty("info.gridworld.gui.watermark"))) return; g2 = (Graphics2D) g2.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Rectangle rect = getBounds(); g2.setPaint(new Color(0xE3, 0xD3, 0xD3)); final int WATERMARK_FONT_SIZE = 100; String s = resources.getString("version.id"); if ("1.0".compareTo(s) <= 0) return; g2.setFont(new Font("SansSerif", Font.BOLD, WATERMARK_FONT_SIZE)); FontRenderContext frc = g2.getFontRenderContext(); Rectangle2D bounds = g2.getFont().getStringBounds(s, frc); float centerX = rect.x + rect.width / 2; float centerY = rect.y + rect.height / 2; float leftX = centerX - (float) bounds.getWidth() / 2; LineMetrics lm = g2.getFont().getLineMetrics(s, frc); float baselineY = centerY - lm.getHeight() / 2 + lm.getAscent(); g2.drawString(s, leftX, baselineY); }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // int w = getWidth(); int h = getHeight(); if (selected) { g2.drawImage(open, PAD, 0, this); } else { g2.drawImage(closed, PAD, 0, this); } g2.setFont(font); FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = font.getLineMetrics(text, frc); float height = lm.getAscent() + lm.getDescent(); float x = OFFSET; float y = (h + height) / 2 - lm.getDescent(); g2.drawString(text, x, y); }
private double getFontHeight(FontRenderContext frc, Font font) { LineMetrics lm = font.getLineMetrics(DUMMY_TEXT, frc); return lm.getAscent() + lm.getDescent(); }
@SuppressWarnings("boxing") private boolean lmEquals(LineMetrics lm1, LineMetrics lm2) { assertEquals("Ascent", lm1.getAscent(), lm2.getAscent()); assertEquals("Baseline Index", lm1.getBaselineIndex(), lm2.getBaselineIndex()); float[] offsets = lm2.getBaselineOffsets(); assertNotNull(offsets); for (int i = 0; i < offsets.length; i++) { assertEquals("Baseline offset[" + i + "]", lm1.getBaselineOffsets()[i], offsets[i]); } assertEquals("Descent", lm1.getDescent(), lm2.getDescent()); assertEquals("Height", lm1.getHeight(), lm2.getHeight()); assertEquals("Leading", lm1.getLeading(), lm2.getLeading()); assertEquals("NumChars", lm1.getNumChars(), lm2.getNumChars()); assertEquals( "Strikethrough offset", lm1.getStrikethroughOffset(), lm2.getStrikethroughOffset()); assertEquals( "Strikethrough thickness", lm1.getStrikethroughThickness(), lm2.getStrikethroughThickness()); assertEquals("Underline offset", lm1.getUnderlineOffset(), lm2.getUnderlineOffset()); assertEquals("Underline thickness", lm1.getUnderlineThickness(), lm2.getUnderlineThickness()); return true; }
/** * Paint the strength curve(s). * * @param g0 java graphics context */ @Override protected void paintComponent(Graphics g0) { Graphics2D g = (Graphics2D) g0; final Stroke savedStroke = g.getStroke(); // Calculate font metrics one time. if (widthYLabel < 0) { FontRenderContext frc = g.getFontRenderContext(); Font font = Labeler.getFont(); LineMetrics metrics = font.getLineMetrics(longestYLabel, frc); widthYLabel = (float) font.getStringBounds(longestYLabel, frc).getWidth(); heightText = metrics.getAscent() + metrics.getDescent(); } // Clear background. int w = getWidth(); int h = getHeight(); g.setColor(Color.WHITE); g.fillRect(0, 0, w, h); // Draw the title. g.setColor(Color.BLACK); /* Labeler.drawJustified(g0, resourceMap.getString("title.text"), w/2, heightPad, Labeler.JUSTIFY_CENTER, Labeler.JUSTIFY_TOP, null); */ // Compute the plot area boundaries and sizes. yPlotAreaTop = Math.round(heightPad + heightText + labelTickSep + tickSize); yPlotAreaBottom = Math.round( h - 1 - heightPad - heightText - titleLabelSep - heightText - labelTickSep - tickSize); xPlotAreaLeft = Math.round(widthPad + heightText + titleLabelSep + widthYLabel + labelTickSep + tickSize); xPlotAreaRight = w - 1 - widthPad; heightPlotArea = yPlotAreaBottom - yPlotAreaTop; widthPlotArea = xPlotAreaRight - xPlotAreaLeft; // Draw the axes. g.drawLine(xPlotAreaLeft, yPlotAreaBottom + tickSize, xPlotAreaLeft, yPlotAreaTop - tickSize); g.drawLine( xPlotAreaLeft - tickSize, yPlotAreaBottom, xPlotAreaRight + tickSize, yPlotAreaBottom); // Decide what we are plotting and able to plot based on caller-provided data. boolean doShowAll = showAll && memberLists != null && memberLists.length > 0; boolean doShowOne = material != null && shape != null; // If we can't plot anything at all, we're done. if (!doShowAll && !doShowOne) { return; } // Find the maximum coordinate of the y-axis. yMax = 0; if (doShowAll) { for (int i = 0; i < memberLists.length; i++) { Member member = memberLists[i][0]; yMax = Math.max(yMax, Inventory.tensileStrength(member.getMaterial(), member.getShape())); } } if (doShowOne) { yMax = Math.max(yMax, Inventory.tensileStrength(material, shape)); } if (analysis != null && members != null) { for (int i = 0; i < members.length; i++) { yMax = Math.max(yMax, analysis.getMemberCompressiveForce(members[i].getIndex())); yMax = Math.max(yMax, analysis.getMemberTensileForce(members[i].getIndex())); } } // Determine the geometry of ticks and grid lines on the y-axis. Adjust y max upward to top of // scale. final double dyTick = getDivisionSize(yMax, (yPlotAreaBottom - yPlotAreaTop) / 50); final int nYTicks = (int) Math.ceil(yMax / dyTick); yMax = nYTicks * dyTick; // Draw ticks and labels on the y-axis. Keep track of actual label width so we can set the // title. int actualLabelWidth = 0; int ix = xPlotAreaLeft - tickSize - titleLabelSep; for (int i = 0; i <= nYTicks; i++) { double t = (double) i / nYTicks; double y = t * yMax; int iy = yPlotAreaBottom - (int) Math.round(t * heightPlotArea); if (i > 0) { g.setColor(Color.GRAY); g.setStroke(gridStroke); g.drawLine(xPlotAreaLeft, iy, xPlotAreaRight, iy); g.setStroke(savedStroke); } g.setColor(Color.BLACK); g.drawLine(xPlotAreaLeft, iy, xPlotAreaLeft - tickSize, iy); Labeler.drawJustified( g0, labelFormatter.format(y), ix, iy, Labeler.JUSTIFY_RIGHT, Labeler.JUSTIFY_CENTER, null, bounds); actualLabelWidth = Math.max(actualLabelWidth, bounds.width); } // Determine x-coordinate of the rotated y-axis title and draw it. ix -= (actualLabelWidth + titleLabelSep); Labeler.drawRotatedAndJustified( g0, resourceMap.getString("yAxisTitle.text"), 90, ix, (yPlotAreaBottom + yPlotAreaTop) / 2, Labeler.JUSTIFY_CENTER, Labeler.JUSTIFY_TOP, null, null, null); // Determine a good width and scale for the x-axis. For now just fix at 12. xMax = 12.0; // Not currently needed: final double dxTick = 1.0; final double nXTicks = 12; // Determine top of label coordinate and draw x-axis ticks and vertical grid lines. int iy = yPlotAreaBottom + tickSize + titleLabelSep; for (int i = 0; i <= nXTicks; i++) { double t = (double) i / nXTicks; double x = t * xMax; ix = xPlotAreaLeft + (int) Math.round(t * widthPlotArea); if (i > 0) { g.setColor(Color.GRAY); g.setStroke(gridStroke); g.drawLine(ix, yPlotAreaBottom, ix, yPlotAreaTop); g.setStroke(savedStroke); } g.setColor(Color.BLACK); g.drawLine(ix, yPlotAreaBottom, ix, yPlotAreaBottom + tickSize); Labeler.drawJustified( g0, labelFormatter.format(x), ix, iy, Labeler.JUSTIFY_CENTER, Labeler.JUSTIFY_TOP, null); } // Draw the x-axis title. iy += heightText + titleLabelSep; Labeler.drawJustified( g0, resourceMap.getString("xAxisTitle.text"), (xPlotAreaLeft + xPlotAreaRight) / 2, iy, Labeler.JUSTIFY_CENTER, Labeler.JUSTIFY_TOP, null); if (doShowAll) { for (int i = 0; i < memberLists.length; i++) { Member member = memberLists[i][0]; if (member.getMaterial() != material || member.getShape() != shape) { plot(g, member.getMaterial(), member.getShape(), true); } } } if (doShowOne) { if (members != null) { plotMemberLengths(g, members); } plot(g, material, shape, false); } }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); double xScale = (w - 2 * PAD) / (xMax - xMin); double yScale = (h - 2 * PAD) / (yMax - yMin); if (firstTime) System.out.printf("xScale = %.1f yScale = %.1f%n", xScale, yScale); Point2D.Double origin = new Point2D.Double(); // Axes origin. Point2D.Double offset = new Point2D.Double(); // Locate data. if (xMax < 0) { origin.x = w - PAD; offset.x = origin.x - xScale * xMax; } else if (xMin < 0) { origin.x = PAD - xScale * xMin; offset.x = origin.x; } else { origin.x = PAD; offset.x = PAD - xScale * xMin; } if (yMax < 0) { origin.y = h - PAD; offset.y = origin.y - yScale * yMax; } else if (yMin < 0) { origin.y = PAD - yScale * yMin; offset.y = origin.y; } else { origin.y = PAD; offset.y = PAD - yScale * yMin; } if (firstTime) { System.out.printf("origin = [%6.1f, %6.1f]%n", origin.x, origin.y); System.out.printf("offset = [%6.1f, %6.1f]%n", offset.x, offset.y); } // Draw abcissa. g2.draw(new Line2D.Double(PAD, origin.y, w - PAD, origin.y)); // Draw ordinate. g2.draw(new Line2D.Double(origin.x, PAD, origin.x, h - PAD)); g2.setPaint(Color.red); // Mark origin. g2.fill(new Ellipse2D.Double(origin.x - 2, origin.y - 2, 4, 4)); // Plot data. g2.setPaint(Color.blue); for (int i = 0; i < x.length; i++) { double x1 = offset.x + xScale * x[i]; double y1 = offset.y + yScale * y[i]; if (firstTime) System.out.printf("i = %d x1 = %6.1f y1 = %.1f%n", i, x1, y1); g2.fill(new Ellipse2D.Double(x1 - 2, y1 - 2, 4, 4)); g2.drawString(String.valueOf(i), (float) x1 + 3, (float) y1 - 3); } // Draw extreme data values. g2.setPaint(Color.black); Font font = g2.getFont(); FontRenderContext frc = g2.getFontRenderContext(); LineMetrics lm = font.getLineMetrics("0", frc); String s = String.format("%.1f", xMin); float width = (float) font.getStringBounds(s, frc).getWidth(); double x = offset.x + xScale * xMin; g2.drawString(s, (float) x, (float) origin.y + lm.getAscent()); s = String.format("%.1f", xMax); width = (float) font.getStringBounds(s, frc).getWidth(); x = offset.x + xScale * xMax; g2.drawString(s, (float) x - width, (float) origin.y + lm.getAscent()); s = String.format("%.1f", yMin); width = (float) font.getStringBounds(s, frc).getWidth(); double y = offset.y + yScale * yMin; g2.drawString(s, (float) origin.x + 1, (float) y + lm.getAscent()); s = String.format("%.1f", yMax); width = (float) font.getStringBounds(s, frc).getWidth(); y = offset.y + yScale * yMax; g2.drawString(s, (float) origin.x + 1, (float) y); if (firstTime) System.out.println("------------------------------"); firstTime = false; }
public double getDescent() { final LineMetrics fm = TextBlockUtils.getLineMetrics(font.getFont(), text); final double descent = fm.getDescent(); return descent; }