]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.debug.graphical/src/org/simantics/debug/graphical/model/LabelContent.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.debug.graphical / src / org / simantics / debug / graphical / model / LabelContent.java
1 package org.simantics.debug.graphical.model;
2
3 import java.awt.Font;
4 import java.awt.Graphics2D;
5 import java.awt.font.FontRenderContext;
6 import java.awt.geom.AffineTransform;
7 import java.awt.geom.Rectangle2D;
8
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;
16     
17     String[] labels;
18     double textX, textY;
19     
20     public LabelContent(String[] labels) {
21         setLabels(labels);
22     }
23
24     @Override
25     public void render(Graphics2D g) {
26         g.setFont(FONT);
27         for(int i=0;i<labels.length;++i) {
28             g.drawString(labels[i], (float)textX, (float)(textY + i*FONT_HEIGHT));    
29         }        
30     }
31     
32     public void setLabels(String[] labels) {
33         this.labels = labels;
34
35         double maxWidth = 0.0;
36         for(String label : labels) {
37             Rectangle2D bounds = FONT.getStringBounds(label, FRC);
38             maxWidth = Math.max(maxWidth, bounds.getWidth());
39         }
40         
41         textX = -0.5*maxWidth;
42         textY = -0.5*labels.length*FONT_HEIGHT + FONT_HEIGHT - MAX_BOUNDS.getMaxY();
43         
44         radiusX = PADDING + 0.5*maxWidth;
45         radiusY = PADDING + 0.5*labels.length*FONT_HEIGHT;
46     }
47     
48 }