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.util.logging.Logger;
29 import javax.swing.BorderFactory;
30 import javax.swing.JButton;
31 import javax.swing.JPanel;
32 import javax.swing.JTextField;
33 import javax.swing.event.DocumentEvent;
34 import javax.swing.event.DocumentListener;
35 import javax.swing.text.Document;
37 import net.pterodactylus.jsite.i18n.I18nable;
38 import net.pterodactylus.jsite.i18n.gui.I18nLabel;
39 import net.pterodactylus.jsite.project.Project;
40 import net.pterodactylus.util.logging.Logging;
43 * A panel that contains all information about a project and lets the user edit
44 * the properties of the project.
46 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
49 public class ProjectPanel extends JPanel implements DocumentListener, I18nable {
52 @SuppressWarnings("unused")
53 private static final Logger logger = Logging.getLogger(ProjectPanel.class.getName());
55 /** The Swing interface. */
56 private final SwingInterface swingInterface;
58 /** The project to show. */
59 private final Project project;
61 /** The “name” label. */
62 private I18nLabel nameLabel;
64 /** The “name” textfield. */
65 private JTextField nameTextField;
67 /** The “description” label. */
68 private I18nLabel descriptionLabel;
70 /** The “description” textfield. */
71 private JTextField descriptionTextField;
74 * Creates a new project panel.
76 * @param swingInterface
79 * The project to display
81 public ProjectPanel(SwingInterface swingInterface, Project project) {
82 super(new BorderLayout(12, 12));
83 this.swingInterface = swingInterface;
84 this.project = project;
93 * Returns the project that is displayed in this panel.
95 * @return The project of this panel
97 public Project getProject() {
106 * Initializes all components of the panel.
108 private void initComponents() {
109 setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
111 JPanel propertiesPanel = createPropertiesPanel();
112 add(propertiesPanel, BorderLayout.CENTER);
114 JPanel buttonPanel = createButtonPanel();
115 add(buttonPanel, BorderLayout.PAGE_END);
119 * Creates the properties panel.
121 * @return The properties panel
123 private JPanel createPropertiesPanel() {
124 JPanel propertiesPanel = new JPanel(new GridBagLayout());
126 nameTextField = new JTextField(project.getName());
127 nameTextField.getDocument().addDocumentListener(this);
128 nameLabel = new I18nLabel("projectPanel.label.name", nameTextField);
129 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));
130 propertiesPanel.add(nameTextField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 6, 0, 0), 0, 0));
132 descriptionTextField = new JTextField(project.getDescription());
133 descriptionTextField.getDocument().addDocumentListener(this);
134 descriptionLabel = new I18nLabel("projectPanel.label.description", descriptionTextField);
135 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));
136 propertiesPanel.add(descriptionTextField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(6, 6, 0, 0), 0, 0));
138 return propertiesPanel;
142 * Creates the button panel.
144 * @return The button panel
146 private JPanel createButtonPanel() {
147 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12));
148 buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12));
150 buttonPanel.add(new JButton(swingInterface.getDeleteProjectAction()));
151 buttonPanel.add(new JButton(swingInterface.getCloneProjectAction()));
157 * Updates the project from changes in the text fields.
160 * The document that was changed
162 private void textFieldsUpdated(Document document) {
163 if (nameTextField.getDocument() == document) {
164 project.setName(nameTextField.getText());
165 } else if (descriptionTextField.getDocument() == document) {
166 project.setDescription(descriptionTextField.getText());
171 // INTERFACE I18nable
177 public void updateI18n() {
178 nameLabel.updateI18n();
179 descriptionLabel.updateI18n();
183 // INTERFACE DocumentListener
189 public void changedUpdate(DocumentEvent documentEvent) {
190 textFieldsUpdated(documentEvent.getDocument());
196 public void insertUpdate(DocumentEvent documentEvent) {
197 textFieldsUpdated(documentEvent.getDocument());
203 public void removeUpdate(DocumentEvent documentEvent) {
204 textFieldsUpdated(documentEvent.getDocument());