1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.ui.wizard;
20
21 import java.awt.AlphaComposite;
22 import java.awt.Component;
23 import java.awt.Graphics;
24 import java.awt.Graphics2D;
25 import java.awt.Image;
26 import java.awt.RenderingHints;
27
28 import javax.swing.ImageIcon;
29
30 import net.sf.magicproject.clickable.targetable.card.MCard;
31 import net.sf.magicproject.token.IdConst;
32 import net.sf.magicproject.tools.MToolKit;
33
34 /***
35 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36 * @since 0.90
37 */
38 public class WizardImageIcon extends ImageIcon {
39
40 /***
41 * The width of displayed icon.
42 */
43 public static final int CARD_ICON_WIDTH = 15;
44
45 /***
46 * The alpha composite of background
47 */
48 public static final float VALUE_ALPHA_COMPOSITE = .7f;
49
50 /***
51 * The height of displayed icon.
52 */
53 public static final int CARD_ICON_HEIGHT = CARD_ICON_WIDTH
54 * IdConst.STD_HEIGHT / IdConst.STD_WIDTH;
55
56 /***
57 * Create a new instance of this class.
58 *
59 * @param card
60 * the card to display in this panel.
61 * @param iconName
62 * the back picture to display in this panel.
63 */
64 public WizardImageIcon(MCard card, String iconName) {
65 this(card.image(), iconName);
66 }
67
68 /***
69 * Create a new instance of this class.
70 *
71 * @param cardImage
72 * the image to display in this panel.
73 * @param iconName
74 * the back picture to display in this panel.
75 */
76 public WizardImageIcon(Image cardImage, String iconName) {
77 super(MToolKit.getIconPath(iconName));
78 this.cardImage = cardImage;
79 }
80
81 /***
82 * Set the card to display in this panel.
83 *
84 * @param card
85 * the card to display in this panel.
86 */
87 public void setCard(MCard card) {
88 cardImage = card.image();
89 }
90
91 @Override
92 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
93 Graphics2D g2D = (Graphics2D) g;
94 g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,
95 VALUE_ALPHA_COMPOSITE));
96 g.drawImage(getImage(), x, y, getIconWidth(), getIconHeight(), c);
97 g2D.setColor(c.getBackground());
98 g2D.fillRect(0, getIconHeight(), getIconWidth(), c.getHeight()
99 - getIconHeight());
100 if (cardImage != null) {
101 g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
102 RenderingHints.VALUE_INTERPOLATION_BICUBIC);
103 g2D.setRenderingHint(RenderingHints.KEY_RENDERING,
104 RenderingHints.VALUE_RENDER_QUALITY);
105 g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
106 RenderingHints.VALUE_ANTIALIAS_DEFAULT);
107 g2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
108 RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT);
109 g.drawImage(cardImage, x, y, CARD_ICON_WIDTH, CARD_ICON_HEIGHT, c);
110 }
111 }
112
113 /***
114 * The optional card to display in the icon.
115 */
116 private Image cardImage;
117
118 }