package org.skylion.mangareader.util;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import javax.swing.ImageIcon;
/**
* Class which extends the StretchIcon class and requests that the system renders the image at high quality.
* @author Skylion
*/
public class StretchIconHQ extends StretchIcon {
/**
* Autogenerated UID
*/
private static final long serialVersionUID = -406655602188443823L;
/**
* Creates a <CODE>StretchIconHQ</CODE> from an array of bytes.
*
* @param imageData an array of pixels in an image format supported by
* the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
*
* @see ImageIcon#ImageIcon(byte[])
*/
public StretchIconHQ(byte[] imageData) {
super(imageData);
}
/**
* Creates a <CODE>StretchIconHQ</CODE> from an array of bytes with the specified behavior.
*
* @param imageData an array of pixels in an image format supported by
* the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
* @param proportionate <code>true</code> to retain the image's aspect ratio,
* <code>false</code> to allow distortion of the image to fit the
* component.
*
* @see ImageIcon#ImageIcon(byte[])
*/
public StretchIconHQ(byte[] imageData, boolean proportionate) {
super(imageData, proportionate);
}
/**
* Creates a <CODE>StretchIconHQ</CODE> from an array of bytes.
*
* @param imageData an array of pixels in an image format supported by
* the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
* @param description a brief textual description of the image
*
* @see ImageIcon#ImageIcon(byte[], java.lang.String)
*/
public StretchIconHQ(byte[] imageData, String description) {
super(imageData, description);
}
/**
* Creates a <CODE>StretchIconHQ</CODE> from an array of bytes with the specified behavior.
*
* @see ImageIcon#ImageIcon(byte[])
* @param imageData an array of pixels in an image format supported by
* the AWT Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
* @param description a brief textual description of the image
* @param proportionate <code>true</code> to retain the image's aspect ratio,
* <code>false</code> to allow distortion of the image to fit the
* component.
*
* @see ImageIcon#ImageIcon(byte[], java.lang.String)
*/
public StretchIconHQ(byte[] imageData, String description, boolean proportionate) {
super(imageData, description, proportionate);
}
/**
* Creates a <CODE>StretchIconHQ</CODE> from the image.
*
* @param image the image
*
* @see ImageIcon#ImageIcon(java.awt.Image)
*/
public StretchIconHQ(Image image) {
super(image);
}
/**
* Creates a <CODE>StretchIconHQ</CODE> from the image with the specified behavior.
*
* @param image the image
* @param proportionate <code>true</code> to retain the image's aspect ratio,
* <code>false</code> to allow distortion of the image to fit the
* component.
*
* @see ImageIcon#ImageIcon(java.awt.Image)
*/
public StretchIconHQ(Image image, boolean proportionate) {
super(image, proportionate);
}
/**
* Creates a <CODE>StretchIconHQ</CODE> from the image.
*
* @param image the image
* @param description a brief textual description of the image
*
* @see ImageIcon#ImageIcon(java.awt.Image, java.lang.String)
*/
public StretchIconHQ(Image image, String description) {
super(image, description);
}
/**
* The image automatically uses Rendering High Quality.
* Paints the icon. The image is reduced or magnified to fit the component to which
* it is painted.
* <P>
* If the proportion has not been specified, or has been specified as <code>true</code>,
* the aspect ratio of the image will be preserved by padding and centering the image
* horizontally or vertically. Otherwise the image may be distorted to fill the
* component it is painted to.
* <P>
* If this icon has no image observer,this method uses the <code>c</code> component
* as the observer.
*
* @param c the component to which the Icon is painted. This is used as the
* observer if this icon has no image observer
* @param g the graphics context
* @param x not used.
* @param y not used.
*
* @see ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
*/
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
//g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
super.paintIcon(c, g2, x, y);
}
}