/** * Query the font height used in calculating line spacing. * * @return fontHeight to use to calculate line spacing. */ public int getFontHeight() { int retval = fontHeight; if (retval < 0) { final FontMetrics fontMetrics = getFontMetrics(getFont()); retval = fontMetrics.getHeight(); setFontHeight(retval); } return retval; }
private void measure() { FontMetrics fontmetrics = getFontMetrics(getFont()); if (fontmetrics == null) return; line_height = fontmetrics.getHeight(); line_ascent = fontmetrics.getAscent(); max_width = 0; for (int i = 0; i < num_lines; i++) { line_widths[i] = fontmetrics.stringWidth(lines[i]); if (line_widths[i] > max_width) max_width = line_widths[i]; } max_width += 2 * btnMarginWidth; max_height = num_lines * line_height + 2 * btnMarginHeight; }
/* * Determine the Y offset for the current row */ private int getOffsetY(int rowStartOffset, FontMetrics fontMetrics) throws BadLocationException { // Get the bounding rectangle of the row Rectangle r = component.modelToView(rowStartOffset); int lineHeight = fontMetrics.getHeight(); int y = r.y + r.height; int descent = 0; // The text needs to be positioned above the bottom of the bounding // rectangle based on the descent of the font(s) contained on the row. if (r.height == lineHeight) { // default font is being used descent = fontMetrics.getDescent(); } else { // We need to check all the attributes for font changes if (fonts == null) { fonts = new HashMap<String, FontMetrics>(); } Element root = component.getDocument().getDefaultRootElement(); int index = root.getElementIndex(rowStartOffset); Element line = root.getElement(index); for (int i = 0; i < line.getElementCount(); i++) { Element child = line.getElement(i); AttributeSet as = child.getAttributes(); String fontFamily = (String) as.getAttribute(StyleConstants.FontFamily); Integer fontSize = (Integer) as.getAttribute(StyleConstants.FontSize); String key = fontFamily + fontSize; FontMetrics fm = fonts.get(key); if (fm == null) { Font font = new Font(fontFamily, Font.PLAIN, fontSize); fm = component.getFontMetrics(font); fonts.put(key, fm); } descent = Math.max(descent, fm.getDescent()); } } return y - descent; }
/** Set the label text. */ private void setLabelText() { if (!active) { return; } StringBuffer buf = new StringBuffer(); buf.append(" "); buf.append(getRangeName()); buf.append(": "); buf.append(StringUtil.padLeft(rangeReadout.getNumericString(), 6)); buf.append(" "); buf.append(getBearingName()); buf.append(": "); buf.append(StringUtil.padLeft(bearingReadout.getNumericString(), 6)); String text = buf.toString(); valueDisplay.setText(text); if (myOwnLabel) { FontMetrics fm = valueDisplay.getFontMetrics(valueDisplay.getFont()); valueDisplay.setPreferredSize(new Dimension(fm.stringWidth(text), fm.getHeight())); } }
/** * Called to paint the outline. * * @param g graphics object to paint. */ public void paint(final Graphics g) { final FontMetrics fontMetrics = getFontMetrics(getFont()); setFontWidth(fontMetrics.stringWidth("_")); setFontHeight(fontMetrics.getHeight()); if (firstTime) { firstTime = false; setVisible("Outline".equalsIgnoreCase(djvuBean.properties.getProperty("navpane"))); } if (!isVisible()) { getParent().setVisible(false); invalidate(); djvuBean.recursiveRevalidate(); } else { synchronized (activeVector) { paintItem(0, g, getBookmark(0)); paintCheckbox(0, g, getBookmark(0)); } } }
public void draw( Graphics2D g, Color stringColor, Color foreground, Color background, String info, double x, double y) { FontMetrics fm = g.getFontMetrics(); int h = fm.getHeight(); int w = fm.stringWidth(info); r1.setRect( x - w / 2 - in.left, y - in.top - h / 2, w + in.right + in.left, h + in.bottom + in.top); g.setColor(background); g.fill(r1); g.setColor(stringColor); g.draw(r1); g.setColor(foreground); r2.setRect(r1.getX() + 1, r1.getY() + 1, r1.getWidth() - 2, r1.getHeight() - 2); g.draw(r2); g.setColor(stringColor); g.drawString( info, (float) (r2.getX() + in.left), (float) (r2.getY() + h - (r2.getHeight() - h) / 2)); }
private int getFontHeight() { return fmRef.getHeight(); }