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();
}
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;
}
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;
}
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));
}
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;
}
Aggregations