Search in sources :

Example 1 with ImageAnnotationImpl

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

the class ImageAnnotationFactory method createAnnotation.

@Override
public ImageAnnotation createAnnotation(Class<? extends ImageAnnotation> clazz, CyNetworkView view, Map<String, String> argMap) {
    if (!(view instanceof DGraphView))
        return null;
    DGraphView dView = (DGraphView) view;
    if (ImageAnnotation.class.equals(clazz)) {
        final CustomGraphicsManager customGraphicsManager = serviceRegistrar.getService(CustomGraphicsManager.class);
        final ImageAnnotationImpl a = new ImageAnnotationImpl(dView, argMap, customGraphicsManager, getActiveWindow());
        a.update();
        return (ImageAnnotation) a;
    } else {
        return null;
    }
}
Also used : ImageAnnotation(org.cytoscape.view.presentation.annotations.ImageAnnotation) ImageAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl) CustomGraphicsManager(org.cytoscape.ding.customgraphics.CustomGraphicsManager) DGraphView(org.cytoscape.ding.impl.DGraphView)

Example 2 with ImageAnnotationImpl

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

the class LoadImageDialog method openButtonActionPerformed.

private void openButtonActionPerformed(ActionEvent evt) {
    try {
        // Read the selected Image, create an Image Annotation, repaint the
        // whole network and then dispose off this Frame
        // Get the file
        File imageFile = fileChooser.getSelectedFile();
        BufferedImage image = ImageIO.read(imageFile);
        URL url = imageFile.toURI().toURL();
        // The Attributes are x, y, Image, componentNumber, scaleFactor
        ImageAnnotationImpl newOne = new ImageAnnotationImpl(view, (int) startingLocation.getX(), (int) startingLocation.getY(), url, image, view.getZoom(), cgm, getOwner());
        newOne.getComponent().setLocation((int) startingLocation.getX(), (int) startingLocation.getY());
        newOne.addComponent(null);
        newOne.update();
        // Update the canvas
        view.getCanvas(DGraphView.Canvas.FOREGROUND_CANVAS).repaint();
        // Set this shape to be resized
        cyAnnotator.resizeShape(newOne);
        try {
            // Warp the mouse to the starting location (if supported).
            // But we want to preserve the aspect ratio, at least initially.
            double width = (double) image.getWidth();
            double height = (double) image.getHeight();
            if (height > width) {
                width = 100.0 * width / height;
                height = 100;
            } else {
                height = 100.0 * height / width;
                width = 100;
            }
            Point start = newOne.getComponent().getLocationOnScreen();
            Robot robot = new Robot();
            robot.mouseMove((int) start.getX() + (int) width, (int) start.getY() + (int) height);
        } catch (Exception e) {
        }
        this.dispose();
    } catch (Exception ex) {
        logger.warn("Unable to load the selected image", ex);
    }
}
Also used : ImageAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl) Point(java.awt.Point) File(java.io.File) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL)

Example 3 with ImageAnnotationImpl

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

Example 4 with ImageAnnotationImpl

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

the class ImageAnnotationDialog method initComponents.

private void initComponents() {
    setTitle(create ? "Create Image Annotation" : "Modify Image Annotation");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setModalityType(DEFAULT_MODALITY_TYPE);
    setResizable(false);
    // Create the preview panel
    preview = new ImageAnnotationImpl(annotation, getOwner());
    Image img = annotation.getImage();
    double width = (double) img.getWidth(this);
    double height = (double) img.getHeight(this);
    double scale = (Math.max(width, height)) / (PREVIEW_HEIGHT - 50);
    preview.setImage(img);
    preview.setUsedForPreviews(true);
    preview.setSize(width / scale, height / scale);
    PreviewPanel previewPanel = new PreviewPanel(preview);
    imageAnnotationPanel = new ImageAnnotationPanel(annotation, 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(imageAnnotationPanel).addComponent(previewPanel, DEFAULT_SIZE, PREVIEW_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(imageAnnotationPanel, 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) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) GroupLayout(javax.swing.GroupLayout) ImageAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl) Image(java.awt.Image) AbstractAction(javax.swing.AbstractAction)

Aggregations

ImageAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ImageAnnotationImpl)4 DGraphView (org.cytoscape.ding.impl.DGraphView)2 Image (java.awt.Image)1 Point (java.awt.Point)1 Robot (java.awt.Robot)1 ActionEvent (java.awt.event.ActionEvent)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 URL (java.net.URL)1 AbstractAction (javax.swing.AbstractAction)1 GroupLayout (javax.swing.GroupLayout)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 CustomGraphicsManager (org.cytoscape.ding.customgraphics.CustomGraphicsManager)1 CyAnnotator (org.cytoscape.ding.impl.cyannotator.CyAnnotator)1 DingAnnotation (org.cytoscape.ding.impl.cyannotator.annotations.DingAnnotation)1 GroupAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.GroupAnnotationImpl)1 ShapeAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.ShapeAnnotationImpl)1 ImageAnnotation (org.cytoscape.view.presentation.annotations.ImageAnnotation)1