Search in sources :

Example 41 with Project

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

the class ProjectThing method createChild.

public ProjectThing createChild(String type) {
    // create the Displayable
    TemplateThing tt = template.getChildTemplate(type);
    if (null == tt) {
        Utils.log2("Can't create a child of type " + type);
        return null;
    }
    Object ob = project.makeObject(tt);
    Layer layer = null;
    if (ob instanceof Displayable) {
        // which layer to add it to? Get it from the front Display
        layer = Display.getFrontLayer(this.project);
        if (null == layer) {
            Utils.showMessage("Open a display first!");
            ((DBObject) ob).removeFromDatabase();
            return null;
        }
    }
    // wrap it in a new ProjectThing
    ProjectThing pt = null;
    try {
        pt = new ProjectThing(tt, project, ob);
    } catch (Exception e) {
        IJError.print(e);
        return null;
    }
    // add it here as child
    addChild(pt);
    // finally, add it to the layer if appropriate
    if (null != layer) {
        if (ob instanceof ZDisplayable) {
            layer.getParent().add((ZDisplayable) ob);
        } else {
            layer.add((Displayable) ob);
        }
    }
    // finally, return it to be added to the ProjectTree as a new node
    return pt;
}
Also used : ZDisplayable(ini.trakem2.display.ZDisplayable) ZDisplayable(ini.trakem2.display.ZDisplayable) Displayable(ini.trakem2.display.Displayable) DBObject(ini.trakem2.persistence.DBObject) Layer(ini.trakem2.display.Layer) DBObject(ini.trakem2.persistence.DBObject)

Example 42 with Project

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

the class ProjectThing method createClonedChild.

/**
 * At the moment only for basic types, which by definition have no children.
 */
public ProjectThing createClonedChild(final ProjectThing child) {
    // must be a child and a basic type
    if (null == child || null == child.object || null == al_children || !al_children.contains(child) || !Project.isBasicType(child.getType())) {
        return null;
    }
    final Displayable displ = (Displayable) ((Displayable) child.object).clone();
    ProjectThing pt = null;
    try {
        pt = new ProjectThing(child.template, project, displ);
        addChild(pt);
        // add to the proper container
        if (displ instanceof ZDisplayable) {
            ZDisplayable original = (ZDisplayable) child.object;
            original.getLayerSet().add((ZDisplayable) displ);
            Display.repaint(original.getLayerSet(), (ZDisplayable) displ, 5);
        } else {
            Displayable original = (Displayable) child.object;
            original.getLayer().add(displ);
            Display.repaint(original.getLayer(), displ, 5);
        }
        // user-friendly copy:
        displ.setLocked(false);
        displ.setVisible(true);
        // set the copy as selected in the front Display, if any
        if (null != Display.getFront())
            Display.getFront().select(displ);
    } catch (Exception e) {
        IJError.print(e);
        return null;
    }
    return pt;
}
Also used : ZDisplayable(ini.trakem2.display.ZDisplayable) ZDisplayable(ini.trakem2.display.ZDisplayable) Displayable(ini.trakem2.display.Displayable)

Example 43 with Project

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

the class ProjectTree method tryAddNewConnector.

/**
 * If the parent node of {@code active} can accept a Connector or has a direct child
 * node that can accept a {@link Connector}, add a new {@link Connector} and return it.
 *
 * @param d The {@link Displayable} that serves as reference, to decide which node to add the new {@link Connector}.
 * @param selectNode Whether to select the new node containing the {@link Connector} in the ProjectTree.
 *
 * @return The newly created {@link Connector}.
 */
public Connector tryAddNewConnector(final Displayable d, final boolean selectNode) {
    ProjectThing pt = project.findProjectThing(d);
    ProjectThing parent = (ProjectThing) pt.getParent();
    TemplateThing connectorType = project.getTemplateThing("connector");
    boolean add = false;
    if (parent.canHaveAsChild(connectorType)) {
        // Add as a sibling of pt
        add = true;
    } else {
        // Inspect if any of the sibling nodes can have it as child
        for (final ProjectThing child : parent.getChildren()) {
            if (child.canHaveAsChild(connectorType)) {
                parent = child;
                add = true;
                break;
            }
        }
    }
    Connector c = null;
    DefaultMutableTreeNode node = null;
    if (add) {
        // reuse same String instance
        c = new Connector(project, connectorType.getType());
        node = addChild(parent, connectorType.getType(), c);
    }
    if (null != node) {
        d.getLayerSet().add(c);
        if (selectNode)
            setSelectionPath(new TreePath(node.getPath()));
        return c;
    }
    Utils.logAll("Could not add a new Connector related to " + d);
    return null;
}
Also used : Connector(ini.trakem2.display.Connector) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 44 with Project

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

the class ProjectTree method keyPressed.

@Override
public void keyPressed(final KeyEvent ke) {
    super.keyPressed(ke);
    if (ke.isConsumed())
        return;
    if (!ke.getSource().equals(ProjectTree.this) || !project.isInputEnabled()) {
        return;
    }
    // get the first selected node only
    TreePath path = getSelectionPath();
    if (null == path)
        return;
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    if (null == node)
        return;
    final ProjectThing pt = (ProjectThing) node.getUserObject();
    if (null == pt)
        return;
    // 
    final int flags = ke.getModifiers();
    switch(ke.getKeyCode()) {
        case KeyEvent.VK_PAGE_UP:
            move(node, -1);
            // in any case
            ke.consume();
            break;
        case KeyEvent.VK_PAGE_DOWN:
            move(node, 1);
            // in any case
            ke.consume();
            break;
        case KeyEvent.VK_F2:
            rename(pt);
            ke.consume();
            break;
        case KeyEvent.VK_H:
            if (0 == (flags ^ Event.ALT_MASK)) {
                pt.setVisible(true);
                ke.consume();
            } else if (0 == flags) {
                pt.setVisible(false);
                ke.consume();
            }
            break;
        case KeyEvent.VK_A:
            if (0 == flags || (0 == (flags ^ Event.SHIFT_MASK))) {
                selectInDisplay(pt, 0 == (flags ^ Event.SHIFT_MASK));
                ke.consume();
            }
            break;
        case KeyEvent.VK_3:
            if (0 == flags) {
                ini.trakem2.display.Display3D.showAndResetView(pt);
                ke.consume();
                break;
            }
        // else, flow:
        case KeyEvent.VK_1:
        case KeyEvent.VK_2:
        case KeyEvent.VK_4:
        case KeyEvent.VK_5:
        case KeyEvent.VK_6:
        case KeyEvent.VK_7:
        case KeyEvent.VK_8:
        case KeyEvent.VK_9:
            // run a plugin, if any
            if (pt.getObject() instanceof Displayable && null != Utils.launchTPlugIn(ke, "Project Tree", project, (Displayable) pt.getObject())) {
                ke.consume();
            }
            break;
    }
    ke.consume();
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 45 with Project

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

the class ProjectTree method remove.

/**
 * If the given node is null, it will be searched for.
 */
public boolean remove(final boolean check, final ProjectThing thing, final DefaultMutableTreeNode node) {
    final Object obd = thing.getObject();
    // shortcut to remove everything regardless.
    if (obd.getClass() == Project.class)
        return ((Project) obd).remove(check);
    final boolean b = thing.remove(check) && removeNode(null != node ? node : findNode(thing, this));
    Display.repaint();
    return b;
}
Also used : DBObject(ini.trakem2.persistence.DBObject)

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