List of usage examples for java.awt Graphics getFontMetrics
public FontMetrics getFontMetrics()
From source file:edu.ku.brc.specify.plugins.imgproc.ImageProcessorPanel.java
@Override public void paint(Graphics g) { ((Graphics2D) g).addRenderingHints(hints); super.paint(g); if (font == null) { font = (new JLabel()).getFont(); font = font.deriveFont(18.0f);/*from www .ja v a 2s.c o m*/ font = font.deriveFont(Font.BOLD); } String title = "Specify Image Processor"; g.setColor(new Color(32, 131, 155)); g.setFont(font); int w = g.getFontMetrics().stringWidth(title); int y = g.getFontMetrics().getHeight() - 5; int x = (getSize().width - w) / 2; g.drawString(title, x, y); }
From source file:org.deegree.portal.standard.wms.control.DynLegendListener.java
/** * takes in a HashMap holding the properties of the legend and returns the size of the legend to be * //from ww w. j a v a2 s . c o m * @param map * Hashmap holding the GetLegendGraphic properties * @return A rectangle holding the legend size */ private Rectangle calcLegendSize(HashMap<String, Object> map) { String[] layers = (String[]) map.get("NAMES"); String[] titles = (String[]) map.get("TITLES"); BufferedImage[] legs = (BufferedImage[]) map.get("IMAGES"); int w = 0; int h = 0; for (int i = 0; i < layers.length; i++) { h += legs[i].getHeight() + 5; if (separator != null && i < layers.length - 1) { h += separator.getHeight() + 5; } Graphics g = legs[i].getGraphics(); if (useLayerTitle && legs[i].getHeight() < maxNNLegendSize && !missing.contains(layers[i])) { Rectangle2D rect = g.getFontMetrics().getStringBounds(titles[i], g); g.dispose(); if ((rect.getWidth() + legs[i].getWidth()) > w) { w = (int) rect.getWidth() + legs[i].getWidth(); } } else { if (legs[i].getWidth() > w) { w = legs[i].getWidth(); } } } w += 20; return new Rectangle(w, h); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFHeaderColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w ww . j a v 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 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); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFNmTokenColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;// w w w .j av a2 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 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:VASSAL.build.module.map.LOS_Thread.java
/** * Writes text showing the range//from w ww . ja va 2 s. c o m * * @param range the range to display, in whatever units returned * by the {@link MapGrid} containing the thread */ public void drawRange(Graphics g, int range) { Point mapArrow = map.componentCoordinates(arrow); Point mapAnchor = map.componentCoordinates(anchor); g.setColor(Color.black); g.setFont(RANGE_FONT); final FontMetrics fm = g.getFontMetrics(); final StringBuilder buffer = new StringBuilder(); int dummy = range; while (dummy >= 1) { dummy = dummy / 10; buffer.append("8"); } if (buffer.length() == 0) { buffer.append("8"); } String rangeMess = Resources.getString("LOS_Thread.range"); int wid = fm.stringWidth(" " + rangeMess + " " + buffer.toString()); int hgt = fm.getAscent() + 2; int w = mapArrow.x - mapAnchor.x; int h = mapArrow.y - mapAnchor.y; int x0 = mapArrow.x + (int) ((wid / 2 + 20) * w / Math.sqrt(w * w + h * h)); int y0 = mapArrow.y + (int) ((hgt / 2 + 20) * h / Math.sqrt(w * w + h * h)); g.fillRect(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid, hgt); g.setColor(Color.white); g.drawString(rangeMess + " " + range, x0 - wid / 2 + fm.stringWidth(" "), y0 + hgt / 2); lastRangeRect = new Rectangle(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid + 1, hgt + 1); Point np = map.mapCoordinates(new Point(lastRangeRect.x, lastRangeRect.y)); lastRangeRect.x = np.x; lastRangeRect.y = np.y; lastRange = String.valueOf(range); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFUuidColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*from w w w . j av a 2s . 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 UUID) { UUID uuid = (UUID) value; str = uuid.toString(); } 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTZDateColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;// w w w .java2 s . 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 Calendar) { Calendar cal = (Calendar) value; str = CFLibXmlUtil.formatTZDate(cal); } 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTZTimeColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w w w . ja va 2s. 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 Calendar) { Calendar cal = (Calendar) value; str = CFLibXmlUtil.formatTZTime(cal); } 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:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTZTimestampColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*from w w w.ja v a 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 Calendar) { Calendar cal = (Calendar) value; str = CFLibXmlUtil.formatTZTimestamp(cal); } 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:net.sourceforge.msscodefactory.cflib.v2_1.CFLib.Swing.CFReferenceColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/* w ww . j a v a2 s . 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 ICFLibAnyObj) { ICFLibAnyObj anyObj = (ICFLibAnyObj) value; str = anyObj.getObjQualifiedName(); } 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); } }