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.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.Toolkit;
29 import java.awt.datatransfer.Clipboard;
30 import java.awt.datatransfer.ClipboardOwner;
31 import java.awt.datatransfer.StringSelection;
32 import java.awt.datatransfer.Transferable;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.KeyEvent;
35 import java.io.IOException;
36 import java.text.MessageFormat;
38 import javax.swing.AbstractAction;
39 import javax.swing.Action;
40 import javax.swing.JButton;
41 import javax.swing.JComponent;
42 import javax.swing.JFileChooser;
43 import javax.swing.JLabel;
44 import javax.swing.JList;
45 import javax.swing.JOptionPane;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JTextField;
49 import javax.swing.ListSelectionModel;
50 import javax.swing.border.EmptyBorder;
51 import javax.swing.event.DocumentEvent;
52 import javax.swing.event.DocumentListener;
53 import javax.swing.event.ListSelectionEvent;
54 import javax.swing.event.ListSelectionListener;
55 import javax.swing.text.AbstractDocument;
56 import javax.swing.text.AttributeSet;
57 import javax.swing.text.BadLocationException;
58 import javax.swing.text.Document;
59 import javax.swing.text.DocumentFilter;
61 import de.todesbaum.jsite.application.Freenet7Interface;
62 import de.todesbaum.jsite.application.Project;
63 import de.todesbaum.jsite.i18n.I18n;
64 import de.todesbaum.jsite.i18n.I18nContainer;
65 import de.todesbaum.util.swing.SortedListModel;
66 import de.todesbaum.util.swing.TLabel;
67 import de.todesbaum.util.swing.TWizard;
68 import de.todesbaum.util.swing.TWizardPage;
71 * Wizard page that lets the user manage his projects and start inserts.
73 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
75 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
77 /** The freenet interface. */
78 private Freenet7Interface freenetInterface;
80 /** The “browse” action. */
81 private Action projectLocalPathBrowseAction;
83 /** The “add project” action. */
84 private Action projectAddAction;
86 /** The “delete project” action. */
87 private Action projectDeleteAction;
89 /** The “clone project” action. */
90 private Action projectCloneAction;
92 /** The “copy URI” action. */
93 private Action projectCopyURIAction;
95 /** The “generate key” action. */
96 private Action projectGenerateKeyAction;
98 /** The “reset edition” action. */
99 private Action projectResetEditionAction;
101 /** The file chooser. */
102 private JFileChooser pathChooser;
104 /** The project list model. */
105 private SortedListModel projectListModel;
107 /** The project list scroll pane. */
108 private JScrollPane projectScrollPane;
110 /** The project list. */
111 private JList projectList;
113 /** The project name textfield. */
114 private JTextField projectNameTextField;
116 /** The project description textfield. */
117 private JTextField projectDescriptionTextField;
119 /** The local path textfield. */
120 private JTextField projectLocalPathTextField;
122 /** The textfield for the complete URI. */
123 private JTextField projectCompleteUriTextField;
125 /** The public key textfield. */
126 private JTextField projectPublicKeyTextField;
128 /** The private key textfield. */
129 private JTextField projectPrivateKeyTextField;
131 /** The project path textfield. */
132 private JTextField projectPathTextField;
135 * Creates a new project page.
138 * The wizard this page belongs to
140 public ProjectPage(final TWizard wizard) {
142 setLayout(new BorderLayout(12, 12));
144 setHeading(I18n.getMessage("jsite.project.heading"));
145 setDescription(I18n.getMessage("jsite.project.description"));
147 I18nContainer.getInstance().registerRunnable(new Runnable() {
150 setHeading(I18n.getMessage("jsite.project.heading"));
151 setDescription(I18n.getMessage("jsite.project.description"));
157 * Initializes the page.
159 private void dialogInit() {
162 pathChooser = new JFileChooser();
163 projectListModel = new SortedListModel();
164 projectList = new JList(projectListModel);
165 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
166 projectList.addListSelectionListener(this);
167 projectList.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
169 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
170 add(createInformationPanel(), BorderLayout.CENTER);
177 public void pageAdded(TWizard wizard) {
178 super.pageAdded(wizard);
179 projectList.clearSelection();
180 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
181 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
182 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
183 this.wizard.setNextEnabled(false);
187 * Adds the given listener to the list of listeners.
190 * The listener to add
192 public void addListSelectionListener(ListSelectionListener listener) {
193 projectList.addListSelectionListener(listener);
197 * Removes the given listener from the list of listeners.
200 * The listener to remove
202 public void removeListSelectionListener(ListSelectionListener listener) {
203 projectList.removeListSelectionListener(listener);
207 * Creates all actions.
209 private void createActions() {
210 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
212 @SuppressWarnings("synthetic-access")
213 public void actionPerformed(ActionEvent actionEvent) {
214 actionLocalPathBrowse();
217 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
218 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
219 projectLocalPathBrowseAction.setEnabled(false);
221 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
223 @SuppressWarnings("synthetic-access")
224 public void actionPerformed(ActionEvent actionEvent) {
228 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
229 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
231 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
233 @SuppressWarnings("synthetic-access")
234 public void actionPerformed(ActionEvent actionEvent) {
238 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
239 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
240 projectDeleteAction.setEnabled(false);
242 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
244 @SuppressWarnings("synthetic-access")
245 public void actionPerformed(ActionEvent actionEvent) {
249 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
250 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
251 projectCloneAction.setEnabled(false);
253 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
255 @SuppressWarnings("synthetic-access")
256 public void actionPerformed(ActionEvent actionEvent) {
260 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
261 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
262 projectCopyURIAction.setEnabled(false);
264 projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) {
266 @SuppressWarnings("synthetic-access")
267 public void actionPerformed(ActionEvent actionEvent) {
268 actionGenerateNewKey();
271 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
272 projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
273 projectGenerateKeyAction.setEnabled(false);
275 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
277 @SuppressWarnings("synthetic-access")
278 public void actionPerformed(ActionEvent actionEvent) {
279 actionResetEdition();
282 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
283 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
284 projectResetEditionAction.setEnabled(false);
286 I18nContainer.getInstance().registerRunnable(new Runnable() {
288 @SuppressWarnings("synthetic-access")
290 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
291 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
292 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
293 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
294 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
295 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
296 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
297 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
298 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
299 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
300 projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key"));
301 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
302 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
303 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
304 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
310 * Creates the information panel.
312 * @return The information panel
314 private JComponent createInformationPanel() {
315 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
317 JPanel informationTable = new JPanel(new GridBagLayout());
319 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
320 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
321 functionButtons.add(new JButton(projectAddAction));
322 functionButtons.add(new JButton(projectDeleteAction));
323 functionButtons.add(new JButton(projectCloneAction));
325 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
326 informationPanel.add(informationTable, BorderLayout.CENTER);
328 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
329 informationTable.add(projectInformationLabel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
331 projectNameTextField = new JTextField();
332 projectNameTextField.getDocument().putProperty("name", "project.name");
333 projectNameTextField.getDocument().addDocumentListener(this);
334 projectNameTextField.setEnabled(false);
336 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
337 informationTable.add(projectNameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
338 informationTable.add(projectNameTextField, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
340 projectDescriptionTextField = new JTextField();
341 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
342 projectDescriptionTextField.getDocument().addDocumentListener(this);
343 projectDescriptionTextField.setEnabled(false);
345 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
346 informationTable.add(projectDescriptionLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
347 informationTable.add(projectDescriptionTextField, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
349 projectLocalPathTextField = new JTextField();
350 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
351 projectLocalPathTextField.getDocument().addDocumentListener(this);
352 projectLocalPathTextField.setEnabled(false);
354 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
355 informationTable.add(projectLocalPathLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
356 informationTable.add(projectLocalPathTextField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
357 informationTable.add(new JButton(projectLocalPathBrowseAction), new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
359 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
360 informationTable.add(projectAddressLabel, new GridBagConstraints(0, 4, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
362 projectPublicKeyTextField = new JTextField(27);
363 projectPublicKeyTextField.getDocument().putProperty("name", "project.publickey");
364 projectPublicKeyTextField.getDocument().addDocumentListener(this);
365 projectPublicKeyTextField.setEnabled(false);
367 final TLabel projectPublicKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.public-key") + ":", KeyEvent.VK_U, projectPublicKeyTextField);
368 informationTable.add(projectPublicKeyLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
369 informationTable.add(projectPublicKeyTextField, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
370 informationTable.add(new JButton(projectGenerateKeyAction), new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
372 projectPrivateKeyTextField = new JTextField(27);
373 projectPrivateKeyTextField.getDocument().putProperty("name", "project.privatekey");
374 projectPrivateKeyTextField.getDocument().addDocumentListener(this);
375 projectPrivateKeyTextField.setEnabled(false);
377 final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField);
378 informationTable.add(projectPrivateKeyLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
379 informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
380 informationTable.add(new JButton(projectResetEditionAction), new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
382 projectPathTextField = new JTextField();
383 projectPathTextField.getDocument().putProperty("name", "project.path");
384 projectPathTextField.getDocument().addDocumentListener(this);
385 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
391 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
392 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
399 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
400 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
403 projectPathTextField.setEnabled(false);
405 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
406 informationTable.add(projectPathLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
407 informationTable.add(projectPathTextField, new GridBagConstraints(1, 7, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
409 projectCompleteUriTextField = new JTextField();
410 projectCompleteUriTextField.setEditable(false);
411 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
412 informationTable.add(projectUriLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
413 informationTable.add(projectCompleteUriTextField, new GridBagConstraints(1, 8, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
414 informationTable.add(new JButton(projectCopyURIAction), new GridBagConstraints(2, 8, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
416 I18nContainer.getInstance().registerRunnable(new Runnable() {
419 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
420 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
421 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
422 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
423 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
424 projectPublicKeyLabel.setText(I18n.getMessage("jsite.project.project.public-key") + ":");
425 projectPrivateKeyLabel.setText(I18n.getMessage("jsite.project.project.private-key") + ":");
426 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
427 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
431 return informationPanel;
435 * Sets the project list.
438 * The list of projects
440 public void setProjects(Project[] projects) {
441 projectListModel.clear();
442 for (Project project : projects) {
443 projectListModel.add(project);
448 * Returns the list of projects.
450 * @return The list of projects
452 public Project[] getProjects() {
453 return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]);
457 * Sets the freenet interface to use.
459 * @param freenetInterface
460 * The freenetInterface to use
462 public void setFreenetInterface(Freenet7Interface freenetInterface) {
463 this.freenetInterface = freenetInterface;
467 * Returns the currently selected project.
469 * @return The currently selected project
471 public Project getSelectedProject() {
472 return (Project) projectList.getSelectedValue();
476 * Updates the currently selected project with changed information from a
479 * @param documentEvent
480 * The document event to process
482 private void setTextField(DocumentEvent documentEvent) {
483 Document document = documentEvent.getDocument();
484 String propertyName = (String) document.getProperty("name");
485 Project project = (Project) projectList.getSelectedValue();
486 if (project == null) {
490 String text = document.getText(0, document.getLength()).trim();
491 if ("project.name".equals(propertyName)) {
492 project.setName(text);
493 projectList.repaint();
494 } else if ("project.description".equals(propertyName)) {
495 project.setDescription(text);
496 } else if ("project.localpath".equals(propertyName)) {
497 project.setLocalPath(text);
498 } else if ("project.privatekey".equals(propertyName)) {
499 project.setInsertURI(text);
500 } else if ("project.publickey".equals(propertyName)) {
501 project.setRequestURI(text);
502 } else if ("project.path".equals(propertyName)) {
503 project.setPath(text);
505 } catch (BadLocationException e) {
515 * Lets the user choose a local path for a project.
517 private void actionLocalPathBrowse() {
518 Project project = (Project) projectList.getSelectedValue();
519 if (project == null) {
522 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
523 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
524 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
529 * Adds a new project.
531 private void actionAdd() {
532 String[] keyPair = null;
533 if (!freenetInterface.hasNode()) {
534 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
538 keyPair = freenetInterface.generateKeyPair();
539 } catch (IOException ioe1) {
540 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
543 Project newProject = new Project();
544 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
545 newProject.setInsertURI(keyPair[0]);
546 newProject.setRequestURI(keyPair[1]);
547 newProject.setEdition(-1);
548 newProject.setPath("");
549 projectListModel.add(newProject);
550 projectScrollPane.revalidate();
551 projectScrollPane.repaint();
552 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
556 * Deletes the currently selected project.
558 private void actionDelete() {
559 int selectedIndex = projectList.getSelectedIndex();
560 if (selectedIndex > -1) {
561 if (JOptionPane.showConfirmDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.action.delete-project.confirm"), ((Project) projectList.getSelectedValue()).getName()), null, JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) {
562 projectListModel.remove(selectedIndex);
563 projectList.clearSelection();
564 if (projectListModel.getSize() != 0) {
565 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
572 * Clones the currently selected project.
574 private void actionClone() {
575 int selectedIndex = projectList.getSelectedIndex();
576 if (selectedIndex > -1) {
577 Project newProject = new Project((Project) projectList.getSelectedValue());
578 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
579 projectListModel.add(newProject);
580 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
585 * Copies the request URI of the currently selected project to the
588 private void actionCopyURI() {
589 int selectedIndex = projectList.getSelectedIndex();
590 if (selectedIndex > -1) {
591 Project selectedProject = (Project) projectList.getSelectedValue();
592 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
593 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
598 * Generates a new key for the currently selected project.
600 private void actionGenerateNewKey() {
601 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
604 int selectedIndex = projectList.getSelectedIndex();
605 if (selectedIndex > -1) {
606 Project selectedProject = (Project) projectList.getSelectedValue();
607 String[] keyPair = null;
609 keyPair = freenetInterface.generateKeyPair();
610 } catch (IOException ioe1) {
611 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
614 selectedProject.setInsertURI(keyPair[0]);
615 selectedProject.setRequestURI(keyPair[1]);
616 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
617 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
622 * Resets the edition of the currently selected project.
624 private void actionResetEdition() {
625 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
628 int selectedIndex = projectList.getSelectedIndex();
629 if (selectedIndex > -1) {
630 Project selectedProject = (Project) projectList.getSelectedValue();
631 selectedProject.setEdition(-1);
636 // INTERFACE ListSelectionListener
642 public void valueChanged(ListSelectionEvent listSelectionEvent) {
643 int selectedRow = projectList.getSelectedIndex();
644 Project selectedProject = (Project) projectList.getSelectedValue();
645 projectNameTextField.setEnabled(selectedRow > -1);
646 projectDescriptionTextField.setEnabled(selectedRow > -1);
647 projectLocalPathTextField.setEnabled(selectedRow > -1);
648 projectPublicKeyTextField.setEnabled(selectedRow > -1);
649 projectPrivateKeyTextField.setEnabled(selectedRow > -1);
650 projectPathTextField.setEnabled(selectedRow > -1);
651 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
652 projectDeleteAction.setEnabled(selectedRow > -1);
653 projectCloneAction.setEnabled(selectedRow > -1);
654 projectCopyURIAction.setEnabled(selectedRow > -1);
655 projectGenerateKeyAction.setEnabled(selectedRow > -1);
656 projectResetEditionAction.setEnabled(selectedRow > -1);
657 if (selectedRow > -1) {
658 projectNameTextField.setText(selectedProject.getName());
659 projectDescriptionTextField.setText(selectedProject.getDescription());
660 projectLocalPathTextField.setText(selectedProject.getLocalPath());
661 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
662 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
663 projectPathTextField.setText(selectedProject.getPath());
664 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
666 projectNameTextField.setText("");
667 projectDescriptionTextField.setText("");
668 projectLocalPathTextField.setText("");
669 projectPublicKeyTextField.setText("");
670 projectPrivateKeyTextField.setText("");
671 projectPathTextField.setText("");
672 projectCompleteUriTextField.setText("");
677 // INTERFACE ChangeListener
681 // INTERFACE DocumentListener
687 public void insertUpdate(DocumentEvent documentEvent) {
688 setTextField(documentEvent);
694 public void removeUpdate(DocumentEvent documentEvent) {
695 setTextField(documentEvent);
701 public void changedUpdate(DocumentEvent documentEvent) {
702 setTextField(documentEvent);
706 // INTERFACE ClipboardOwner
712 public void lostOwnership(Clipboard clipboard, Transferable contents) {