1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.firemox.deckbuilder;
20
21 import java.awt.Image;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24
25 import net.sf.firemox.DeckBuilder;
26 import net.sf.firemox.token.IdConst;
27 import net.sf.firemox.tools.Configuration;
28 import net.sf.firemox.tools.Picture;
29 import net.sf.firemox.ui.TimerGlassPane;
30
31 /***
32 * Internal implementation detail: we happen to use javax.swing.Timer currently,
33 * which sends its timing events to an ActionListener. This internal private
34 * class is our ActionListener that traps these calls and forwards them to the
35 * TimingController.timingEvent() method.
36 *
37 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
38 * @since 0.95
39 */
40 public class CardLoader implements ActionListener {
41
42 private int deadlyCounter;
43
44 private final int thresholdCpu;
45
46 private Image playerThinkingPicture;
47
48 /***
49 * The progress bar pictures.
50 */
51 private final Image[] byGifPictures;
52
53 private TimerGlassPane timerPanel;
54
55 /***
56 * Create a new instance of this class.
57 *
58 * @param timerPanel
59 * the associated timer panel.
60 */
61 public CardLoader(TimerGlassPane timerPanel) {
62 super();
63 this.thresholdCpu = Configuration.getInt("timer.waiting-delay");
64 this.byGifPictures = new Image[6];
65 this.timerPanel = timerPanel;
66 try {
67 playerThinkingPicture = Picture.loadImage(IdConst.IMAGES_DIR
68 + "hourglass.jpg");
69 for (int i = byGifPictures.length; i-- > 0;) {
70 byGifPictures[i] = Picture.loadImage(IdConst.IMAGES_DIR + "progress"
71 + i + ".gif");
72 }
73 timerPanel.updatePicture(playerThinkingPicture, byGifPictures);
74 } catch (Exception e) {
75
76 }
77 }
78
79 public void actionPerformed(ActionEvent e) {
80 deadlyCounter++;
81 if (deadlyCounter >= thresholdCpu) {
82 timerPanel.updatePicture(playerThinkingPicture, byGifPictures);
83 if (DeckBuilder.form.getGlassPane() == timerPanel
84 && !timerPanel.isVisible()) {
85 timerPanel.setVisible(true);
86 timerPanel.repaint();
87 }
88 }
89 }
90
91 /***
92 * Reset counter
93 */
94 public void resetCounter() {
95 timerPanel.updatePicture(null, null);
96 deadlyCounter = 0;
97 }
98
99 }