eca390e7413fab63853d60d91b7fb90d30a62daa
[jSite.git] / src / de / todesbaum / jsite / gui / PreferencesPage.java
1 /*
2  * jSite - PreferencesPage.java -
3  * Copyright © 2009 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.jsite.gui;
21
22 import java.awt.BorderLayout;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.event.ActionEvent;
27
28 import javax.swing.AbstractAction;
29 import javax.swing.Action;
30 import javax.swing.ButtonGroup;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.JRadioButton;
34
35 import de.todesbaum.jsite.i18n.I18n;
36 import de.todesbaum.jsite.i18n.I18nContainer;
37 import de.todesbaum.util.swing.TWizard;
38 import de.todesbaum.util.swing.TWizardPage;
39
40 /**
41  * Page that shows some preferences that are valid for the complete application.
42  *
43  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
44  */
45 public class PreferencesPage extends TWizardPage {
46
47         /** Action that chooses a new temp directory. */
48         private Action chooseTempDirectoryAction;
49
50         /** The temp directory. */
51         private String tempDirectory;
52
53         /**
54          * Creates a new “preferences” page.
55          *
56          * @param wizard
57          *            The wizard this page belongs to
58          */
59         public PreferencesPage(TWizard wizard) {
60                 super(wizard);
61                 pageInit();
62                 setHeading(I18n.getMessage("jsite.preferences.heading"));
63                 setDescription(I18n.getMessage("jsite.preferences.description"));
64                 I18nContainer.getInstance().registerRunnable(new Runnable() {
65
66                         /**
67                          * {@inheritDoc}
68                          */
69                         @Override
70                         public void run() {
71                                 setHeading(I18n.getMessage("jsite.preferences.heading"));
72                                 setDescription(I18n.getMessage("jsite.preferences.description"));
73                         }
74                 });
75         }
76
77         //
78         // ACCESSORS
79         //
80
81         /**
82          * Returns the temp directory.
83          *
84          * @return The temp directory, or {@code null} to use the default temp
85          *         directory
86          */
87         public String getTempDirectory() {
88                 return tempDirectory;
89         }
90
91         /**
92          * Sets the temp directory.
93          *
94          * @param tempDirectory
95          *            The temp directory, or {@code null} to use the default temp
96          *            directory
97          */
98         public void setTempDirectory(String tempDirectory) {
99                 this.tempDirectory = tempDirectory;
100         }
101
102         //
103         // PRIVATE METHODS
104         //
105
106         /**
107          * Initializes this page.
108          */
109         private void pageInit() {
110                 createActions();
111                 setLayout(new BorderLayout(12, 12));
112                 add(createPreferencesPanel(), BorderLayout.CENTER);
113         }
114
115         /**
116          * Creates all actions.
117          */
118         private void createActions() {
119                 chooseTempDirectoryAction = new AbstractAction(I18n.getMessage("jsite.preferences.choose-temp-directory")) {
120
121                         @Override
122                         @SuppressWarnings("synthetic-access")
123                         public void actionPerformed(ActionEvent e) {
124                                 chooseTempDirectory();
125                         }
126                 };
127
128                 I18nContainer.getInstance().registerRunnable(new Runnable() {
129
130                         @Override
131                         @SuppressWarnings("synthetic-access")
132                         public void run() {
133                                 chooseTempDirectoryAction.putValue(Action.NAME, I18n.getMessage("jsite.preferences.choose-temp-directory"));
134                         }
135                 });
136         }
137
138         /**
139          * Creates the panel containing all preferences.
140          *
141          * @return The preferences panel
142          */
143         private JPanel createPreferencesPanel() {
144                 JPanel preferencesPanel = new JPanel(new BorderLayout(12, 12));
145
146                 JPanel tempDirectoryPanel = new JPanel(new GridBagLayout());
147                 preferencesPanel.add(tempDirectoryPanel, BorderLayout.CENTER);
148
149                 final JLabel tempDirectoryLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.preferences.temp-directory") + "</b></html>");
150                 tempDirectoryPanel.add(tempDirectoryLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
151
152                 final JRadioButton defaultTempDirectory = new JRadioButton(I18n.getMessage("jsite.preferences.temp-directory.default"));
153                 tempDirectoryPanel.add(defaultTempDirectory, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 18, 0, 0), 0, 0));
154
155                 final JRadioButton customTempDirectory = new JRadioButton(I18n.getMessage("jsite.preferences.temp-directory.custom"));
156                 tempDirectoryPanel.add(customTempDirectory, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 18, 0, 0), 0, 0));
157
158                 ButtonGroup tempDirectoryButtonGroup = new ButtonGroup();
159                 defaultTempDirectory.getModel().setGroup(tempDirectoryButtonGroup);
160                 customTempDirectory.getModel().setGroup(tempDirectoryButtonGroup);
161
162                 I18nContainer.getInstance().registerRunnable(new Runnable() {
163
164                         /**
165                          * {@inheritDoc}
166                          */
167                         @Override
168                         public void run() {
169                                 tempDirectoryLabel.setText("<html><b>" + I18n.getMessage("jsite.preferences.temp-directory") + "</b></html>");
170                                 defaultTempDirectory.setText(I18n.getMessage("jsite.preferences.temp-directory.default"));
171                                 customTempDirectory.setText(I18n.getMessage("jsite.preferences.temp-directory.custom"));
172                         }
173                 });
174
175                 return preferencesPanel;
176         }
177
178         /**
179          * Lets the user choose a new temp directory.
180          */
181         private void chooseTempDirectory() {
182                 /* TODO */
183         }
184
185 }