This plugin implements the File/Batch/Macro and File/Batch/Virtual Stack commands.
| 11 | |
| 12 | /** This plugin implements the File/Batch/Macro and File/Batch/Virtual Stack commands. */ |
| 13 | public class BatchProcesser implements PlugIn, ActionListener, ItemListener, Runnable { |
| 14 | private static final String MACRO_FILE_NAME = "BatchMacro.ijm"; |
| 15 | private static final String[] formats = {"TIFF", "8-bit TIFF", "JPEG", "GIF", "PNG", "PGM", "BMP", "FITS", "Text Image", "ZIP", "Raw"}; |
| 16 | private static String format = Prefs.get("batch.format", formats[0]); |
| 17 | private static final String[] code = { |
| 18 | "[Select from list]", |
| 19 | "Add Border", |
| 20 | "Convert to RGB", |
| 21 | "Crop", |
| 22 | "Gaussian Blur", |
| 23 | "Invert", |
| 24 | "Label", |
| 25 | "Timestamp", |
| 26 | "Max Dimension", |
| 27 | "Measure", |
| 28 | "Print Index and Title", |
| 29 | "Resize", |
| 30 | "Scale", |
| 31 | "Show File Info", |
| 32 | "Unsharp Mask", |
| 33 | }; |
| 34 | private String macro = ""; |
| 35 | private int testImage; |
| 36 | private Button input, output, open, save, test; |
| 37 | private TextField inputDir, outputDir; |
| 38 | private GenericDialog gd; |
| 39 | private Thread thread; |
| 40 | private ImagePlus virtualStack; |
| 41 | private ImagePlus outputImage; |
| 42 | |
| 43 | public void run(String arg) { |
| 44 | if (arg.equals("stack")) { |
| 45 | virtualStack = IJ.getImage(); |
| 46 | if (virtualStack.getStackSize()==1) { |
| 47 | error("This command requires a stack or virtual stack."); |
| 48 | return; |
| 49 | } |
| 50 | } |
| 51 | String macroPath = IJ.getDirectory("macros")+MACRO_FILE_NAME; |
| 52 | macro = IJ.openAsString(macroPath); |
| 53 | if (macro==null || macro.startsWith("Error: ")) { |
| 54 | IJ.showStatus(macro.substring(7) + ": "+macroPath); |
| 55 | macro = ""; |
| 56 | } |
| 57 | if (!showDialog()) return; |
| 58 | String inputPath = null; |
| 59 | if (virtualStack==null) { |
| 60 | inputPath = inputDir.getText(); |
| 61 | if (inputPath.equals("")) { |
| 62 | error("Please choose an input folder"); |
| 63 | return; |
| 64 | } |
| 65 | inputPath = addSeparator(inputPath); |
| 66 | File f1 = new File(inputPath); |
| 67 | if (!f1.exists() || !f1.isDirectory()) { |
| 68 | error("Input does not exist or is not a folder\n \n"+inputPath); |
| 69 | return; |
| 70 | } |