From cd2f6fe4177b41ca0e9fb3596fa866a35543849f Mon Sep 17 00:00:00 2001 From: Bane Stojkovic Date: Thu, 13 Feb 2025 20:15:30 +0100 Subject: [PATCH] Loading files that contain lines with end arrows sometimes produces errors in the log and lines not to be loaded --- .../src/org/diylc/presenter/update.xml | 4 +++ .../diylc/components/connectivity/Line.java | 25 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml index 2b8dac4b..392f0f1a 100644 --- a/diylc/diylc-core/src/org/diylc/presenter/update.xml +++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml @@ -4486,6 +4486,10 @@ BUG_FIX Fixed null pointer exceptions when trying to add components to the layout in some cases + + BUG_FIX + Loading files that contain lines with end arrows sometimes produces errors in the log and lines not to be loaded + https://github.com/bancika/diy-layout-creator/releases diff --git a/diylc/diylc-library/src/org/diylc/components/connectivity/Line.java b/diylc/diylc-library/src/org/diylc/components/connectivity/Line.java index 4e6edf58..cb240bf0 100644 --- a/diylc/diylc-library/src/org/diylc/components/connectivity/Line.java +++ b/diylc/diylc-library/src/org/diylc/components/connectivity/Line.java @@ -60,9 +60,12 @@ public class Line extends AbstractLeadedComponent { private Size thickness = new Size(1d, SizeUnit.px); private Size arrowSize = new Size(5d, SizeUnit.px); private Polygon arrow = null; - private AffineTransform arrowTx = new AffineTransform(); private boolean arrowStart = false; - private boolean arrowEnd = false; + private boolean arrowEnd = false; + + @SuppressWarnings("unused") + @Deprecated + private transient AffineTransform arrowTx; @Override public void drawIcon(Graphics2D g2d, int width, int height) { @@ -95,13 +98,15 @@ public class Line extends AbstractLeadedComponent { Point2D startPoint = new Point2D.Double(first.getX(), first.getY()); Point2D endPoint = new Point2D.Double(second.getX(), second.getY()); + AffineTransform arrowPosTx = new AffineTransform(); + if (arrowStart) { - arrowTx.setToIdentity(); + arrowPosTx.setToIdentity(); double angle = Math.atan2(getControlPoint(1).getY() - getControlPoint(0).getY(), getControlPoint(1).getX() - getControlPoint(0).getX()); - arrowTx.translate(getControlPoint(0).getX(), getControlPoint(0).getY()); - arrowTx.rotate((angle + Math.PI / 2d)); + arrowPosTx.translate(getControlPoint(0).getX(), getControlPoint(0).getY()); + arrowPosTx.rotate((angle + Math.PI / 2d)); AffineTransform oldTx = g2d.getTransform(); - g2d.transform(arrowTx); + g2d.transform(arrowPosTx); g2d.fill(getArrow()); g2d.setTransform(oldTx); @@ -110,12 +115,12 @@ public class Line extends AbstractLeadedComponent { interpolate(startPoint, endPoint, getArrowSize().convertToPixels() * 0.9 / distance, startPoint); } if (arrowEnd) { - arrowTx.setToIdentity(); + arrowPosTx.setToIdentity(); double angle = Math.atan2(getControlPoint(1).getY() - getControlPoint(0).getY(), getControlPoint(1).getX() - getControlPoint(0).getX()); - arrowTx.translate(getControlPoint(1).getX(), getControlPoint(1).getY()); - arrowTx.rotate((angle - Math.PI / 2d)); + arrowPosTx.translate(getControlPoint(1).getX(), getControlPoint(1).getY()); + arrowPosTx.rotate((angle - Math.PI / 2d)); AffineTransform oldTx = g2d.getTransform(); - g2d.transform(arrowTx); + g2d.transform(arrowPosTx); g2d.fill(getArrow()); g2d.setTransform(oldTx);