Skip to content

Commit

Permalink
Add a public opener API to Read_Stratec_File
Browse files Browse the repository at this point in the history
This means external plugins can open Stratec pQCT files and control what
happens to the resulting ImagePlus (e.g. when to call show() on it).
  • Loading branch information
mdoube committed Oct 25, 2011
1 parent 7ad10ba commit cc1d97d
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions src/org/doube/bonej/pqct/Read_Stratec_File.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public Read_Stratec_File() { //Constructor
//this = null;
}

/**
* Opens a Stratec pQCT file
*
* @param path full path to the file
* @return ImagePlus containing the calibrated pQCT image
* @throws IllegalArgumentException if the path is null or the file is not normal
*/
public ImagePlus open(String path) throws IllegalArgumentException {
if (path == null)
throw new IllegalArgumentException("Path cannot be null");
File theFile = new File(path);
if (!theFile.isFile())
throw new IllegalArgumentException("Path is not a normal file");
String directory = theFile.getParent()+"/";
fileName = theFile.getName();
read(directory);
fileInfo();
return this;
}

//Overriding the abstract runnable run method. Apparently plugins run in threads
public void run(String arg) {
String directory;
Expand All @@ -71,6 +91,15 @@ public void run(String arg) {
}
if (fileName==null) return;
read(directory);
fileInfo();
if (arg.isEmpty() && this.getHeight()>0){
this.show();
return;
}
if (this.getHeight()<1) return;
}

private void fileInfo() {
FileInfo fi = this.getFileInfo();
fi.pixelWidth = VoxelSize;
fi.pixelHeight = VoxelSize;
Expand All @@ -79,13 +108,8 @@ public void run(String arg) {
fi.info = properties;
fi.fileType = ij.io.FileInfo.GRAY16_SIGNED; //
this.setFileInfo(fi);
if (arg.isEmpty() && this.getHeight()>0){
this.show();
return;
}
if (this.getHeight()<1) return;
}

private void read(String directory){
File fileIn = new File(directory+fileName);
long fileLength = fileIn.length();
Expand Down

0 comments on commit cc1d97d

Please sign in to comment.