Search in sources :

Example 21 with ZDisplayable

use of ini.trakem2.display.ZDisplayable in project TrakEM2 by trakem2.

the class DBLoader method fetchLayer.

/**
 * Load all objects into the Layer: Profile and Pipe from the hs_pt (full of ProjectThing wrapping them), and Patch, LayerSet, DLabel, etc from the database.
 */
private Layer fetchLayer(Project project, long id, HashMap hs_pt) throws Exception {
    ResultSet r = connection.prepareStatement("SELECT * FROM ab_layers WHERE id=" + id).executeQuery();
    Layer layer = null;
    if (r.next()) {
        long layer_id = r.getLong("id");
        layer = new Layer(project, layer_id, r.getDouble("z"), r.getDouble("thickness"));
        // find the Layer's parent
        long parent_id = r.getLong("layer_set_id");
        Object set = hs_pt.get(new Long(parent_id));
        if (null != set) {
            ((LayerSet) set).addSilently(layer);
        } else {
            Utils.log("Loader.fetchLayer: WARNING no parent for layer " + layer);
        }
        // add the displayables from hs_pt that correspond to this layer (and all other objects that belong to the layer)
        HashMap hs_d = new HashMap();
        ResultSet rd = connection.prepareStatement("SELECT ab_displayables.id, ab_profiles.id, layer_id, stack_index FROM ab_displayables,ab_profiles WHERE ab_displayables.id=ab_profiles.id AND layer_id=" + layer_id).executeQuery();
        while (rd.next()) {
            Long idd = new Long(rd.getLong("id"));
            Object ob = hs_pt.get(idd);
            // Utils.log("Found profile with id=" + idd + " and ob = " + ob);
            if (null != ob) {
                hs_d.put(new Integer(rd.getInt("stack_index")), ob);
            }
        }
        rd.close();
        // fetch LayerSet objects (which are also Displayable), and put them in the hs_pt (this is hackerous)
        ResultSet rls = connection.prepareStatement("SELECT * FROM ab_layer_sets, ab_displayables WHERE ab_layer_sets.id=ab_displayables.id AND ab_layer_sets.parent_layer_id=" + id).executeQuery();
        while (rls.next()) {
            long ls_id = rls.getLong("id");
            LayerSet layer_set = new LayerSet(project, ls_id, rls.getString("title"), (float) rls.getDouble("width"), (float) rls.getDouble("height"), rls.getDouble("rot_x"), rls.getDouble("rot_y"), rls.getDouble("rot_z"), (float) rls.getDouble("layer_width"), (float) rls.getDouble("layer_height"), rls.getBoolean("locked"), rls.getInt("snapshots_mode"), new AffineTransform(rls.getDouble("m00"), rls.getDouble("m10"), rls.getDouble("m01"), rls.getDouble("m11"), rls.getDouble("m02"), rls.getDouble("m12")));
            hs_pt.put(new Long(ls_id), layer_set);
            hs_d.put(new Integer(rls.getInt("stack_index")), layer_set);
            layer_set.setLayer(layer, false);
            // find the pipes (or other possible ZDisplayable objects) in the hs_pt that belong to this LayerSet and add them silently
            ResultSet rpi = connection.prepareStatement("SELECT ab_displayables.id, ab_zdisplayables.id, layer_id, layer_set_id, stack_index FROM ab_displayables,ab_zdisplayables WHERE ab_displayables.id=ab_zdisplayables.id AND layer_set_id=" + ls_id + " ORDER BY stack_index ASC").executeQuery();
            while (rpi.next()) {
                Long idd = new Long(rpi.getLong("id"));
                Object ob = hs_pt.get(idd);
                if (null != ob && ob instanceof ZDisplayable) {
                    layer_set.addSilently((ZDisplayable) ob);
                } else {
                    Utils.log("fetchLayer: failed to add a ZDisplayable to the layer_set. zdispl id = " + idd);
                }
            }
            rpi.close();
        }
        rls.close();
        // add Patch objects from ab_patches joint-called with ab_displayables
        ResultSet rp = connection.prepareStatement("SELECT ab_patches.id, ab_displayables.id, layer_id, title, width, height, stack_index, imp_type, locked, min, max, m00, m10, m01, m11, m02, m12 FROM ab_patches,ab_displayables WHERE ab_patches.id=ab_displayables.id AND ab_displayables.layer_id=" + layer_id).executeQuery();
        while (rp.next()) {
            long patch_id = rp.getLong("id");
            Patch patch = new Patch(project, patch_id, rp.getString("title"), (float) rp.getDouble("width"), (float) rp.getDouble("height"), rp.getInt("o_width"), rp.getInt("o_height"), rp.getInt("imp_type"), rp.getBoolean("locked"), rp.getDouble("min"), rp.getDouble("max"), new AffineTransform(rp.getDouble("m00"), rp.getDouble("m10"), rp.getDouble("m01"), rp.getDouble("m11"), rp.getDouble("m02"), rp.getDouble("m12")));
            // collecting all Displayable objects to reconstruct links
            hs_pt.put(new Long(patch_id), patch);
            hs_d.put(new Integer(rp.getInt("stack_index")), patch);
        }
        rp.close();
        // add DLabel objects
        ResultSet rl = connection.prepareStatement("SELECT ab_labels.id, ab_displayables.id, layer_id, title, width, height, m00, m10, m01, m11, m02, m12, stack_index, font_name, font_style, font_size, ab_labels.type, locked FROM ab_labels,ab_displayables WHERE ab_labels.id=ab_displayables.id AND ab_displayables.layer_id=" + layer_id).executeQuery();
        while (rl.next()) {
            long label_id = rl.getLong("id");
            DLabel label = new DLabel(project, label_id, rl.getString("title"), (float) rl.getDouble("width"), (float) rl.getDouble("height"), rl.getInt("type"), rl.getString("font_name"), rl.getInt("font_style"), rl.getInt("font_size"), rl.getBoolean("locked"), new AffineTransform(rl.getDouble("m00"), rl.getDouble("m10"), rl.getDouble("m01"), rl.getDouble("m11"), rl.getDouble("m02"), rl.getDouble("m12")));
            // collecting all Displayable objects to reconstruct links
            hs_pt.put(new Long(label_id), label);
            hs_d.put(new Integer(rl.getInt("stack_index")), label);
        }
        rl.close();
        // Add silently to the Layer ordered by stack index
        Set e = hs_d.keySet();
        Object[] si = new Object[hs_d.size()];
        si = e.toArray(si);
        // will it sort an array of integers correctly? Who knows!
        Arrays.sort(si);
        for (int i = 0; i < si.length; i++) {
            // Utils.log("Loader layer.addSilently: adding " + (DBObject)hs_d.get(si[i]));
            layer.addSilently((DBObject) hs_d.get(si[i]));
        }
        // find displays and open later, when fully loaded.
        ResultSet rdi = connection.prepareStatement("SELECT * FROM ab_displays WHERE layer_id=" + layer.getId()).executeQuery();
        while (rdi.next()) {
            fetchDisplay(rdi, layer);
        }
        rdi.close();
    }
    r.close();
    return layer;
}
Also used : ResultSet(java.sql.ResultSet) Set(java.util.Set) LayerSet(ini.trakem2.display.LayerSet) LayerSet(ini.trakem2.display.LayerSet) HashMap(java.util.HashMap) Layer(ini.trakem2.display.Layer) Point(java.awt.Point) PGpoint(org.postgresql.geometric.PGpoint) ZDisplayable(ini.trakem2.display.ZDisplayable) DLabel(ini.trakem2.display.DLabel) ResultSet(java.sql.ResultSet) AffineTransform(java.awt.geom.AffineTransform) Patch(ini.trakem2.display.Patch)

Example 22 with ZDisplayable

use of ini.trakem2.display.ZDisplayable in project TrakEM2 by trakem2.

the class Merger method makeGUI.

private static void makeGUI(final Project p1, final Project p2, HashSet<ZDisplayable> empty1, HashSet<ZDisplayable> empty2, HashMap<Displayable, List<Change>> matched, HashSet<ZDisplayable> unmatched1, HashSet<ZDisplayable> unmatched2) {
    final ArrayList<Row> rows = new ArrayList<Row>();
    for (Map.Entry<Displayable, List<Change>> e : matched.entrySet()) {
        for (Change c : e.getValue()) {
            rows.add(new Row(c));
        }
        if (e.getValue().size() > 1) {
            Utils.log("More than one assigned to " + e.getKey());
        }
    }
    JTabbedPane tabs = new JTabbedPane();
    final Table table = new Table();
    tabs.addTab("Matched", new JScrollPane(table));
    JTable tu1 = createTable(unmatched1, "Unmatched 1", p1, p2);
    JTable tu2 = createTable(unmatched2, "Unmatched 2", p1, p2);
    JTable tu3 = createTable(empty1, "Empty 1", p1, p2);
    JTable tu4 = createTable(empty2, "Empty 2", p1, p2);
    tabs.addTab("Unmatched 1", new JScrollPane(tu1));
    tabs.addTab("Unmatched 2", new JScrollPane(tu2));
    tabs.addTab("Empty 1", new JScrollPane(tu3));
    tabs.addTab("Empty 2", new JScrollPane(tu4));
    for (int i = 0; i < tabs.getTabCount(); i++) {
        if (null == tabs.getTabComponentAt(i)) {
            Utils.log2("null at " + i);
            continue;
        }
        tabs.getTabComponentAt(i).setPreferredSize(new Dimension(1024, 768));
    }
    String xml1 = new File(((FSLoader) p1.getLoader()).getProjectXMLPath()).getName();
    String xml2 = new File(((FSLoader) p2.getLoader()).getProjectXMLPath()).getName();
    JFrame frame = new JFrame("1: " + xml1 + "  ||  2: " + xml2);
    tabs.setPreferredSize(new Dimension(1024, 768));
    frame.getContentPane().add(tabs);
    frame.pack();
    frame.setVisible(true);
    // so the bullshit starts: any other way to set the model fails, because it tries to render it while setting it
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            table.setModel(new Model(rows));
            CustomCellRenderer cc = new CustomCellRenderer();
            for (int i = 0; i < Row.COLUMNS; i++) {
                table.setDefaultRenderer(table.getColumnClass(i), cc);
            }
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) ZDisplayable(ini.trakem2.display.ZDisplayable) Displayable(ini.trakem2.display.Displayable) JTable(javax.swing.JTable) JTabbedPane(javax.swing.JTabbedPane) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) FSLoader(ini.trakem2.persistence.FSLoader) JFrame(javax.swing.JFrame) JTable(javax.swing.JTable) ListSelectionModel(javax.swing.ListSelectionModel) AbstractTableModel(javax.swing.table.AbstractTableModel) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Aggregations

ZDisplayable (ini.trakem2.display.ZDisplayable)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 Displayable (ini.trakem2.display.Displayable)9 Layer (ini.trakem2.display.Layer)7 Worker (ini.trakem2.utils.Worker)6 Map (java.util.Map)6 GenericDialog (ij.gui.GenericDialog)5 LayerSet (ini.trakem2.display.LayerSet)5 Project (ini.trakem2.Project)4 DBObject (ini.trakem2.persistence.DBObject)4 ProjectThing (ini.trakem2.tree.ProjectThing)4 Point (java.awt.Point)4 Collection (java.util.Collection)4 List (java.util.List)4 TreeMap (java.util.TreeMap)4 ImagePlus (ij.ImagePlus)3 Roi (ij.gui.Roi)3 Display (ini.trakem2.display.Display)3