Search in sources :

Example 11 with DirectoryChooser

use of ij.io.DirectoryChooser in project TrakEM2 by trakem2.

the class FSLoader method obtainUNUIdFolder.

/**
 * Return the unuid_dir or null if none valid selected.
 */
private String obtainUNUIdFolder() {
    YesNoCancelDialog yn = ControlWindow.makeYesNoCancelDialog("Old .xml version!", "The loaded XML file does not contain an UNUId. Select a shared UNUId folder?\nShould look similar to: trakem2.12345678.12345678.12345678");
    if (!yn.yesPressed())
        return null;
    DirectoryChooser dc = new DirectoryChooser("Select UNUId folder");
    String unuid_dir = dc.getDirectory();
    String unuid_dir_name = new File(unuid_dir).getName();
    Utils.log2("Selected UNUId folder: " + unuid_dir + "\n with name: " + unuid_dir_name);
    if (null != unuid_dir) {
        if (IJ.isWindows())
            unuid_dir = unuid_dir.replace('\\', '/');
        if (!unuid_dir_name.startsWith("trakem2.")) {
            Utils.logAll("Invalid UNUId folder: must start with \"trakem2.\". Try again or cancel.");
            return obtainUNUIdFolder();
        } else {
            String[] nums = unuid_dir_name.split("\\.");
            if (nums.length != 4) {
                Utils.logAll("Invalid UNUId folder: needs trakem + 3 number blocks. Try again or cancel.");
                return obtainUNUIdFolder();
            }
            for (int i = 1; i < nums.length; i++) {
                try {
                    Long.parseLong(nums[i]);
                } catch (NumberFormatException nfe) {
                    Utils.logAll("Invalid UNUId folder: at least one block is not a number. Try again or cancel.");
                    return obtainUNUIdFolder();
                }
            }
            // ok, aceptamos pulpo
            // remove prefix "trakem2."
            String unuid = unuid_dir_name.substring(8);
            if (unuid.endsWith("/"))
                unuid = unuid.substring(0, unuid.length() - 1);
            this.unuid = unuid;
            if (!unuid_dir.endsWith("/"))
                unuid_dir += "/";
            String dir_storage = new File(unuid_dir).getParent().replace('\\', '/');
            if (!dir_storage.endsWith("/"))
                dir_storage += "/";
            this.dir_storage = dir_storage;
            this.dir_mipmaps = unuid_dir + "trakem2.mipmaps/";
            return unuid_dir;
        }
    }
    return null;
}
Also used : YesNoCancelDialog(ij.gui.YesNoCancelDialog) File(java.io.File) DirectoryChooser(ij.io.DirectoryChooser)

Example 12 with DirectoryChooser

use of ij.io.DirectoryChooser in project TrakEM2 by trakem2.

the class FSLoader method createMipMapsDir.

/**
 * If parent path is null, it's asked for.
 */
private boolean createMipMapsDir(String parent_path) {
    if (null == this.unuid)
        this.unuid = createUNUId(parent_path);
    if (null == parent_path) {
        // try to create it in the same directory where the XML file is
        if (null != dir_storage) {
            File f = new File(getUNUIdFolder() + "/trakem2.mipmaps");
            if (!f.exists()) {
                try {
                    if (f.mkdir()) {
                        this.dir_mipmaps = f.getAbsolutePath().replace('\\', '/');
                        if (!dir_mipmaps.endsWith("/"))
                            this.dir_mipmaps += "/";
                        return true;
                    }
                } catch (Exception e) {
                }
            } else if (f.isDirectory()) {
                this.dir_mipmaps = f.getAbsolutePath().replace('\\', '/');
                if (!dir_mipmaps.endsWith("/"))
                    this.dir_mipmaps += "/";
                return true;
            }
        // else can't use it
        }
        // else,  ask for a new folder
        final DirectoryChooser dc = new DirectoryChooser("Select MipMaps parent directory");
        parent_path = dc.getDirectory();
        if (null == parent_path)
            return false;
        if (IJ.isWindows())
            parent_path = parent_path.replace('\\', '/');
        if (!parent_path.endsWith("/"))
            parent_path += "/";
    }
    // examine parent path
    final File file = new File(parent_path);
    if (file.exists()) {
        if (file.isDirectory()) {
            // all OK
            this.dir_mipmaps = parent_path + "trakem2." + unuid + "/trakem2.mipmaps/";
            try {
                File f = new File(this.dir_mipmaps);
                f.mkdirs();
                if (!f.exists()) {
                    Utils.log("Could not create trakem2.mipmaps!");
                    return false;
                }
            } catch (Exception e) {
                IJError.print(e);
                return false;
            }
        } else {
            Utils.showMessage("Selected parent path is not a directory. Please choose another one.");
            return createMipMapsDir(null);
        }
    } else {
        Utils.showMessage("Parent path does not exist. Please select a new one.");
        return createMipMapsDir(null);
    }
    return true;
}
Also used : File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) DirectoryChooser(ij.io.DirectoryChooser)

Aggregations

DirectoryChooser (ij.io.DirectoryChooser)12 File (java.io.File)10 ImagePlus (ij.ImagePlus)7 Worker (ini.trakem2.utils.Worker)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 YesNoCancelDialog (ij.gui.YesNoCancelDialog)4 Layer (ini.trakem2.display.Layer)4 Calibration (ij.measure.Calibration)3 ByteProcessor (ij.process.ByteProcessor)3 LayerSet (ini.trakem2.display.LayerSet)3 Rectangle (java.awt.Rectangle)3 AffineTransform (java.awt.geom.AffineTransform)3 IOException (java.io.IOException)3 Future (java.util.concurrent.Future)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ImageStack (ij.ImageStack)2 GenericDialog (ij.gui.GenericDialog)2 Roi (ij.gui.Roi)2 FileSaver (ij.io.FileSaver)2