Search in sources :

Example 1 with GroupAnnotation

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();
            });
        });
    });
}
Also used : GroupAnnotation(org.cytoscape.view.presentation.annotations.GroupAnnotation) ArbitraryGraphicsCanvas(org.cytoscape.ding.impl.ArbitraryGraphicsCanvas) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) DGraphView(org.cytoscape.ding.impl.DGraphView)

Example 2 with GroupAnnotation

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();
}
Also used : GroupAnnotation(org.cytoscape.view.presentation.annotations.GroupAnnotation) JComponent(javax.swing.JComponent) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) CyAnnotator(org.cytoscape.ding.impl.cyannotator.CyAnnotator) GroupAnnotation(org.cytoscape.view.presentation.annotations.GroupAnnotation) Annotation(org.cytoscape.view.presentation.annotations.Annotation) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) DGraphView(org.cytoscape.ding.impl.DGraphView)

Example 3 with GroupAnnotation

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;
    }
}
Also used : GroupAnnotation(org.cytoscape.view.presentation.annotations.GroupAnnotation) GroupAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.GroupAnnotationImpl) DGraphView(org.cytoscape.ding.impl.DGraphView)

Example 4 with GroupAnnotation

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);
            }
        }
    }
}
Also used : GroupAnnotation(org.cytoscape.view.presentation.annotations.GroupAnnotation) HashMap(java.util.HashMap) ArrowAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ArrowAnnotationImpl) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) TreeMap(java.util.TreeMap) AbstractAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.AbstractAnnotation) GroupAnnotation(org.cytoscape.view.presentation.annotations.GroupAnnotation) Annotation(org.cytoscape.view.presentation.annotations.Annotation) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) CyTable(org.cytoscape.model.CyTable) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

GroupAnnotation (org.cytoscape.view.presentation.annotations.GroupAnnotation)4 DGraphView (org.cytoscape.ding.impl.DGraphView)3 DingAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)3 Annotation (org.cytoscape.view.presentation.annotations.Annotation)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Collectors.toList (java.util.stream.Collectors.toList)1 JComponent (javax.swing.JComponent)1 ArbitraryGraphicsCanvas (org.cytoscape.ding.impl.ArbitraryGraphicsCanvas)1 CyAnnotator (org.cytoscape.ding.impl.cyannotator.CyAnnotator)1 AbstractAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.AbstractAnnotation)1 ArrowAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ArrowAnnotationImpl)1 GroupAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.GroupAnnotationImpl)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTable (org.cytoscape.model.CyTable)1