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