Search in sources :

Example 1 with ShapeAnnotationImpl

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

the class ShapeAnnotationDialog method initComponents.

private void initComponents() {
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setModalityType(DEFAULT_MODALITY_TYPE);
    setResizable(false);
    setTitle(create ? "Create Shape Annotation" : "Modify Shape Annotation");
    // Create the preview panel
    preview = new ShapeAnnotationImpl(shapeAnnotation, 150, 150, getOwner());
    preview.setUsedForPreviews(true);
    preview.getComponent().setSize(152, 152);
    final PreviewPanel previewPanel = new PreviewPanel(preview);
    shapeAnnotationPanel = new ShapeAnnotationPanel(shapeAnnotation, previewPanel);
    applyButton = new JButton(new AbstractAction("OK") {

        @Override
        public void actionPerformed(ActionEvent e) {
            applyButtonActionPerformed(e);
        }
    });
    cancelButton = new JButton(new AbstractAction("Cancel") {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    final JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(applyButton, cancelButton);
    final JPanel contents = new JPanel();
    final GroupLayout layout = new GroupLayout(contents);
    contents.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createParallelGroup(LEADING, true).addComponent(shapeAnnotationPanel).addComponent(previewPanel, DEFAULT_SIZE, PREVIEW_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(shapeAnnotationPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(previewPanel, DEFAULT_SIZE, PREVIEW_HEIGHT, Short.MAX_VALUE).addComponent(buttonPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), applyButton.getAction(), cancelButton.getAction());
    getRootPane().setDefaultButton(applyButton);
    getContentPane().add(contents);
    pack();
}
Also used : JPanel(javax.swing.JPanel) ShapeAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GroupLayout(javax.swing.GroupLayout) AbstractAction(javax.swing.AbstractAction)

Example 2 with ShapeAnnotationImpl

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

the class ShapeAnnotationFactory method createAnnotation.

@Override
public ShapeAnnotation createAnnotation(Class<? extends ShapeAnnotation> type, CyNetworkView view, Map<String, String> argMap) {
    if (!(view instanceof DGraphView))
        return null;
    DGraphView dView = (DGraphView) view;
    if (type.equals(ShapeAnnotation.class)) {
        final ShapeAnnotationImpl a = new ShapeAnnotationImpl(dView, argMap, getActiveWindow());
        a.update();
        return (ShapeAnnotation) a;
    }
    return null;
}
Also used : ShapeAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl) ShapeAnnotation(org.cytoscape.view.presentation.annotations.ShapeAnnotation) DGraphView(org.cytoscape.ding.impl.DGraphView)

Example 3 with ShapeAnnotationImpl

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

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

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

the class ResizeAnnotationTaskFactory method isReady.

@Override
public boolean isReady(CyNetworkView networkView, Point2D javaPt, Point2D xformPt) {
    CyAnnotator cyAnnotator = ((DGraphView) networkView).getCyAnnotator();
    DingAnnotation annotation = cyAnnotator.getAnnotationAt(javaPt);
    if (annotation != null && (annotation instanceof ShapeAnnotationImpl || annotation instanceof ImageAnnotationImpl || annotation instanceof GroupAnnotationImpl)) {
        return true;
    }
    return false;
}
Also used : ShapeAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl) GroupAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.GroupAnnotationImpl) ImageAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl) CyAnnotator(org.cytoscape.ding.impl.cyannotator.CyAnnotator) DingAnnotation(org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation) DGraphView(org.cytoscape.ding.impl.DGraphView)

Aggregations

ShapeAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl)5 DingAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)3 Component (java.awt.Component)2 DGraphView (org.cytoscape.ding.impl.DGraphView)2 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 Point2D (java.awt.geom.Point2D)1 AbstractAction (javax.swing.AbstractAction)1 GroupLayout (javax.swing.GroupLayout)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)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 ImageAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl)1 CyNode (org.cytoscape.model.CyNode)1 ShapeAnnotation (org.cytoscape.view.presentation.annotations.ShapeAnnotation)1