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.util.swing.SwingUtils;
29 * The configuration dialog.
31 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
34 public class ConfigurationDialog extends JDialog implements I18nable {
36 /** The “okay” action. */
37 private I18nAction okayAction;
39 /** The “cancel” action. */
40 private I18nAction cancelAction;
42 /** The “beautify GUI” action. */
43 private I18nAction antialiasAction;
45 /** The “use custom control font” action. */
46 private I18nAction useCustomControlFontAction;
48 /** The “use custom user font” action. */
49 private I18nAction useCustomUserFontAction;
51 /** The “beautify” checkbox. */
52 private JCheckBox antialiasCheckBox;
54 /** The “use custom” fonts checkbox. */
55 private JCheckBox useCustomControlFontCheckBox;
57 /** The control font list. */
58 private FontComboBox controlFontList;
60 /** The checkbox for “use same as control font”. */
61 private JCheckBox useCustomUserFontCheckBox;
63 /** The user font list. */
64 private FontComboBox userFontList;
66 /** Whether the dialog was cancelled. */
67 private boolean cancelled;
70 * Creates a new configuration dialog.
72 * @param swingInterface
75 public ConfigurationDialog(SwingInterface swingInterface) {
76 super(swingInterface.getMainWindow(), I18n.get("configurationDialog.title"), true);
80 SwingUtils.center(this);
81 I18n.registerI18nable(this);
89 * Returns whether the dialog was cancelled or confirmed. If the dialog was
90 * cancelled, no further processing should be done.
92 * @return <code>true</code> if the dialog was cancelled,
93 * <code>false</code> otherwise
95 public boolean wasCancelled() {
100 * Returns whether the “beautify” checkbox has been selected. The result of
101 * this method should not be used if {@link #wasCancelled()} returned
104 * @return <code>true</code> if the checkbox was selected,
105 * <code>false</code> otherwise
107 public boolean isAntialias() {
108 return antialiasCheckBox.isSelected();
112 * Sets the state of the “antialias” checkbox.
115 * The state of the checkbox
117 public void setAntialias(boolean antialias) {
118 antialiasCheckBox.setSelected(antialias);
122 * Returns the font for the controls.
124 * @return The control font, or <code>null</code> if no custom control
127 public String getControlFont() {
128 return (String) (useCustomControlFontCheckBox.isSelected() ? controlFontList.getSelectedItem() : null);
132 * Sets the font for the controls.
135 * The control font, or <code>null</code> if no custom control
138 public void setControlFont(String controlFont) {
139 useCustomControlFontCheckBox.setSelected(controlFont != null);
140 controlFontList.setEnabled(controlFont != null);
141 controlFontList.setSelectedItem(controlFont);
145 * Returns the font for user input.
147 * @return The font for user input, or <code>null</code> if no custom user
148 * input font is to be used
150 public String getUserFont() {
151 return (String) (useCustomUserFontCheckBox.isSelected() ? userFontList.getSelectedItem() : null);
155 * Sets the font for user input.
158 * The font for user input, or <code>null</code> if no custom
159 * user input font is to be used
161 public void setUserFont(String userFont) {
162 useCustomUserFontCheckBox.setSelected(userFont != null);
163 userFontList.setEnabled(userFont != null);
164 userFontList.setSelectedItem(userFont);
172 * Creates all actions.
174 private void initActions() {
175 okayAction = new I18nAction("general.button.okay") {
178 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
180 @SuppressWarnings("synthetic-access")
181 public void actionPerformed(ActionEvent actionEvent) {
185 cancelAction = new I18nAction("general.button.cancel") {
188 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
190 @SuppressWarnings("synthetic-access")
191 public void actionPerformed(ActionEvent actionEvent) {
195 antialiasAction = new I18nAction("configurationDialog.page.interface.item.beautify") {
198 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
200 public void actionPerformed(ActionEvent actionEvent) {
204 useCustomControlFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomControlFont") {
209 @SuppressWarnings("synthetic-access")
210 public void actionPerformed(ActionEvent e) {
211 controlFontList.setEnabled(useCustomControlFontCheckBox.isSelected());
214 useCustomUserFontAction = new I18nAction("configurationDialog.page.interface.item.useCustomUserFont") {
219 @SuppressWarnings("synthetic-access")
220 public void actionPerformed(ActionEvent e) {
221 userFontList.setEnabled(useCustomUserFontCheckBox.isSelected());
227 * Creates all internal components.
229 private void initComponents() {
230 JPanel contentPane = new JPanel(new BorderLayout(12, 12));
231 contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
233 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
234 contentPane.add(tabbedPane, BorderLayout.CENTER);
236 JComponent interfaceConfig = createInterfaceConfig();
237 tabbedPane.add(I18n.get("configurationDialog.page.interface.name"), interfaceConfig);
239 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
240 contentPane.add(buttonPanel, BorderLayout.PAGE_END);
241 buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
242 buttonPanel.add(new JButton(cancelAction));
243 JButton okayButton = new JButton(okayAction);
244 buttonPanel.add(okayButton);
245 getRootPane().setDefaultButton(okayButton);
247 getContentPane().add(contentPane, BorderLayout.CENTER);
251 * Creates the panel for the interface configuration.
253 * @return The interface configuration panel
255 private JComponent createInterfaceConfig() {
256 JPanel interfaceConfigPanel = new JPanel(new GridBagLayout());
257 interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
259 antialiasCheckBox = new JCheckBox(antialiasAction);
260 interfaceConfigPanel.add(antialiasCheckBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
262 useCustomControlFontCheckBox = new JCheckBox(useCustomControlFontAction);
263 interfaceConfigPanel.add(useCustomControlFontCheckBox, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
265 controlFontList = new FontComboBox();
266 interfaceConfigPanel.add(controlFontList, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
268 useCustomUserFontCheckBox = new JCheckBox(useCustomUserFontAction);
269 interfaceConfigPanel.add(useCustomUserFontCheckBox, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
271 userFontList = new FontComboBox();
272 interfaceConfigPanel.add(userFontList, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
274 interfaceConfigPanel.add(new JPanel(), new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
276 return interfaceConfigPanel;
284 * Called when the “okay” button is clicked.
286 private void actionOkay() {
292 * Called when the “cancel” button is clicked.
294 private void actionCancel() {
300 // INTERFACE I18nable
304 * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
306 public void updateI18n() {
307 okayAction.updateI18n();
308 cancelAction.updateI18n();
309 antialiasAction.updateI18n();
310 useCustomControlFontAction.updateI18n();
311 useCustomUserFontAction.updateI18n();
312 SwingUtils.repackCentered(this);