2 * © 2008 INA Service GmbH
5 package net.pterodactylus.jsite.gui;
7 import java.awt.BorderLayout;
8 import java.awt.FlowLayout;
9 import java.awt.GridBagConstraints;
10 import java.awt.GridBagLayout;
11 import java.awt.Insets;
12 import java.awt.event.ActionEvent;
14 import javax.swing.BorderFactory;
15 import javax.swing.JButton;
16 import javax.swing.JCheckBox;
17 import javax.swing.JComponent;
18 import javax.swing.JDialog;
19 import javax.swing.JPanel;
20 import javax.swing.JTabbedPane;
21 import javax.swing.SwingConstants;
23 import net.pterodactylus.jsite.i18n.I18n;
24 import net.pterodactylus.jsite.i18n.I18nable;
25 import net.pterodactylus.jsite.i18n.gui.I18nAction;
26 import net.pterodactylus.jsite.i18n.gui.I18nLabel;
27 import net.pterodactylus.util.swing.SwingUtils;
30 * The configuration dialog.
32 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
35 public class ConfigurationDialog extends JDialog implements I18nable {
37 /** The “okay” action. */
38 private I18nAction okayAction;
40 /** The “cancel” action. */
41 private I18nAction cancelAction;
43 /** The “beautify GUI” action. */
44 private I18nAction antialiasAction;
46 /** The “use custom control font” action. */
47 private I18nAction useCustomControlFontAction;
49 /** The “use custom user font” action. */
50 private I18nAction useCustomUserFontAction;
52 /** The “restart required” warning label. */
53 private I18nLabel restartRequiredLabel;
55 /** The “beautify” checkbox. */
56 private JCheckBox antialiasCheckBox;
58 /** The “use custom” fonts checkbox. */
59 private JCheckBox useCustomControlFontCheckBox;
61 /** The control font list. */
62 private FontComboBox controlFontList;
64 /** The checkbox for “use same as control font”. */
65 private JCheckBox useCustomUserFontCheckBox;
67 /** The user font list. */
68 private FontComboBox userFontList;
70 /** Whether the dialog was cancelled. */
71 private boolean cancelled;
74 * Creates a new configuration dialog.
76 * @param swingInterface
79 public ConfigurationDialog(SwingInterface swingInterface) {
80 super(swingInterface.getMainWindow(), I18n.get("configurationDialog.title"), true);
84 SwingUtils.center(this);
85 I18n.registerI18nable(this);
93 * Returns whether the dialog was cancelled or confirmed. If the dialog was
94 * cancelled, no further processing should be done.
96 * @return <code>true</code> if the dialog was cancelled,
97 * <code>false</code> otherwise
99 public boolean wasCancelled() {
104 * Returns whether the “beautify” checkbox has been selected. The result of
105 * this method should not be used if {@link #wasCancelled()} returned
108 * @return <code>true</code> if the checkbox was selected,
109 * <code>false</code> otherwise
111 public boolean isAntialias() {
112 return antialiasCheckBox.isSelected();
116 * Sets the state of the “antialias” checkbox.
119 * The state of the checkbox
121 public void setAntialias(boolean antialias) {
122 antialiasCheckBox.setSelected(antialias);
126 * Returns the font for the controls.
128 * @return The control font, or <code>null</code> if no custom control
131 public String getControlFont() {
132 return (String) (useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() : null);
136 * Sets the font for the controls.
139 * The control font, or <code>null</code> if no custom control
142 public void setControlFont(String controlFont) {
143 useCustomControlFontCheckBox.setSelected(controlFont != null);
144 controlFontList.setEnabled(controlFont != null);
145 controlFontList.setSelectedItem(controlFont);
149 * Returns the font for user input.
151 * @return The font for user input, or <code>null</code> if no custom user
152 * input font is to be used
154 public String getUserFont() {
155 return (String) (useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() : null);
159 * Sets the font for user input.
162 * The font for user input, or <code>null</code> if no custom
163 * user input font is to be used
165 public void setUserFont(String userFont) {
166 useCustomUserFontCheckBox.setSelected(userFont != null);
167 userFontList.setEnabled(userFont != null);
168 userFontList.setSelectedItem(userFont);
176 * Creates all actions.
178 private void initActions() {
179 okayAction = new I18nAction("general.button.okay") {
182 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
184 @SuppressWarnings("synthetic-access")
185 public void actionPerformed(ActionEvent actionEvent) {
189 cancelAction = new I18nAction("general.button.cancel") {
192 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
194 @SuppressWarnings("synthetic-access")
195 public void actionPerformed(ActionEvent actionEvent) {
199 antialiasAction = new I18nAction("configurationDialog.page.interface.item.antialias") {
202 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
204 public void actionPerformed(ActionEvent actionEvent) {
208 useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") {
213 @SuppressWarnings("synthetic-access")
214 public void actionPerformed(ActionEvent e) {
215 controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected());
218 useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") {
223 @SuppressWarnings("synthetic-access")
224 public void actionPerformed(ActionEvent e) {
225 userFontList.setEnabled(useCustomUserFontCheckBox.isSelected());
231 * Creates all internal components.
233 private void initComponents() {
234 JPanel contentPane = new JPanel(new BorderLayout(12, 12));
235 contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
237 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
238 contentPane.add(tabbedPane, BorderLayout.CENTER);
240 JComponent interfaceConfig = createInterfaceConfig();
241 tabbedPane.add(I18n.get("configurationDialog.page.interface.name"), interfaceConfig);
243 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
244 contentPane.add(buttonPanel, BorderLayout.PAGE_END);
245 buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
246 buttonPanel.add(new JButton(cancelAction));
247 JButton okayButton = new JButton(okayAction);
248 buttonPanel.add(okayButton);
249 getRootPane().setDefaultButton(okayButton);
251 getContentPane().add(contentPane, BorderLayout.CENTER);
255 * Creates the panel for the interface configuration.
257 * @return The interface configuration panel
259 private JComponent createInterfaceConfig() {
260 JPanel interfaceConfigPanel = new JPanel(new GridBagLayout());
261 interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
263 restartRequiredLabel = new I18nLabel("configurationDialog.page.interface.item.restartRequired");
264 interfaceConfigPanel.add(restartRequiredLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
266 antialiasCheckBox = new JCheckBox(antialiasAction);
267 interfaceConfigPanel.add(antialiasCheckBox, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(18, 0, 0, 0), 0, 0));
269 useCustomControlFontCheckBox = new JCheckBox(useCustomControlFontAction);
270 interfaceConfigPanel.add(useCustomControlFontCheckBox, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
272 controlFontList = new FontComboBox();
273 interfaceConfigPanel.add(controlFontList, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
275 useCustomUserFontCheckBox = new JCheckBox(useCustomUserFontAction);
276 interfaceConfigPanel.add(useCustomUserFontCheckBox, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
278 userFontList = new FontComboBox();
279 interfaceConfigPanel.add(userFontList, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
281 interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 4, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
283 return interfaceConfigPanel;
291 * Called when the “okay” button is clicked.
293 private void actionOkay() {
299 * Called when the “cancel” button is clicked.
301 private void actionCancel() {
307 // INTERFACE I18nable
311 * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
313 public void updateI18n() {
314 okayAction.updateI18n();
315 cancelAction.updateI18n();
316 restartRequiredLabel.updateI18n();
317 antialiasAction.updateI18n();
318 useCustomControlFontAction.updateI18n();
319 useCustomUserFontAction.updateI18n();
320 SwingUtils.repackCentered(this);