Skip to content

Commit

Permalink
v1.93F Fixes
Browse files Browse the repository at this point in the history
Abstract data

Made the fields protected for easier access by subclasses

ExportManager

Introduced a current working directory field, so that the file chooser
keeps track of the browsing history.

Exporter

Fixed directory not updating after selection in the file chooser

NetzschCSVReader / PulseCSVReader

Added support to different locales (delimiter chars and decimal separator).

ReaderManager 

Importing all files in a directory (e.g. with Linseis format) now invokes
an Execution Service to take advantage of the concurrency.

Problem

It is now possible to select sample thickness as an optimisation variable.

NumericPropertyFormatter

Added missing condition to skip scientific formatting if html had been
disabled.

Normality tests

Minor fixes to logic

Status

Prevent status from updating to QUEUED when task is in progress or has
failed

Launcher

Removed pop-up exception windows completely, as this caused uncontrollable 
breeding of pop-up windows

Chart

Fixed value markers not taking into account the numerical conversion 
factor (ms -> s and vice versa). 

MouseOnMarkerListener

Fixed wrong concurrent updates of both value markers when switching statuses.

MainGraphFrame

Prevented tasks from plotting while being in progress. Avoids ConcurrentModificationException.

ExportDialog

Changed from Save dialog to Open dialog to avoid ambiguity

Other minors changes
  • Loading branch information
kotik-coder committed Dec 15, 2021
1 parent 4216825 commit 7b9081f
Show file tree
Hide file tree
Showing 25 changed files with 223 additions and 163 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>kotik-coder</groupId>
<artifactId>PULsE</artifactId>
<version>1.93</version>
<version>1.93F</version>
<name>PULsE</name>
<description>Processing Unit for Laser flash Experiments</description>
<developers>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pulse/AbstractData.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public abstract class AbstractData extends PropertyHolder {

private int count;

private List<Double> time;
private List<Double> signal;
protected List<Double> time;
protected List<Double> signal;

private String name;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pulse/input/ExperimentalData.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,14 @@ private void doSetRange() {
}

/**
* Retrieves the
* Retrieves the time limit.
*
* @see pulse.problem.schemes.DifferenceScheme
* @return a double, equal to the last element of the {@code time List}.
*/
@Override
public double timeLimit() {
return timeAt(indexRange.getUpperBound());
}
}

}
5 changes: 4 additions & 1 deletion src/main/java/pulse/io/export/ExportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*
*/
public class ExportManager {

//current working dir
private static File cwd = null;

private ExportManager() {
// intentionally blank
Expand Down Expand Up @@ -85,7 +88,7 @@ public static <T extends Descriptive> Exporter<T> findExporter(Class<T> target)
public static <T extends Descriptive> void askToExport(T target, JFrame parentWindow, String fileTypeLabel) {
var exporter = findExporter(target);
if (exporter != null) {
exporter.askToExport(target, parentWindow, fileTypeLabel);
cwd = exporter.askToExport(target, parentWindow, fileTypeLabel, cwd);
} else {
throw new IllegalArgumentException("No exporter for " + target.getClass().getSimpleName());
}
Expand Down
53 changes: 29 additions & 24 deletions src/main/java/pulse/io/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,11 @@ public default void export(T target, File directory, Extension extension) {
* @param target the exported target
* @param parentWindow the parent frame.
* @param fileTypeLabel the label describing the specific type of files that
* will be saved.
* @param directory the default directory of the file will be saved.
* @return the directory where files were exported
*/
public default void askToExport(T target, JFrame parentWindow, String fileTypeLabel) {
var fileChooser = new JFileChooser();
var workingDirectory = new File(System.getProperty("user.home"));
fileChooser.setCurrentDirectory(workingDirectory);
public default File askToExport(T target, JFrame parentWindow, String fileTypeLabel, File directory) {
var fileChooser = new JFileChooser(directory);
fileChooser.setMultiSelectionEnabled(true);

FileNameExtensionFilter choosable = null;
Expand All @@ -113,29 +112,35 @@ public default void askToExport(T target, JFrame parentWindow, String fileTypeLa
var file = fileChooser.getSelectedFile();
var path = file.getPath();

if (!(fileChooser.getFileFilter() instanceof FileNameExtensionFilter)) {
return;
}
directory = file.isDirectory() ? file : file.getParentFile();

var currentFilter = (FileNameExtensionFilter) fileChooser.getFileFilter();
var ext = currentFilter.getExtensions()[0];
if ((fileChooser.getFileFilter() instanceof FileNameExtensionFilter)) {

var currentFilter = (FileNameExtensionFilter) fileChooser.getFileFilter();
var ext = currentFilter.getExtensions()[0];

if (!path.contains(".")) {
file = new File(path + "." + ext);
} else {
file = new File(path.substring(0, path.indexOf(".") + 1) + ext);
}

try {
var fos = new FileOutputStream(file);
printToStream(target, fos, Extension.valueOf(ext.toUpperCase()));
fos.close();
} catch (IOException e) {
System.err.println("An exception has been encountered while writing the contents of "
+ target.getClass().getSimpleName() + " to " + file);
e.printStackTrace();
}

if (!path.contains(".")) {
file = new File(path + "." + ext);
}
else
file = new File(path.substring(0, path.indexOf(".") + 1) + ext);

try {
var fos = new FileOutputStream(file);
printToStream(target, fos, Extension.valueOf(ext.toUpperCase()));
fos.close();
} catch (IOException e) {
System.err.println("An exception has been encountered while writing the contents of "
+ target.getClass().getSimpleName() + " to " + file);
e.printStackTrace();
}

}

return directory;

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/pulse/io/readers/AbstractReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* lists, arrays and containers may (and usually will) change as a result of
* using the reader.
* </p>
* @param <T>
*/
public interface AbstractReader<T> extends AbstractHandler {

Expand Down
86 changes: 60 additions & 26 deletions src/main/java/pulse/io/readers/NetzschCSVReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

import pulse.AbstractData;
import pulse.input.ExperimentalData;
Expand Down Expand Up @@ -44,10 +50,16 @@ public class NetzschCSVReader implements CurveReader {
/**
* Note comma is included as a delimiter character here.
*/
public final static String delims = "[#();,/°Cx%^]+";

private final static String ENGLISH_DELIMS = "[#(),/°Cx%^]+";
private final static String GERMAN_DELIMS = "[#();/°Cx%^]+";

private static String delims = ENGLISH_DELIMS;

//default number format (British format)
private static Locale locale = Locale.ENGLISH;

private NetzschCSVReader() {
// intentionally blank
//intentionally blank
}

/**
Expand Down Expand Up @@ -87,19 +99,25 @@ public List<ExperimentalData> read(File file) throws IOException {
Objects.requireNonNull(file, Messages.getString("DATReader.1"));

ExperimentalData curve = new ExperimentalData();

//gets the number format for this locale

try (BufferedReader reader = new BufferedReader(new FileReader(file))) {

int shotId = determineShotID(reader, file);

var format = DecimalFormat.getInstance(locale);
format.setGroupingUsed(false);

var tempTokens = findLineByLabel(reader, THICKNESS, delims).split(delims);
final double thickness = Double.parseDouble(tempTokens[tempTokens.length - 1]) * TO_METRES;

final double thickness = format.parse(tempTokens[tempTokens.length - 1]).doubleValue() * TO_METRES;

tempTokens = findLineByLabel(reader, DIAMETER, delims).split(delims);
final double diameter = Double.parseDouble(tempTokens[tempTokens.length - 1]) * TO_METRES;
final double diameter = format.parse(tempTokens[tempTokens.length - 1]).doubleValue() * TO_METRES;

tempTokens = findLineByLabel(reader, SAMPLE_TEMPERATURE, delims).split(delims);
final double sampleTemperature = Double.parseDouble(tempTokens[tempTokens.length - 1]) + TO_KELVIN;
final double sampleTemperature = format.parse(tempTokens[tempTokens.length - 1]).doubleValue() + TO_KELVIN;

/*
* Finds the detector keyword.
Expand All @@ -122,32 +140,52 @@ public List<ExperimentalData> read(File file) throws IOException {

curve.setMetadata(met);
curve.setRange(new Range(curve.getTimeSequence()));
return new ArrayList<>(Arrays.asList(curve));

} catch (ParseException ex) {
Logger.getLogger(NetzschCSVReader.class.getName()).log(Level.SEVERE, null, ex);
}

return new ArrayList<>(Arrays.asList(curve));
return null;

}

protected static void populate(AbstractData data, BufferedReader reader) throws IOException {
protected static void populate(AbstractData data, BufferedReader reader) throws IOException, ParseException {
double time;
double power;
String[] tokens;
var format = DecimalFormat.getInstance(locale);
format.setGroupingUsed(false);

for (String line = reader.readLine(); line != null && !line.trim().isEmpty(); line = reader.readLine()) {
tokens = line.split(delims);

time = Double.parseDouble(tokens[0]) * NetzschCSVReader.TO_SECONDS;
power = Double.parseDouble(tokens[1]);
time = format.parse(tokens[0]).doubleValue() * NetzschCSVReader.TO_SECONDS;
power = format.parse(tokens[1]).doubleValue();
data.addPoint(time, power);
}

}

protected static int determineShotID(BufferedReader reader, File file) throws IOException {
String[] shotID = reader.readLine().split(delims);
String shotIDLine = reader.readLine();
String[] shotID = shotIDLine.split(delims);

int shotId = -1;

if(shotID.length < 3) {

if(locale == Locale.ENGLISH) {
delims = GERMAN_DELIMS;
locale = Locale.GERMAN;
}
else {
delims = ENGLISH_DELIMS;
locale = Locale.ENGLISH;
}

shotID = shotIDLine.split(delims);
}

//check if first entry makes sense
if (!shotID[shotID.length - 2].equalsIgnoreCase(SHOT_DATA)) {
Expand All @@ -160,19 +198,7 @@ protected static int determineShotID(BufferedReader reader, File file) throws IO
return shotId;

}

/*
private double parseDoubleWithComma(String s) {
var format = NumberFormat.getInstance(Locale.GERMANY);
try {
return format.parse(s).doubleValue();
} catch (ParseException e) {
System.out.println("Couldn't parse double from: " + s);
e.printStackTrace();
}
return Double.NaN;
}
*/

protected static String findLineByLabel(BufferedReader reader, String label, String delims) throws IOException {

String line = "";
Expand All @@ -195,7 +221,6 @@ protected static String findLineByLabel(BufferedReader reader, String label, Str
return line;

}

/**
* As this class uses the singleton pattern, only one instance is created
* using an empty no-argument constructor.
Expand All @@ -205,5 +230,14 @@ protected static String findLineByLabel(BufferedReader reader, String label, Str
public static CurveReader getInstance() {
return instance;
}


/**
* Get the standard delimiter chars.
* @return delims
*/

public static String getDelims() {
return delims;
}

}
27 changes: 11 additions & 16 deletions src/main/java/pulse/io/readers/NetzschPulseCSVReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

import pulse.problem.laser.NumericPulseData;
import pulse.ui.Messages;
Expand Down Expand Up @@ -37,10 +40,12 @@ public String getSupportedExtension() {

/**
* This performs a basic check, finding the shot ID, which is then passed to
* a new {@code NumericPulseData} object. The latter is populated using the
* time-power sequence stored in this file. If the {@value PULSE} keyword is
* a new {@code NumericPulseData} object.The latter is populated using the
* time-power sequence stored in this file.If the {@value PULSE} keyword is
* not found, the method will display an error.
*
* @param file
* @throws java.io.IOException
* @see pulse.io.readers.NetzschCSVReader.read()
* @return a new {@code NumericPulseData} object encapsulating the contents
* of {@code file}
Expand All @@ -49,14 +54,14 @@ public String getSupportedExtension() {
public NumericPulseData read(File file) throws IOException {
Objects.requireNonNull(file, Messages.getString("DATReader.1"));

NumericPulseData data;
NumericPulseData data = null;

try (BufferedReader reader = new BufferedReader(new FileReader(file))) {

int shotId = NetzschCSVReader.determineShotID(reader, file);
data = new NumericPulseData(shotId);

var pulseLabel = NetzschCSVReader.findLineByLabel(reader, PULSE, NetzschCSVReader.delims);
var pulseLabel = NetzschCSVReader.findLineByLabel(reader, PULSE, NetzschCSVReader.getDelims());

if (pulseLabel == null) {
System.err.println("Skipping " + file.getName());
Expand All @@ -66,24 +71,14 @@ public NumericPulseData read(File file) throws IOException {
reader.readLine();
NetzschCSVReader.populate(data, reader);

} catch (ParseException ex) {
Logger.getLogger(NetzschPulseCSVReader.class.getName()).log(Level.SEVERE, null, ex);
}

return data;

}

/*
private double parseDoubleWithComma(String s) {
var format = NumberFormat.getInstance(Locale.GERMANY);
try {
return format.parse(s).doubleValue();
} catch (ParseException e) {
System.out.println("Couldn't parse double from: " + s);
e.printStackTrace();
}
return Double.NaN;
}
*/
/**
* As this class uses the singleton pattern, only one instance is created
* using an empty no-argument constructor.
Expand Down
Loading

0 comments on commit 7b9081f

Please sign in to comment.