Skip to content

Commit 612b67d

Browse files
committed
if-cases fixed
1 parent e214d53 commit 612b67d

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

src/UI/BranchData.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class BranchData {
2+
public int x;
3+
public int y;
4+
public int width;
5+
public int height;
6+
7+
public BranchData(int x, int y) {
8+
this.x = x;
9+
this.y = y;
10+
}
11+
12+
public BranchData(int x, int y, int width) {
13+
this(x, y);
14+
this.width = width;
15+
}
16+
17+
public BranchData(int x, int y, int width, int height) {
18+
this(x, y, width);
19+
this.height = height;
20+
}
21+
22+
public int nextX() {
23+
return x + width;
24+
}
25+
26+
public int nextY() {
27+
return y + height;
28+
}
29+
}

src/UI/Flowduino.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void createProgramViewFromNode(Node n) {
238238
root.getChildren().add(scrollPane);
239239
maxX = 0;
240240
maxY = 0;
241-
createProgramViewFromNodeRecursively(n, 50, 125, true);
241+
createProgramViewFromNodeRecursively(n, 50, 50, true);
242242
updateProgramViewSize();
243243

244244
System.out.println("----------------------------");
@@ -248,14 +248,15 @@ public void createProgramViewFromNode(Node n) {
248248

249249
private int maxX;
250250
private int maxY;
251-
public Point createProgramViewFromNodeRecursively(Node n, int x, int y, boolean first) {
251+
public BranchData createProgramViewFromNodeRecursively(Node n, int x, int y, boolean first) {
252+
BranchData thisBranch = new BranchData(x, y, 0, 75);
252253
if (first) {
253-
Rectangle r = insertDropTargetAtPosWithSize(x, y - 75, 50, 25);
254+
Rectangle r = insertDropTargetAtPosWithSize(x, y, 50, 25);
254255
targetNodeMap.put(r, n);
255256
targetFirstMap.put(r, true);
256257
}
257258
if (n.getComponent() == null) {
258-
return new Point(x, y);
259+
return new BranchData(x, y, 0, 75);
259260
}
260261
if (n.getComponent().getClass() == DelayComponent.class) {
261262
// draw delay
@@ -267,29 +268,28 @@ public Point createProgramViewFromNodeRecursively(Node n, int x, int y, boolean
267268
// draw loop
268269
// draw extra targets
269270
Loop loop = (Loop)n.getComponent();
270-
Point loopSize = createProgramViewFromNodeRecursively(loop.getHeadOfContent(), x, y + 75, true);
271-
y = loopSize.y;
271+
BranchData loopSize = createProgramViewFromNodeRecursively(loop.getHeadOfContent(), thisBranch.x, thisBranch.nextY(), true);
272+
thisBranch.width = loopSize.width;
273+
thisBranch.height = loopSize.height + 75;
272274
} else if (n.getComponent().getClass() == IfComponent.class) {
273275
// draw if
274276
IfComponent ifComponent = (IfComponent)n.getComponent();
275-
Point ifSize = new Point(x, y);
276277
for (Node ifNode : ifComponent.getHeadOfContents()) {
277-
Point ifNodeSize = createProgramViewFromNodeRecursively(ifNode, ifSize.x, y + 75, true);
278-
ifSize.x = Math.max(ifNodeSize.x + 100, ifSize.x);
279-
ifSize.y = Math.max(ifNodeSize.y, ifSize.y);
278+
BranchData ifNodeSize = createProgramViewFromNodeRecursively(ifNode, thisBranch.nextX(), thisBranch.y + 75, true);
279+
thisBranch.width += ifNodeSize.width + 100;
280+
thisBranch.height = Math.max(ifNodeSize.height + 75, thisBranch.height);
280281
}
281-
y = ifSize.y;
282+
thisBranch.width -= 100;
282283
}
283284
// make target for after
284-
Rectangle r = insertDropTargetAtPosWithSize(x, y, 50, 25);
285+
Rectangle r = insertDropTargetAtPosWithSize(thisBranch.x, thisBranch.nextY(), 50, 25);
285286
targetNodeMap.put(r, n);
286287
targetFirstMap.put(r, false);
287288
if (n.getNext() != null) {
288-
Point temp = createProgramViewFromNodeRecursively(n.getNext(), x, y + 75, false);
289-
x = temp.x;
290-
y = temp.y;
289+
BranchData temp = createProgramViewFromNodeRecursively(n.getNext(), thisBranch.x, thisBranch.nextY(), false);
290+
thisBranch.height += temp.height;
291291
}
292-
return new Point(x, y);
292+
return thisBranch;
293293
}
294294

295295
public void updateProgramViewSize() {

0 commit comments

Comments
 (0)