1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.magicproject.ui.component;
20
21 import java.awt.Graphics;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24
25 import javax.swing.ImageIcon;
26 import javax.swing.JButton;
27
28 import net.sf.magicproject.action.BackgroundMessaging;
29 import net.sf.magicproject.clickable.ability.Ability;
30 import net.sf.magicproject.event.context.ContextEventListener;
31 import net.sf.magicproject.ui.i18n.LanguageManager;
32 import net.sf.magicproject.ui.wizard.Wizard;
33
34 /***
35 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36 * @since 0.90
37 */
38 public class MessageButton extends JButton implements ActionListener {
39
40 /***
41 * Create a new instance of this class.
42 *
43 * @param enabledPicture1
44 * @param enabledPicture2
45 */
46 public MessageButton(ImageIcon enabledPicture1, ImageIcon enabledPicture2) {
47 this.enabledPicture1 = enabledPicture1;
48 this.enabledPicture2 = enabledPicture2;
49 addActionListener(this);
50 }
51
52 /***
53 * Show the button enabling to restore the background wizard.
54 *
55 * @param context
56 * the context of wizard put in background.
57 * @param ability
58 * the ability of wizard put in background.
59 * @param action
60 * the action of wizard put in background.
61 * @param wizard
62 * the wizard put in background.
63 */
64 public void startButton(ContextEventListener context, Ability ability,
65 BackgroundMessaging action, Wizard wizard) {
66 this.context = context;
67 this.ability = ability;
68 this.action = action;
69 this.wizard = wizard;
70 state = 0;
71 setVisible(true);
72 setToolTipText(LanguageManager.getString("wiz_recallmsgTTenabled"));
73 }
74
75 @Override
76 public void update(Graphics g) {
77 paint(g);
78 }
79
80 /***
81 * Hidde the button put in background.
82 */
83 public void stopButton() {
84 state = 0;
85 setVisible(false);
86 setToolTipText(LanguageManager.getString("wiz_recallmsgTTdisabled"));
87 }
88
89 public void actionPerformed(ActionEvent e) {
90
91 stopButton();
92 action.replayAction(context, ability, wizard);
93 }
94
95 /***
96 * Display the next picture of this button.
97 */
98 public void nextPicture() {
99 state = ++state % 2;
100 if (isVisible()) {
101 if (state == 0) {
102 setIcon(enabledPicture1);
103 } else {
104 setIcon(enabledPicture2);
105 }
106 }
107 }
108
109 private ImageIcon enabledPicture1;
110
111 private ImageIcon enabledPicture2;
112
113 private int state;
114
115 private ContextEventListener context;
116
117 private Ability ability;
118
119 private BackgroundMessaging action;
120
121 private Wizard wizard;
122 }