Search in sources :

Example 26 with DingAnnotation

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());
}
Also used : DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)

Example 27 with DingAnnotation

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;
}
Also used : ArrayList(java.util.ArrayList) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)

Example 28 with DingAnnotation

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);
            }
        }
    }
}
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)

Example 29 with DingAnnotation

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());
}
Also used : 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 30 with DingAnnotation

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();
}
Also used : ArrayList(java.util.ArrayList) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)

Aggregations

DingAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)34 DGraphView (org.cytoscape.ding.impl.DGraphView)21 CyAnnotator (org.cytoscape.ding.impl.cyannotator.CyAnnotator)19 TaskIterator (org.cytoscape.work.TaskIterator)8 ArrayList (java.util.ArrayList)5 GroupAnnotation (org.cytoscape.view.presentation.annotations.GroupAnnotation)5 AbstractAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.AbstractAnnotation)4 Annotation (org.cytoscape.view.presentation.annotations.Annotation)4 Component (java.awt.Component)3 ArrowAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ArrowAnnotationImpl)3 GroupAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.GroupAnnotationImpl)3 ShapeAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl)3 Point (java.awt.Point)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 JComponent (javax.swing.JComponent)2 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Point2D (java.awt.geom.Point2D)1