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.Dimension;
22 import java.awt.event.ActionEvent;
23
24 import javax.swing.JButton;
25 import javax.swing.JLabel;
26 import javax.swing.JOptionPane;
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.ToolKit;
32 import net.sf.magicproject.ui.i18n.LanguageManager;
33
34 /***
35 * <ul>
36 * A simple OK message box with
37 * <li>header containing Html tile, description, icon
38 * <li>Text
39 * <li>OK button
40 * <li>BACKGROUND button
41 * <li>validator
42 * </ul>
43 *
44 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
45 * @since 0.82
46 */
47 public class Ok extends Wizard {
48
49 /***
50 * Maximal text content's size.
51 */
52 protected static final int MAXIMAL_TXT_SIZE = 25;
53
54 /***
55 *
56 */
57 protected static final int UNBOUNDED_TXT_SIZE = 2100;
58
59 /***
60 * Left margin.
61 */
62 protected static final int MARGIN_SIZE = 95;
63
64 /***
65 * The OK key label for button.
66 */
67 public static final String LABEL_OK = "ok";
68
69 /***
70 * The CANCEL key label for button.
71 */
72 public static final String LABEL_CANCEL = "cancel";
73
74 /***
75 * Creates a new instance of Ok <br>
76 *
77 * @param context
78 * context of associated ability. This context will be used to
79 * restart this wizard in case of Backgroud button is used.
80 * @param ability
81 * ability to associate to this ability. If this ability has an
82 * assosciated picture, it will be used instead of given picture.
83 * Ability's name is also used to fill the title. This ability will
84 * be used to restart this wizard in case of Background button is
85 * used.
86 * @param action
87 * the action's name and content will be used in the wizard totle and
88 * also message text.
89 * @param title
90 * the title of this wizard.
91 * @param description
92 * the description appendend to the title of this wizard. This
93 * content will be displayed as Html.
94 * @param iconName
95 * the icon's name to display on the top right place.
96 * @param button
97 * the button text to use. If is <code>null</code>, OK will be
98 * used.
99 * @param width
100 * the preferred width.
101 * @param height
102 * the preferred height.
103 */
104 public Ok(ContextEventListener context, Ability ability,
105 BackgroundMessaging action, String title, String description,
106 String iconName, String button, int width, int height) {
107 super(context, ability, action, title, description, iconName, width, height);
108
109
110 if (button == null) {
111 cancelBtn = new JButton(LanguageManager.getString(LABEL_OK));
112 } else {
113 cancelBtn = new JButton(button);
114 }
115 cancelBtn.setMnemonic(cancelBtn.getText().charAt(0));
116 cancelBtn.addActionListener(this);
117 cancelBtn.setMaximumSize(new Dimension(100, 76));
118 buttonPanel.add(cancelBtn, 0);
119 getRootPane().setDefaultButton(cancelBtn);
120 ToolKit.addCancelByEscapeKey(this, cancelBtn);
121 }
122
123 /***
124 * Creates a new instance of Ok <br>
125 *
126 * @param title
127 * the title of this wizard.
128 * @param description
129 * the description appendend to the title of this wizard. This
130 * content will be displayed as Html.
131 * @param iconName
132 * the icon's name to display on the top right place.
133 * @param button
134 * the button text to use. If is <code>null</code>, OK will be
135 * used.
136 * @param width
137 * the preferred width.
138 * @param height
139 * the preferred height.
140 */
141 public Ok(String title, String description, String iconName, String button,
142 int width, int height) {
143 this(null, null, null, title, description, iconName, button, width, height);
144 }
145
146 /***
147 * Creates a new instance of Ok <br>
148 *
149 * @param context
150 * context of associated ability. This context will be used to
151 * restart this wizard in case of Backgroud button is used.
152 * @param ability
153 * ability to associate to this ability. If this ability has an
154 * assosciated picture, it will be used instead of given picture.
155 * Ability's name is also used to fill the title. This ability will
156 * be used to restart this wizard in case of Background button is
157 * used.
158 * @param action
159 * the action's name and content will be used in the wizard totle and
160 * also message text.
161 * @param title
162 * the title of this wizard.
163 * @param description
164 * the description appendend to the title of this wizard. This
165 * content will be displayed as Html.
166 * @param iconName
167 * the icon's name to display on the top right place.
168 * @param width
169 * the preferred width.
170 * @param height
171 * the preferred height.
172 * @param text
173 */
174 public Ok(ContextEventListener context, Ability ability,
175 BackgroundMessaging action, String title, String description,
176 String iconName, int width, int height, String text) {
177 this(context, ability, action, title, description, iconName, null, width,
178 height);
179 gameParamPanel.add(new JLabel("<html>" + text));
180 }
181
182 @Override
183 public void actionPerformed(ActionEvent event) {
184 if (event.getSource() == cancelBtn) {
185 validAnswer(JOptionPane.OK_OPTION);
186 } else {
187 super.actionPerformed(event);
188 }
189 }
190
191 @Override
192 protected boolean checkValidity() {
193 return true;
194 }
195
196 /***
197 * The "cancel" button
198 */
199 protected JButton cancelBtn;
200
201 }