1 package org.simantics.debug.graphical.model;
4 import java.awt.Graphics2D;
5 import java.awt.font.FontRenderContext;
6 import java.awt.geom.AffineTransform;
7 import java.awt.geom.Rectangle2D;
9 public class LabelContent extends Content {
10 public static final Font FONT = new Font("Arial", Font.PLAIN, 12);
11 public static final FontRenderContext FRC =
12 new FontRenderContext(new AffineTransform(), true, true);
13 public static final Rectangle2D MAX_BOUNDS = FONT.getMaxCharBounds(FRC);
14 public static final double FONT_HEIGHT = MAX_BOUNDS.getHeight();
15 public static double PADDING = 3.0;
20 public LabelContent(String[] labels) {
25 public void render(Graphics2D g) {
27 for(int i=0;i<labels.length;++i) {
28 g.drawString(labels[i], (float)textX, (float)(textY + i*FONT_HEIGHT));
32 public void setLabels(String[] labels) {
35 double maxWidth = 0.0;
36 for(String label : labels) {
37 Rectangle2D bounds = FONT.getStringBounds(label, FRC);
38 maxWidth = Math.max(maxWidth, bounds.getWidth());
41 textX = -0.5*maxWidth;
42 textY = -0.5*labels.length*FONT_HEIGHT + FONT_HEIGHT - MAX_BOUNDS.getMaxY();
44 radiusX = PADDING + 0.5*maxWidth;
45 radiusY = PADDING + 0.5*labels.length*FONT_HEIGHT;