Search in sources :

Example 1 with DingAnnotation

use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.

the class ArbitraryGraphicsCanvas method drawCanvas.

public void drawCanvas(VolatileImage image, double xMin, double yMin, double xCenter, double yCenter, double scaleFactor) {
    // get image graphics
    final Graphics2D image2D = image.createGraphics();
    // System.out.println("drawCanvas: new scaleFactor = "+scaleFactor+", xCenter = "+xCenter+", yCenter = "+yCenter);
    if (m_isOpaque)
        clearImage(image2D);
    double xOffset = ((image.getWidth() / 2) / scaleFactor - xCenter);
    double yOffset = ((image.getHeight() / 2) / scaleFactor - yCenter);
    // get list of child components
    Component[] components = getComponents();
    // Since we're doing this because we're doing the draw on our own
    zSort(components);
    // no components, outta here
    if (components.length == 0)
        return;
    // iterate through the components
    for (Component c : components) {
        // get position of this component in network coordinates
        Point position = m_componentToPointMap.get(c);
        if (position == null)
            continue;
        // int xOrig = position.x;
        // int yOrig = position.y;
        final double[] nodeCanvasCoordinates = new double[2];
        nodeCanvasCoordinates[0] = position.getX() + xOffset;
        nodeCanvasCoordinates[1] = position.getY() + yOffset;
        // If we're painting an annotation, set the zoom
        if (c instanceof DingAnnotation) {
            DingAnnotation a = (DingAnnotation) c;
            a.drawAnnotation(image2D, position.getX() + xOffset, position.getY() + yOffset, scaleFactor);
        }
    }
// System.out.println("drawCanvas: done");
}
Also used : Point(java.awt.Point) Component(java.awt.Component) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) Graphics2D(java.awt.Graphics2D)

Example 2 with DingAnnotation

use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.

the class CyAnnotator method getAnnotationAt.

public DingAnnotation getAnnotationAt(Point2D position) {
    DingAnnotation a = getComponentAt(foreGroundCanvas, (int) position.getX(), (int) position.getY());
    if (a != null) {
        while (a.getGroupParent() != null) {
            a = (DingAnnotation) a.getGroupParent();
        }
        return a;
    }
    a = getComponentAt(backGroundCanvas, (int) position.getX(), (int) position.getY());
    if (a != null) {
        while (a.getGroupParent() != null) a = (DingAnnotation) a.getGroupParent();
    }
    return a;
}
Also used : DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)

Example 3 with DingAnnotation

use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.

the class CyAnnotator method updateNetworkAttributes.

private void updateNetworkAttributes(CyNetwork network) {
    // Convert the annotation to a list
    List<Map<String, String>> networkAnnotations = new ArrayList<Map<String, String>>();
    for (DingAnnotation annotation : annotationMap.keySet()) {
        if (view.getModel().equals(network))
            networkAnnotations.add(annotationMap.get(annotation));
    }
    // Save it in the network attributes
    List<String> networkAnnotation = convertAnnotationMap(networkAnnotations);
    if (network.getDefaultNetworkTable().getColumn(ANNOTATION_ATTRIBUTE) == null) {
        network.getDefaultNetworkTable().createListColumn(ANNOTATION_ATTRIBUTE, String.class, false, Collections.EMPTY_LIST);
    }
    network.getRow(network, CyNetwork.LOCAL_ATTRS).set(ANNOTATION_ATTRIBUTE, networkAnnotation);
}
Also used : ArrayList(java.util.ArrayList) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 4 with DingAnnotation

use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation 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 5 with DingAnnotation

use of org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation in project cytoscape-impl by cytoscape.

the class CanvasMouseListener method mouseClicked.

public void mouseClicked(MouseEvent e) {
    // Check to see if we're resizing
    if (cyAnnotator.getResizeShape() != null) {
        cyAnnotator.getResizeShape().contentChanged();
        cyAnnotator.resizeShape(null);
        return;
    }
    if (cyAnnotator.getRepositioningArrow() != null) {
        cyAnnotator.getRepositioningArrow().contentChanged();
        cyAnnotator.positionArrow(null);
        return;
    }
    if (cyAnnotator.getMovingAnnotation() != null) {
        cyAnnotator.getMovingAnnotation().contentChanged();
        cyAnnotator.moveAnnotation(null);
        return;
    }
    DingAnnotation annotation = cyAnnotator.getAnnotationAt(new Point(e.getX(), e.getY()));
    if (annotation == null) {
        // cyAnnotator.clearSelectedAnnotations();
        if (!e.isConsumed()) {
            networkCanvas.processMouseEvent(e);
            e.consume();
        }
        return;
    }
/*
 * It seems to be a little confusing to have double-click
 * selection on annotations.
 */
/*
		if(e.getClickCount()==2 && !e.isConsumed()) {
			e.consume();
			//We have doubled clicked on an Annotation
			if (annotation.isSelected()) {
				annotation.setSelected(false);
			} else {
				//This preVZoom value will help in resizing the selected Annotations
				// double prevZoom=networkCanvas.getScaleFactor();

				// annotation.setSpecificZoom(prevZoom);
				annotation.setSelected(true);

				//We request focus in this window, so that we can move these selected Annotations around using arrow keys
				annotation.getCanvas().requestFocusInWindow();
			}

			//Repaint the canvas
			annotation.getCanvas().repaint();	
		}
*/
}
Also used : Point(java.awt.Point) 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