1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| public class Thumbnail implements Icon {
/** Width of the thumbnail.
*/
private int width;
/** Height of the thumbnail.
*/
private int height;
/** The image.
*/
private Image image;
/** Creates a new instance.
* @param width Width of the thumbnail.
* @param height Height of the thumbnail.
* @param Image The image.
*/
public Thumbnail(int width, int height, Image image) {
this.width = width;
this.height = height;
this.image = image;
}
/** @inheritDoc
*/
public int getIconHeight() {
return heigh;
}
/** @inheritDoc
*/
public int getIconWidth() {
return width;
}
/** @inheritDoc
*/
public void paintIcon(Component c, Graphics g, int x, int y) {
if (c != null) {
g.setColor(c.getBackground().darker());
g.fillRect(x, y, getIconWidth(), getIconHeight());
}
if (image != null) {
// We may want to do other kind of scaling.
// Eg : to keep the aspect ratio of the original image.
g.drawImage(image, x, y, getIconWidth(), getIconHeight(), null);
}
}
} |
Partager