List of usage examples for java.awt FontMetrics getLeading
public int getLeading()
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFInt64ColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//w w w .j a va 2 s. c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Long) { Long val = (Long) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFDoubleColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w w w. j a va 2 s. c om } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Double) { Double val = (Double) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFFloatColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from ww w. j av a2s . c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Float) { Float val = (Float) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFUInt64ColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*from w w w . j av a 2 s. com*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof BigDecimal) { BigDecimal val = (BigDecimal) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTimeColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from ww w . j av a2 s. c om } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Calendar) { Calendar cal = (Calendar) value; Format fmt = getDefaultFormat(); Calendar withoutDate = Calendar.getInstance(); withoutDate.clear(); withoutDate.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY)); withoutDate.set(Calendar.MINUTE, cal.get(Calendar.MINUTE)); withoutDate.set(Calendar.SECOND, cal.get(Calendar.SECOND)); str = fmt.format(withoutDate.getTime()); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }
From source file:Main.java
public void paint(Graphics g) { g.setFont(new Font("SansSerif", Font.BOLD, 12)); FontMetrics fm = g.getFontMetrics(); g.drawString("Current font: " + g.getFont(), 10, 40); g.drawString("Ascent: " + fm.getAscent(), 10, 55); g.drawString("Descent: " + fm.getDescent(), 10, 70); g.drawString("Height: " + fm.getHeight(), 10, 85); g.drawString("Leading: " + fm.getLeading(), 10, 100); Font font = new Font("Serif", Font.ITALIC, 14); fm = g.getFontMetrics(font);//from w w w . j a v a 2 s .c o m g.setFont(font); g.drawString("Current font: " + font, 10, 130); g.drawString("Ascent: " + fm.getAscent(), 10, 145); g.drawString("Descent: " + fm.getDescent(), 10, 160); g.drawString("Height: " + fm.getHeight(), 10, 175); g.drawString("Leading: " + fm.getLeading(), 10, 190); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFNumberColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*from w w w . j a v a 2 s .c om*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof BigDecimal) { BigDecimal val = (BigDecimal) value; Format fmt = getNumberFormat(digits, precis); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFBoolColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/* w ww. j a v a 2 s. co m*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); int xoffbox = (bounds.width - 16) / 2; int yoffbox = (bounds.height - 16) / 2; g.drawRect(xoffbox, yoffbox, 16, 16); Boolean useval; if (value instanceof Boolean) { useval = (Boolean) value; } else if (value instanceof String) { String s = (String) value; if (s.equals("true")) { useval = new Boolean(true); } else if (s.equals("false")) { useval = new Boolean(false); } else { useval = null; } } else { useval = null; } String str; if (useval == null) { str = "?"; } else if (useval.booleanValue()) { str = "X"; } else { str = null; } if (str != null) { FontMetrics fm = g.getFontMetrics(); Rectangle sb = fm.getStringBounds(str, g).getBounds(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int sxoff = xoffbox + ((16 - sb.width) / 2); int syoff = yoffbox + ((16 - (leading + ascent)) / 2) + leading + ascent; g.drawString(str, sxoff, syoff); } }
From source file:metrics.java
License:asdf
public void paint(Graphics g) { g.translate(100, 100);/*from ww w . ja va 2s .c om*/ FontMetrics fm = null; int ascent, descent, leading, width1, width2, height; String string1 = "dsdas"; String string2 = "asdf"; int xPos = 25, yPos = 50; fm = g.getFontMetrics(); ascent = fm.getAscent(); descent = fm.getDescent(); leading = fm.getLeading(); height = fm.getHeight(); width1 = fm.stringWidth(string1); width2 = fm.stringWidth(string2); g.drawString(string1, xPos, yPos); g.drawLine(xPos, yPos - ascent - leading, xPos + width1, yPos - ascent - leading); g.drawLine(xPos, yPos - ascent, xPos + width1, yPos - ascent); g.drawLine(xPos, yPos, xPos + width1, yPos); g.drawLine(xPos, yPos + descent, xPos + width1, yPos + descent); g.drawString(string2, xPos, yPos + height); g.drawLine(xPos, yPos - ascent - leading + height, xPos + width2, yPos - ascent - leading + height); g.drawLine(xPos, yPos - ascent + height, xPos + width2, yPos - ascent + height); g.drawLine(xPos, yPos + height, xPos + width2, yPos + height); g.drawLine(xPos, yPos + descent + height, xPos + width2, yPos + descent + height); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFHeaderColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*from w w w. j a v a 2s . co m*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int width = fm.stringWidth(firstLine); int x = (bounds.width - width) / 2; int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, x, leading + ascent + 4); } }