From b8c8237ae40a58bb8d16a5936122075c99d38856 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 15 Dec 2018 12:21:42 -0500 Subject: [PATCH] [fixes #499] prevents an exception after coneverting-to-freeform --- .../rocketcomponent/FreeformFinSet.java | 20 +++++++++---------- .../configdialog/FreeformFinSetConfig.java | 3 ++- .../gui/util/CustomFinImporter.java | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java index 499b62181..99bc17bdf 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FreeformFinSet.java @@ -4,7 +4,6 @@ import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.slf4j.Logger; @@ -19,8 +18,9 @@ import net.sf.openrocket.util.Coordinate; public class FreeformFinSet extends FinSet { private static final Logger log = LoggerFactory.getLogger(FreeformFinSet.class); private static final Translator trans = Application.getTranslator(); - - private List points = new ArrayList<>(); + + // this class uses certain features of 'ArrayList' which are not implemented in other 'List' implementations. + private ArrayList points = new ArrayList<>(); private static final double SNAP_SMALLER_THAN = 1e-6; private static final double IGNORE_SMALLER_THAN = 1e-12; @@ -47,8 +47,8 @@ public class FreeformFinSet extends FinSet { public static FreeformFinSet convertFinSet(FinSet finset) { final RocketComponent root = finset.getRoot(); FreeformFinSet freeform; - List toInvalidate = Collections.emptyList(); - + List toInvalidate = new ArrayList<>(); + try { if (root instanceof Rocket) { ((Rocket) root).freeze(); @@ -67,7 +67,7 @@ public class FreeformFinSet extends FinSet { // Create the freeform fin set Coordinate[] finPoints = finset.getFinPoints(); freeform = new FreeformFinSet(); - freeform.setPoints(Arrays.asList(finPoints)); + freeform.setPoints(finPoints); freeform.setAxialOffset(finset.getAxialMethod(), finset.getAxialOffset()); // Copy component attributes @@ -130,7 +130,7 @@ public class FreeformFinSet extends FinSet { } // copy the old list in case the operation fails - List copy = new ArrayList<>(this.points); + ArrayList copy = new ArrayList<>(this.points); this.points.remove(index); if (!validate()) { @@ -163,15 +163,15 @@ public class FreeformFinSet extends FinSet { * * @param newPoints New points to set as the exposed edges of the fin */ - public void setPoints( List newPoints) { + public void setPoints( ArrayList newPoints) { // copy the old points, in case validation fails - List copy = new ArrayList<>(this.points); + ArrayList copy = new ArrayList<>(this.points); this.points = newPoints; this.length = newPoints.get(newPoints.size() -1).x; update(); -// StackTraceElement[] stacktrack = Thread.currentThread().getStackTrace(); + //StackTraceElement[] stacktrack = Thread.currentThread().getStackTrace(); if("Canard fins, mounted to transition".equals(this.getName())) { log.error(String.format("starting to set %d points @ %s", newPoints.size(), this.getName()), new NullPointerException()); System.err.println( toDebugDetail()); diff --git a/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java index dff8e0349..b81980537 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/FreeformFinSetConfig.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.util.ArrayList; import java.util.List; import javax.swing.JButton; @@ -337,7 +338,7 @@ public class FreeformFinSetConfig extends FinSetConfig { if (option == JFileChooser.APPROVE_OPTION) { try { CustomFinImporter importer = new CustomFinImporter(); - List points = importer.getPoints(chooser.getSelectedFile()); + ArrayList points = importer.getPoints(chooser.getSelectedFile()); document.startUndo(trans.get("CustomFinImport.undo")); finset.setPoints( points); } catch (IOException e) { diff --git a/swing/src/net/sf/openrocket/gui/util/CustomFinImporter.java b/swing/src/net/sf/openrocket/gui/util/CustomFinImporter.java index ae2f7bf42..290cc5892 100644 --- a/swing/src/net/sf/openrocket/gui/util/CustomFinImporter.java +++ b/swing/src/net/sf/openrocket/gui/util/CustomFinImporter.java @@ -24,7 +24,7 @@ public class CustomFinImporter { - public List getPoints(File file) throws IOException { + public ArrayList getPoints(File file) throws IOException { ArrayList points = new ArrayList(); BufferedImage pic = ImageIO.read(file);