Skip to content

Commit 9bfb15a

Browse files
committed
Customize Summary File Path
Adding an option to customize the file path at which the summary text file is saved after processing all images.
1 parent 464def8 commit 9bfb15a

File tree

3 files changed

+67
-16
lines changed

3 files changed

+67
-16
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111

1212
<artifactId>SpermQ_</artifactId>
13-
<version>0.2.3-SNAPSHOT</version>
13+
<version>0.2.4-SNAPSHOT</version>
1414
<groupId>JNH</groupId>
1515
<description>An ImageJ plugin to analyze the flagellar beat of sperm and sperm steering. Copyright (C) 2017-2020: Jan N. Hansen, Sebastian Rassmann, Jan F. Jikeli, and Dagmar Wachten; research group Biophysical Imaging, Institute of Innate Immunity, Bonn, Germany (http://www.iii.uni-bonn.de/en/wachten_lab/). Funding: DFG priority program SPP 1726 &quot;Microswimmers&quot;. This software is part of the following publication: https://www.mdpi.com/2073-4409/8/1/10.</description>
1616

src/main/java/spermQ/main.java

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/***===============================================================================
22
3-
SpermQ_.java Version v0.2.3
3+
SpermQ_.java Version v0.2.4
44
55
This program is free software; you can redistribute it and/or
66
modify it under the terms of the GNU General Public License
@@ -13,7 +13,7 @@ as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.tx
1313
1414
See the GNU General Public License for more details.
1515
16-
Copyright (C) 2016 - 2022: Jan N Hansen and Jan F Jikeli
16+
Copyright (C) 2016 - 2023: Jan N Hansen and Jan F Jikeli
1717
1818
For any questions please feel free to contact me ([email protected]).
1919
@@ -39,7 +39,7 @@ For any questions please feel free to contact me ([email protected]).
3939
public class main implements PlugIn, Measurements{
4040
//Name
4141
static final String PLUGINNAME = "SpermQ_";
42-
static final String PLUGINVERSION = "v0.2.3";
42+
static final String PLUGINVERSION = "v0.2.4";
4343
static final double threshold = 0.70;
4444

4545
//default settings loader
@@ -98,6 +98,12 @@ public class main implements PlugIn, Measurements{
9898

9999
@Override
100100
public void run(String arg) {
101+
// Initialize home path
102+
String homePath = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
103+
if(System.getProperty("os.name").toUpperCase().contains("MAC")){
104+
homePath += System.getProperty("file.separator") + "Desktop";
105+
}
106+
101107
/**&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
102108
Load Default Settings
103109
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
@@ -395,6 +401,11 @@ else if(selectedDSL.equals(selectionsDSL[14]) || selectedDSL.equals(selectionsDS
395401
gd.setInsets(0,0,0); gd.addNumericField("FFT: Grouped consecutive time-steps", groupedTimesteps, 0);
396402
gd.setInsets(0,0,0); gd.addNumericField("FFT: Do not analyze initial ... µm from head", neglectedInitialArclength, 0);
397403
gd.setInsets(0,0,0); gd.addNumericField("Head rotation matrix radius", hrPlusMinusRange, 0);
404+
405+
gd.setInsets(10,0,0); gd.addMessage("Output of summary file", constants.BoldTxt);
406+
gd.setInsets(-3,0,0); gd.addMessage("In the field below you may, if needed, adapt the file path where the file summarizing results for all analyzed images will be stored.", constants.PlTxt);
407+
gd.setInsets(-3,0,0); gd.addStringField("File path for output of the summary txt-file: ", homePath, 30);
408+
398409

399410
gd.showDialog();
400411

@@ -424,6 +435,7 @@ else if(selectedDSL.equals(selectionsDSL[14]) || selectedDSL.equals(selectionsDS
424435
groupedTimesteps = (int) gd.getNextNumber();
425436
neglectedInitialArclength = (double) gd.getNextNumber();
426437
hrPlusMinusRange = (int) hrPlusMinusRange;
438+
homePath = gd.getNextString();
427439

428440
if (gd.wasCanceled())return;
429441
}
@@ -499,12 +511,33 @@ public void windowClosing(WindowEvent winEvt) {
499511
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
500512

501513
//Initialize
502-
ImagePlus imp;
503-
String homePath = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
504-
if(System.getProperty("os.name").toUpperCase().contains("MAC")){
505-
homePath += System.getProperty("file.separator") + "Desktop";
514+
ImagePlus imp;
515+
516+
//Checking for existing saving path for the summary
517+
if(!new File(homePath).exists()) {
518+
while(true) {
519+
GenericDialog gd = new GenericDialog(PLUGINNAME);
520+
// setInsets(top, left, bottom)
521+
gd.setInsets(0,0,0); gd.addMessage(PLUGINNAME + ", version " + PLUGINVERSION + " (\u00a9 2013-" + constants.dateY.format(new Date()) + ", JF Jikeli \u0026 JN Hansen)", constants.Head1);
522+
523+
gd.setInsets(10,0,0); gd.addMessage("The path for saving the summary file does not exist.", constants.PlTxt);
524+
gd.setInsets(0,0,0); gd.addMessage("Correct the path in the box below or enter an existing path for storing the summary file.", constants.PlTxt);
525+
526+
gd.setInsets(10,0,0); gd.addStringField("File path for saving the summary file: ", homePath, 30);
527+
528+
gd.showDialog();
529+
530+
homePath = gd.getNextString();
531+
532+
if (gd.wasCanceled()) return;
533+
534+
if(new File(homePath).exists()) {
535+
break;
536+
}
537+
}
506538
}
507539

540+
508541
//get head selections
509542
Roi [] selections = new Roi [tasks];
510543
if(tethered){
@@ -977,8 +1010,16 @@ public void windowClosing(WindowEvent winEvt) {
9771010
+ " " + constants.df6US.format(freqSummaryCAngle [task][2][2]));
9781011

9791012

980-
tools2D.addFooter(tp);
981-
tp.saveAs(dir [task] + saveName + System.getProperty("file.separator") + "results.txt");
1013+
tools2D.addFooter(tp);
1014+
try {
1015+
tp.saveAs(dir [task] + saveName + System.getProperty("file.separator") + "results.txt");
1016+
}catch(Exception e) {
1017+
String out = "";
1018+
for(int err = 0; err < e.getStackTrace().length; err++){
1019+
out += " \n " + e.getStackTrace()[err].toString();
1020+
}
1021+
progress.notifyMessage("Failed to write the file path " + dir [task] + saveName + System.getProperty("file.separator") + "results.txt" + " .\nAn error occured:\n" + out, ProgressDialog.ERROR);
1022+
}
9821023

9831024
//save selection
9841025
rm = RoiManager.getInstance();
@@ -1314,10 +1355,20 @@ public void windowClosing(WindowEvent winEvt) {
13141355
}
13151356
}
13161357
tools2D.addFooter(tp);
1317-
tp.saveAs(homePath + System.getProperty("file.separator") + "SpermQ_Summary_" + constants.dateName.format(new Date()) + ".txt");
1358+
1359+
try {
1360+
tp.saveAs(homePath + System.getProperty("file.separator") + "SpermQ_Summary_" + constants.dateName.format(new Date()) + ".txt");
1361+
}catch(Exception e) {
1362+
String out = "";
1363+
for(int err = 0; err < e.getStackTrace().length; err++){
1364+
out += " \n " + e.getStackTrace()[err].toString();
1365+
}
1366+
progress.notifyMessage("Failed to save the file " + homePath + System.getProperty("file.separator") + "SpermQ_Summary_" + constants.dateName.format(new Date()) + ".txt " + " due to an error:\n" + out, ProgressDialog.ERROR);
1367+
}
1368+
13181369
System.gc();
13191370
done = true;
1320-
new WaitForUserDialog("All tasks have been processed. A summary file has been saved on the desktop!").show();
1371+
new WaitForUserDialog("All tasks have been processed. A summary file has been saved at\n" + homePath + "!").show();
13211372
}
13221373
}
13231374
}

src/main/resources/plugins.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# #%L
33
# SpermQ_ plugin for ImageJ.
44
# %%
5-
# Copyright (C) 2016-2022 Jan Niklas Hansen and Jan F Jikeli.
5+
# Copyright (C) 2016-2023 Jan N. Hansen and Jan F Jikeli.
66
# %%
77
# This program is free software: you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as
@@ -21,9 +21,9 @@
2121
###
2222
# Name: SpermQ
2323

24-
# Author: Jan Niklas Hansen <[email protected]>
25-
# Version: 0.2.3
24+
# Author: Jan N. Hansen <[email protected]>
25+
# Version: 0.2.4
2626
# Date: 2016/11/14
2727
# Requires: ImageJ
2828

29-
Plugins>JNH>Analysis, "SpermQ v0.2.3", spermQ.main
29+
Plugins>JNH>Analysis, "SpermQ v0.2.4", spermQ.main

0 commit comments

Comments
 (0)