2 * jSite2 - ProjectPanel.java -
3 * Copyright © 2008 David Roden
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.
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.
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.
20 package net.pterodactylus.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.FlowLayout;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.event.ActionEvent;
28 import java.util.logging.Logger;
30 import javax.swing.BorderFactory;
31 import javax.swing.JButton;
32 import javax.swing.JPanel;
33 import javax.swing.JTextField;
34 import javax.swing.event.DocumentEvent;
35 import javax.swing.event.DocumentListener;
36 import javax.swing.text.Document;
38 import net.pterodactylus.jsite.i18n.I18nable;
39 import net.pterodactylus.jsite.i18n.gui.I18nAction;
40 import net.pterodactylus.jsite.i18n.gui.I18nLabel;
41 import net.pterodactylus.jsite.project.Project;
42 import net.pterodactylus.util.logging.Logging;
45 * A panel that contains all information about a project and lets the user edit
46 * the properties of the project.
48 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
51 public class ProjectPanel extends JPanel implements DocumentListener, I18nable {
54 @SuppressWarnings("unused")
55 private static final Logger logger = Logging.getLogger(ProjectPanel.class.getName());
57 /** The Swing interface. */
58 private final SwingInterface swingInterface;
60 /** The project to show. */
61 private final Project project;
63 /** The “change base path” action. */
64 private I18nAction changeBasePathAction;
66 /** The “name” label. */
67 private I18nLabel nameLabel;
69 /** The “name” textfield. */
70 private JTextField nameTextField;
72 /** The “description” label. */
73 private I18nLabel descriptionLabel;
75 /** The “description” textfield. */
76 private JTextField descriptionTextField;
78 /** The “base path” label. */
79 private I18nLabel basePathLabel;
81 /** The “base path” textfield. */
82 private JTextField basePathTextField;
85 * Creates a new project panel.
87 * @param swingInterface
90 * The project to display
92 public ProjectPanel(SwingInterface swingInterface, Project project) {
93 super(new BorderLayout(12, 12));
94 this.swingInterface = swingInterface;
95 this.project = project;
105 * Returns the project that is displayed in this panel.
107 * @return The project of this panel
109 public Project getProject() {
118 * Initializes all actions.
120 private void initActions() {
121 changeBasePathAction = new I18nAction("projectPanel.button.changeBasePath") {
126 @SuppressWarnings("synthetic-access")
127 public void actionPerformed(ActionEvent actionEvent) {
134 * Initializes all components of the panel.
136 private void initComponents() {
137 setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
139 JPanel propertiesPanel = createPropertiesPanel();
140 add(propertiesPanel, BorderLayout.CENTER);
142 JPanel buttonPanel = createButtonPanel();
143 add(buttonPanel, BorderLayout.PAGE_END);
147 * Creates the properties panel.
149 * @return The properties panel
151 private JPanel createPropertiesPanel() {
152 JPanel propertiesPanel = new JPanel(new GridBagLayout());
154 nameTextField = new JTextField(project.getName());
155 nameTextField.getDocument().addDocumentListener(this);
156 nameLabel = new I18nLabel("projectPanel.label.name", nameTextField);
157 propertiesPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
158 propertiesPanel.add(nameTextField, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 6, 0, 0), 0, 0));
160 descriptionTextField = new JTextField(project.getDescription());
161 descriptionTextField.getDocument().addDocumentListener(this);
162 descriptionLabel = new I18nLabel("projectPanel.label.description", descriptionTextField);
163 propertiesPanel.add(descriptionLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
164 propertiesPanel.add(descriptionTextField, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
166 basePathTextField = new JTextField(project.getBasePath());
167 basePathTextField.setEditable(false);
168 basePathLabel = new I18nLabel("projectPanel.label.basePath");
169 JButton changeBasePathButton = new JButton(changeBasePathAction);
170 propertiesPanel.add(basePathLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0));
171 propertiesPanel.add(basePathTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
172 propertiesPanel.add(changeBasePathButton, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
174 propertiesPanel.add(new JPanel(), new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
176 return propertiesPanel;
180 * Creates the button panel.
182 * @return The button panel
184 private JPanel createButtonPanel() {
185 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
186 buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
188 buttonPanel.add(new JButton(swingInterface.getDeleteProjectAction()));
189 buttonPanel.add(new JButton(swingInterface.getCloneProjectAction()));
195 * Updates the project from changes in the text fields.
198 * The document that was changed
200 private void textFieldsUpdated(Document document) {
201 if (nameTextField.getDocument() == document) {
202 project.setName(nameTextField.getText());
203 } else if (descriptionTextField.getDocument() == document) {
204 project.setDescription(descriptionTextField.getText());
213 * Lets the user select a new base path and repopulates the file list.
215 private void changeBasePath() {
216 /* TODO - edit base path */
220 // INTERFACE I18nable
226 public void updateI18n() {
227 nameLabel.updateI18n();
228 descriptionLabel.updateI18n();
232 // INTERFACE DocumentListener
238 public void changedUpdate(DocumentEvent documentEvent) {
239 textFieldsUpdated(documentEvent.getDocument());
245 public void insertUpdate(DocumentEvent documentEvent) {
246 textFieldsUpdated(documentEvent.getDocument());
252 public void removeUpdate(DocumentEvent documentEvent) {
253 textFieldsUpdated(documentEvent.getDocument());