int textHeight = graphics.getFontMetrics().getHeight() - graphics.getFontMetrics().getMaxDescent(); Point imageLocation = new Point(textLocation.getX() - width / 2 - 1, textLocation.getY() - textHeight / 2 - clanchatImage.getHeight() / 2); OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage);
prefSize.height += (fm.getMaxAscent() + fm.getMaxDescent());
int txtH = fm.getMaxAscent() + fm.getMaxDescent(); Insets ins = r.getInsets(); txtY = (txtH + ins.top + ((availH / 2) - (txtH / 2))) - fm.getMaxDescent(); } else if (r.getHeight() > txtH) { txtY = txtH + (rHeight - txtH) / 2 - fm.getMaxDescent(); } else {
public PMSimpleLabel(String s, FontMetrics fm, Color c) { string = s; this.fm = fm; width = fm.stringWidth(string); height = fm.getHeight(); descent = fm.getMaxDescent(); color = c; }
public void setString(String s) { string = s; // The width use to just be the stringWidth, but this // sometimes caused cropping when setString was called. // The value of 140% was chosen by trial and error, and // may be incorrect. In fact, this whole fix is // basically a kludge, since I don't know why it // is needed. width = (int) Math.ceil(fm.stringWidth(string) * 1.4); height = fm.getHeight(); descent = fm.getMaxDescent(); }
@Override public void drawInto(Graphics g) { if (!visible) return; Color temp = g.getColor(); g.setColor(color); g.drawString(string, x - width / 2, y - fm.getMaxDescent()); g.setColor(temp); }
private int centralizeTextY(String text, int y, int h) { FontMetrics fm = screen.getFontMetrics(); int ascent = fm.getMaxAscent(); int descent= fm.getMaxDescent(); int dy = y+h/2 - descent/2 + ascent/2; return dy; }
public static void draw(final Graphics g, final int startX, final int startY, final String... lines){ final FontMetrics metrics = g.getFontMetrics(); final int spacing = metrics.getHeight() + metrics.getMaxDescent(); draw(g, startX, startY, spacing, lines); } public static void draw(final Graphics g, final int startX, final int startY, final int vSpacing, final String... lines){ int y = startY; for(final String line : lines){ g.drawString(line, startX, y); y += vSpacing; } }
private int centralizeTextY(String text, int y, int h) { FontMetrics fm = screen.getFontMetrics(); int ascent = fm.getMaxAscent(); int descent = fm.getMaxDescent(); int dy = y + h / 2 - descent / 2 + ascent / 2; return dy; }
@Override public Dimension getPreferredSize() { if (componentWidth == 0 && textInLines == null) { componentWidth = getViewportWidth(); textInLines = text2Lines(componentWidth); realNumLines = textInLines.size(); } return new Dimension(componentWidth, realNumLines * FM.getHeight() + FM.getMaxDescent()); }
/** * En fonction de <code>_g</code>, renvoie la hauteur de la Font <code>FONTBASE</code>. */ private static int getHauteurFONTBASE(final Graphics _g){ _g.setFont(FONTBASE); final FontMetrics metric = _g.getFontMetrics(); return metric.getMaxAscent() + metric.getMaxDescent() + metric.getLeading(); }
public int lineToBottomY(int line) { FontMetrics fm = painter.getFontMetrics(); return (line - firstLine) * fm.getHeight() + (fm.getLeading()+ fm.getAscent()+ fm.getMaxDescent()); }
/** * Converts a line index to a y co-ordinate. * @param line The line */ public int lineToY(int line) { FontMetrics fm = painter.getFontMetrics(); return (line - firstLine) * fm.getHeight() - (fm.getLeading() + fm.getMaxDescent()); } public int lineToBottomY(int line)
/** Calculate the height of rows based on the current font. This is * done when the first paint occurs, to ensure that a valid Graphics * object is available. * @since 1.25 */ private void calcRowHeight(Graphics g) { Font f = getFont(); FontMetrics fm = g.getFontMetrics(f); int rowHeight = fm.getHeight() + fm.getMaxDescent(); needCalcRowHeight = false; rowHeight = Math.max(20, rowHeight); tree.setRowHeight (rowHeight); setRowHeight(rowHeight); }
@Override public Dimension getPreferredSize() { FontMetrics fm = getFontMetrics(getFont()); Rectangle2D renderingBounds = fm.getStringBounds(rendering, getGraphics()); int prefWidth = 2 + (int) renderingBounds.getWidth(); if(parentArrowVisible) { prefWidth += PARENT_ARROW_BOX_WIDTH; } int prefTextHeight = fm.getMaxAscent() + fm.getMaxDescent() + fm.getLeading(); return new Dimension(prefWidth, prefTextHeight); }
private void setupFontMetrics() { _fm_small = _owner.getFontMetrics( _small_font ); _fm_large = _owner.getFontMetrics( _large_font ); _small_max_descent = _fm_small.getMaxDescent(); _small_max_ascent = _fm_small.getMaxAscent() + 1; }
/** * Marks a line as needing a repaint. * @param line The line to invalidate */ public final void invalidateLine(int line) { repaint(0,textArea.lineToY(line) + fm.getMaxDescent() + fm.getLeading(), getWidth(),fm.getHeight()); }
/** * Marks a range of lines as needing a repaint. * @param firstLine The first line to invalidate * @param lastLine The last line to invalidate */ public final void invalidateLineRange(int firstLine, int lastLine) { repaint(0,textArea.lineToY(firstLine) + fm.getMaxDescent() + fm.getLeading(), getWidth(),(lastLine - firstLine + 1) * fm.getHeight()); }
/** * Marks a line as needing a repaint. * @param line The line to invalidate */ public final void invalidateLine(int line) { repaint(0,textArea.lineToY(line) + fm.getMaxDescent() + fm.getLeading(), getWidth(),fm.getHeight()); }
/** * Marks a range of lines as needing a repaint. * @param firstLine The first line to invalidate * @param lastLine The last line to invalidate */ public final void invalidateLineRange(int firstLine, int lastLine) { repaint(0,textArea.lineToY(firstLine) + fm.getMaxDescent() + fm.getLeading(), getWidth(),(lastLine - firstLine + 1) * fm.getHeight()); }