use of ij.io.OpenDialog in project imagingbook-common by imagingbook.
the class IjUtils method askForOpenPath.
/**
* Queries the user for an arbitrary file to be opened.
*
* @param title string to be shown in the interaction window.
* @return path of the selected resource.
*/
public static String askForOpenPath(String title) {
OpenDialog od = new OpenDialog(title, "");
String dir = od.getDirectory();
String name = od.getFileName();
if (name == null)
return null;
return encodeURL(dir + name);
}
use of ij.io.OpenDialog in project bioformats by openmicroscopy.
the class Read_Image method run.
public void run(String arg) {
OpenDialog od = new OpenDialog("Open Image File...", arg);
String dir = od.getDirectory();
String name = od.getFileName();
String id = dir + name;
ImageProcessorReader r = new ImageProcessorReader(new ChannelSeparator(LociPrefs.makeImageReader()));
try {
IJ.showStatus("Examining file " + name);
r.setId(id);
int num = r.getImageCount();
int width = r.getSizeX();
int height = r.getSizeY();
ImageStack stack = new ImageStack(width, height);
byte[][][] lookupTable = new byte[r.getSizeC()][][];
for (int i = 0; i < num; i++) {
IJ.showStatus("Reading image plane #" + (i + 1) + "/" + num);
ImageProcessor ip = r.openProcessors(i)[0];
stack.addSlice("" + (i + 1), ip);
int channel = r.getZCTCoords(i)[1];
lookupTable[channel] = r.get8BitLookupTable();
}
IJ.showStatus("Constructing image");
ImagePlus imp = new ImagePlus(name, stack);
ImagePlus colorizedImage = applyLookupTables(r, imp, lookupTable);
r.close();
colorizedImage.show();
IJ.showStatus("");
} catch (FormatException exc) {
IJ.error("Sorry, an error occurred: " + exc.getMessage());
} catch (IOException exc) {
IJ.error("Sorry, an error occurred: " + exc.getMessage());
}
}
use of ij.io.OpenDialog in project bioformats by openmicroscopy.
the class IdDialog method displayDialog.
/**
* Asks user whether Bio-Formats should automatically check for upgrades,
* and if so, checks for an upgrade and prompts user to install it.
*
* @return status of operation
*/
@Override
protected boolean displayDialog(GenericDialog gd) {
if (options.isLocal()) {
if (options.isFirstTime() && IJ.isMacOSX() && !options.isQuiet()) {
String osVersion = System.getProperty("os.version");
if (osVersion == null || osVersion.startsWith("10.4.") || osVersion.startsWith("10.3.") || osVersion.startsWith("10.2.")) {
// present user with one-time dialog box
IJ.showMessage("Bio-Formats", "One-time warning: There is a bug in Java on Mac OS X with the " + "native file chooser\nthat crashes ImageJ if you click on a file " + "in CXD, IPW, OIB or ZVI format while in\ncolumn view mode. You " + "can work around the problem in one of two ways:\n \n" + " 1. Switch to list view (press Command+2)\n" + " 2. Check \"Use JFileChooser to Open/Save\" under " + "Edit>Options>Input/Output...");
}
}
String idLabel = options.getLabel(ImporterOptions.KEY_ID);
od = new OpenDialog(idLabel, options.getId());
name = od.getFileName();
if (name == null)
return false;
} else if (options.isHTTP() || options.isOMERO()) {
gd.showDialog();
if (gd.wasCanceled())
return false;
}
return true;
}
use of ij.io.OpenDialog in project TrakEM2 by trakem2.
the class Loader method importImage.
/**
* Import a new image at the given coordinates; does not puts it into any layer, unless it's a stack -in which case importStack is called with the current front layer of the given project as target. If a path is not provided it will be asked for.
*/
public Patch importImage(final Project project, final double x, final double y, String path, final boolean synch_mipmap_generation) {
if (null == path) {
final OpenDialog od = new OpenDialog("Import image", "");
final String name = od.getFileName();
if (null == name || 0 == name.length())
return null;
String dir = od.getDirectory().replace('\\', '/');
if (!dir.endsWith("/"))
dir += "/";
path = dir + name;
} else {
path = path.replace('\\', '/');
}
// avoid opening trakem2 projects
if (path.toLowerCase().endsWith(".xml")) {
Utils.showMessage("Cannot import " + path + " as a stack.");
return null;
}
releaseToFit(new File(path).length() * 3);
IJ.redirectErrorMessages();
final ImagePlus imp = openImagePlus(path);
if (null == imp)
return null;
if (imp.getNSlices() > 1) {
// a stack!
final Layer layer = Display.getFrontLayer(project);
if (null == layer)
return null;
importStack(layer, x, y, imp, true, path, true);
return null;
}
if (0 == imp.getWidth() || 0 == imp.getHeight()) {
Utils.showMessage("Can't import image of zero width or height.");
flush(imp);
return null;
}
final Patch p = new Patch(project, imp.getTitle(), x, y, imp);
addedPatchFrom(path, p);
// WARNING may be altered concurrently
last_opened_path = path;
if (isMipMapsRegenerationEnabled()) {
if (synch_mipmap_generation) {
try {
// wait
regenerateMipMaps(p).get();
} catch (final Exception e) {
IJError.print(e);
}
} else
// queue for regeneration
regenerateMipMaps(p);
}
return p;
}
use of ij.io.OpenDialog in project TrakEM2 by trakem2.
the class Loader method openStack.
/**
* A dialog to open a stack, making sure there is enough memory for it.
*/
public synchronized ImagePlus openStack() {
final OpenDialog od = new OpenDialog("Select stack", OpenDialog.getDefaultDirectory(), null);
final String file_name = od.getFileName();
if (null == file_name || file_name.toLowerCase().startsWith("null"))
return null;
String dir = od.getDirectory().replace('\\', '/');
if (!dir.endsWith("/"))
dir += "/";
final File f = new File(dir + file_name);
if (!f.exists()) {
Utils.showMessage("File " + dir + file_name + " does not exist.");
return null;
}
// avoid opening trakem2 projects
if (file_name.toLowerCase().endsWith(".xml")) {
Utils.showMessage("Cannot import " + file_name + " as a stack.");
return null;
}
// estimate file size: assumes an uncompressed tif, or a zipped tif with an average compression ratio of 2.5
// in megabytes
long size = f.length() / 1024;
if (file_name.length() - 4 == file_name.toLowerCase().lastIndexOf(".zip")) {
// 2.5 is a reasonable compression ratio estimate based on my experience
size = (long) (size * 2.5);
}
releaseToFit(size);
ImagePlus imp_stack = null;
try {
IJ.redirectErrorMessages();
imp_stack = openImagePlus(f.getCanonicalPath());
} catch (final Exception e) {
IJError.print(e);
return null;
}
if (null == imp_stack) {
Utils.showMessage("Can't open the stack.");
return null;
} else if (1 == imp_stack.getStackSize()) {
Utils.showMessage("Not a stack!");
return null;
}
// the open... command
return imp_stack;
}
Aggregations