Skip to content

Commit

Permalink
Replacing ij.text.TextPanel with java.io.FileWriter - #3
Browse files Browse the repository at this point in the history
  • Loading branch information
hansenjn committed Jul 31, 2024
1 parent 12dc29d commit a1c7ea9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Thresholder/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<artifactId>MotiQ_Thresholder</artifactId>
<groupId>JNH</groupId>
<version>0.2.3-SNAPSHOT</version>
<version>0.2.4-SNAPSHOT</version>

<!-- Plugin Information -->
<name>MotiQ thresholder</name>
Expand Down
67 changes: 67 additions & 0 deletions Thresholder/src/main/java/motiQ_thr/OutputTextFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/***===============================================================================
*
* MotiQ_Thresholder plugin for imageJ
*
* Copyright (C) 2015-2024 Jan N. Hansen
* First version: January 05, 2015
* This Version: July 31, 2024
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
*
* For any questions please feel free to contact me (jan.hansen@uni-bonn.de).
*
* =============================================================================**/

package motiQ_thr;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

class OutputTextFile {
String path;
FileWriter writer = null;
String output;

public OutputTextFile(String outputPath) {
output = "";
path = outputPath;
}

public void append(String text) {
output += (text + "\n");
}

public boolean finish() {
if(output.length() == 0) return false;
if(path.length() == 0) return false;

output = output.replaceAll("\n$", "");

try {
writer = new FileWriter(new File(path));
writer.write(output);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
output = "";
path = "";
return true;
}

public void changePath(String newOutputPath) {
path = newOutputPath;
}
}
9 changes: 4 additions & 5 deletions Thresholder/src/main/java/motiQ_thr/Thresholder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Copyright (C) 2015-2024 Jan N. Hansen
* First version: January 05, 2015
* This version: July 30, 2024
* This version: July 31, 2024
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -38,13 +38,12 @@
import ij.process.*;
import ij.plugin.*;
import ij.plugin.frame.Recorder;
import ij.text.*;
import java.text.*;

public class Thresholder implements PlugIn, Measurements{//, DialogListener {
//Name variables
final static String PLUGINNAME = "MotiQ Thresholder";
final static String PLUGINVERSION = "v0.2.3";
final static String PLUGINVERSION = "v0.2.4";

//Fonts
static final Font SuperHeadingFont = new Font("Sansserif", Font.BOLD, 16);
Expand Down Expand Up @@ -1244,7 +1243,7 @@ else if(chosenStackMethod.equals(stackMethod[4])){

//generate log file
SimpleDateFormat FullDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
TextPanel tw1 =new TextPanel("Results");
OutputTextFile tw1 = new OutputTextFile(outputPath + "_log.txt");
tw1.append("Output image name: " + outputPath.substring(dir[task].length()) + ".tif");
tw1.append("Input image name: " + name[task]);
tw1.append("Processing started: " + FullDateFormatter.format(startDate));
Expand Down Expand Up @@ -1312,7 +1311,7 @@ else if(chosenStackMethod.equals(stackMethod[4])){
if (record) {
Recorder.record = false;
}
tw1.saveAs(outputPath + "_log.txt");
tw1.finish();
if (record) {
Recorder.record = true;
}
Expand Down
4 changes: 2 additions & 2 deletions Thresholder/src/main/resources/plugins.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# Belongs to the MotiQ toolbox for analyzing cellular morphology, dynamics, and signaling (https://github.com/hansenjn/MotiQ). MotiQ_thresholder is a automated thresholding tool for image stacks. MotiQ thresholder calculates a threshold in a separate reference image and applies it to the input image. The reference image is optionally processed by MotiQ thresholder prior to threshold calculation, whereby the image histogram used for threshold calculation can be improved.

# Author: Jan N. Hansen <Jan.Hansen@uni-bonn.de>
# Version: 0.2.3
# Version: 0.2.4
# Date: 2017/09/15
# Requires: ImageJ

Plugins>MotiQ, "MotiQ Thresholder (v0.2.3)", motiQ_thr.Thresholder
Plugins>MotiQ, "MotiQ Thresholder (v0.2.4)", motiQ_thr.Thresholder

0 comments on commit a1c7ea9

Please sign in to comment.