EOS 2  1.1.0
Einfache Objektbasierte Sprache
Alternative.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.gui.structogram;
2 
3 import de.lathanda.eos.baseparser.AlternativeUnit;
4 import de.lathanda.eos.gui.diagram.Drawing;
5 import de.lathanda.eos.gui.diagram.Unit;
6 import de.lathanda.eos.gui.text.Text;
7 
15 public class Alternative extends Unit {
16  private final Sequence A; // true
17  private final Sequence B; // false
18  private final String label;
19  private final String yes = Text.LABEL.getString("Yes");
20  private final String no = Text.LABEL.getString("No");
21  private float condy;
22  private float condx;
23  private float textx;
24  private float texty;
25  private float yesx;
26  private float yesy;
27  private float nox;
28  private float noy;
29 
31  label = au.getLabel();
32  A = new Sequence(au.getThen());
33  B = new Sequence(au.getElse());
35  }
36 
37  @Override
38  public void layoutUnit(Drawing d) {
39  A.layout(d);
40  B.layout(d);
41  if (A.getWidth() < 2 * d.stringWidth(yes)) {
42  A.setWidth(2 * d.stringWidth(yes));
43  }
44  if (B.getWidth() < 2 * d.stringWidth(no)) {
45  B.setWidth(2 * d.stringWidth(no));
46  }
47  float textwidth = d.stringWidth(label);
48  float textheight = d.getHeight();
49  if (2 * textwidth > A.getWidth() + B.getWidth()) {
50  width = 2 * textwidth;
51  float diff = (width - A.getWidth() - B.getWidth()) / 2;
52  A.setWidth(A.getWidth() + diff);
53  B.setWidth(B.getWidth() + diff);
54  } else {
55  width = A.getWidth() + B.getWidth();
56  }
57  condy = (textheight * 2);
58  condx = A.getWidth();
59  B.setOffsetX(A.getWidth());
60  A.setOffsetY(condy);
61  B.setOffsetY(condy);
62  texty = d.getAscent();
63  textx = condx / 2 + width / 4 - textwidth / 2;
64  yesx = BORDER;
65  yesy = texty + textheight;
66  nox = width - BORDER - d.stringWidth(no);
67  noy = yesy;
68  height = condy + Math.max(A.getHeight(), B.getHeight());
69  }
70 
71  @Override
72  public void drawUnit(Drawing d) {
73  d.drawRect(0, 0, width, height);
74  d.drawString(label, textx, texty);
75  d.drawString(yes, yesx, yesy);
76  d.drawString(no, nox, noy);
77  d.drawLine(0, 0, condx, condy);
78  d.drawLine(condx, condy, width, 0);
79  A.draw(d);
80  B.draw(d);
81  }
82 
83  @Override
84  public void setWidth(float width) {
85  float diff = (width - this.width) / 2;
86  this.width = width;
87  condx += diff;
88  nox += 2 * diff;
89  textx += diff;
90  A.setWidth(A.getWidth() + diff);
91  B.setWidth(B.getWidth() + diff);
92  B.setOffsetX(A.getWidth());
93  }
94 }
float stringWidth(String text)
Definition: Drawing.java:111
void drawLine(float x1, float y1, float x2, float y2)
Definition: Drawing.java:138
void drawRect(float x, float y, float width, float height)
Definition: Drawing.java:211
void drawString(String text, float x, float y)
Definition: Drawing.java:148
final void layout(Drawing d)
Definition: Unit.java:50
final void draw(Drawing d)
Definition: Unit.java:29
void setOffsetY(float offsetY)
Definition: Unit.java:79
void setOffsetX(float offsetX)
Definition: Unit.java:63
static final float BORDER
Definition: Unit.java:13
ResourceBundle LABEL
Definition: Text.java:8
Impressum