File: Raw.java

package info (click to toggle)
imagej 1.52j-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,604 kB
  • sloc: java: 120,017; sh: 279; xml: 161; makefile: 6
file content (66 lines) | stat: -rw-r--r-- 1,895 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package ij.plugin;

import java.awt.*;
import java.io.*;
import ij.*;
import ij.io.*;

/** This plugin implements the File/Import/Raw command. */
public class Raw implements PlugIn {

	private static String defaultDirectory = null;

	public void run(String arg) {
		OpenDialog od = new OpenDialog("Open Raw...", arg);
		String directory = od.getDirectory();
		String fileName = od.getFileName();
		if (fileName==null)
			return;
		ImportDialog d = new ImportDialog(fileName, directory);
		d.openImage();
	}

	/** Opens the image at 'filePath' using the format specified by 'fi'. */
	public static ImagePlus open(String filePath, FileInfo fi) {
		File f = new File(filePath);
		fi.directory = f.getParent()+ "/";
		fi.fileName = f.getName();
		return (new FileOpener(fi)).open(false);
	}	


	/** Opens all the images in the specified directory as a stack,
		using the format specified by 'fi'. */
	public static ImagePlus openAll(String directory, FileInfo fi) {
		ImagePlus imp = openAllVirtual(directory,fi);
		if (imp!=null)
			return imp.duplicate();
		else
			return null;
	}	

	/** Opens all the images in the specified directory as a virtual stack,
		using the format specified by 'fi'. */
	public static ImagePlus openAllVirtual(String directory, FileInfo fi) {
		String[] list = new File(directory).list();
		if (list==null)
			return null;
		FolderOpener fo = new FolderOpener();
		list = fo.trimFileList(list);
		list = fo.sortFileList(list);
		if (list==null)
			return null;
		if (!(directory.endsWith(File.separator)||directory.endsWith("/")))
			directory += "/";
		FileInfo[] info = new FileInfo[list.length];
		for (int i=0; i<list.length; i++) {
			info[i] = (FileInfo)fi.clone();
			info[i].directory = directory;
			info[i].fileName = list[i];
		}
		VirtualStack stack = new FileInfoVirtualStack(info);
		ImagePlus imp = new ImagePlus(directory, stack);
		return imp;
	}	
	
}