Search in sources :

Example 1 with ImageDocument

use of org.intellij.images.editor.ImageDocument in project intellij-community by JetBrains.

the class ThumbnailComponentUI method paintImageThumbnail.

private void paintImageThumbnail(Graphics g, ThumbnailComponent tc) {
    ImageComponent imageComponent = tc.getImageComponent();
    // Paint blank
    if (imageComponent.isFileSizeVisible())
        ImagesIcons.ThumbnailBlank.paintIcon(tc, g, 5, 5);
    ImageDocument document = imageComponent.getDocument();
    BufferedImage image = document.getValue();
    if (image != null) {
        paintImage(g, tc);
    } else {
        paintError(g, tc);
    }
    if (imageComponent.isFileSizeVisible())
        paintFileSize(g, tc);
}
Also used : ImageDocument(org.intellij.images.editor.ImageDocument) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ImageDocument

use of org.intellij.images.editor.ImageDocument in project intellij-community by JetBrains.

the class ImageEditorUI method setImage.

public void setImage(BufferedImage image, String format) {
    ImageDocument document = imageComponent.getDocument();
    BufferedImage previousImage = document.getValue();
    document.setValue(image);
    if (image == null)
        return;
    document.setFormat(format);
    ImageZoomModel zoomModel = getZoomModel();
    if (previousImage == null || !zoomModel.isZoomLevelChanged()) {
        // Set smart zooming behaviour on open
        Options options = OptionsManager.getInstance().getOptions();
        ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions();
        // Open as actual size
        zoomModel.setZoomFactor(1.0d);
        if (zoomOptions.isSmartZooming()) {
            Dimension prefferedSize = zoomOptions.getPrefferedSize();
            if (prefferedSize.width > image.getWidth() && prefferedSize.height > image.getHeight()) {
                // Resize to preffered size
                // Calculate zoom factor
                double factor = (prefferedSize.getWidth() / (double) image.getWidth() + prefferedSize.getHeight() / (double) image.getHeight()) / 2.0d;
                zoomModel.setZoomFactor(Math.ceil(factor));
            }
        }
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ImageDocument(org.intellij.images.editor.ImageDocument) BufferedImage(java.awt.image.BufferedImage)

Example 3 with ImageDocument

use of org.intellij.images.editor.ImageDocument in project android by JetBrains.

the class LayeredImageEditor method setImage.

private void setImage(Image image) throws IOException {
    ImageDocument document = myImageEditor.getDocument();
    BufferedImage previousImage = document.getValue();
    document.setValue(Utilities.getDisplayableImage(image));
    String format = image.getFormat() + "/" + image.getColorMode();
    String description = image.getColorProfileDescription();
    if (!description.isEmpty()) {
        format += ", " + description;
    }
    document.setFormat(format);
    // from ImageEditorUI
    ImageZoomModel zoomModel = myImageEditor.getZoomModel();
    if (previousImage == null || !zoomModel.isZoomLevelChanged()) {
        Options options = OptionsManager.getInstance().getOptions();
        ZoomOptions zoomOptions = options.getEditorOptions().getZoomOptions();
        zoomModel.setZoomFactor(1.0d);
        if (zoomOptions.isSmartZooming()) {
            Dimension preferred = zoomOptions.getPrefferedSize();
            if (preferred.width > image.getWidth() && preferred.height > image.getHeight()) {
                double factor = (preferred.getWidth() / (double) image.getWidth() + preferred.getHeight() / (double) image.getHeight()) / 2.0d;
                zoomModel.setZoomFactor(Math.ceil(factor));
            }
        }
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ZoomOptions(org.intellij.images.options.ZoomOptions) Options(org.intellij.images.options.Options) ZoomOptions(org.intellij.images.options.ZoomOptions) ImageDocument(org.intellij.images.editor.ImageDocument) BufferedImage(java.awt.image.BufferedImage)

Example 4 with ImageDocument

use of org.intellij.images.editor.ImageDocument in project intellij-community by JetBrains.

the class ImageEditorUI method updateInfo.

private void updateInfo() {
    ImageDocument document = imageComponent.getDocument();
    BufferedImage image = document.getValue();
    if (image != null) {
        ColorModel colorModel = image.getColorModel();
        String format = document.getFormat();
        if (format == null) {
            format = editor != null ? ImagesBundle.message("unknown.format") : "";
        } else {
            format = format.toUpperCase(Locale.ENGLISH);
        }
        VirtualFile file = editor != null ? editor.getFile() : null;
        infoLabel.setText(ImagesBundle.message("image.info", image.getWidth(), image.getHeight(), format, colorModel.getPixelSize(), file != null ? StringUtil.formatFileSize(file.getLength()) : ""));
    } else {
        infoLabel.setText(null);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ColorModel(java.awt.image.ColorModel) ImageDocument(org.intellij.images.editor.ImageDocument) BufferedImage(java.awt.image.BufferedImage)

Example 5 with ImageDocument

use of org.intellij.images.editor.ImageDocument in project intellij-community by JetBrains.

the class ImageEditorUI method performCopy.

@Override
public void performCopy(@NotNull DataContext dataContext) {
    ImageDocument document = imageComponent.getDocument();
    BufferedImage image = document.getValue();
    CopyPasteManager.getInstance().setContents(new ImageTransferable(image));
}
Also used : ImageDocument(org.intellij.images.editor.ImageDocument) BufferedImage(java.awt.image.BufferedImage)

Aggregations

BufferedImage (java.awt.image.BufferedImage)7 ImageDocument (org.intellij.images.editor.ImageDocument)7 ImageZoomModel (org.intellij.images.editor.ImageZoomModel)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ColorModel (java.awt.image.ColorModel)1 Options (org.intellij.images.options.Options)1 ZoomOptions (org.intellij.images.options.ZoomOptions)1