/** Called from io/Opener.java. */ public void run(String path) { if (path.equals("")) return; File theFile = new File(path); String directory = theFile.getParent(); String fileName = theFile.getName(); if (directory == null) directory = ""; // Try and recognise file type and load the file if recognised ImagePlus imp = openImage(directory, fileName, path); if (imp == null) { IJ.showStatus(""); return; // failed to load file or plugin has opened and displayed it } ImageStack stack = imp.getStack(); // get the title from the stack (falling back to the fileName) String title = imp.getTitle().equals("") ? fileName : imp.getTitle(); // set the stack of this HandleExtraFileTypes object // to that attached to the ImagePlus object returned by openImage() setStack(title, stack); // copy over the calibration info since it doesn't come with the ImageProcessor setCalibration(imp.getCalibration()); // also copy the Show Info field over if it exists if (imp.getProperty("Info") != null) setProperty("Info", imp.getProperty("Info")); // copy the FileInfo setFileInfo(imp.getOriginalFileInfo()); // copy dimensions if (IJ.getVersion().compareTo("1.38s") >= 0) setDimensions(imp.getNChannels(), imp.getNSlices(), imp.getNFrames()); if (IJ.getVersion().compareTo("1.41o") >= 0) setOpenAsHyperStack(imp.getOpenAsHyperStack()); }
void addScrollbars(ImagePlus imp) { ImageStack s = imp.getStack(); int stackSize = s.getSize(); nSlices = stackSize; hyperStack = imp.getOpenAsHyperStack(); // imp.setOpenAsHyperStack(false); int[] dim = imp.getDimensions(); int nDimensions = 2 + (dim[2] > 1 ? 1 : 0) + (dim[3] > 1 ? 1 : 0) + (dim[4] > 1 ? 1 : 0); if (nDimensions <= 3 && dim[2] != nSlices) hyperStack = false; if (hyperStack) { nChannels = dim[2]; nSlices = dim[3]; nFrames = dim[4]; } // IJ.log("StackWindow: "+hyperStack+" "+nChannels+" "+nSlices+" "+nFrames); if (nSlices == stackSize) hyperStack = false; if (nChannels * nSlices * nFrames != stackSize) hyperStack = false; if (cSelector != null || zSelector != null || tSelector != null) removeScrollbars(); ImageJ ij = IJ.getInstance(); if (nChannels > 1) { cSelector = new ScrollbarWithLabel(this, 1, 1, 1, nChannels + 1, 'c'); add(cSelector); if (ij != null) cSelector.addKeyListener(ij); cSelector.addAdjustmentListener(this); cSelector.setFocusable(false); // prevents scroll bar from blinking on Windows cSelector.setUnitIncrement(1); cSelector.setBlockIncrement(1); } if (nSlices > 1) { char label = nChannels > 1 || nFrames > 1 ? 'z' : 't'; if (stackSize == dim[2] && imp.isComposite()) label = 'c'; zSelector = new ScrollbarWithLabel(this, 1, 1, 1, nSlices + 1, label); if (label == 't') animationSelector = zSelector; add(zSelector); if (ij != null) zSelector.addKeyListener(ij); zSelector.addAdjustmentListener(this); zSelector.setFocusable(false); int blockIncrement = nSlices / 10; if (blockIncrement < 1) blockIncrement = 1; zSelector.setUnitIncrement(1); zSelector.setBlockIncrement(blockIncrement); sliceSelector = zSelector.bar; } if (nFrames > 1) { animationSelector = tSelector = new ScrollbarWithLabel(this, 1, 1, 1, nFrames + 1, 't'); add(tSelector); if (ij != null) tSelector.addKeyListener(ij); tSelector.addAdjustmentListener(this); tSelector.setFocusable(false); int blockIncrement = nFrames / 10; if (blockIncrement < 1) blockIncrement = 1; tSelector.setUnitIncrement(1); tSelector.setBlockIncrement(blockIncrement); } }