View Javadoc

1   /*
2    *   Magic-Project is a turn based strategy simulator
3    *   Copyright (C) 2003-2007 Fabrice Daugan
4    *
5    *   This program is free software; you can redistribute it and/or modify it 
6    * under the terms of the GNU General Public License as published by the Free 
7    * Software Foundation; either version 2 of the License, or (at your option) any
8    * later version.
9    *
10   *   This program is distributed in the hope that it will be useful, but WITHOUT 
11   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
13   * details.
14   *
15   *   You should have received a copy of the GNU General Public License along  
16   * with this program; if not, write to the Free Software Foundation, Inc., 
17   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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.action.MessagingAction;
30  import net.sf.magicproject.clickable.ability.Ability;
31  import net.sf.magicproject.event.context.ContextEventListener;
32  import net.sf.magicproject.ui.i18n.LanguageManager;
33  
34  /***
35   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36   * @since 0.82
37   */
38  public class YesNo extends Ok {
39  
40  	/***
41  	 * The YES key label for button.
42  	 */
43  	public static final String LABEL_YES = "yes";
44  
45  	/***
46  	 * The NO key label for button.
47  	 */
48  	public static final String LABEL_NO = "no";
49  
50  	/***
51  	 * Create a new instance of this class.
52  	 * 
53  	 * @param context
54  	 *          context of associated ability. This context will be used to
55  	 *          restart this wizard in case of Backgroud button is used.
56  	 * @param ability
57  	 *          ability to associate to this ability. If this ability has an
58  	 *          assosciated picture, it will be used instead of given picture.
59  	 *          Ability's name is also used to fill the title. This ability will
60  	 *          be used to restart this wizard in case of Background button is
61  	 *          used.
62  	 * @param action
63  	 *          the action's name and content will be used in the wizard totle and
64  	 *          also message text.
65  	 * @param title
66  	 *          the title of this wizard.
67  	 * @param description
68  	 *          the description appendend to the title of this wizard. This
69  	 *          content will be displayed as Html.
70  	 * @param iconName
71  	 *          the icon's name to display on the top right place.
72  	 * @param yesButton
73  	 *          the 'yes button' label.
74  	 * @param noButton
75  	 *          the 'no button' label.
76  	 * @param width
77  	 *          the preferred width.
78  	 * @param height
79  	 *          the preferred height.
80  	 */
81  	public YesNo(ContextEventListener context, Ability ability,
82  			BackgroundMessaging action, String title, String description,
83  			String iconName, String yesButton, String noButton, int width, int height) {
84  		super(context, ability, action, title, description, iconName, noButton,
85  				width, height);
86  
87  		// buttons
88  		if (yesButton == null) {
89  			okBtn = new JButton(LanguageManager.getString(LABEL_YES));
90  		} else {
91  			okBtn = new JButton(yesButton);
92  		}
93  		okBtn.setMnemonic(okBtn.getText().charAt(0));
94  		okBtn.setMaximumSize(new Dimension(100, 26));
95  		okBtn.addActionListener(this);
96  		buttonPanel.add(okBtn, 0);
97  		getRootPane().setDefaultButton(okBtn);
98  	}
99  
100 	/***
101 	 * Create a new instance of this class.
102 	 * 
103 	 * @param title
104 	 *          the title of this wizard.
105 	 * @param description
106 	 *          the description appendend to the title of this wizard. This
107 	 *          content will be displayed as Html.
108 	 * @param iconName
109 	 *          the icon's name to display on the top right place.
110 	 * @param yesButton
111 	 *          the 'yes button' label.
112 	 * @param noButton
113 	 *          the 'no button' label.
114 	 * @param width
115 	 *          the preferred width.
116 	 * @param height
117 	 *          the preferred height.
118 	 */
119 	public YesNo(String title, String description, String iconName,
120 			String yesButton, String noButton, int width, int height) {
121 		this(null, null, null, title, description, iconName, yesButton, noButton,
122 				width, height);
123 	}
124 
125 	/***
126 	 * Create a new instance of this class.
127 	 * 
128 	 * @param context
129 	 *          context of associated ability. This context will be used to
130 	 *          restart this wizard in case of Backgroud button is used.
131 	 * @param ability
132 	 *          ability to associate to this ability. If this ability has an
133 	 *          assosciated picture, it will be used instead of given picture.
134 	 *          Ability's name is also used to fill the title. This ability will
135 	 *          be used to restart this wizard in case of Background button is
136 	 *          used.
137 	 * @param action
138 	 *          the action's name and content will be used in the wizard totle and
139 	 *          also message text.
140 	 * @param title
141 	 *          the title of this wizard.
142 	 * @param description
143 	 *          the description appendend to the title of this wizard. This
144 	 *          content will be displayed as Html.
145 	 * @param iconName
146 	 *          the icon's name to display on the top right place.
147 	 * @param width
148 	 *          the preferred width.
149 	 * @param height
150 	 *          the preferred height.
151 	 */
152 	public YesNo(ContextEventListener context, Ability ability,
153 			MessagingAction action, String title, String description,
154 			String iconName, int width, int height) {
155 		this(context, ability, action, title, description, iconName,
156 				LanguageManager.getString(LABEL_YES), LanguageManager
157 						.getString(LABEL_NO), width, height);
158 	}
159 
160 	/***
161 	 * Create a new instance of this class.
162 	 * 
163 	 * @param context
164 	 *          context of associated ability. This context will be used to
165 	 *          restart this wizard in case of Backgroud button is used.
166 	 * @param ability
167 	 *          ability to associate to this ability. If this ability has an
168 	 *          assosciated picture, it will be used instead of given picture.
169 	 *          Ability's name is also used to fill the title. This ability will
170 	 *          be used to restart this wizard in case of Background button is
171 	 *          used.
172 	 * @param action
173 	 *          the action's name and content will be used in the wizard totle and
174 	 *          also message text.
175 	 * @param title
176 	 *          the title of this wizard.
177 	 * @param description
178 	 *          the description appendend to the title of this wizard. This
179 	 *          content will be displayed as Html.
180 	 * @param iconName
181 	 *          the icon's name to display on the top right place.
182 	 * @param width
183 	 *          the preferred width.
184 	 * @param height
185 	 *          the preferred height.
186 	 * @param text
187 	 */
188 	public YesNo(ContextEventListener context, Ability ability,
189 			MessagingAction action, String title, String description,
190 			String iconName, int width, int height, String text) {
191 		this(context, ability, action, title, description, iconName, width, height);
192 		gameParamPanel.add(new JLabel("<html>" + text));
193 	}
194 
195 	@Override
196 	public void actionPerformed(ActionEvent event) {
197 		if (event.getSource() == cancelBtn) {
198 			validAnswer(JOptionPane.NO_OPTION);
199 		} else if (event.getSource() == okBtn) {
200 			validAnswer(JOptionPane.YES_OPTION);
201 		} else {
202 			super.actionPerformed(event);
203 		}
204 	}
205 
206 	/***
207 	 */
208 	protected final JButton okBtn;
209 
210 }