Search in sources :

Example 6 with DingAnnotation

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

the class CanvasMouseWheelListener method mouseWheelMoved.

// To handle zooming in and out
public void mouseWheelMoved(MouseWheelEvent e) {
    int notches = e.getWheelRotation();
    double factor = 1.0;
    // scroll up, zoom in
    if (notches < 0)
        factor = 1.1;
    else if (notches > 0)
        factor = 0.9;
    else
        return;
    Set<DingAnnotation> selectedAnnotations = cyAnnotator.getSelectedAnnotations();
    if (selectedAnnotations != null && selectedAnnotations.size() > 0) {
        // If some annotations are selected
        for (DingAnnotation annotation : selectedAnnotations) {
            annotation.setSpecificZoom(prevZoom * factor);
        }
        // In that case only increase the size (Change font in some cases)
        // for those specific annotations
        prevZoom *= factor;
    } else {
        networkCanvas.mouseWheelMoved(e);
    }
}
Also used : DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)

Example 7 with DingAnnotation

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

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

the class CanvasKeyListener method keyPressed.

public void keyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    Set<DingAnnotation> selectedAnnotations = cyAnnotator.getSelectedAnnotations();
    if ((selectedAnnotations != null && selectedAnnotations.size() > 0) && ((code == KeyEvent.VK_UP) || (code == KeyEvent.VK_DOWN) || (code == KeyEvent.VK_LEFT) || (code == KeyEvent.VK_RIGHT))) {
        // Some annotations have been double clicked and selected
        int move = 2;
        for (DingAnnotation annotation : selectedAnnotations) {
            Component c = annotation.getComponent();
            int x = c.getX(), y = c.getY();
            int shiftMask = e.getModifiers() & KeyEvent.SHIFT_DOWN_MASK;
            if (annotation instanceof ShapeAnnotationImpl && e.isShiftDown()) {
                ShapeAnnotationImpl sa = (ShapeAnnotationImpl) annotation;
                int width = c.getWidth(), height = c.getHeight();
                if (code == KeyEvent.VK_UP) {
                    height -= move;
                } else if (code == KeyEvent.VK_DOWN) {
                    height += move;
                } else if (code == KeyEvent.VK_LEFT) {
                    width -= move;
                } else if (code == KeyEvent.VK_RIGHT) {
                    width += move;
                }
                // Adjust the size of the selected annotations
                sa.setSize((double) width, (double) height);
            } else {
                if (code == KeyEvent.VK_UP)
                    y -= move;
                else if (code == KeyEvent.VK_DOWN)
                    y += move;
                else if (code == KeyEvent.VK_LEFT)
                    x -= move;
                else if (code == KeyEvent.VK_RIGHT)
                    x += move;
                // Adjust the locations of the selected annotations
                annotation.getComponent().setLocation(x, y);
            }
            annotation.update();
            annotation.getCanvas().repaint();
        }
        return;
    } else if (code == KeyEvent.VK_ESCAPE) {
        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;
        }
    }
    networkCanvas.keyPressed(e);
}
Also used : ShapeAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) Component(java.awt.Component)

Example 9 with DingAnnotation

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

the class CanvasMouseMotionListener method mouseMoved.

public void mouseMoved(MouseEvent e) {
    AbstractAnnotation resizeAnnotation = cyAnnotator.getResizeShape();
    DingAnnotation moveAnnotation = cyAnnotator.getMovingAnnotation();
    ArrowAnnotationImpl repositionAnnotation = cyAnnotator.getRepositioningArrow();
    if (resizeAnnotation == null && moveAnnotation == null && repositionAnnotation == null) {
        networkCanvas.mouseMoved(e);
        return;
    }
    int mouseX = e.getX();
    int mouseY = e.getY();
    if (moveAnnotation != null) {
        // Get our current transform
        double[] nextLocn = new double[2];
        nextLocn[0] = (double) mouseX;
        nextLocn[1] = (double) mouseY;
        view.xformComponentToNodeCoords(nextLocn);
        // OK, now update
        moveAnnotation.moveAnnotation(new Point2D.Double(nextLocn[0], nextLocn[1]));
        moveAnnotation.update();
        moveAnnotation.getCanvas().repaint();
    } else if (resizeAnnotation != null) {
        Component resizeComponent = resizeAnnotation.getComponent();
        int cornerX1 = resizeComponent.getX();
        int cornerY1 = resizeComponent.getY();
        // int cornerX2 = cornerX1 + resizeComponent.getWidth();
        // int cornerY2 = cornerY1 + resizeComponent.getHeight();
        int cornerX2 = mouseX;
        int cornerY2 = mouseY;
        double borderWidth = 0;
        if (resizeAnnotation instanceof ShapeAnnotationImpl)
            borderWidth = ((ShapeAnnotationImpl) resizeAnnotation).getBorderWidth();
        /*
			 * TODO: change over to use anchors at some point
			 */
        /*
			if (Math.abs(mouseX-cornerX1) < Math.abs(mouseX-cornerX2)) {
				// Left
				cornerX1 = mouseX;
			} else {
				// Right
				cornerX2 = mouseX;
			}
			*/
        // System.out.println("X1 = "+cornerX1+", X2 = "+cornerX2+" width = "+resizeComponent.getWidth());
        double width = (double) cornerX2 - (double) cornerX1 - (borderWidth * 2 * resizeAnnotation.getZoom());
        // System.out.println("width = "+width);
        /*
			if (mouseY <= cornerY1) {
				// Upper
				cornerY1 = mouseY;
			} else if (mouseY >= cornerY2-resizeComponent.getHeight()/2) {
				// Lower
				cornerY2 = mouseY;
			}
			*/
        double height = (double) cornerY2 - (double) cornerY1 - (borderWidth * 2 * resizeAnnotation.getZoom());
        if (width == 0.0)
            width = 2;
        if (height == 0.0)
            height = 2;
        if ((Math.abs(width - resizeComponent.getWidth()) < 5) && (Math.abs(height - resizeComponent.getHeight()) < 5))
            return;
        Dimension d = new Dimension();
        d.setSize(width, height);
        // If shift is down, adjust to preserve the aspect ratio
        if (e.isShiftDown()) {
            d = resizeAnnotation.adjustAspectRatio(d);
        }
        // resizeComponent.setLocation(cornerX1, cornerY1);
        resizeAnnotation.setSize(d);
        resizeAnnotation.update();
        resizeAnnotation.getCanvas().repaint();
    } else if (repositionAnnotation != null) {
        Point2D mousePoint = new Point2D.Double(mouseX, mouseY);
        // See what's under our mouse
        // Annotation?
        List<DingAnnotation> annotations = cyAnnotator.getAnnotationsAt(mousePoint);
        if (annotations.contains(repositionAnnotation))
            annotations.remove(repositionAnnotation);
        if (annotations.size() > 0) {
            repositionAnnotation.setTarget(annotations.get(0));
        // Node?
        } else if (overNode(mousePoint)) {
            CyNode overNode = getNodeAtLocation(mousePoint);
            repositionAnnotation.setTarget(overNode);
        // Nope, just set the point
        } else {
            repositionAnnotation.setTarget(mousePoint);
        }
        repositionAnnotation.update();
        repositionAnnotation.getCanvas().repaint();
    }
}
Also used : ArrowAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ArrowAnnotationImpl) Dimension(java.awt.Dimension) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) AbstractAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.AbstractAnnotation) ShapeAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl) Point2D(java.awt.geom.Point2D) CyNode(org.cytoscape.model.CyNode) Component(java.awt.Component)

Example 10 with DingAnnotation

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

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