Search in sources :

Example 21 with ProjectThing

use of ini.trakem2.tree.ProjectThing 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 22 with ProjectThing

use of ini.trakem2.tree.ProjectThing 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)

Example 23 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class ProjectTree method getPopupMenu.

/**
 * Get a custom, context-sensitive popup menu for the selected node.
 */
private JPopupMenu getPopupMenu(DefaultMutableTreeNode node) {
    Object ob = node.getUserObject();
    ProjectThing thing = null;
    if (ob instanceof ProjectThing) {
        thing = (ProjectThing) ob;
    } else {
        return null;
    }
    // context-sensitive popup
    JMenuItem[] items = thing.getPopupItems(this);
    if (0 == items.length)
        return null;
    JPopupMenu popup = new JPopupMenu();
    for (int i = 0; i < items.length; i++) {
        popup.add(items[i]);
    }
    JMenu node_menu = new JMenu("Node");
    JMenuItem item = new JMenuItem("Move up");
    item.addActionListener(this);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0, true));
    node_menu.add(item);
    item = new JMenuItem("Move down");
    item.addActionListener(this);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0, true));
    node_menu.add(item);
    item = new JMenuItem("Collapse nodes of children nodes");
    item.addActionListener(this);
    node_menu.add(item);
    popup.add(node_menu);
    JMenu send_menu = new JMenu("Send to");
    item = new JMenuItem("Sibling project");
    item.addActionListener(this);
    send_menu.add(item);
    popup.add(send_menu);
    return popup;
}
Also used : DBObject(ini.trakem2.persistence.DBObject) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu)

Example 24 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class ProjectTree method rename.

public void rename(final ProjectThing thing) {
    final Object ob = thing.getObject();
    final String old_title;
    if (null == ob)
        old_title = thing.getType();
    else if (ob instanceof DBObject)
        old_title = ((DBObject) ob).getTitle();
    else
        old_title = ob.toString();
    GenericDialog gd = ControlWindow.makeGenericDialog("New name");
    gd.addMessage("Old name: " + old_title);
    gd.addStringField("New name: ", old_title, 40);
    gd.showDialog();
    if (gd.wasCanceled())
        return;
    String title = gd.getNextString();
    if (null == title) {
        Utils.log("WARNING: avoided setting the title to null for " + thing);
        return;
    }
    // avoid XML problems - could also replace by double '', then replace again by " when reading.
    title = title.replace('"', '\'').trim();
    project.getRootLayerSet().addUndoStep(new RenameThingStep(thing));
    if (title.length() == 0) {
        // Set the title to the template type
        thing.setTitle(thing.getTemplate().getType());
        return;
    }
    thing.setTitle(title);
    this.updateUILater();
    project.getRootLayerSet().addUndoStep(new RenameThingStep(thing));
}
Also used : GenericDialog(ij.gui.GenericDialog) DBObject(ini.trakem2.persistence.DBObject) DBObject(ini.trakem2.persistence.DBObject)

Example 25 with ProjectThing

use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.

the class ProjectTree method remove.

/**
 * Remove the Thing and DefaultMutableTreeNode that wrap each of the Displayable;
 *  calls softRemove on each Displayable, and does NOT call remove on the Displayable.
 *  If a Displayable is not found, it returns it in a set of not found objects.
 *  If all are removed, returns an empty set.
 */
public final Set<Displayable> remove(final Set<? extends Displayable> displayables, final DefaultMutableTreeNode top) {
    final Enumeration<?> en = (null == top ? (DefaultMutableTreeNode) getModel().getRoot() : top).depthFirstEnumeration();
    final HashSet<DefaultMutableTreeNode> to_remove = new HashSet<DefaultMutableTreeNode>();
    final HashSet<Displayable> remaining = new HashSet<Displayable>(displayables);
    while (en.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
        final ProjectThing pt = (ProjectThing) node.getUserObject();
        if (remaining.remove(pt.getObject())) {
            // don't call remove on the object!
            pt.remove(false, false);
            ((Displayable) pt.getObject()).softRemove();
            to_remove.add(node);
        }
    }
    // Updates the model properly:
    for (final DefaultMutableTreeNode node : to_remove) {
        ((DefaultTreeModel) this.getModel()).removeNodeFromParent(node);
    }
    if (!remaining.isEmpty()) {
        Utils.log("Could not remove:", remaining);
    }
    return remaining;
}
Also used : Displayable(ini.trakem2.display.Displayable) ZDisplayable(ini.trakem2.display.ZDisplayable) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) HashSet(java.util.HashSet)

Aggregations

ProjectThing (ini.trakem2.tree.ProjectThing)27 DBObject (ini.trakem2.persistence.DBObject)17 HashMap (java.util.HashMap)17 ZDisplayable (ini.trakem2.display.ZDisplayable)16 Displayable (ini.trakem2.display.Displayable)15 ArrayList (java.util.ArrayList)12 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 HashSet (java.util.HashSet)10 TreePath (javax.swing.tree.TreePath)10 Project (ini.trakem2.Project)9 TemplateThing (ini.trakem2.tree.TemplateThing)8 Layer (ini.trakem2.display.Layer)7 LayerSet (ini.trakem2.display.LayerSet)7 Map (java.util.Map)7 LayerThing (ini.trakem2.tree.LayerThing)6 GenericDialog (ij.gui.GenericDialog)5 Profile (ini.trakem2.display.Profile)5 TreeMap (java.util.TreeMap)5 ImagePlus (ij.ImagePlus)4 Display (ini.trakem2.display.Display)3