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 file chooser. */
99 private JFileChooser pathChooser;
101 /** The project list model. */
102 private SortedListModel projectListModel;
104 /** The project list scroll pane. */
105 private JScrollPane projectScrollPane;
107 /** The project list. */
108 private JList projectList;
110 /** The project name textfield. */
111 private JTextField projectNameTextField;
113 /** The project description textfield. */
114 private JTextField projectDescriptionTextField;
116 /** The local path textfield. */
117 private JTextField projectLocalPathTextField;
119 /** The public key textfield. */
120 private JTextField projectPublicKeyTextField;
122 /** The private key textfield. */
123 private JTextField projectPrivateKeyTextField;
125 /** The project path textfield. */
126 private JTextField projectPathTextField;
129 * Creates a new project page.
132 * The wizard this page belongs to
134 public ProjectPage(final TWizard wizard) {
136 setLayout(new BorderLayout(12, 12));
138 setHeading(I18n.getMessage("jsite.project.heading"));
139 setDescription(I18n.getMessage("jsite.project.description"));
141 I18nContainer.getInstance().registerRunnable(new Runnable() {
144 setHeading(I18n.getMessage("jsite.project.heading"));
145 setDescription(I18n.getMessage("jsite.project.description"));
151 * Initializes the page.
153 private void dialogInit() {
156 pathChooser = new JFileChooser();
157 projectListModel = new SortedListModel();
158 projectList = new JList(projectListModel);
159 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
160 projectList.addListSelectionListener(this);
161 projectList.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
163 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
164 add(createInformationPanel(), BorderLayout.CENTER);
171 public void pageAdded(TWizard wizard) {
172 super.pageAdded(wizard);
173 projectList.clearSelection();
174 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
175 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
176 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
177 this.wizard.setNextEnabled(false);
181 * Adds the given listener to the list of listeners.
184 * The listener to add
186 public void addListSelectionListener(ListSelectionListener listener) {
187 projectList.addListSelectionListener(listener);
191 * Removes the given listener from the list of listeners.
194 * The listener to remove
196 public void removeListSelectionListener(ListSelectionListener listener) {
197 projectList.removeListSelectionListener(listener);
201 * Creates all actions.
203 private void createActions() {
204 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
206 @SuppressWarnings("synthetic-access")
207 public void actionPerformed(ActionEvent actionEvent) {
208 actionLocalPathBrowse();
211 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
212 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
213 projectLocalPathBrowseAction.setEnabled(false);
215 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
217 @SuppressWarnings("synthetic-access")
218 public void actionPerformed(ActionEvent actionEvent) {
222 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
223 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
225 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
227 @SuppressWarnings("synthetic-access")
228 public void actionPerformed(ActionEvent actionEvent) {
232 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
233 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
234 projectDeleteAction.setEnabled(false);
236 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
238 @SuppressWarnings("synthetic-access")
239 public void actionPerformed(ActionEvent actionEvent) {
243 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
244 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
245 projectCloneAction.setEnabled(false);
247 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
249 @SuppressWarnings("synthetic-access")
250 public void actionPerformed(ActionEvent actionEvent) {
254 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
255 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
256 projectCopyURIAction.setEnabled(false);
258 projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) {
260 @SuppressWarnings("synthetic-access")
261 public void actionPerformed(ActionEvent actionEvent) {
262 actionGenerateNewKey();
265 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
266 projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
267 projectGenerateKeyAction.setEnabled(false);
269 I18nContainer.getInstance().registerRunnable(new Runnable() {
271 @SuppressWarnings("synthetic-access")
273 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
274 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
275 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
276 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
277 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
278 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
279 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
280 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
281 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
282 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
283 projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key"));
284 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
285 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
291 * Creates the information panel.
293 * @return The information panel
295 private JComponent createInformationPanel() {
296 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
298 JPanel informationTable = new JPanel(new GridBagLayout());
300 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
301 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
302 functionButtons.add(new JButton(projectAddAction));
303 functionButtons.add(new JButton(projectDeleteAction));
304 functionButtons.add(new JButton(projectCloneAction));
305 functionButtons.add(new JButton(projectCopyURIAction));
307 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
308 informationPanel.add(informationTable, BorderLayout.CENTER);
310 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
311 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));
313 projectNameTextField = new JTextField();
314 projectNameTextField.getDocument().putProperty("name", "project.name");
315 projectNameTextField.getDocument().addDocumentListener(this);
316 projectNameTextField.setEnabled(false);
318 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
319 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));
320 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));
322 projectDescriptionTextField = new JTextField();
323 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
324 projectDescriptionTextField.getDocument().addDocumentListener(this);
325 projectDescriptionTextField.setEnabled(false);
327 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
328 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));
329 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));
331 projectLocalPathTextField = new JTextField();
332 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
333 projectLocalPathTextField.getDocument().addDocumentListener(this);
334 projectLocalPathTextField.setEnabled(false);
336 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
337 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));
338 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));
339 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));
341 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
342 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));
344 projectPublicKeyTextField = new JTextField(27);
345 projectPublicKeyTextField.getDocument().putProperty("name", "project.publickey");
346 projectPublicKeyTextField.getDocument().addDocumentListener(this);
347 projectPublicKeyTextField.setEnabled(false);
349 final TLabel projectPublicKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.public-key") + ":", KeyEvent.VK_U, projectPublicKeyTextField);
350 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));
351 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));
352 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));
354 projectPrivateKeyTextField = new JTextField(27);
355 projectPrivateKeyTextField.getDocument().putProperty("name", "project.privatekey");
356 projectPrivateKeyTextField.getDocument().addDocumentListener(this);
357 projectPrivateKeyTextField.setEnabled(false);
359 final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField);
360 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));
361 informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
363 projectPathTextField = new JTextField();
364 projectPathTextField.getDocument().putProperty("name", "project.path");
365 projectPathTextField.getDocument().addDocumentListener(this);
366 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
372 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
373 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
380 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
381 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
384 projectPathTextField.setEnabled(false);
386 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
387 I18nContainer.getInstance().registerRunnable(new Runnable() {
390 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
391 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
392 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
393 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
394 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
395 projectPublicKeyLabel.setText(I18n.getMessage("jsite.project.project.public-key") + ":");
396 projectPrivateKeyLabel.setText(I18n.getMessage("jsite.project.project.private-key") + ":");
397 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
400 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));
401 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));
403 return informationPanel;
407 * Sets the project list.
410 * The list of projects
412 public void setProjects(Project[] projects) {
413 projectListModel.clear();
414 for (Project project : projects) {
415 projectListModel.add(project);
420 * Returns the list of projects.
422 * @return The list of projects
424 public Project[] getProjects() {
425 return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]);
429 * Sets the freenet interface to use.
431 * @param freenetInterface
432 * The freenetInterface to use
434 public void setFreenetInterface(Freenet7Interface freenetInterface) {
435 this.freenetInterface = freenetInterface;
439 * Returns the currently selected project.
441 * @return The currently selected project
443 public Project getSelectedProject() {
444 return (Project) projectList.getSelectedValue();
448 * Updates the currently selected project with changed information from a
451 * @param documentEvent
452 * The document event to process
454 private void setTextField(DocumentEvent documentEvent) {
455 Document document = documentEvent.getDocument();
456 String propertyName = (String) document.getProperty("name");
457 Project project = (Project) projectList.getSelectedValue();
458 if (project == null) {
462 String text = document.getText(0, document.getLength()).trim();
463 if ("project.name".equals(propertyName)) {
464 project.setName(text);
465 projectList.repaint();
466 } else if ("project.description".equals(propertyName)) {
467 project.setDescription(text);
468 } else if ("project.localpath".equals(propertyName)) {
469 project.setLocalPath(text);
470 } else if ("project.privatekey".equals(propertyName)) {
471 project.setInsertURI(text);
472 } else if ("project.publickey".equals(propertyName)) {
473 project.setRequestURI(text);
474 } else if ("project.path".equals(propertyName)) {
475 project.setPath(text);
477 } catch (BadLocationException e) {
487 * Lets the user choose a local path for a project.
489 private void actionLocalPathBrowse() {
490 Project project = (Project) projectList.getSelectedValue();
491 if (project == null) {
494 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
495 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
496 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
501 * Adds a new project.
503 private void actionAdd() {
504 String[] keyPair = null;
505 if (!freenetInterface.hasNode()) {
506 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
510 keyPair = freenetInterface.generateKeyPair();
511 } catch (IOException ioe1) {
512 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
515 Project newProject = new Project();
516 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
517 newProject.setInsertURI(keyPair[0]);
518 newProject.setRequestURI(keyPair[1]);
519 newProject.setEdition(-1);
520 newProject.setPath("");
521 projectListModel.add(newProject);
522 projectScrollPane.revalidate();
523 projectScrollPane.repaint();
524 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
528 * Deletes the currently selected project.
530 private void actionDelete() {
531 int selectedIndex = projectList.getSelectedIndex();
532 if (selectedIndex > -1) {
533 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) {
534 projectListModel.remove(selectedIndex);
535 projectList.clearSelection();
536 if (projectListModel.getSize() != 0) {
537 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
544 * Clones the currently selected project.
546 private void actionClone() {
547 int selectedIndex = projectList.getSelectedIndex();
548 if (selectedIndex > -1) {
549 Project newProject = new Project((Project) projectList.getSelectedValue());
550 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
551 projectListModel.add(newProject);
552 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
557 * Copies the request URI of the currently selected project to the
560 private void actionCopyURI() {
561 int selectedIndex = projectList.getSelectedIndex();
562 if (selectedIndex > -1) {
563 Project selectedProject = (Project) projectList.getSelectedValue();
564 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
565 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
570 * Generates a new key for the currently selected project.
572 private void actionGenerateNewKey() {
573 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
576 int selectedIndex = projectList.getSelectedIndex();
577 if (selectedIndex > -1) {
578 Project selectedProject = (Project) projectList.getSelectedValue();
579 String[] keyPair = null;
581 keyPair = freenetInterface.generateKeyPair();
582 } catch (IOException ioe1) {
583 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
586 selectedProject.setInsertURI(keyPair[0]);
587 selectedProject.setRequestURI(keyPair[1]);
588 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
589 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
594 // INTERFACE ListSelectionListener
600 public void valueChanged(ListSelectionEvent listSelectionEvent) {
601 int selectedRow = projectList.getSelectedIndex();
602 Project selectedProject = (Project) projectList.getSelectedValue();
603 projectNameTextField.setEnabled(selectedRow > -1);
604 projectDescriptionTextField.setEnabled(selectedRow > -1);
605 projectLocalPathTextField.setEnabled(selectedRow > -1);
606 projectPublicKeyTextField.setEnabled(selectedRow > -1);
607 projectPrivateKeyTextField.setEnabled(selectedRow > -1);
608 projectPathTextField.setEnabled(selectedRow > -1);
609 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
610 projectDeleteAction.setEnabled(selectedRow > -1);
611 projectCloneAction.setEnabled(selectedRow > -1);
612 projectCopyURIAction.setEnabled(selectedRow > -1);
613 projectGenerateKeyAction.setEnabled(selectedRow > -1);
614 if (selectedRow > -1) {
615 projectNameTextField.setText(selectedProject.getName());
616 projectDescriptionTextField.setText(selectedProject.getDescription());
617 projectLocalPathTextField.setText(selectedProject.getLocalPath());
618 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
619 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
620 projectPathTextField.setText(selectedProject.getPath());
622 projectNameTextField.setText("");
623 projectDescriptionTextField.setText("");
624 projectLocalPathTextField.setText("");
625 projectPublicKeyTextField.setText("");
626 projectPrivateKeyTextField.setText("");
627 projectPathTextField.setText("");
632 // INTERFACE ChangeListener
636 // INTERFACE DocumentListener
642 public void insertUpdate(DocumentEvent documentEvent) {
643 setTextField(documentEvent);
649 public void removeUpdate(DocumentEvent documentEvent) {
650 setTextField(documentEvent);
656 public void changedUpdate(DocumentEvent documentEvent) {
657 setTextField(documentEvent);
661 // INTERFACE ClipboardOwner
667 public void lostOwnership(Clipboard clipboard, Transferable contents) {