Search in sources :

Example 71 with Project

use of ini.trakem2.Project in project TrakEM2 by trakem2.

the class Display method importNextImage.

protected Bureaucrat importNextImage() {
    final Worker worker = new // / all this verbosity is what happens when functions are not first class citizens. I could abstract it away by passing a string name "importImage" and invoking it with reflection, but that is an even bigger PAIN
    Worker(// / all this verbosity is what happens when functions are not first class citizens. I could abstract it away by passing a string name "importImage" and invoking it with reflection, but that is an even bigger PAIN
    "Import image") {

        @Override
        public void run() {
            startedWorking();
            try {
                final Rectangle srcRect = canvas.getSrcRect();
                // - imp.getWidth() / 2;
                final int x = srcRect.x + srcRect.width / 2;
                // - imp.getHeight()/ 2;
                final int y = srcRect.y + srcRect.height / 2;
                final Patch p = project.getLoader().importNextImage(project, x, y);
                if (null == p) {
                    Utils.showMessage("Could not open next image.");
                    finishedWorking();
                    return;
                }
                Display.this.getLayerSet().addLayerContentStep(layer);
                // will add it to the proper Displays
                layer.add(p);
                Display.this.getLayerSet().addLayerContentStep(layer);
            } catch (final Exception e) {
                IJError.print(e);
            }
            finishedWorking();
        }
    };
    return Bureaucrat.createAndStart(worker, getProject());
}
Also used : Rectangle(java.awt.Rectangle) Worker(ini.trakem2.utils.Worker) Point(java.awt.Point) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException)

Example 72 with Project

use of ini.trakem2.Project in project TrakEM2 by trakem2.

the class Project method getUniqueTypes.

/**
 * Returns a list of existing unique types in the template tree
 * (thus the 'project' type is not included, nor the label).
 * The basic types are guaranteed to be present even if there are no instances in the template tree.
 * As a side effect, this method populates the HashMap of unique TemplateThing types.
 */
public String[] getUniqueTypes() {
    synchronized (ht_unique_tt) {
        // ensure the basic types (pipe, ball, profile, profile_list) are present
        if (!ht_unique_tt.containsKey("profile"))
            ht_unique_tt.put("profile", new TemplateThing("profile"));
        if (!ht_unique_tt.containsKey("profile_list")) {
            TemplateThing tpl = new TemplateThing("profile_list");
            tpl.addChild((TemplateThing) ht_unique_tt.get("profile"));
            ht_unique_tt.put("profile_list", tpl);
        }
        if (!ht_unique_tt.containsKey("pipe"))
            ht_unique_tt.put("pipe", new TemplateThing("pipe"));
        if (!ht_unique_tt.containsKey("polyline"))
            ht_unique_tt.put("polyline", new TemplateThing("polyline"));
        if (!ht_unique_tt.containsKey("treeline"))
            ht_unique_tt.put("treeline", new TemplateThing("treeline"));
        if (!ht_unique_tt.containsKey("areatree"))
            ht_unique_tt.put("areatree", new TemplateThing("areatree"));
        if (!ht_unique_tt.containsKey("connector"))
            ht_unique_tt.put("connector", new TemplateThing("connector"));
        if (!ht_unique_tt.containsKey("ball"))
            ht_unique_tt.put("ball", new TemplateThing("ball"));
        if (!ht_unique_tt.containsKey("area_list"))
            ht_unique_tt.put("area_list", new TemplateThing("area_list"));
        if (!ht_unique_tt.containsKey("dissector"))
            ht_unique_tt.put("dissector", new TemplateThing("dissector"));
        // this should be done automagically by querying the classes in the package ... but java can't do that without peeking into the .jar .class files. Buh.
        TemplateThing project_tt = ht_unique_tt.remove("project");
        /* // debug
		for (Iterator it = ht_unique_tt.keySet().iterator(); it.hasNext(); ) {
			Utils.log2("class: " + it.next().getClass().getName());
		} */
        final String[] ut = new String[ht_unique_tt.size()];
        ht_unique_tt.keySet().toArray(ut);
        ht_unique_tt.put("project", project_tt);
        Arrays.sort(ut);
        return ut;
    }
}
Also used : TemplateThing(ini.trakem2.tree.TemplateThing)

Example 73 with Project

use of ini.trakem2.Project in project TrakEM2 by trakem2.

the class Project method destroy.

public boolean destroy() {
    if (null == loader) {
        return true;
    }
    if (loader.hasChanges() && !getBooleanProperty("no_shutdown_hook")) {
        // DBLoader always returns false
        if (ControlWindow.isGUIEnabled()) {
            final YesNoDialog yn = ControlWindow.makeYesNoDialog("TrakEM2", "There are unsaved changes in project " + title + ". Save them?");
            if (yn.yesPressed()) {
                save();
            }
        } else {
            Utils.log2("WARNING: closing project '" + title + "' with unsaved changes.");
        }
    }
    try {
        if (null != autosaving)
            autosaving.cancel(true);
    } catch (Throwable t) {
    }
    al_open_projects.remove(this);
    // flush all memory
    if (null != loader) {
        // the last project is destroyed twice for some reason, if several are open. This is a PATCH
        // and disconnect
        loader.destroy();
        loader = null;
    }
    if (null != layer_set)
        layer_set.destroy();
    // AFTER loader.destroy() call.
    ControlWindow.remove(this);
    if (null != template_tree)
        template_tree.destroy();
    if (null != project_tree)
        project_tree.destroy();
    if (null != layer_tree)
        layer_tree.destroy();
    Polyline.flushTraceCache(this);
    // flag to mean: we're closing
    this.template_tree = null;
    // close all open Displays
    Display.close(this);
    Search.removeTabs(this);
    synchronized (ptcache) {
        ptcache.clear();
    }
    return true;
}
Also used : YesNoDialog(ini.trakem2.display.YesNoDialog)

Example 74 with Project

use of ini.trakem2.Project in project TrakEM2 by trakem2.

the class Project method removeAll.

/**
 * Remove any set of Displayable objects from the Layer, LayerSet and Project Tree as necessary.
 *  ASSUMES there aren't any nested LayerSet objects in @param col.
 */
public final boolean removeAll(final Set<Displayable> col, final DefaultMutableTreeNode top_node) {
    // 0. Sort into Displayable and ZDisplayable
    final Set<ZDisplayable> zds = new HashSet<ZDisplayable>();
    final List<Displayable> ds = new ArrayList<Displayable>();
    for (final Displayable d : col) {
        if (d instanceof ZDisplayable) {
            zds.add((ZDisplayable) d);
        } else {
            ds.add(d);
        }
    }
    // Displayable:
    // 1. First the Profile from the Project Tree, one by one,
    // while creating a map of Layer vs Displayable list to remove in that layer:
    final HashMap<Layer, Set<Displayable>> ml = new HashMap<Layer, Set<Displayable>>();
    for (final Iterator<Displayable> it = ds.iterator(); it.hasNext(); ) {
        final Displayable d = it.next();
        if (d.getClass() == Profile.class) {
            if (!project_tree.remove(false, findProjectThing(d), null)) {
                // like Profile.remove2
                Utils.log("Could NOT delete " + d);
                continue;
            }
            // remove the Profile
            it.remove();
            continue;
        }
        // The map of Layer vs Displayable list
        Set<Displayable> l = ml.get(d.getLayer());
        if (null == l) {
            l = new HashSet<Displayable>();
            ml.put(d.getLayer(), l);
        }
        l.add(d);
    }
    // 2. Then the rest, in bulk:
    if (ml.size() > 0) {
        for (final Map.Entry<Layer, Set<Displayable>> e : ml.entrySet()) {
            e.getKey().removeAll(e.getValue());
        }
    }
    // 3. Stacks
    if (zds.size() > 0) {
        final Set<ZDisplayable> stacks = new HashSet<ZDisplayable>();
        for (final Iterator<ZDisplayable> it = zds.iterator(); it.hasNext(); ) {
            final ZDisplayable zd = it.next();
            if (zd.getClass() == Stack.class) {
                it.remove();
                stacks.add(zd);
            }
        }
        layer_set.removeAll(stacks);
    }
    // 4. ZDisplayable: bulk removal
    if (zds.size() > 0) {
        // 1. From the Project Tree:
        Set<Displayable> not_removed = project_tree.remove(zds, top_node);
        // 2. Then only those successfully removed, from the LayerSet:
        zds.removeAll(not_removed);
        layer_set.removeAll(zds);
    }
    // TODO
    return true;
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) Set(java.util.Set) HashSet(java.util.HashSet) LayerSet(ini.trakem2.display.LayerSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Layer(ini.trakem2.display.Layer) ZDisplayable(ini.trakem2.display.ZDisplayable) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 75 with Project

use of ini.trakem2.Project in project TrakEM2 by trakem2.

the class Project method save.

/**
 * Save the project regardless of what getLoader().hasChanges() reports.
 */
public String save() {
    // let it repaint the log window
    Thread.yield();
    XMLOptions options = new XMLOptions();
    options.overwriteXMLFile = true;
    options.export_images = false;
    options.patches_dir = null;
    options.include_coordinate_transform = true;
    String path = loader.save(this, options);
    if (null != path)
        restartAutosaving();
    return path;
}
Also used : XMLOptions(ini.trakem2.persistence.XMLOptions)

Aggregations

ArrayList (java.util.ArrayList)33 Project (ini.trakem2.Project)26 HashMap (java.util.HashMap)25 Layer (ini.trakem2.display.Layer)21 Displayable (ini.trakem2.display.Displayable)19 Patch (ini.trakem2.display.Patch)18 File (java.io.File)18 HashSet (java.util.HashSet)18 ZDisplayable (ini.trakem2.display.ZDisplayable)17 ImagePlus (ij.ImagePlus)16 ProjectThing (ini.trakem2.tree.ProjectThing)16 Worker (ini.trakem2.utils.Worker)16 TemplateThing (ini.trakem2.tree.TemplateThing)15 Map (java.util.Map)15 LayerSet (ini.trakem2.display.LayerSet)14 ResultSet (java.sql.ResultSet)13 DBObject (ini.trakem2.persistence.DBObject)12 AffineTransform (java.awt.geom.AffineTransform)11 TreeMap (java.util.TreeMap)11 FSLoader (ini.trakem2.persistence.FSLoader)10