01: package org.enhydra.jawe;
02:
03: import java.awt.Component;
04: import java.awt.Graphics;
05:
06: import javax.swing.Icon;
07: import javax.swing.ImageIcon;
08:
09: public class CombinedIcon extends ImageIcon {
10:
11: public static final int POS_BOTTOM_LEFT = 0;
12: public static final int POS_BOTTOM_RIGHT = 1;
13: public static final int POS_TOP_LEFT = 2;
14: public static final int POS_TOP_RIGHT = 3;
15:
16: private final Icon icon1;
17: private final Icon icon2;
18:
19: private int secondIconPos = 0;
20:
21: public CombinedIcon(Icon icon1, Icon icon2) {
22: this .icon1 = icon1;
23: this .icon2 = icon2;
24: }
25:
26: public CombinedIcon(Icon icon1, Icon icon2, int secondIconPos) {
27: this (icon1, icon2);
28: this .secondIconPos = secondIconPos;
29: }
30:
31: public int getIconWidth() {
32: return Math.max(icon1.getIconWidth(), icon2.getIconWidth());
33: }
34:
35: public int getIconHeight() {
36: return Math.max(icon1.getIconHeight(), icon2.getIconHeight());
37: }
38:
39: public void paintIcon(Component c, Graphics g, int x, int y) {
40: icon1.paintIcon(c, g, x, y);
41: if (secondIconPos == POS_BOTTOM_RIGHT) {
42: icon2.paintIcon(c, g, icon1.getIconWidth()
43: - icon2.getIconWidth(), icon1.getIconHeight()
44: - icon2.getIconHeight());
45: } else if (secondIconPos == POS_TOP_LEFT) {
46: icon2.paintIcon(c, g, x, y);
47: } else if (secondIconPos == POS_TOP_RIGHT) {
48: icon2.paintIcon(c, g, icon1.getIconWidth()
49: - icon2.getIconWidth(), y);
50: } else {
51: icon2.paintIcon(c, g, x, icon1.getIconHeight()
52: - icon2.getIconHeight());
53: }
54: }
55:
56: }
|