Search in sources :

Example 1 with Annotation

use of org.cytoscape.view.presentation.annotations.Annotation in project cytoscape-impl by cytoscape.

the class CyAnnotator method addAnnotations.

public void addAnnotations(Collection<? extends Annotation> annotations) {
    for (Annotation annotation : annotations) {
        if (annotation instanceof DingAnnotation) {
            DingAnnotation dingAnnotation = (DingAnnotation) annotation;
            annotationMap.put(dingAnnotation, dingAnnotation.getArgMap());
        }
    }
    updateNetworkAttributes(view.getModel());
}
Also used : DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) 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)

Example 2 with Annotation

use of org.cytoscape.view.presentation.annotations.Annotation in project cytoscape-impl by cytoscape.

the class ArrowAnnotationImpl method getArgMap.

public Map<String, String> getArgMap() {
    Map<String, String> argMap = super.getArgMap();
    argMap.put(TYPE, ArrowAnnotation.class.getName());
    if (this.lineColor != null)
        argMap.put(ARROWCOLOR, convertColor(this.lineColor));
    argMap.put(ARROWTHICKNESS, Float.toString(this.lineWidth));
    if (source != null)
        argMap.put(SOURCEANN, source.getUUID().toString());
    argMap.put(SOURCETYPE, Integer.toString(this.sourceType.ordinal()));
    argMap.put(SOURCESIZE, Double.toString(this.sourceSize));
    if (this.sourceColor != null)
        argMap.put(SOURCECOLOR, convertColor(this.sourceColor));
    if (target != null && target instanceof Point2D) {
        Point2D xy = (Point2D) target;
        argMap.put(TARGETPOINT, Double.toString(xy.getX()) + "," + Double.toString(xy.getY()));
    } else if (target != null && target instanceof Annotation) {
        argMap.put(TARGETANN, ((DingAnnotation) target).getUUID().toString());
    } else if (target != null && target instanceof CyNode) {
        DNodeView nv = (DNodeView) view.getNodeView((CyNode) target);
        double xCenter = nv.getXPosition();
        double yCenter = nv.getYPosition();
        argMap.put(TARGETNODE, Double.toString(xCenter) + "," + Double.toString(yCenter));
    }
    argMap.put(TARGETTYPE, Integer.toString(this.targetType.ordinal()));
    argMap.put(TARGETSIZE, Double.toString(this.targetSize));
    if (this.targetColor != null)
        argMap.put(TARGETCOLOR, convertColor(this.targetColor));
    return argMap;
}
Also used : ArrowAnnotation(org.cytoscape.view.presentation.annotations.ArrowAnnotation) DNodeView(org.cytoscape.ding.impl.DNodeView) Point2D(java.awt.geom.Point2D) CyNode(org.cytoscape.model.CyNode) ArrowAnnotation(org.cytoscape.view.presentation.annotations.ArrowAnnotation) Annotation(org.cytoscape.view.presentation.annotations.Annotation)

Example 3 with Annotation

use of org.cytoscape.view.presentation.annotations.Annotation 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 4 with Annotation

use of org.cytoscape.view.presentation.annotations.Annotation in project cytoscape-impl by cytoscape.

the class UngroupAnnotationsTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    if (view instanceof DGraphView) {
        DGraphView dView = (DGraphView) view;
        CyAnnotator cyAnnotator = dView.getCyAnnotator();
        for (Annotation child : group.getMembers()) {
            group.removeMember(child);
            child.setSelected(true);
        }
        group.removeAnnotation();
    }
}
Also used : CyAnnotator(org.cytoscape.ding.impl.cyannotator.CyAnnotator) Annotation(org.cytoscape.view.presentation.annotations.Annotation) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) DGraphView(org.cytoscape.ding.impl.DGraphView)

Example 5 with Annotation

use of org.cytoscape.view.presentation.annotations.Annotation 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

Annotation (org.cytoscape.view.presentation.annotations.Annotation)6 DingAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)5 GroupAnnotation (org.cytoscape.view.presentation.annotations.GroupAnnotation)4 AbstractAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.AbstractAnnotation)3 DGraphView (org.cytoscape.ding.impl.DGraphView)2 CyAnnotator (org.cytoscape.ding.impl.cyannotator.CyAnnotator)2 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 JComponent (javax.swing.JComponent)1 DNodeView (org.cytoscape.ding.impl.DNodeView)1 ArrowAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ArrowAnnotationImpl)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyTable (org.cytoscape.model.CyTable)1 ArrowAnnotation (org.cytoscape.view.presentation.annotations.ArrowAnnotation)1