Search in sources :

Example 11 with Treeline

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

the class ProjectTree method insertSegmentations.

/* // makes no sense, because there may be multiple projects open and thus the viewport and position may interfere with each other across multiple projects. Saving the collapsed node state suffices.
	public void exportXML(final StringBuffer sb_body, String indent, JScrollPane jsp) {
		Point p = jsp.getViewport().getViewPosition();
		Dimension d = jsp.getSize(null);
		sb_body.append(indent).append("<t2_tree")
		       .append(" width=\"").append(d.width).append('\"')
		       .append(" height=\"").append(d.height).append('\"')
		       .append(" viewport_x=\"").append(p.e).append('\"')
		       .append(" viewport_y=\"").append(p.y).append('\"')
		;
		sb_body.append("\n").append(indent).append("</t2_tree>\n");
	}
	*/
/**
 * Creates a new node of basic type for each AreaList, Ball, Pipe or Polyline present in the ArrayList. Other elements are ignored.
 */
public void insertSegmentations(final Collection<? extends Displayable> al) {
    final TemplateThing tt_root = (TemplateThing) project.getTemplateTree().getRoot().getUserObject();
    // create a new abstract node called "imported_segmentations", if not there
    final String imported_labels = "imported_labels";
    if (!project.typeExists(imported_labels)) {
        // create it
        // yes I know I should check for the project of each Displayable in the ArrayList
        TemplateThing tet = new TemplateThing(imported_labels, project);
        project.addUniqueType(tet);
        DefaultMutableTreeNode root = project.getTemplateTree().getRoot();
        tt_root.addChild(tet);
        DefaultMutableTreeNode child_node = addChild(tet, root);
        DNDTree.expandNode(project.getTemplateTree(), child_node);
    // JTree is serious pain
    }
    // it's the same as 'tet' above, unless it existed
    TemplateThing tt_is = project.getTemplateThing(imported_labels);
    // create a project node from "imported_segmentations" template under a new top node
    final DefaultMutableTreeNode project_node = project.getProjectTree().getRoot();
    ProjectThing project_pt = (ProjectThing) project_node.getUserObject();
    final ProjectThing ct = project_pt.createChild(tt_root.getType());
    ProjectThing pt_is = ct.createChild(imported_labels);
    // addChild(pt_is, ctn);
    final DefaultMutableTreeNode node_pt_is = new DefaultMutableTreeNode(pt_is);
    final HashMap<Class<?>, String> types = new HashMap<Class<?>, String>();
    types.put(AreaList.class, "area_list");
    types.put(Pipe.class, "pipe");
    types.put(Polyline.class, "polyline");
    types.put(Ball.class, "ball");
    types.put(Treeline.class, "treeline");
    types.put(AreaTree.class, "areatree");
    types.put(Connector.class, "connector");
    // now, insert a new ProjectThing if of type AreaList, Ball and/or Pipe under node_child
    for (final Displayable d : al) {
        final String type = types.get(d.getClass());
        if (null == type) {
            Utils.log("insertSegmentations: ignoring " + d);
            continue;
        }
        try {
            final TemplateThing tt = getOrCreateChildTemplateThing(tt_is, type);
            ProjectThing one = new ProjectThing(tt, project, d);
            pt_is.addChild(one);
            // addChild(one, node_pt_is);
            // at the end
            node_pt_is.add(new DefaultMutableTreeNode(one));
        // Utils.log2("one parent : " + one.getParent());
        } catch (Exception e) {
            IJError.print(e);
        }
    }
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            DefaultMutableTreeNode ctn = addChild(ct, project_node);
            ctn.add(node_pt_is);
            try {
                ProjectTree.this.scrollPathToVisible(new TreePath(node_pt_is.getPath()));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    DNDTree.expandNode(this, node_pt_is);
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) HashMap(java.util.HashMap)

Aggregations

HashSet (java.util.HashSet)6 GenericDialog (ij.gui.GenericDialog)4 AreaTree (ini.trakem2.display.AreaTree)4 Displayable (ini.trakem2.display.Displayable)4 ZDisplayable (ini.trakem2.display.ZDisplayable)4 Color (java.awt.Color)4 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LayerSet (ini.trakem2.display.LayerSet)3 Node (ini.trakem2.display.Node)3 Treeline (ini.trakem2.display.Treeline)3 List (java.util.List)3 PolygonRoi (ij.gui.PolygonRoi)2 Roi (ij.gui.Roi)2 ShapeRoi (ij.gui.ShapeRoi)2 AreaList (ini.trakem2.display.AreaList)2 Ball (ini.trakem2.display.Ball)2 Connector (ini.trakem2.display.Connector)2 DLabel (ini.trakem2.display.DLabel)2