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