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;
134 /** Whether the “copy URI to clipboard” action was used. */
135 private boolean uriCopied;
138 * Creates a new project page.
141 * The wizard this page belongs to
143 public ProjectPage(final TWizard wizard) {
145 setLayout(new BorderLayout(12, 12));
147 setHeading(I18n.getMessage("jsite.project.heading"));
148 setDescription(I18n.getMessage("jsite.project.description"));
150 I18nContainer.getInstance().registerRunnable(new Runnable() {
153 setHeading(I18n.getMessage("jsite.project.heading"));
154 setDescription(I18n.getMessage("jsite.project.description"));
160 * Initializes the page.
162 private void dialogInit() {
165 pathChooser = new JFileChooser();
166 projectListModel = new SortedListModel();
167 projectList = new JList(projectListModel);
168 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
169 projectList.addListSelectionListener(this);
170 projectList.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
172 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
173 add(createInformationPanel(), BorderLayout.CENTER);
180 public void pageAdded(TWizard wizard) {
181 super.pageAdded(wizard);
182 projectList.clearSelection();
183 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
184 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
185 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
186 this.wizard.setNextEnabled(false);
190 * Adds the given listener to the list of listeners.
193 * The listener to add
195 public void addListSelectionListener(ListSelectionListener listener) {
196 projectList.addListSelectionListener(listener);
200 * Removes the given listener from the list of listeners.
203 * The listener to remove
205 public void removeListSelectionListener(ListSelectionListener listener) {
206 projectList.removeListSelectionListener(listener);
210 * Creates all actions.
212 private void createActions() {
213 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
215 @SuppressWarnings("synthetic-access")
216 public void actionPerformed(ActionEvent actionEvent) {
217 actionLocalPathBrowse();
220 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
221 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
222 projectLocalPathBrowseAction.setEnabled(false);
224 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
226 @SuppressWarnings("synthetic-access")
227 public void actionPerformed(ActionEvent actionEvent) {
231 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
232 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
234 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
236 @SuppressWarnings("synthetic-access")
237 public void actionPerformed(ActionEvent actionEvent) {
241 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
242 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
243 projectDeleteAction.setEnabled(false);
245 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
247 @SuppressWarnings("synthetic-access")
248 public void actionPerformed(ActionEvent actionEvent) {
252 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
253 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
254 projectCloneAction.setEnabled(false);
256 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
258 @SuppressWarnings("synthetic-access")
259 public void actionPerformed(ActionEvent actionEvent) {
263 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
264 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
265 projectCopyURIAction.setEnabled(false);
267 projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) {
269 @SuppressWarnings("synthetic-access")
270 public void actionPerformed(ActionEvent actionEvent) {
271 actionGenerateNewKey();
274 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
275 projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
276 projectGenerateKeyAction.setEnabled(false);
278 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
280 @SuppressWarnings("synthetic-access")
281 public void actionPerformed(ActionEvent actionEvent) {
282 actionResetEdition();
285 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
286 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
287 projectResetEditionAction.setEnabled(false);
289 I18nContainer.getInstance().registerRunnable(new Runnable() {
291 @SuppressWarnings("synthetic-access")
293 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
294 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
295 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
296 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
297 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
298 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
299 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
300 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
301 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
302 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
303 projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key"));
304 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
305 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
306 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
307 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
313 * Creates the information panel.
315 * @return The information panel
317 private JComponent createInformationPanel() {
318 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
320 JPanel informationTable = new JPanel(new GridBagLayout());
322 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
323 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
324 functionButtons.add(new JButton(projectAddAction));
325 functionButtons.add(new JButton(projectDeleteAction));
326 functionButtons.add(new JButton(projectCloneAction));
328 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
329 informationPanel.add(informationTable, BorderLayout.CENTER);
331 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
332 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));
334 projectNameTextField = new JTextField();
335 projectNameTextField.getDocument().putProperty("name", "project.name");
336 projectNameTextField.getDocument().addDocumentListener(this);
337 projectNameTextField.setEnabled(false);
339 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
340 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));
341 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));
343 projectDescriptionTextField = new JTextField();
344 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
345 projectDescriptionTextField.getDocument().addDocumentListener(this);
346 projectDescriptionTextField.setEnabled(false);
348 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
349 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));
350 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));
352 projectLocalPathTextField = new JTextField();
353 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
354 projectLocalPathTextField.getDocument().addDocumentListener(this);
355 projectLocalPathTextField.setEnabled(false);
357 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
358 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));
359 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));
360 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));
362 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
363 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));
365 projectPublicKeyTextField = new JTextField(27);
366 projectPublicKeyTextField.getDocument().putProperty("name", "project.publickey");
367 projectPublicKeyTextField.getDocument().addDocumentListener(this);
368 projectPublicKeyTextField.setEnabled(false);
370 final TLabel projectPublicKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.public-key") + ":", KeyEvent.VK_U, projectPublicKeyTextField);
371 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));
372 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));
373 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));
375 projectPrivateKeyTextField = new JTextField(27);
376 projectPrivateKeyTextField.getDocument().putProperty("name", "project.privatekey");
377 projectPrivateKeyTextField.getDocument().addDocumentListener(this);
378 projectPrivateKeyTextField.setEnabled(false);
380 final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField);
381 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));
382 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));
383 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));
385 projectPathTextField = new JTextField();
386 projectPathTextField.getDocument().putProperty("name", "project.path");
387 projectPathTextField.getDocument().addDocumentListener(this);
388 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
394 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
395 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
402 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
403 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
406 projectPathTextField.setEnabled(false);
408 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
409 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));
410 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));
412 projectCompleteUriTextField = new JTextField();
413 projectCompleteUriTextField.setEditable(false);
414 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
415 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));
416 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));
417 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));
419 I18nContainer.getInstance().registerRunnable(new Runnable() {
422 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
423 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
424 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
425 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
426 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
427 projectPublicKeyLabel.setText(I18n.getMessage("jsite.project.project.public-key") + ":");
428 projectPrivateKeyLabel.setText(I18n.getMessage("jsite.project.project.private-key") + ":");
429 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
430 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
434 return informationPanel;
438 * Sets the project list.
441 * The list of projects
443 public void setProjects(Project[] projects) {
444 projectListModel.clear();
445 for (Project project : projects) {
446 projectListModel.add(project);
451 * Returns the list of projects.
453 * @return The list of projects
455 public Project[] getProjects() {
456 return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]);
460 * Sets the freenet interface to use.
462 * @param freenetInterface
463 * The freenetInterface to use
465 public void setFreenetInterface(Freenet7Interface freenetInterface) {
466 this.freenetInterface = freenetInterface;
470 * Returns the currently selected project.
472 * @return The currently selected project
474 public Project getSelectedProject() {
475 return (Project) projectList.getSelectedValue();
479 * Returns whether the “copy URI to clipboard” button was used.
481 * @return {@code true} if the “copy URI to clipboard” button was used,
482 * {@code false} otherwise
484 public boolean wasUriCopied() {
489 * Updates the currently selected project with changed information from a
492 * @param documentEvent
493 * The document event to process
495 private void setTextField(DocumentEvent documentEvent) {
496 Document document = documentEvent.getDocument();
497 String propertyName = (String) document.getProperty("name");
498 Project project = (Project) projectList.getSelectedValue();
499 if (project == null) {
503 String text = document.getText(0, document.getLength()).trim();
504 if ("project.name".equals(propertyName)) {
505 project.setName(text);
506 projectList.repaint();
507 } else if ("project.description".equals(propertyName)) {
508 project.setDescription(text);
509 } else if ("project.localpath".equals(propertyName)) {
510 project.setLocalPath(text);
511 } else if ("project.privatekey".equals(propertyName)) {
512 project.setInsertURI(text);
513 } else if ("project.publickey".equals(propertyName)) {
514 project.setRequestURI(text);
515 } else if ("project.path".equals(propertyName)) {
516 project.setPath(text);
518 } catch (BadLocationException e) {
528 * Lets the user choose a local path for a project.
530 private void actionLocalPathBrowse() {
531 Project project = (Project) projectList.getSelectedValue();
532 if (project == null) {
535 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
536 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
537 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
542 * Adds a new project.
544 private void actionAdd() {
545 String[] keyPair = null;
546 if (!freenetInterface.hasNode()) {
547 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
551 keyPair = freenetInterface.generateKeyPair();
552 } catch (IOException ioe1) {
553 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
556 Project newProject = new Project();
557 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
558 newProject.setInsertURI(keyPair[0]);
559 newProject.setRequestURI(keyPair[1]);
560 newProject.setEdition(-1);
561 newProject.setPath("");
562 projectListModel.add(newProject);
563 projectScrollPane.revalidate();
564 projectScrollPane.repaint();
565 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
569 * Deletes the currently selected project.
571 private void actionDelete() {
572 int selectedIndex = projectList.getSelectedIndex();
573 if (selectedIndex > -1) {
574 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) {
575 projectListModel.remove(selectedIndex);
576 projectList.clearSelection();
577 if (projectListModel.getSize() != 0) {
578 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
585 * Clones the currently selected project.
587 private void actionClone() {
588 int selectedIndex = projectList.getSelectedIndex();
589 if (selectedIndex > -1) {
590 Project newProject = new Project((Project) projectList.getSelectedValue());
591 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
592 projectListModel.add(newProject);
593 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
598 * Copies the request URI of the currently selected project to the
601 private void actionCopyURI() {
602 int selectedIndex = projectList.getSelectedIndex();
603 if (selectedIndex > -1) {
604 Project selectedProject = (Project) projectList.getSelectedValue();
605 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
606 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
612 * Generates a new key for the currently selected project.
614 private void actionGenerateNewKey() {
615 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
618 int selectedIndex = projectList.getSelectedIndex();
619 if (selectedIndex > -1) {
620 Project selectedProject = (Project) projectList.getSelectedValue();
621 String[] keyPair = null;
623 keyPair = freenetInterface.generateKeyPair();
624 } catch (IOException ioe1) {
625 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
628 selectedProject.setInsertURI(keyPair[0]);
629 selectedProject.setRequestURI(keyPair[1]);
630 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
631 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
636 * Resets the edition of the currently selected project.
638 private void actionResetEdition() {
639 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
642 int selectedIndex = projectList.getSelectedIndex();
643 if (selectedIndex > -1) {
644 Project selectedProject = (Project) projectList.getSelectedValue();
645 selectedProject.setEdition(-1);
650 // INTERFACE ListSelectionListener
656 public void valueChanged(ListSelectionEvent listSelectionEvent) {
657 int selectedRow = projectList.getSelectedIndex();
658 Project selectedProject = (Project) projectList.getSelectedValue();
659 projectNameTextField.setEnabled(selectedRow > -1);
660 projectDescriptionTextField.setEnabled(selectedRow > -1);
661 projectLocalPathTextField.setEnabled(selectedRow > -1);
662 projectPublicKeyTextField.setEnabled(selectedRow > -1);
663 projectPrivateKeyTextField.setEnabled(selectedRow > -1);
664 projectPathTextField.setEnabled(selectedRow > -1);
665 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
666 projectDeleteAction.setEnabled(selectedRow > -1);
667 projectCloneAction.setEnabled(selectedRow > -1);
668 projectCopyURIAction.setEnabled(selectedRow > -1);
669 projectGenerateKeyAction.setEnabled(selectedRow > -1);
670 projectResetEditionAction.setEnabled(selectedRow > -1);
671 if (selectedRow > -1) {
672 projectNameTextField.setText(selectedProject.getName());
673 projectDescriptionTextField.setText(selectedProject.getDescription());
674 projectLocalPathTextField.setText(selectedProject.getLocalPath());
675 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
676 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
677 projectPathTextField.setText(selectedProject.getPath());
678 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
680 projectNameTextField.setText("");
681 projectDescriptionTextField.setText("");
682 projectLocalPathTextField.setText("");
683 projectPublicKeyTextField.setText("");
684 projectPrivateKeyTextField.setText("");
685 projectPathTextField.setText("");
686 projectCompleteUriTextField.setText("");
691 // INTERFACE ChangeListener
695 // INTERFACE DocumentListener
701 public void insertUpdate(DocumentEvent documentEvent) {
702 setTextField(documentEvent);
708 public void removeUpdate(DocumentEvent documentEvent) {
709 setTextField(documentEvent);
715 public void changedUpdate(DocumentEvent documentEvent) {
716 setTextField(documentEvent);
720 // INTERFACE ClipboardOwner
726 public void lostOwnership(Clipboard clipboard, Transferable contents) {