use of org.cytoscape.view.presentation.annotations.GroupAnnotation in project cytoscape-impl by cytoscape.
the class AnnotationManagerImpl method removeAnnotations.
@Override
public void removeAnnotations(Collection<? extends Annotation> annotations) {
Map<DGraphView, List<DingAnnotation>> annotationsByView = groupByView(annotations);
if (annotationsByView.isEmpty())
return;
invokeOnEDTAndWait(() -> {
annotationsByView.forEach((view, viewAnnotations) -> {
Map<ArbitraryGraphicsCanvas, List<DingAnnotation>> annotationsByCanvas = groupByCanvas(view, viewAnnotations);
annotationsByCanvas.forEach((canvas, dingAnnotations) -> {
// The following code is a batch version of Annotation.removeAnnotation()
for (DingAnnotation a : dingAnnotations) {
GroupAnnotation parent = a.getGroupParent();
if (parent != null) {
parent.removeMember(a);
}
}
canvas.removeAnnotations(getArrows(dingAnnotations));
canvas.removeAnnotations(dingAnnotations);
canvas.repaint();
});
});
});
}
use of org.cytoscape.view.presentation.annotations.GroupAnnotation in project cytoscape-impl by cytoscape.
the class LayerAnnotationTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
JComponent canvas = annotation.getCanvas();
if (annotation instanceof GroupAnnotation) {
int z = zorder;
for (Annotation ann : ((GroupAnnotation) annotation).getMembers()) {
DingAnnotation dAnn = (DingAnnotation) ann;
z += 1;
dAnn.getCanvas().setComponentZOrder(dAnn.getComponent(), z);
}
}
canvas.setComponentZOrder(annotation.getComponent(), zorder);
canvas.repaint();
if (view instanceof DGraphView) {
DGraphView dView = (DGraphView) view;
CyAnnotator cyAnnotator = dView.getCyAnnotator();
// Force an update of all of the argMaps
for (Annotation ann : cyAnnotator.getAnnotations()) cyAnnotator.addAnnotation(ann);
}
// We need to do this to update the Bird's Eye View
annotation.contentChanged();
}
use of org.cytoscape.view.presentation.annotations.GroupAnnotation in project cytoscape-impl by cytoscape.
the class GroupAnnotationFactory method createAnnotation.
@Override
public GroupAnnotation createAnnotation(Class<? extends GroupAnnotation> type, CyNetworkView view, Map<String, String> argMap) {
if (!(view instanceof DGraphView))
return null;
DGraphView dView = (DGraphView) view;
if (type.equals(GroupAnnotation.class)) {
final GroupAnnotationImpl a = new GroupAnnotationImpl(dView, argMap, getActiveWindow());
a.update();
return (GroupAnnotation) a;
} else {
return null;
}
}
use of org.cytoscape.view.presentation.annotations.GroupAnnotation in project cytoscape-impl by cytoscape.
the class CyAnnotator method loadAnnotations.
public void loadAnnotations() {
// Make sure we're on the EDT since we directly add annotations to the canvas
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
loadAnnotations();
}
});
return;
}
// System.out.println("Loading annotations");
CyNetwork network = view.getModel();
// Now, see if this network has any existing annotations
final CyTable networkAttributes = network.getTable(CyNetwork.class, CyNetwork.LOCAL_ATTRS);
if (networkAttributes.getColumn(ANNOTATION_ATTRIBUTE) == null) {
networkAttributes.createListColumn(ANNOTATION_ATTRIBUTE, String.class, false, Collections.EMPTY_LIST);
}
List<String> annotations = network.getRow(network, CyNetwork.LOCAL_ATTRS).getList(ANNOTATION_ATTRIBUTE, String.class);
List<Map<String, String>> arrowList = // Keep a list of arrows
new ArrayList<Map<String, String>>();
Map<GroupAnnotation, String> groupMap = // Keep a map of groups and uuids
new HashMap<GroupAnnotation, String>();
Map<String, Annotation> uuidMap = new HashMap<String, Annotation>();
Map<Object, Map<Integer, DingAnnotation>> zOrderMap = new HashMap<>();
if (annotations != null) {
for (String s : annotations) {
Map<String, String> argMap = createArgMap(s);
DingAnnotation annotation = null;
String type = argMap.get("type");
if (type == null)
continue;
if (type.equals("ARROW") || type.equals("org.cytoscape.view.presentation.annotations.ArrowAnnotation")) {
arrowList.add(argMap);
continue;
}
Annotation a = annotationFactoryManager.createAnnotation(type, view, argMap);
if (a == null || !(a instanceof DingAnnotation))
continue;
annotation = (DingAnnotation) a;
uuidMap.put(annotation.getUUID().toString(), annotation);
Object canvas;
if (annotation.getCanvas() != null) {
annotation.getCanvas().add(annotation.getComponent());
canvas = annotation.getCanvas();
} else {
canvas = foreGroundCanvas;
foreGroundCanvas.add(annotation.getComponent());
}
if (argMap.containsKey(Annotation.Z)) {
int zOrder = Integer.parseInt(argMap.get(Annotation.Z));
if (zOrder >= 0) {
if (!zOrderMap.containsKey(canvas))
zOrderMap.put(canvas, new TreeMap<>());
zOrderMap.get(canvas).put(zOrder, annotation);
}
}
addAnnotation(annotation);
// If this is a group, save the annotation and the memberUIDs list
if (type.equals("GROUP") || type.equals("org.cytoscape.view.presentation.annotations.GroupAnnotation")) {
// Don't bother adding the group if it doesn't have any children
if (argMap.containsKey("memberUUIDs"))
groupMap.put((GroupAnnotation) a, argMap.get("memberUUIDs"));
}
}
// Now, handle all of our groups
for (GroupAnnotation group : groupMap.keySet()) {
String uuids = groupMap.get(group);
String[] uuidArray = uuids.split(",");
for (String uuid : uuidArray) {
if (uuidMap.containsKey(uuid)) {
Annotation child = uuidMap.get(uuid);
group.addMember(child);
}
}
}
// Now, handle all of our arrows
for (Map<String, String> argMap : arrowList) {
String type = argMap.get("type");
Annotation annotation = annotationFactoryManager.createAnnotation(type, view, argMap);
if (annotation instanceof ArrowAnnotationImpl) {
ArrowAnnotationImpl arrow = (ArrowAnnotationImpl) annotation;
arrow.getSource().addArrow(arrow);
Object canvas;
if (arrow.getCanvas() != null) {
arrow.getCanvas().add(arrow.getComponent());
canvas = arrow.getCanvas();
} else {
foreGroundCanvas.add(arrow.getComponent());
canvas = foreGroundCanvas;
}
if (argMap.containsKey(Annotation.Z)) {
int zOrder = Integer.parseInt(argMap.get(Annotation.Z));
if (zOrder >= 0) {
if (!zOrderMap.containsKey(canvas))
zOrderMap.put(canvas, new TreeMap<>());
zOrderMap.get(canvas).put(zOrder, arrow);
}
}
addAnnotation(arrow);
}
}
// We use a TreeMap so that the keys (the zOrder are ordered)
for (Map<Integer, DingAnnotation> map : zOrderMap.values()) {
for (Integer zOrder : map.keySet()) {
// System.out.println("zOrder = "+zOrder);
DingAnnotation a = map.get(zOrder);
if (a.getCanvas() != null)
a.getCanvas().setComponentZOrder(a.getComponent(), zOrder);
else
foreGroundCanvas.setComponentZOrder(a.getComponent(), zOrder);
}
}
}
}
Aggregations