MCPcopy Create free account
hub / github.com/Neop/mudmap2 / LegendEntryTitle

Class LegendEntryTitle

src/main/java/mudmap2/backend/legend/LegendEntryTitle.java:31–68  ·  view source on GitHub ↗

This legend item creates a title text label @author neop

Source from the content-addressed store, hash-verified

29 * @author neop
30 */
31public class LegendEntryTitle implements LegendEntry {
32
33 String title;
34
35 public LegendEntryTitle(String title) {
36 this.title = title;
37 }
38
39 @Override
40 public int getHeight(Graphics g) {
41 return g.getFontMetrics().getHeight();
42 }
43
44 @Override
45 public int getWidth(Graphics g) {
46 FontMetrics fm = g.getFontMetrics();
47 return fm.stringWidth(title);
48 }
49
50 @Override
51 public void renderGraphic(Graphics g, int sx, int sy, int width, int height) {
52 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
53 Graphics graphics = image.getGraphics();
54 ((Graphics2D) graphics).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
55
56 Font font = graphics.getFont();
57 graphics.setFont(font.deriveFont(Font.BOLD));
58
59 FontMetrics fm = graphics.getFontMetrics();
60
61 graphics.setColor(Color.black);
62 graphics.drawString(title, 0, fm.getAscent());
63 g.drawImage(image, sx, sy, null);
64
65 graphics.dispose();
66 }
67
68}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected