2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 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 de.todesbaum.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.text.DateFormat;
27 import java.text.MessageFormat;
28 import java.util.Date;
30 import javax.swing.JComponent;
31 import javax.swing.JLabel;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.JProgressBar;
35 import javax.swing.JTextField;
36 import javax.swing.SwingUtilities;
38 import de.todesbaum.jsite.application.EditionProject;
39 import de.todesbaum.jsite.application.Freenet7Interface;
40 import de.todesbaum.jsite.application.InsertListener;
41 import de.todesbaum.jsite.application.Project;
42 import de.todesbaum.jsite.application.ProjectInserter;
43 import de.todesbaum.jsite.i18n.I18n;
44 import de.todesbaum.util.swing.TWizard;
45 import de.todesbaum.util.swing.TWizardPage;
48 * @author David Roden <droden@gmail.com>
49 * @version $Id: ProjectInsertPage.java 408 2006-03-29 09:31:10Z bombe $
51 public class ProjectInsertPage extends TWizardPage implements InsertListener {
53 protected TWizard wizard;
54 protected ProjectInserter projectInserter;
56 protected JTextField requestURITextField;
57 protected JLabel startTimeLabel;
58 protected JProgressBar progressBar;
59 protected long startTime;
61 public ProjectInsertPage() {
64 setHeading(I18n.getMessage("jsite.insert.heading"));
65 setDescription(I18n.getMessage("jsite.insert.description"));
66 projectInserter = new ProjectInserter();
67 projectInserter.addInsertListener(this);
70 private void pageInit() {
71 setLayout(new BorderLayout(12, 12));
72 add(createProjectInsertPanel(), BorderLayout.CENTER);
75 private JComponent createProjectInsertPanel() {
76 JComponent projectInsertPanel = new JPanel(new GridBagLayout());
78 requestURITextField = new JTextField();
79 requestURITextField.setEditable(false);
80 requestURITextField.setBackground(getBackground());
81 requestURITextField.setBorder(null);
83 startTimeLabel = new JLabel();
85 progressBar = new JProgressBar(0, 1);
86 progressBar.setStringPainted(true);
87 progressBar.setValue(0);
89 projectInsertPanel.add(new JLabel("<html><b>" + I18n.getMessage("jsite.insert.project-information") + "</b></html>"), new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
90 projectInsertPanel.add(new JLabel(I18n.getMessage("jsite.insert.request-uri") + ":"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
91 projectInsertPanel.add(requestURITextField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
92 projectInsertPanel.add(new JLabel(I18n.getMessage("jsite.insert.start-time") + ":"), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
93 projectInsertPanel.add(startTimeLabel, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
94 projectInsertPanel.add(new JLabel(I18n.getMessage("jsite.insert.progress") + ":"), new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 18, 0, 0), 0, 0));
95 projectInsertPanel.add(progressBar, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
97 return projectInsertPanel;
104 public void pageAdded(TWizard wizard) {
105 this.wizard = wizard;
106 wizard.setPreviousEnabled(false);
107 wizard.setNextEnabled(false);
108 wizard.setQuitEnabled(false);
109 progressBar.setValue(0);
110 projectInserter.start();
117 public void setDebug(boolean debug) {
118 projectInserter.setDebug(debug);
123 * The project to set.
125 public void setProject(final Project project) {
126 projectInserter.setProject(project);
127 SwingUtilities.invokeLater(new Runnable() {
130 StringBuffer uriBuffer = new StringBuffer();
131 uriBuffer.append(project.getRequestURI());
132 uriBuffer.append(project.getPath());
133 if (project instanceof EditionProject) {
134 uriBuffer.append('-').append(((EditionProject) project).getEdition());
136 uriBuffer.append('/');
137 requestURITextField.setText(uriBuffer.toString());
142 public void setFreenetInterface(Freenet7Interface freenetInterface) {
143 projectInserter.setFreenetInterface(freenetInterface);
147 // INTERFACE InsertListener
153 public void projectInsertStarted(final Project project) {
154 startTime = System.currentTimeMillis();
155 SwingUtilities.invokeLater(new Runnable() {
158 startTimeLabel.setText(DateFormat.getDateTimeInstance().format(new Date(startTime)));
166 public void projectInsertProgress(Project project, final int succeeded, final int failed, final int fatal, final int total, final boolean finalized) {
167 SwingUtilities.invokeLater(new Runnable() {
170 progressBar.setMaximum(total);
171 progressBar.setValue(succeeded + failed + fatal);
179 public void projectInsertFinished(Project project, boolean success, Throwable cause) {
181 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.insert.inserted"), null, JOptionPane.INFORMATION_MESSAGE);
184 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.insert.insert-failed"), null, JOptionPane.ERROR_MESSAGE);
186 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.insert.insert-failed-with-cause"), cause.getMessage()), null, JOptionPane.ERROR_MESSAGE);
189 SwingUtilities.invokeLater(new Runnable() {
192 wizard.setNextEnabled(true);
193 wizard.setQuitEnabled(true);