diff --git a/CaGe.ini b/CaGe.ini index e4251ef..c5924a8 100644 --- a/CaGe.ini +++ b/CaGe.ini @@ -239,4 +239,14 @@ RasmolViewer.Title: Rasmol # is to be checked for questions requiring a user response RasmolViewer.WatchInterval: 500 - +# Spinput writer configuration +# if the following property is set to true, then all vertices +# are of the same element type +Spinput.UseSingleElement: false +# if the property above is true, then the following two properties +# specify the specific element to use for each vertex +Spinput.ElementNumber: 6 +Spinput.ElementName: C +# the next property specify the scaling that needs to be done. +# Each coordinate will be multiplied with this factor. +Spinput.scaling: 1.0 \ No newline at end of file diff --git a/cage/CaGe.java b/cage/CaGe.java index 8ba12a5..4247b62 100644 --- a/cage/CaGe.java +++ b/cage/CaGe.java @@ -225,6 +225,10 @@ public static String getCaGeProperty(String name) { return config.getProperty(name); } + public static String getCaGeProperty(String name, String defaultValue) { + return config.getProperty(name, defaultValue); + } + public static int getCaGePropertyAsInt(String name, int defaultValue) { int intValue = defaultValue; try { @@ -238,6 +242,19 @@ public static int getCaGePropertyAsInt(String name, int defaultValue) { return intValue; } + public static float getCaGePropertyAsFloat(String name, float defaultValue) { + float floatValue = defaultValue; + try { + String stringValue = config.getProperty(name); + floatValue = Float.parseFloat(stringValue); + } catch (NullPointerException e) { + System.err.println("Property '" + name + "' not present in .ini file"); + } catch (NumberFormatException e) { + System.err.println("Property '" + name + "' in .ini file is not a number"); + } + return floatValue; + } + public static boolean getCaGePropertyAsBoolean(String name, boolean defaultValue) { boolean booleanValue = defaultValue; diff --git a/cage/writer/SpinputWriterConfigurationHandler.java b/cage/writer/SpinputWriterConfigurationHandler.java index b99aeac..25dc8e3 100644 --- a/cage/writer/SpinputWriterConfigurationHandler.java +++ b/cage/writer/SpinputWriterConfigurationHandler.java @@ -1,5 +1,6 @@ package cage.writer; +import cage.CaGe; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; @@ -54,11 +55,18 @@ public void configureWriter(CaGeWriter writer) { } private static class SpinputWriterConfigurationModel { - private boolean useSingleElementRule = false; - private int singleElementNumber = 6; - private String singleElementName = "C"; + private boolean useSingleElementRule; + private int singleElementNumber; + private String singleElementName; - private float scalingFactor = 1.0f; + private float scalingFactor; + + public SpinputWriterConfigurationModel() { + useSingleElementRule = CaGe.getCaGePropertyAsBoolean("Spinput.UseSingleElement", false); + singleElementNumber = CaGe.getCaGePropertyAsInt("Spinput.ElementNumber", 6); + singleElementName = CaGe.getCaGeProperty("Spinput.ElementName", "C"); + scalingFactor = CaGe.getCaGePropertyAsFloat("Spinput.scaling", 1.0f); + } private final List listeners = new ArrayList<>();