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