EOS 2  1.1.0
Einfache Objektbasierte Sprache
Sequence.java
gehe zur Dokumentation dieser Datei
1 package de.lathanda.eos.gui.flowchart;
2 
3 import java.util.ArrayList;
4 
5 import de.lathanda.eos.baseparser.ProgramSequence;
6 import de.lathanda.eos.gui.diagram.Drawing;
7 
14 public class Sequence extends ConnectedUnit {
15  private ArrayList<ConnectedUnit> units;
16 
17  Sequence(ProgramSequence programSequence) {
18  units = new ArrayList<>();
19  if (programSequence != null) {
20  programSequence.getInstructions().stream().forEachOrdered((n) -> {
21  units.add(Toolkit.create(n));
22  });
23  }
24  }
25 
26  @Override
27  public void drawUnit(Drawing d) {
28  float cx = width / 2;
29  float cy = 0;
30  ConnectedUnit previous = null;
31  for (ConnectedUnit u : units) {
32  if (previous == null) {
33  needsIncomingArrow = u.needsIncomingArrow;
34  } else if (!previous.neverEnds) {
35 
36  if (u.needsIncomingArrow) {
37  d.drawArrow(cx, cy, cx, cy + SPACE, 2);
38  } else {
39  d.drawLine(cx, cy, cx, cy + SPACE);
40  }
41  }
42  previous = u;
43  u.draw(d);
44  cy = u.getOffsetY() + u.getHeight();
45  }
46  if (previous != null) {
47  neverEnds = previous.neverEnds;
48  }
49  }
50 
51  @Override
52  public void layoutUnit(Drawing d) {
53  units.forEach(p -> p.layout(d));
54  float maxw = 0;
55  float h = 0;
56  for (ConnectedUnit u : units) {
57  if (maxw < u.getWidth()) {
58  maxw = u.getWidth();
59  }
60  u.setOffsetY(h);
61  h = h + u.getHeight() + SPACE;
62  }
63  height = h - SPACE;
64  width = maxw;
65  units.stream().forEach((u) -> {
66  u.centerX(width);
67  });
68  }
69 }
void drawLine(float x1, float y1, float x2, float y2)
Definition: Drawing.java:138
void drawArrow(float x1, float y1, float x2, float y2, float size)
Definition: Drawing.java:284
final void draw(Drawing d)
Definition: Unit.java:29
static final float SPACE
Definition: Unit.java:14
static ConnectedUnit create(ProgramNode n)
Definition: Toolkit.java:11
ArrayList< ProgramNode > getInstructions()
Impressum