use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CyAnnotator method addAnnotation.
public void addAnnotation(Annotation annotation) {
if (!(annotation instanceof DingAnnotation))
return;
DingAnnotation dingAnnotation = (DingAnnotation) annotation;
annotationMap.put(dingAnnotation, dingAnnotation.getArgMap());
updateNetworkAttributes(view.getModel());
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CyAnnotator method getComponentsAt.
/**
* Find all of our annotations that are at this point. Return the top annotation
* (the one with the lowest Z value) if there are more than one.
*
* @param cnvs the Canvas we're looking at
* @param x the x value of the point
* @param y the y value of the point
* @return the list of components
*/
public List<DingAnnotation> getComponentsAt(ArbitraryGraphicsCanvas cnvs, int x, int y) {
List<DingAnnotation> list = new ArrayList<>();
for (DingAnnotation a : annotationMap.keySet()) {
if (a.getCanvas().equals(cnvs) && a.getComponent().contains(x, y)) {
// Make sure to find the parent if this is a group
while (a.getGroupParent() != null) {
a = (DingAnnotation) a.getGroupParent();
}
if (!list.contains(a))
list.add(a);
}
}
// Now sort the list by Z order, smallest to largest
Collections.sort(list, new ZComparator(cnvs));
return list;
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation 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);
}
}
}
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CyAnnotator method removeAnnotations.
public void removeAnnotations(Collection<? extends Annotation> annotations) {
for (Annotation annotation : annotations) {
annotationMap.remove((DingAnnotation) annotation);
selectedAnnotations.remove(annotation);
}
updateNetworkAttributes(view.getModel());
}
use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.
the class CyAnnotator method clearSelectedAnnotations.
public void clearSelectedAnnotations() {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
clearSelectedAnnotations();
}
});
return;
}
boolean repaintForeGround = false;
boolean repaintBackGround = false;
for (DingAnnotation a : new ArrayList<DingAnnotation>(selectedAnnotations)) {
setSelectedAnnotation(a, false);
if (a.getCanvasName().equals(Annotation.FOREGROUND))
repaintForeGround = true;
else
repaintBackGround = true;
}
if (repaintForeGround)
foreGroundCanvas.repaint();
if (repaintBackGround)
backGroundCanvas.repaint();
}
Aggregations