use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.
the class ProjectThing method setVisible.
/**
* Switch the visibility of the Displayable objects contained here or in the children.
*/
public void setVisible(boolean b) {
if (object instanceof Displayable) {
Displayable d = (Displayable) object;
d.setVisible(b);
Display.updateCheckboxes(d, DisplayablePanel.VISIBILITY_STATE, b);
}
if (null != al_children) {
synchronized (al_children) {
for (ProjectThing pt : al_children) pt.setVisible(b);
}
}
}
use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.
the class ProjectThing method setTitle.
public void setTitle(String title) {
// A Thing has a title as the object when it has no object, because the object gives it the title (the Thing only defines the type)
if (null == title || title.length() < 1) {
// reset title
if (object != null && object instanceof String)
this.object = template.getType();
return;
}
if (null == object || object instanceof String) {
object = title;
updateInDatabase("title");
// find any children that are using this title in addition to their own for the DisplayablePanel, and update it.
if (null != al_children) {
synchronized (al_children) {
for (ProjectThing pt : al_children) {
if (pt.object instanceof Displayable) {
Displayable d = (Displayable) pt.object;
Display.updateTitle(d.getLayer(), d);
} else if (pt.getType().equals("profile_list")) {
if (null == pt.al_children)
continue;
for (ProjectThing pd : pt.al_children) {
Displayable d = (Displayable) pd.object;
Display.updateTitle(d.getLayer(), d);
}
}
}
}
}
} else {
try {
Method setTitle = null;
if (object instanceof Displayable) {
((Displayable) object).setTitle(title);
} else {
setTitle = object.getClass().getDeclaredMethod("setTitle", new Class[] { String.class });
setTitle.invoke(object, new Object[] { title });
}
} catch (NoSuchMethodException nsme) {
Utils.log("No such method: setTitle, for object " + object);
} catch (Exception e) {
Utils.log("ProjectThing.setTitle: no such method setTitle or can't access it, in the object " + object);
IJError.print(e);
}
}
}
use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.
the class ProjectThing method measure.
/**
* Call on children things, and on itself if it contains a basic data type directly.
* All children of the same type report to the same table.
* Result tables are returned without ever displaying them.
*/
public HashMap<Class<?>, ResultsTable> measure(HashMap<Class<?>, ResultsTable> ht) {
if (null == ht)
ht = new HashMap<Class<?>, ResultsTable>();
if (null != object && object instanceof Displayable) {
Displayable d = (Displayable) object;
if (d.isVisible()) {
ResultsTable rt = d.measure(ht.get(d.getClass()));
if (null != rt)
ht.put(d.getClass(), rt);
// Areas:
if (object instanceof AreaContainer) {
ResultsTable rta = ((AreaContainer) object).measureAreas(ht.get(AreaContainer.class));
if (null != rta)
ht.put(AreaContainer.class, rta);
}
} else {
Utils.log("Measure: skipping hidden object " + d.getProject().getMeaningfulTitle(d));
}
}
if (null == al_children)
return ht;
// profile list: always special ...
if (template.getType().equals("profile_list") && null != al_children) {
synchronized (al_children) {
if (al_children.size() > 1) {
Profile[] p = new Profile[al_children.size()];
for (int i = 0; i < al_children.size(); i++) p[i] = (Profile) al_children.get(i).object;
ResultsTable rt = Profile.measure(p, ht.get(Profile.class), this.id);
if (null != rt)
ht.put(Profile_List.class, rt);
// return ht; // don't return: do each profile separately as well
}
}
}
synchronized (al_children) {
for (ProjectThing child : al_children) child.measure(ht);
}
return ht;
}
use of ini.trakem2.tree.ProjectThing in project TrakEM2 by trakem2.
the class ProjectTree method mousePressed.
public void mousePressed(final MouseEvent me) {
super.dispatcher.execSwing(new Runnable() {
public void run() {
if (!me.getSource().equals(ProjectTree.this) || !project.isInputEnabled()) {
return;
}
final int x = me.getX();
final int y = me.getY();
// find the node and set it selected
final TreePath path = getPathForLocation(x, y);
if (null == path) {
return;
}
ProjectTree.this.setSelectionPath(path);
selected_node = (DefaultMutableTreeNode) path.getLastPathComponent();
if (2 == me.getClickCount() && !me.isPopupTrigger() && MouseEvent.BUTTON1 == me.getButton()) {
// show in the front Display
if (null == selected_node)
return;
Object obt = selected_node.getUserObject();
if (!(obt instanceof ProjectThing))
return;
ProjectThing thing = (ProjectThing) obt;
thing.setVisible(true);
Object obd = thing.getObject();
if (obd instanceof Displayable) {
// additionaly, get the front Display (or make a new one if none) and show in it the layer in which the Displayable object is contained.
Displayable displ = (Displayable) obd;
Display.showCentered(displ.getLayer(), displ, true, me.isShiftDown());
}
return;
} else if (me.isPopupTrigger() || (ij.IJ.isMacOSX() && me.isControlDown()) || MouseEvent.BUTTON2 == me.getButton() || 0 != (me.getModifiers() & Event.META_MASK)) {
// the last block is from ij.gui.ImageCanvas, aparently to make the right-click work on windows?
JPopupMenu popup = getPopupMenu(selected_node);
if (null == popup)
return;
popup.show(ProjectTree.this, x, y);
return;
}
}
});
}
use of ini.trakem2.tree.ProjectThing 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;
}
Aggregations