added more german i18n
[jSite2.git] / src / net / pterodactylus / jsite / gui / ConfigurationDialog.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4
5 package net.pterodactylus.jsite.gui;
6
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;
13
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;
22
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;
28
29 /**
30  * The configuration dialog.
31  *
32  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
33  * @version $Id$
34  */
35 public class ConfigurationDialog extends JDialog implements I18nable {
36
37         /** The “okay” action. */
38         private I18nAction okayAction;
39
40         /** The “cancel” action. */
41         private I18nAction cancelAction;
42
43         /** The “beautify GUI” action. */
44         private I18nAction antialiasAction;
45
46         /** The “use custom control font” action. */
47         private I18nAction useCustomControlFontAction;
48
49         /** The “use custom user font” action. */
50         private I18nAction useCustomUserFontAction;
51
52         /** The “restart required” warning label. */
53         private I18nLabel restartRequiredLabel;
54
55         /** The “beautify” checkbox. */
56         private JCheckBox antialiasCheckBox;
57
58         /** The “use custom” fonts checkbox. */
59         private JCheckBox useCustomControlFontCheckBox;
60
61         /** The control font list. */
62         private FontComboBox controlFontList;
63
64         /** The checkbox for “use same as control font”. */
65         private JCheckBox useCustomUserFontCheckBox;
66
67         /** The user font list. */
68         private FontComboBox userFontList;
69
70         /** Whether the dialog was cancelled. */
71         private boolean cancelled;
72
73         /**
74          * Creates a new configuration dialog.
75          *
76          * @param swingInterface
77          *            The Swing interface
78          */
79         public ConfigurationDialog(SwingInterface swingInterface) {
80                 super(swingInterface.getMainWindow(), I18n.get("configurationDialog.title"), true);
81                 initActions();
82                 initComponents();
83                 pack();
84                 SwingUtils.center(this);
85                 I18n.registerI18nable(this);
86         }
87
88         //
89         // ACCESSORS
90         //
91
92         /**
93          * Returns whether the dialog was cancelled or confirmed. If the dialog was
94          * cancelled, no further processing should be done.
95          *
96          * @return <code>true</code> if the dialog was cancelled,
97          *         <code>false</code> otherwise
98          */
99         public boolean wasCancelled() {
100                 return cancelled;
101         }
102
103         /**
104          * Returns whether the “beautify” checkbox has been selected. The result of
105          * this method should not be used if {@link #wasCancelled()} returned
106          * <code>true</code>!
107          *
108          * @return <code>true</code> if the checkbox was selected,
109          *         <code>false</code> otherwise
110          */
111         public boolean isAntialias() {
112                 return antialiasCheckBox.isSelected();
113         }
114
115         /**
116          * Sets the state of the “antialias” checkbox.
117          *
118          * @param antialias
119          *            The state of the checkbox
120          */
121         public void setAntialias(boolean antialias) {
122                 antialiasCheckBox.setSelected(antialias);
123         }
124
125         /**
126          * Returns the font for the controls.
127          *
128          * @return The control font, or <code>null</code> if no custom control
129          *         font is to be used
130          */
131         public String getControlFont() {
132                 return (String) (useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() : null);
133         }
134
135         /**
136          * Sets the font for the controls.
137          *
138          * @param controlFont
139          *            The control font, or <code>null</code> if no custom control
140          *            font is to be used
141          */
142         public void setControlFont(String controlFont) {
143                 useCustomControlFontCheckBox.setSelected(controlFont != null);
144                 controlFontList.setEnabled(controlFont != null);
145                 controlFontList.setSelectedItem(controlFont);
146         }
147
148         /**
149          * Returns the font for user input.
150          *
151          * @return The font for user input, or <code>null</code> if no custom user
152          *         input font is to be used
153          */
154         public String getUserFont() {
155                 return (String) (useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() : null);
156         }
157
158         /**
159          * Sets the font for user input.
160          *
161          * @param userFont
162          *            The font for user input, or <code>null</code> if no custom
163          *            user input font is to be used
164          */
165         public void setUserFont(String userFont) {
166                 useCustomUserFontCheckBox.setSelected(userFont != null);
167                 userFontList.setEnabled(userFont != null);
168                 userFontList.setSelectedItem(userFont);
169         }
170
171         //
172         // PRIVATE METHODS
173         //
174
175         /**
176          * Creates all actions.
177          */
178         private void initActions() {
179                 okayAction = new I18nAction("general.button.okay") {
180
181                         /**
182                          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
183                          */
184                         @SuppressWarnings("synthetic-access")
185                         public void actionPerformed(ActionEvent actionEvent) {
186                                 actionOkay();
187                         }
188                 };
189                 cancelAction = new I18nAction("general.button.cancel") {
190
191                         /**
192                          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
193                          */
194                         @SuppressWarnings("synthetic-access")
195                         public void actionPerformed(ActionEvent actionEvent) {
196                                 actionCancel();
197                         }
198                 };
199                 antialiasAction = new I18nAction("configurationDialog.page.interface.item.antialias") {
200
201                         /**
202                          * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
203                          */
204                         public void actionPerformed(ActionEvent actionEvent) {
205                                 /* do nothing. */
206                         }
207                 };
208                 useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") {
209
210                         /**
211                          * {@inheritDoc}
212                          */
213                         @SuppressWarnings("synthetic-access")
214                         public void actionPerformed(ActionEvent e) {
215                                 controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected());
216                         }
217                 };
218                 useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") {
219
220                         /**
221                          * {@inheritDoc}
222                          */
223                         @SuppressWarnings("synthetic-access")
224                         public void actionPerformed(ActionEvent e) {
225                                 userFontList.setEnabled(useCustomUserFontCheckBox.isSelected());
226                         }
227                 };
228         }
229
230         /**
231          * Creates all internal components.
232          */
233         private void initComponents() {
234                 JPanel contentPane = new JPanel(new BorderLayout(12, 12));
235                 contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
236
237                 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
238                 contentPane.add(tabbedPane, BorderLayout.CENTER);
239
240                 JComponent interfaceConfig = createInterfaceConfig();
241                 tabbedPane.add(I18n.get("configurationDialog.page.interface.name"), interfaceConfig);
242
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);
250
251                 getContentPane().add(contentPane, BorderLayout.CENTER);
252         }
253
254         /**
255          * Creates the panel for the interface configuration.
256          *
257          * @return The interface configuration panel
258          */
259         private JComponent createInterfaceConfig() {
260                 JPanel interfaceConfigPanel = new JPanel(new GridBagLayout());
261                 interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
262
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));
265
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));
268
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));
271
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));
274
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));
277
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));
280
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));
282
283                 return interfaceConfigPanel;
284         }
285
286         //
287         // PRIVATE ACTIONS
288         //
289
290         /**
291          * Called when the “okay” button is clicked.
292          */
293         private void actionOkay() {
294                 cancelled = false;
295                 setVisible(false);
296         }
297
298         /**
299          * Called when the “cancel” button is clicked.
300          */
301         private void actionCancel() {
302                 cancelled = true;
303                 setVisible(false);
304         }
305
306         //
307         // INTERFACE I18nable
308         //
309
310         /**
311          * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
312          */
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);
321         }
322
323 }