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.Freenet7Interface;
39 import de.todesbaum.jsite.application.InsertListener;
40 import de.todesbaum.jsite.application.Project;
41 import de.todesbaum.jsite.application.ProjectInserter;
42 import de.todesbaum.jsite.i18n.I18n;
43 import de.todesbaum.util.swing.TWizard;
44 import de.todesbaum.util.swing.TWizardPage;
47 * @author David Roden <droden@gmail.com>
50 public class ProjectInsertPage extends TWizardPage implements InsertListener {
52 protected TWizard wizard;
53 protected ProjectInserter projectInserter;
55 protected JTextField requestURITextField;
56 protected JLabel startTimeLabel;
57 protected JProgressBar progressBar;
58 protected long startTime;
60 public ProjectInsertPage() {
63 setHeading(I18n.getMessage("jsite.insert.heading"));
64 setDescription(I18n.getMessage("jsite.insert.description"));
65 projectInserter = new ProjectInserter();
66 projectInserter.addInsertListener(this);
69 private void pageInit() {
70 setLayout(new BorderLayout(12, 12));
71 add(createProjectInsertPanel(), BorderLayout.CENTER);
74 private JComponent createProjectInsertPanel() {
75 JComponent projectInsertPanel = new JPanel(new GridBagLayout());
77 requestURITextField = new JTextField();
78 requestURITextField.setEditable(false);
80 startTimeLabel = new JLabel();
82 progressBar = new JProgressBar(0, 1);
83 progressBar.setStringPainted(true);
84 progressBar.setValue(0);
86 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));
87 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));
88 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));
89 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));
90 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));
91 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));
92 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));
94 return projectInsertPanel;
101 public void pageAdded(TWizard wizard) {
102 this.wizard = wizard;
103 wizard.setPreviousEnabled(false);
104 wizard.setNextEnabled(false);
105 wizard.setQuitEnabled(false);
106 progressBar.setValue(0);
107 projectInserter.start();
114 public void setDebug(boolean debug) {
115 projectInserter.setDebug(debug);
120 * The project to set.
122 public void setProject(final Project project) {
123 projectInserter.setProject(project);
124 SwingUtilities.invokeLater(new Runnable() {
127 requestURITextField.setText(project.getFinalRequestURI(0));
132 public void setFreenetInterface(Freenet7Interface freenetInterface) {
133 projectInserter.setFreenetInterface(freenetInterface);
137 // INTERFACE InsertListener
143 public void projectInsertStarted(final Project project) {
144 startTime = System.currentTimeMillis();
145 SwingUtilities.invokeLater(new Runnable() {
148 startTimeLabel.setText(DateFormat.getDateTimeInstance().format(new Date(startTime)));
156 public void projectURIGenerated(Project project, final String uri) {
157 SwingUtilities.invokeLater(new Runnable() {
159 requestURITextField.setText(uri);
167 public void projectInsertProgress(Project project, final int succeeded, final int failed, final int fatal, final int total, final boolean finalized) {
168 SwingUtilities.invokeLater(new Runnable() {
171 progressBar.setMaximum(total);
172 progressBar.setValue(succeeded + failed + fatal);
180 public void projectInsertFinished(Project project, boolean success, Throwable cause) {
182 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.insert.inserted"), null, JOptionPane.INFORMATION_MESSAGE);
185 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.insert.insert-failed"), null, JOptionPane.ERROR_MESSAGE);
187 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.insert.insert-failed-with-cause"), cause.getMessage()), null, JOptionPane.ERROR_MESSAGE);
190 SwingUtilities.invokeLater(new Runnable() {
193 wizard.setNextEnabled(true);
194 wizard.setQuitEnabled(true);