2 * © 2008 INA Service GmbH
4 package net.pterodactylus.jsite.gui;
6 import java.awt.BorderLayout;
7 import java.awt.FlowLayout;
8 import java.awt.event.ActionEvent;
10 import javax.swing.BorderFactory;
11 import javax.swing.JButton;
12 import javax.swing.JCheckBox;
13 import javax.swing.JComponent;
14 import javax.swing.JDialog;
15 import javax.swing.JPanel;
16 import javax.swing.JTabbedPane;
17 import javax.swing.SwingConstants;
19 import net.pterodactylus.jsite.i18n.I18n;
20 import net.pterodactylus.jsite.i18n.I18nable;
21 import net.pterodactylus.jsite.i18n.gui.I18nAction;
22 import net.pterodactylus.util.swing.SwingUtils;
25 * The configuration dialog.
27 * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
30 public class ConfigurationDialog extends JDialog implements I18nable {
32 /** The “okay” action. */
33 private I18nAction okayAction;
35 /** The “cancel” action. */
36 private I18nAction cancelAction;
38 /** The “beautify GUI” action. */
39 private I18nAction beautifyAction;
41 /** The “beautify” checkbox. */
42 private JCheckBox beautifyCheckBox;
44 /** Whether the dialog was cancelled. */
45 private boolean cancelled;
48 * Creates a new configuration dialog.
50 * @param swingInterface
53 public ConfigurationDialog(SwingInterface swingInterface) {
54 super(swingInterface.getMainWindow(), I18n.get("configurationDialog.title"), true);
58 SwingUtils.center(this);
59 I18n.registerI18nable(this);
67 * Returns whether the dialog was cancelled or confirmed. If the dialog was
68 * cancelled, no further processing should be done.
70 * @return <code>true</code> if the dialog was cancelled,
71 * <code>false</code> otherwise
73 public boolean wasCancelled() {
78 * Returns whether the “beautify” checkbox has been selected. The result of
79 * this method should not be used if {@link #wasCancelled()} returned
82 * @return <code>true</code> if the checkbox was selected,
83 * <code>false</code> otherwise
85 public boolean getBeautify() {
86 return beautifyCheckBox.isSelected();
90 * Sets the state of the “beautify” checkbox.
93 * The state of the checkbox
95 public void setBeautify(boolean beautify) {
96 beautifyCheckBox.setSelected(beautify);
104 * Creates all actions.
106 private void initActions() {
107 okayAction = new I18nAction("general.button.okay") {
109 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
111 @SuppressWarnings("synthetic-access")
112 public void actionPerformed(ActionEvent actionEvent) {
116 cancelAction = new I18nAction("general.button.cancel") {
118 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
120 @SuppressWarnings("synthetic-access")
121 public void actionPerformed(ActionEvent actionEvent) {
125 beautifyAction = new I18nAction("configurationDialog.page.interface.item.beautify") {
127 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
129 public void actionPerformed(ActionEvent actionEvent) {
130 /* don't do anything. */
136 * Creates all internal components.
138 private void initComponents() {
139 JPanel contentPane = new JPanel(new BorderLayout(12, 12));
140 contentPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
142 JTabbedPane tabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
143 contentPane.add(tabbedPane, BorderLayout.CENTER);
145 JComponent interfaceConfig = createInterfaceConfig();
146 tabbedPane.add("Swing Interface", interfaceConfig);
148 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
149 contentPane.add(buttonPanel, BorderLayout.PAGE_END);
150 buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
151 buttonPanel.add(new JButton(cancelAction));
152 JButton okayButton = new JButton(okayAction);
153 buttonPanel.add(okayButton);
154 getRootPane().setDefaultButton(okayButton);
156 getContentPane().add(contentPane, BorderLayout.CENTER);
160 * Creates the panel for the interface configuration.
162 * @return The interface configuration panel
164 private JComponent createInterfaceConfig() {
165 JPanel interfaceConfigPanel = new JPanel(new BorderLayout(12, 12));
166 interfaceConfigPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
168 beautifyCheckBox = new JCheckBox(beautifyAction);
169 interfaceConfigPanel.add(beautifyCheckBox, BorderLayout.PAGE_START);
171 return interfaceConfigPanel;
179 * Called when the “okay” button is clicked.
181 private void actionOkay() {
187 * Called when the “cancel” button is clicked.
189 private void actionCancel() {
195 // INTERFACE I18nable
199 * @see net.pterodactylus.jsite.i18n.I18nable#updateI18n()
201 public void updateI18n() {
202 okayAction.updateI18n();
203 cancelAction.updateI18n();
204 beautifyAction.updateI18n();
205 SwingUtils.repackCentered(this);