EOS 2  1.1.0
Einfache Objektbasierte Sprache
TextUnit.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.gui.diagram;
2 
3 public class TextUnit extends Unit {
4  private String text;
5  private float x;
6  private float y;
7  private float textheight;
8  private float textwidth;
9  private float ascent;
10 
11  public TextUnit(String text) {
12  super();
13  if (text != null) {
14  this.text = text;
15  } else {
16  this.text = "\uFFFD";
17  }
18  }
19 
20  @Override
21  public void drawUnit(Drawing d) {
22  d.drawString(text, x, y);
23  }
24 
25  @Override
26  public void layoutUnit(Drawing d) {
27  textheight = d.getHeight();
28  textwidth = d.stringWidth(text);
29  ascent = d.getAscent();
30  height = textheight;
31  width = textwidth;
32  y = ascent;
33  x = 0;
34  }
35 
36  public void alignCentralX() {
37  x = (width - textwidth) / 2;
38  }
39 
40  public void alignLeft() {
41  x = 0;
42  }
43 
44  public void alignRight() {
45  x = width - textwidth;
46  }
47 
48  public void allignCentralY() {
49  y = (height - textheight) / 2 + ascent;
50  }
51 
52  public void alignTop() {
53  y = ascent;
54  }
55 
56  public void alignBottom() {
57  y = height - textheight + ascent;
58  }
59 }
float stringWidth(String text)
Definition: Drawing.java:111
void drawString(String text, float x, float y)
Definition: Drawing.java:148
Impressum