Skip to content

Commit

Permalink
Take the default values for the spinput configuration from CaGe.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
nvcleemp committed Apr 1, 2015
1 parent e765b58 commit 4a4558c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
12 changes: 11 additions & 1 deletion CaGe.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions cage/CaGe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
16 changes: 12 additions & 4 deletions cage/writer/SpinputWriterConfigurationHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cage.writer;

import cage.CaGe;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
Expand Down Expand Up @@ -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<SpinputWriterConfigurationModelListener> listeners =
new ArrayList<>();
Expand Down

0 comments on commit 4a4558c

Please sign in to comment.