Search in sources :

Example 1 with ImageZoomModel

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

the class ActualSizeAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
    if (decorator != null) {
        ImageZoomModel zoomModel = decorator.getZoomModel();
        zoomModel.setZoomFactor(1.0d);
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ImageComponentDecorator(org.intellij.images.ui.ImageComponentDecorator)

Example 2 with ImageZoomModel

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

the class ZoomInAction method update.

public void update(AnActionEvent e) {
    super.update(e);
    if (ImageEditorActionUtil.setEnabled(e)) {
        ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
        ImageZoomModel zoomModel = decorator.getZoomModel();
        e.getPresentation().setEnabled(zoomModel.canZoomIn());
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ImageComponentDecorator(org.intellij.images.ui.ImageComponentDecorator)

Example 3 with ImageZoomModel

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

the class ZoomInAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
    if (decorator != null) {
        ImageZoomModel zoomModel = decorator.getZoomModel();
        zoomModel.zoomIn();
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ImageComponentDecorator(org.intellij.images.ui.ImageComponentDecorator)

Example 4 with ImageZoomModel

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

the class ZoomOutAction method actionPerformed.

public void actionPerformed(AnActionEvent e) {
    ImageComponentDecorator decorator = ImageEditorActionUtil.getImageComponentDecorator(e);
    if (decorator != null) {
        ImageZoomModel zoomModel = decorator.getZoomModel();
        zoomModel.zoomOut();
    }
}
Also used : ImageZoomModel(org.intellij.images.editor.ImageZoomModel) ImageComponentDecorator(org.intellij.images.ui.ImageComponentDecorator)

Example 5 with ImageZoomModel

use of org.intellij.images.editor.ImageZoomModel 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)

Aggregations

ImageZoomModel (org.intellij.images.editor.ImageZoomModel)10 ImageComponentDecorator (org.intellij.images.ui.ImageComponentDecorator)6 BufferedImage (java.awt.image.BufferedImage)3 ImageDocument (org.intellij.images.editor.ImageDocument)2 ImageEditor (org.intellij.images.editor.ImageEditor)1 Options (org.intellij.images.options.Options)1 ZoomOptions (org.intellij.images.options.ZoomOptions)1