package jetbrains.mps.util; /*Generated by MPS */ import jetbrains.mps.smodel.runtime.IconResource; import org.apache.log4j.Logger; import org.apache.log4j.LogManager; import javax.swing.Icon; import java.awt.image.BufferedImage; import java.awt.Graphics2D; import java.io.ByteArrayOutputStream; import javax.imageio.stream.ImageOutputStream; import javax.imageio.ImageIO; import java.io.IOException; import org.apache.log4j.Level; import java.io.InputStream; import java.io.ByteArrayInputStream; /** * * @deprecated this class is for compatibility purposes and must not be used except internally. It will be removed after 3.4 */ @Deprecated public class Icon2IconResourceAdapter_Deprecated extends IconResource { private static final Logger LOG = LogManager.getLogger(Icon2IconResourceAdapter_Deprecated.class); private byte[] myIcon = null; @Deprecated public Icon2IconResourceAdapter_Deprecated(Icon icon) { super(null, null); BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageOutputStream ios = ImageIO.createImageOutputStream(baos); try { ImageIO.write(image, "png", ios); // Set a flag to indicate that the write was successful } finally { ios.close(); } myIcon = baos.toByteArray(); } catch (IOException ex) { if (LOG.isEnabledFor(Level.ERROR)) { LOG.error("Can't read icon", ex); } } } @Override public boolean isAlreadyReloaded() { return false; } @Override public InputStream getResource() { if (myIcon == null) { return null; } return new ByteArrayInputStream(myIcon); } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Icon2IconResourceAdapter_Deprecated that = (Icon2IconResourceAdapter_Deprecated) o; return eq_odhe5t_a0d0f(myIcon, that.myIcon); } @Override public int hashCode() { return (myIcon == null ? 0 : myIcon.hashCode()); } private static boolean eq_odhe5t_a0d0f(Object a, Object b) { return (a != null ? a.equals(b) : a == b); } }