use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class NeighbourAnalysis method saveTraces.
private void saveTraces(Trace[] traces) {
String[] path = Utils.decodePath(filename);
OpenDialog chooser = new OpenDialog("Traces_File", path[0], path[1]);
if (chooser.getFileName() != null) {
filename = chooser.getDirectory() + chooser.getFileName();
// Remove extension and replace with .xls
int index = filename.lastIndexOf('.');
if (index > 0) {
filename = filename.substring(0, index);
}
filename += ".xls";
boolean showDeviations = (!results.getResults().isEmpty() && results.getHead().paramsStdDev != null);
FilePeakResults traceResults = new FilePeakResults(filename, showDeviations);
traceResults.copySettings(results);
traceResults.begin();
if (!traceResults.isActive()) {
IJ.error(TITLE, "Failed to write to file: " + filename);
return;
}
traceResults.addComment(createSettingsComment());
for (Trace trace : traces) // addTrace(...) does a sort on the results
traceResults.addCluster(trace);
traceResults.end();
}
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class FilterAnalysis method readFilterSets.
@SuppressWarnings("unchecked")
private List<FilterSet> readFilterSets() {
GlobalSettings gs = SettingsManager.loadSettings();
FilterSettings filterSettings = gs.getFilterSettings();
String[] path = Utils.decodePath(filterSettings.filterSetFilename);
OpenDialog chooser = new OpenDialog("Filter_File", path[0], path[1]);
if (chooser.getFileName() != null) {
IJ.showStatus("Reading filters ...");
filterSettings.filterSetFilename = chooser.getDirectory() + chooser.getFileName();
BufferedReader input = null;
try {
FileInputStream fis = new FileInputStream(filterSettings.filterSetFilename);
input = new BufferedReader(new UnicodeReader(fis, null));
Object o = XStreamWrapper.getInstance().fromXML(input);
if (o != null && o instanceof List<?>) {
SettingsManager.saveSettings(gs);
return (List<FilterSet>) o;
}
IJ.log("No filter sets defined in the specified file: " + filterSettings.filterSetFilename);
} catch (Exception e) {
IJ.log("Unable to load the filter sets from file: " + e.getMessage());
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
// Ignore
}
}
IJ.showStatus("");
}
}
return null;
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class DriftCalculator method getDriftFilename.
private boolean getDriftFilename() {
String[] path = Utils.decodePath(driftFilename);
OpenDialog chooser = new OpenDialog("Drift_file", path[0], path[1]);
if (chooser.getFileName() == null)
return false;
driftFilename = chooser.getDirectory() + chooser.getFileName();
Utils.replaceExtension(driftFilename, "tsv");
return true;
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class CreateData method saveImage.
/**
* Save the image to a TIFF file
*
* @param imp
*/
private void saveImage(ImagePlus imp) {
if (!settings.saveImage)
return;
String[] path = Utils.decodePath(settings.imageFilename);
OpenDialog chooser = new OpenDialog("Image_File", path[0], path[1]);
if (chooser.getFileName() != null) {
settings.imageFilename = chooser.getDirectory() + chooser.getFileName();
settings.imageFilename = Utils.replaceExtension(settings.imageFilename, "tiff");
FileSaver fs = new FileSaver(imp);
boolean ok;
if (imp.getStackSize() > 1)
ok = fs.saveAsTiffStack(settings.imageFilename);
else
ok = fs.saveAsTiff(settings.imageFilename);
if (!ok)
IJ.log("Failed to save image to file: " + settings.imageFilename);
}
}
use of ij.io.OpenDialog in project GDSC-SMLM by aherbert.
the class CreateData method saveLocalisations.
/**
* Save the localisations to a text file
*
* @param localisations
*/
private void saveLocalisations(List<LocalisationModel> localisations) {
if (!settings.saveLocalisations)
return;
sortLocalisationsByTime(localisations);
// Collections.sort(localisations, new Comparator<LocalisationModel>(){
//
// public int compare(LocalisationModel o1, LocalisationModel o2)
// {
// int cellx1 = (int)(o1.getX() / settings.cellSize);
// int cellx2 = (int)(o2.getX() / settings.cellSize);
// int result = cellx2 - cellx1;
// if (result != 0)
// return result;
// int celly1 = (int)(o1.getY() / settings.cellSize);
// int celly2 = (int)(o2.getY() / settings.cellSize);
// result = celly2 - celly1;
// if (result != 0)
// return result;
// return (o1.getZ() == o2.getZ()) ? 0 : (o1.getZ() == 0) ? -1 : 1;
// }});
String[] path = Utils.decodePath(settings.localisationsFilename);
OpenDialog chooser = new OpenDialog("Localisations_File", path[0], path[1]);
if (chooser.getFileName() != null) {
settings.localisationsFilename = chooser.getDirectory() + chooser.getFileName();
settings.localisationsFilename = Utils.replaceExtension(settings.localisationsFilename, "xls");
BufferedWriter output = null;
try {
output = new BufferedWriter(new FileWriter(settings.localisationsFilename));
output.write(createResultsFileHeader());
output.write("#T\tId\tX\tY\tZ\tIntensity");
output.newLine();
for (LocalisationModel l : localisations) {
StringBuffer sb = new StringBuffer();
sb.append(l.getTime()).append("\t");
sb.append(l.getId()).append("\t");
sb.append(IJ.d2s(l.getX(), 6)).append("\t");
sb.append(IJ.d2s(l.getY(), 6)).append("\t");
sb.append(IJ.d2s(l.getZ(), 6)).append("\t");
sb.append(l.getIntensity());
output.write(sb.toString());
output.newLine();
}
} catch (Exception e) {
// Q. Add better handling of errors?
e.printStackTrace();
IJ.log("Failed to save localisations to file: " + settings.localisationsFilename);
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
Aggregations