1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.deckbuilder;
20
21 import java.awt.Dimension;
22 import java.awt.Graphics;
23 import java.awt.Graphics2D;
24 import java.awt.Image;
25 import java.awt.RenderingHints;
26
27 import javax.swing.JComponent;
28
29 import net.sf.magicproject.database.DatabaseCard;
30 import net.sf.magicproject.database.DatabaseFactory;
31 import net.sf.magicproject.management.MonitorListener;
32 import net.sf.magicproject.token.IdConst;
33 import net.sf.magicproject.tools.MCardCompare;
34
35 /***
36 * @author <a href="mailto:goldeneyemdk@users.sourceforge.net">Sebastien Genete
37 * </a>
38 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
39 * @since 0.83
40 */
41 public final class CardView extends JComponent implements MonitorListener {
42 private CardView() {
43 setPreferredSize(new Dimension(IdConst.STD_WIDTH, IdConst.STD_HEIGHT));
44 setMaximumSize(getPreferredSize());
45 setMinimumSize(getPreferredSize());
46 setSize(getPreferredSize());
47 }
48
49 public final void notifyChange() {
50 repaint();
51 }
52
53 /***
54 * Display the given card name. If this card name is not locally present, it
55 * will be downloaded from a web location depending on settings of current
56 * TBS. Theses settings are defined in the <code>tbs/xxx.xml</code>
57 *
58 * @param card
59 * the card name to display.
60 */
61 public void setCard(MCardCompare card) {
62 String errorMsg = null;
63 try {
64 databaseCard = DatabaseFactory.getDatabase(null, card
65 .getModel(MdbLoader.lastMdbStream), null);
66 } catch (Throwable e) {
67 errorMsg = "<html>Error :" + e.getMessage();
68 } finally {
69 if (errorMsg != null) {
70 databaseCard = null;
71 }
72 }
73 repaint();
74 }
75
76 private DatabaseCard databaseCard;
77
78 @Override
79 public void paint(Graphics g) {
80 final Image picture;
81 if (databaseCard == null) {
82 picture = DatabaseFactory.backImage;
83 } else {
84 picture = databaseCard.getImage(this);
85 }
86 Graphics2D g2d = (Graphics2D) g;
87 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
88 RenderingHints.VALUE_INTERPOLATION_BILINEAR);
89 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
90 RenderingHints.VALUE_ANTIALIAS_ON);
91 g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
92 RenderingHints.VALUE_RENDER_QUALITY);
93 g.drawImage(picture, 0, 0, getSize().width, getSize().height, this);
94
95
96 if (databaseCard != null) {
97 databaseCard.updatePaintNotification(this, g);
98 }
99 }
100
101 /***
102 * Unique instance of CardView class.
103 */
104 public static CardView instance = new CardView();
105
106 }