EOS 2  1.1.0
Einfache Objektbasierte Sprache
Property.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.gui.objectchart;
2 
3 import de.lathanda.eos.gui.diagram.Unit;
4 import de.lathanda.eos.gui.diagram.Drawing;
5 
11 public class Property extends Unit {
12  private String name;
13  private Unit value;
14  private float xEquals;
15  private float yLine;
16 
17  public Property(String name, Object data) {
19  value = Toolkit.formatValue(data);
20  if (name != null) {
21  this.name = name;
22  } else {
23  this.name = "\uFFFD";
24  }
25  }
26 
27  @Override
28  public void drawUnit(Drawing d) {
29  d.drawString(name, 0, yLine);
30  d.drawString("=", xEquals, yLine);
31  value.draw(d);
32  }
33 
34  @Override
35  public void layoutUnit(Drawing d) {
36  xEquals = d.stringWidth(name) + INDENT;
37  value.layout(d);
38  value.setOffsetX(xEquals + d.stringWidth("=") + INDENT);
39  yLine = d.getAscent();
40  this.height = Math.max(d.getHeight(), value.getHeight());
41  this.width = xEquals + INDENT + value.getWidth();
42  }
43 
44  public static float align(Drawing d, Iterable<Property> properties) {
45  float alignedValueWidth = 0;
46  float alignedXEquals = 0;
47  for (Property property : properties) {
48  if (alignedValueWidth < property.value.getWidth()) {
49  alignedValueWidth = property.value.getWidth();
50  }
51  if (alignedXEquals < property.xEquals) {
52  alignedXEquals = property.xEquals;
53  }
54  }
55  float alignedXValues = alignedXEquals + d.stringWidth("=") + INDENT;
56  float alignedWidth = alignedXValues + alignedValueWidth;
57  for (Property property : properties) {
58  property.xEquals = alignedXEquals;
59  property.value.setOffsetX(alignedXValues);
60  property.width = alignedWidth;
61  }
62  return alignedWidth;
63  }
64 }
float stringWidth(String text)
Definition: Drawing.java:111
void drawString(String text, float x, float y)
Definition: Drawing.java:148
static final float INDENT
Definition: Unit.java:12
Property(String name, Object data)
Definition: Property.java:17
static float align(Drawing d, Iterable< Property > properties)
Definition: Property.java:44
static Unit formatValue(Object value)
Definition: Toolkit.java:21
Impressum