01: package Schmortopf.Utility.gui;
02:
03: /**
04: * A JLabel, which draws its Image tiled onto its content.
05: */
06:
07: import javax.swing.*;
08: import javax.swing.border.*;
09: import javax.swing.event.*;
10: import javax.swing.text.*;
11: import java.awt.*;
12: import java.awt.event.*;
13:
14: public class TileImageLabel extends JLabel {
15:
16: ImageIcon imageIcon;
17:
18: public TileImageLabel() {
19: super ();
20: }
21:
22: public void setImageIcon(ImageIcon theImageIcon) {
23: this .imageIcon = theImageIcon;
24: }
25:
26: public void paint(Graphics g) {
27: super .paint(g);
28: if (this .imageIcon != null) {
29: Graphics2D g2 = (Graphics2D) g;
30: int xMax = this .getWidth();
31: int yMax = this .getHeight();
32: int imageWidth = imageIcon.getIconWidth();
33: int imageHeight = imageIcon.getIconHeight();
34: // Security [prevents endless loop, case an attribute is zero]
35: if ((xMax > 0) && (yMax > 0) && (imageWidth > 0)
36: && (imageHeight > 0)) {
37: int x = 0;
38: int y = 0;
39: while (x < xMax) {
40: while (y < yMax) {
41: g2.drawImage(imageIcon.getImage(), x, y,
42: imageWidth, imageHeight, imageIcon
43: .getImageObserver());
44: y += imageHeight;
45: } // while y
46: y = 0;
47: x += imageWidth;
48: } // while x
49: } // if
50: } // if
51: }
52:
53: public void update(Graphics g) {
54: this .paint(g);
55: }
56:
57: } // TileImageLabel
|