a7004aae1cc7d68bdbe2a28a6872541c29e71fae
[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.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JRadioButton;
33
34 import de.todesbaum.jsite.i18n.I18n;
35 import de.todesbaum.jsite.i18n.I18nContainer;
36 import de.todesbaum.util.swing.TWizard;
37 import de.todesbaum.util.swing.TWizardPage;
38
39 /**
40  * Page that shows some preferences that are valid for the complete application.
41  *
42  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
43  */
44 public class PreferencesPage extends TWizardPage {
45
46         /** Action that chooses a new temp directory. */
47         private Action chooseTempDirectoryAction;
48
49         /** The temp directory. */
50         private String tempDirectory;
51
52         /**
53          * Creates a new “preferences” page.
54          *
55          * @param wizard
56          *            The wizard this page belongs to
57          */
58         public PreferencesPage(TWizard wizard) {
59                 super(wizard);
60                 pageInit();
61                 setHeading(I18n.getMessage("jsite.preferences.heading"));
62                 setDescription(I18n.getMessage("jsite.preferences.description"));
63                 I18nContainer.getInstance().registerRunnable(new Runnable() {
64
65                         /**
66                          * {@inheritDoc}
67                          */
68                         @Override
69                         public void run() {
70                                 setHeading(I18n.getMessage("jsite.preferences.heading"));
71                                 setDescription(I18n.getMessage("jsite.preferences.description"));
72                         }
73                 });
74         }
75
76         //
77         // ACCESSORS
78         //
79
80         /**
81          * Returns the temp directory.
82          *
83          * @return The temp directory, or {@code null} to use the default temp
84          *         directory
85          */
86         public String getTempDirectory() {
87                 return tempDirectory;
88         }
89
90         /**
91          * Sets the temp directory.
92          *
93          * @param tempDirectory
94          *            The temp directory, or {@code null} to use the default temp
95          *            directory
96          */
97         public void setTempDirectory(String tempDirectory) {
98                 this.tempDirectory = tempDirectory;
99         }
100
101         //
102         // PRIVATE METHODS
103         //
104
105         /**
106          * Initializes this page.
107          */
108         private void pageInit() {
109                 createActions();
110                 setLayout(new BorderLayout(12, 12));
111                 add(createPreferencesPanel(), BorderLayout.CENTER);
112         }
113
114         /**
115          * Creates all actions.
116          */
117         private void createActions() {
118                 chooseTempDirectoryAction = new AbstractAction(I18n.getMessage("jsite.preferences.choose-temp-directory")) {
119
120                         @Override
121                         @SuppressWarnings("synthetic-access")
122                         public void actionPerformed(ActionEvent e) {
123                                 chooseTempDirectory();
124                         }
125                 };
126
127                 I18nContainer.getInstance().registerRunnable(new Runnable() {
128
129                         @Override
130                         @SuppressWarnings("synthetic-access")
131                         public void run() {
132                                 chooseTempDirectoryAction.putValue(Action.NAME, I18n.getMessage("jsite.preferences.choose-temp-directory"));
133                         }
134                 });
135         }
136
137         /**
138          * Creates the panel containing all preferences.
139          *
140          * @return The preferences panel
141          */
142         private JPanel createPreferencesPanel() {
143                 JPanel preferencesPanel = new JPanel(new BorderLayout(12, 12));
144
145                 JPanel tempDirectoryPanel = new JPanel(new GridBagLayout());
146                 preferencesPanel.add(tempDirectoryPanel, BorderLayout.CENTER);
147
148                 final JLabel tempDirectoryLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.preferences.temp-directory") + "</b></html>");
149                 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));
150
151                 final JRadioButton defaultTempDirectory = new JRadioButton(I18n.getMessage("jsite.preferences.temp-directory.default"));
152                 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));
153
154                 I18nContainer.getInstance().registerRunnable(new Runnable() {
155
156                         /**
157                          * {@inheritDoc}
158                          */
159                         @Override
160                         public void run() {
161                                 tempDirectoryLabel.setText("<html><b>" + I18n.getMessage("jsite.preferences.temp-directory") + "</b></html>");
162                                 defaultTempDirectory.setText(I18n.getMessage("jsite.preferences.temp-directory.default"));
163                         }
164                 });
165
166                 return preferencesPanel;
167         }
168
169         /**
170          * Lets the user choose a new temp directory.
171          */
172         private void chooseTempDirectory() {
173                 /* TODO */
174         }
175
176 }