Search in sources :

Example 6 with Project

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

the class DBLoader method getChildrenTemplateThings.

/**
 * Recursive into children.
 */
private ArrayList getChildrenTemplateThings(Project project, long parent_id) throws Exception {
    ArrayList al = new ArrayList();
    ResultSet r = connection.prepareStatement("SELECT * FROM ab_things WHERE parent_id=" + parent_id).executeQuery();
    while (r.next()) {
        long id = r.getLong("id");
        String type = r.getString("type");
        TemplateThing tt = new TemplateThing(type, project, id);
        tt.setup(getChildrenTemplateThings(project, id));
        al.add(tt);
    }
    r.close();
    return al;
}
Also used : TemplateThing(ini.trakem2.tree.TemplateThing) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet)

Example 7 with Project

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

the class DBLoader method fetchProfile.

private Profile fetchProfile(Project project, long id) throws Exception {
    // joint call
    ResultSet r = connection.prepareStatement("SELECT ab_profiles.id, ab_displayables.id, title, width, height, alpha, visible, color_red, color_green, color_blue, closed, locked, m00, m10, m01, m11, m02, m12 FROM ab_profiles, ab_displayables WHERE ab_profiles.id=ab_displayables.id AND ab_profiles.id=" + id).executeQuery();
    Profile p = null;
    if (r.next()) {
        p = new Profile(project, id, r.getString("title"), (float) r.getDouble("width"), (float) r.getDouble("height"), (float) r.getDouble("alpha"), r.getBoolean("visible"), new Color(r.getInt("color_red"), r.getInt("color_green"), r.getInt("color_blue")), r.getBoolean("closed"), r.getBoolean("locked"), new AffineTransform(r.getDouble("m00"), r.getDouble("m10"), r.getDouble("m01"), r.getDouble("m11"), r.getDouble("m02"), r.getDouble("m12")));
    // the polygon is not loaded, only when repainting the profile.
    }
    r.close();
    return p;
}
Also used : Color(java.awt.Color) ResultSet(java.sql.ResultSet) AffineTransform(java.awt.geom.AffineTransform) Profile(ini.trakem2.display.Profile)

Example 8 with Project

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

the class DBLoader method getProjectThing.

private ProjectThing getProjectThing(ResultSet r, Project project, HashMap<String, TemplateThing> hs_tt, HashMap<Long, Displayable> hs_d) throws Exception {
    long id = r.getLong("id");
    String type = r.getString("type");
    TemplateThing tt = (TemplateThing) hs_tt.get(type);
    if (null == tt) {
        Utils.log("Loader.getProjectThing: can not find a proper TemplateThing of type " + type + " for the ProjectThing of id=" + id);
        return null;
    }
    long object_id = r.getLong("object_id");
    // may be null
    Object ob = r.getString("title");
    if (-1 != object_id) {
        ob = getProjectObject(project, object_id);
        if (ob instanceof Displayable)
            hs_d.put(new Long(((Displayable) ob).getId()), (Displayable) ob);
        else
            Utils.log("Loader.getProjectThing: not adding to hs_d: " + ob);
    }
    return new ProjectThing(tt, project, id, ob, getChildrenProjectThings(project, id, type, hs_tt, hs_d));
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) TemplateThing(ini.trakem2.tree.TemplateThing) ProjectThing(ini.trakem2.tree.ProjectThing)

Example 9 with Project

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

the class DBLoader method fetchAreaList.

private AreaList fetchAreaList(Project project, long id) throws Exception {
    ResultSet r = connection.createStatement().executeQuery("SELECT area_list_id, layer_id FROM ab_area_paths WHERE area_list_id=" + id);
    ArrayList al_ul = new ArrayList();
    while (r.next()) {
        // the ids of the unloaded layers
        al_ul.add(new Long(r.getLong(2)));
    }
    r.close();
    r = connection.prepareStatement("SELECT ab_displayables.id, title, ab_displayables.width, height, alpha, visible, color_red, color_green, color_blue, locked, m00, m10, m01, m11, m02, m12, ab_zdisplayables.id FROM ab_zdisplayables, ab_displayables WHERE ab_zdisplayables.id=ab_displayables.id AND ab_zdisplayables.id=" + id).executeQuery();
    AreaList area_list = null;
    if (r.next()) {
        area_list = new AreaList(project, id, r.getString("title"), (float) r.getDouble("width"), (float) r.getDouble("height"), r.getFloat("alpha"), r.getBoolean("visible"), new Color(r.getInt("color_red"), r.getInt("color_green"), r.getInt("color_blue")), r.getBoolean("locked"), al_ul, new AffineTransform(r.getDouble("m00"), r.getDouble("m10"), r.getDouble("m01"), r.getDouble("m11"), r.getDouble("m02"), r.getDouble("m12")));
    }
    r.close();
    return area_list;
}
Also used : Color(java.awt.Color) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) AffineTransform(java.awt.geom.AffineTransform) AreaList(ini.trakem2.display.AreaList)

Example 10 with Project

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

the class DBLoader method getLayerThing.

private LayerThing getLayerThing(ResultSet r, Project project, HashMap hs_pt, TemplateThing layer_set_tt, TemplateThing layer_tt) throws Exception {
    long id = r.getLong("id");
    String type = r.getString("type");
    // if not a "Layer", then it's a "Layer Set"
    TemplateThing template = type.equals("layer_set") ? layer_set_tt : layer_tt;
    // HERE the order of the arguments layer_set_tt and layer_tt was inverted, and it worked??? There was a compensating bug, incredibly enough, in the type.equals(.. above.
    return new LayerThing(template, project, id, r.getString("title"), getLayerThingObject(project, r.getLong("object_id"), template, hs_pt), getChildrenLayerThing(project, id, hs_pt, layer_set_tt, layer_tt));
}
Also used : LayerThing(ini.trakem2.tree.LayerThing) TemplateThing(ini.trakem2.tree.TemplateThing)

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