File: ImagePainter.java

package info (click to toggle)
mac-widgets 0.9.5%2Bsvn369-dfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,920 kB
  • sloc: java: 8,318; makefile: 13; sh: 12
file content (34 lines) | stat: -rw-r--r-- 802 bytes parent folder | download
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
package com.explodingpixels.painter;

import javax.imageio.ImageIO;
import java.awt.Component;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;

public class ImagePainter implements Painter<Component> {

    private final Image fImage;

    public ImagePainter(Image image) {
        fImage = image;
    }

    public ImagePainter(URL url) {
        try {
            fImage = ImageIO.read(url);
        } catch (IOException e) {
            throw new IllegalArgumentException("Problem reading image file.");
        }

    }

    public void paint(Graphics2D graphics, Component objectToPaint, int width, int height) {
        graphics.drawImage(fImage, 0, 0, width, height, null);
    }

    public Image getImage() {
        return fImage;
    }
}