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