/*
 * Copyright 2000-2013 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.util;

import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;

/**
* @author Konstantin Bulenkov
*/
public class JBHiDPIScaledImage extends BufferedImage {
  private final Image myImage;
  private final int myWidth;
  private final int myHeight;

  /**
   * Creates a HiDPI-aware BufferedImage to draw on.
   *
   * @param width width in a user space coordinates
   * @param height height in a user space coordinates
   * @param type type of the created image
   */
  public JBHiDPIScaledImage(int width, int height, int type) {
    this(new BufferedImage(width * 2, height * 2, type), width, height, type);
  }

  /**
   * Creates a HiDPI-aware BufferedImage wrapping a delegate Image.
   *
   * @param image the delegate image of size in a device space coordinates to wrap
   * @param width width in a user space coordinates
   * @param height height in a user space coordinates
   * @param type type of the created image
   */
  public JBHiDPIScaledImage(@NotNull Image image, int width, int height, int type) {
    super(1, 1, type); // give the wrapper a minimal 1x1 size to save space
    myImage = image;
    myWidth = width;
    myHeight = height;
  }

  public Image getDelegate() {
    return myImage;
  }

  @Override
  public int getWidth() {
    return myWidth;
  }

  @Override
  public int getHeight() {
    return myHeight;
  }

  @Override
  public int getWidth(ImageObserver observer) {
    return myWidth;
  }

  @Override
  public int getHeight(ImageObserver observer) {
    return myHeight;
  }

  @Override
  public Graphics2D createGraphics() {
    assert myImage instanceof BufferedImage : "graphics should only be created for the image used for drawing";
    if (myImage instanceof BufferedImage) {
      return new HiDPIScaledGraphics(((BufferedImage)myImage).createGraphics());
    }
    return super.createGraphics();
  }
}

@@ -757,16 +757,54 @@
 bserver;
+%0Aimport java.awt.image.WritableRaster;
 %0A%0A/**%0A* 
@@ -2353,70 +2353,47 @@
  : %22
-graphics should only be created for the image used for drawing
+the delegate image is not BufferedImage
 %22;%0A 
@@ -2522,16 +2522,16 @@
 ;%0A    %7D%0A
-
     retu
@@ -2560,11 +2560,286 @@
 s();%0A  %7D
+%0A%0A  @Override%0A  public WritableRaster getRaster() %7B%0A    assert myImage instanceof BufferedImage : %22the delegate image is not BufferedImage%22;%0A    if (myImage instanceof BufferedImage) %7B%0A      return ((BufferedImage)myImage).getRaster();%0A    %7D%0A    return super.getRaster();%0A  %7D
 %0A%7D%0A

Fix code inspection error icon miss.