File: ImagePainter.java

package info (click to toggle)
mac-widgets 0.10.0%2Bsvn416-dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,968 kB
  • ctags: 2,003
  • sloc: java: 9,909; makefile: 13; sh: 12
file content (35 lines) | stat: -rw-r--r-- 813 bytes parent folder | download | duplicates (4)
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
package com.explodingpixels.painter;

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

import javax.imageio.ImageIO;

public class ImagePainter implements MacWidgetsPainter<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;
    }
}