From d238c521ea42a333b23e7a223abbf500311704cb Mon Sep 17 00:00:00 2001 From: Bjorn Pijnacker Date: Sat, 27 Feb 2021 09:30:21 +0100 Subject: [PATCH] fixed an issue where the spacing was decided by the first element and not the (vertically) largest --- .../erme/control/actions/AutoPositionAction.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java index ec3d2fe..ae1e378 100644 --- a/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java +++ b/src/main/java/nl/andrewlalis/erme/control/actions/AutoPositionAction.java @@ -78,11 +78,15 @@ public class AutoPositionAction extends AbstractAction { */ private void positionRelations(ArrayList orderList) { if (orderList.isEmpty()) return; - - int vertSpace = (int) orderList.get(0).getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight() + PADDING; + AtomicInteger vertSpace = new AtomicInteger(0); + orderList.forEach(r -> { + int height = (int) r.getViewModel().getBounds(diagramPanel.getGraphics2D()).getHeight(); + vertSpace.set(Math.max(vertSpace.get(), height)); + }); + vertSpace.addAndGet(PADDING); AtomicInteger vertPos = new AtomicInteger(MARGIN); orderList.forEach(r -> { - r.setPosition(new Point(MARGIN, vertPos.getAndAdd(vertSpace))); + r.setPosition(new Point(MARGIN, vertPos.getAndAdd(vertSpace.get()))); }); diagramPanel.centerModel();