View Javadoc

1   /*
2    *   Firemox 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.firemox.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.firemox.clickable.ability.Ability;
29  import net.sf.firemox.ui.i18n.LanguageManager;
30  
31  /***
32   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
33   * @since 0.82
34   */
35  public class YesNo extends Ok {
36  
37  	/***
38  	 * The YES key label for button.
39  	 */
40  	public static final String LABEL_YES = "yes";
41  
42  	/***
43  	 * The NO key label for button.
44  	 */
45  	public static final String LABEL_NO = "no";
46  
47  	/***
48  	 * Create a new instance of this class.
49  	 * 
50  	 * @param ability
51  	 *          ability to associate to this ability. If this ability has an
52  	 *          associated picture, it will be used instead of given picture.
53  	 *          Ability's name is also used to fill the title. This ability will
54  	 *          be used to restart this wizard in case of Background button is
55  	 *          used.
56  	 * @param title
57  	 *          the title of this wizard.
58  	 * @param description
59  	 *          the description appended to the title of this wizard. This content
60  	 *          will be displayed as Html.
61  	 * @param iconName
62  	 *          the icon's name to display on the top right place.
63  	 * @param yesButton
64  	 *          the 'yes button' label.
65  	 * @param noButton
66  	 *          the 'no button' label.
67  	 * @param width
68  	 *          the preferred width.
69  	 * @param height
70  	 *          the preferred height.
71  	 */
72  	public YesNo(Ability ability, String title, String description,
73  			String iconName, String yesButton, String noButton, int width, int height) {
74  		super(ability, title, description, iconName, noButton, width, height);
75  
76  		// buttons
77  		if (yesButton == null) {
78  			okBtn = new JButton(LanguageManager.getString(LABEL_YES));
79  		} else {
80  			okBtn = new JButton(yesButton);
81  		}
82  		okBtn.setMnemonic(okBtn.getText().charAt(0));
83  		okBtn.setMaximumSize(new Dimension(100, 26));
84  		okBtn.addActionListener(this);
85  		buttonPanel.add(okBtn, 0);
86  		getRootPane().setDefaultButton(okBtn);
87  	}
88  
89  	/***
90  	 * Create a new instance of this class.
91  	 * 
92  	 * @param title
93  	 *          the title of this wizard.
94  	 * @param description
95  	 *          the description appended to the title of this wizard. This content
96  	 *          will be displayed as Html.
97  	 * @param iconName
98  	 *          the icon's name to display on the top right place.
99  	 * @param yesButton
100 	 *          the 'yes button' label.
101 	 * @param noButton
102 	 *          the 'no button' label.
103 	 * @param width
104 	 *          the preferred width.
105 	 * @param height
106 	 *          the preferred height.
107 	 */
108 	public YesNo(String title, String description, String iconName,
109 			String yesButton, String noButton, int width, int height) {
110 		this(null, title, description, iconName, yesButton, noButton, width, height);
111 	}
112 
113 	/***
114 	 * Create a new instance of this class.
115 	 * 
116 	 * @param ability
117 	 *          ability to associate to this ability. If this ability has an
118 	 *          associated picture, it will be used instead of given picture.
119 	 *          Ability's name is also used to fill the title. This ability will
120 	 *          be used to restart this wizard in case of Background button is
121 	 *          used.
122 	 * @param title
123 	 *          the title of this wizard.
124 	 * @param description
125 	 *          the description appended to the title of this wizard. This content
126 	 *          will be displayed as Html.
127 	 * @param iconName
128 	 *          the icon's name to display on the top right place.
129 	 * @param width
130 	 *          the preferred width.
131 	 * @param height
132 	 *          the preferred height.
133 	 */
134 	public YesNo(Ability ability, String title, String description,
135 			String iconName, int width, int height) {
136 		this(ability, title, description, iconName, LanguageManager
137 				.getString(LABEL_YES), LanguageManager.getString(LABEL_NO), width,
138 				height);
139 	}
140 
141 	/***
142 	 * Create a new instance of this class.
143 	 * 
144 	 * @param ability
145 	 *          ability to associate to this ability. If this ability has an
146 	 *          associated picture, it will be used instead of given picture.
147 	 *          Ability's name is also used to fill the title. This ability will
148 	 *          be used to restart this wizard in case of Background button is
149 	 *          used.
150 	 * @param title
151 	 *          the title of this wizard.
152 	 * @param description
153 	 *          the description appended to the title of this wizard. This content
154 	 *          will be displayed as Html.
155 	 * @param iconName
156 	 *          the icon's name to display on the top right place.
157 	 * @param width
158 	 *          the preferred width.
159 	 * @param height
160 	 *          the preferred height.
161 	 * @param text
162 	 *          the text to display.
163 	 */
164 	public YesNo(Ability ability, String title, String description,
165 			String iconName, int width, int height, String text) {
166 		this(ability, title, description, iconName, width, height);
167 		gameParamPanel.add(new JLabel("<html>" + text));
168 	}
169 
170 	@Override
171 	public void actionPerformed(ActionEvent event) {
172 		if (event.getSource() == cancelBtn) {
173 			validAnswer(JOptionPane.NO_OPTION);
174 		} else if (event.getSource() == okBtn) {
175 			validAnswer(JOptionPane.YES_OPTION);
176 		} else {
177 			super.actionPerformed(event);
178 		}
179 	}
180 
181 	/***
182 	 */
183 	protected final JButton okBtn;
184 
185 }