9f5c9699fb1db9262fcd17bf7ae061f77e1f9748
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectPage.java
1 /*
2  * jSite - a tool for uploading websites into Freenet
3  * Copyright (C) 2006 David Roden
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 package de.todesbaum.jsite.gui;
21
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;
37
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.BadLocationException;
56 import javax.swing.text.Document;
57
58 import de.todesbaum.jsite.application.Freenet7Interface;
59 import de.todesbaum.jsite.application.Project;
60 import de.todesbaum.jsite.i18n.I18n;
61 import de.todesbaum.jsite.i18n.I18nContainer;
62 import de.todesbaum.util.swing.SortedListModel;
63 import de.todesbaum.util.swing.TLabel;
64 import de.todesbaum.util.swing.TWizard;
65 import de.todesbaum.util.swing.TWizardPage;
66
67 /**
68  * @author David Roden <droden@gmail.com>
69  * @version $Id$
70  */
71 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
72
73         private Freenet7Interface freenetInterface;
74
75         protected Action projectLocalPathBrowseAction;
76         protected Action projectAddAction;
77         protected Action projectDeleteAction;
78         protected Action projectCloneAction;
79         protected Action projectCopyURIAction;
80         protected Action projectGenerateKeyAction;
81
82         private JFileChooser pathChooser;
83         private SortedListModel projectListModel;
84         private JList projectList;
85         private JTextField projectNameTextField;
86         private JTextField projectDescriptionTextField;
87         private JTextField projectLocalPathTextField;
88         private JTextField projectPublicKeyTextField;
89         private JTextField projectPrivateKeyTextField;
90         private JTextField projectPathTextField;
91
92         public ProjectPage(final TWizard wizard) {
93                 super(wizard);
94                 setLayout(new BorderLayout(12, 12));
95                 dialogInit();
96                 setHeading(I18n.getMessage("jsite.project.heading"));
97                 setDescription(I18n.getMessage("jsite.project.description"));
98                 
99                 I18nContainer.getInstance().registerRunnable(new Runnable() {
100
101                         public void run() {
102                                 setHeading(I18n.getMessage("jsite.project.heading"));
103                                 setDescription(I18n.getMessage("jsite.project.description"));
104                         }
105                 });
106         }
107
108         protected void dialogInit() {
109                 createActions();
110
111                 pathChooser = new JFileChooser();
112                 projectListModel = new SortedListModel();
113                 projectList = new JList(projectListModel);
114                 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
115                 projectList.addListSelectionListener(this);
116                 projectList.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
117
118                 add(new JScrollPane(projectList), BorderLayout.LINE_START);
119                 add(createInformationPanel(), BorderLayout.CENTER);
120         }
121
122         /**
123          * {@inheritDoc}
124          */
125         @Override
126         public void pageAdded(TWizard wizard) {
127                 super.pageAdded(wizard);
128                 projectList.clearSelection();
129                 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
130                 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
131                 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
132                 this.wizard.setNextEnabled(false);
133         }
134
135         /**
136          */
137         public void addListSelectionListener(ListSelectionListener listener) {
138                 projectList.addListSelectionListener(listener);
139         }
140
141         /**
142          */
143         public void removeListSelectionListener(ListSelectionListener listener) {
144                 projectList.removeListSelectionListener(listener);
145         }
146
147         private void createActions() {
148                 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
149
150                         public void actionPerformed(ActionEvent actionEvent) {
151                                 actionLocalPathBrowse();
152                         }
153                 };
154                 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
155                 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
156                 projectLocalPathBrowseAction.setEnabled(false);
157
158                 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
159
160                         public void actionPerformed(ActionEvent actionEvent) {
161                                 actionAdd();
162                         }
163                 };
164                 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
165                 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
166
167                 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
168
169                         public void actionPerformed(ActionEvent actionEvent) {
170                                 actionDelete();
171                         }
172                 };
173                 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
174                 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
175                 projectDeleteAction.setEnabled(false);
176
177                 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
178
179                         public void actionPerformed(ActionEvent actionEvent) {
180                                 actionClone();
181                         }
182                 };
183                 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
184                 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
185                 projectCloneAction.setEnabled(false);
186
187                 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
188
189                         public void actionPerformed(ActionEvent actionEvent) {
190                                 actionCopyURI();
191                         }
192                 };
193                 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
194                 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
195                 projectCopyURIAction.setEnabled(false);
196
197                 projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) {
198
199                         public void actionPerformed(ActionEvent actionEvent) {
200                                 actionGenerateNewKey();
201                         }
202                 };
203                 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
204                 projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
205                 projectGenerateKeyAction.setEnabled(false);
206                 
207                 I18nContainer.getInstance().registerRunnable(new Runnable() {
208
209                         public void run() {
210                                 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
211                                 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
212                                 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
213                                 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
214                                 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
215                                 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
216                                 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
217                                 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
218                                 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
219                                 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
220                                 projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key"));
221                                 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
222                         }
223                 });
224         }
225
226         private JComponent createInformationPanel() {
227                 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
228
229                 JPanel informationTable = new JPanel(new GridBagLayout());
230
231                 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
232                 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
233                 functionButtons.add(new JButton(projectAddAction));
234                 functionButtons.add(new JButton(projectDeleteAction));
235                 functionButtons.add(new JButton(projectCloneAction));
236                 functionButtons.add(new JButton(projectCopyURIAction));
237
238                 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
239                 informationPanel.add(informationTable, BorderLayout.CENTER);
240
241                 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
242                 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));
243
244                 projectNameTextField = new JTextField();
245                 projectNameTextField.getDocument().putProperty("name", "project.name");
246                 projectNameTextField.getDocument().addDocumentListener(this);
247                 projectNameTextField.setEnabled(false);
248
249                 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
250                 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));
251                 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));
252
253                 projectDescriptionTextField = new JTextField();
254                 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
255                 projectDescriptionTextField.getDocument().addDocumentListener(this);
256                 projectDescriptionTextField.setEnabled(false);
257
258                 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
259                 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));
260                 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));
261
262                 projectLocalPathTextField = new JTextField();
263                 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
264                 projectLocalPathTextField.getDocument().addDocumentListener(this);
265                 projectLocalPathTextField.setEnabled(false);
266
267                 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
268                 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));
269                 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));
270                 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));
271
272                 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
273                 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));
274
275                 projectPublicKeyTextField = new JTextField(27);
276                 projectPublicKeyTextField.getDocument().putProperty("name", "project.publickey");
277                 projectPublicKeyTextField.getDocument().addDocumentListener(this);
278                 projectPublicKeyTextField.setEnabled(false);
279
280                 final TLabel projectPublicKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.public-key") + ":", KeyEvent.VK_U, projectPublicKeyTextField);
281                 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));
282                 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));
283                 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));
284
285                 projectPrivateKeyTextField = new JTextField(27);
286                 projectPrivateKeyTextField.getDocument().putProperty("name", "project.privatekey");
287                 projectPrivateKeyTextField.getDocument().addDocumentListener(this);
288                 projectPrivateKeyTextField.setEnabled(false);
289
290                 final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField);
291                 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));
292                 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));
293
294                 projectPathTextField = new JTextField();
295                 projectPathTextField.getDocument().putProperty("name", "project.path");
296                 projectPathTextField.getDocument().addDocumentListener(this);
297                 projectPathTextField.setEnabled(false);
298
299                 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
300                 I18nContainer.getInstance().registerRunnable(new Runnable() {
301
302                         public void run() {
303                                 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
304                                 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
305                                 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
306                                 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
307                                 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
308                                 projectPublicKeyLabel.setText(I18n.getMessage("jsite.project.project.public-key") + ":");
309                                 projectPrivateKeyLabel.setText(I18n.getMessage("jsite.project.project.private-key") + ":");
310                                 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
311                         }
312                 });
313                 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));
314                 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));
315
316                 return informationPanel;
317         }
318
319         public void setProjects(Project[] projects) {
320                 projectListModel.clear();
321                 for (Project project: projects) {
322                         projectListModel.add(project);
323                 }
324         }
325
326         public Project[] getProjects() {
327                 return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]);
328         }
329
330         /**
331          * @param freenetInterface
332          *            The freenetInterface to set.
333          */
334         public void setFreenetInterface(Freenet7Interface freenetInterface) {
335                 this.freenetInterface = freenetInterface;
336         }
337
338         public Project getSelectedProject() {
339                 return (Project) projectList.getSelectedValue();
340         }
341
342         private void setTextField(DocumentEvent documentEvent) {
343                 Document document = documentEvent.getDocument();
344                 String propertyName = (String) document.getProperty("name");
345                 Project project = (Project) projectList.getSelectedValue();
346                 if (project == null) {
347                         return;
348                 }
349                 try {
350                         String text = document.getText(0, document.getLength()).trim();
351                         if ("project.name".equals(propertyName)) {
352                                 project.setName(text);
353                                 projectList.repaint();
354                         } else if ("project.description".equals(propertyName)) {
355                                 project.setDescription(text);
356                         } else if ("project.localpath".equals(propertyName)) {
357                                 project.setLocalPath(text);
358                         } else if ("project.privatekey".equals(propertyName)) {
359                                 project.setInsertURI(text);
360                         } else if ("project.publickey".equals(propertyName)) {
361                                 project.setRequestURI(text);
362                         } else if ("project.path".equals(propertyName)) {
363                                 project.setPath(text);
364                         }
365                 } catch (BadLocationException e) {
366                 }
367         }
368
369         //
370         // ACTIONS
371         //
372
373         protected void actionLocalPathBrowse() {
374                 Project project = (Project) projectList.getSelectedValue();
375                 if (project == null) {
376                         return;
377                 }
378                 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
379                 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
380                         projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
381                 }
382         }
383
384         protected void actionAdd() {
385                 String[] keyPair = null;
386                 if (!freenetInterface.hasNode()) {
387                         JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
388                         return;
389                 }
390                 try {
391                         keyPair = freenetInterface.generateKeyPair();
392                 } catch (IOException ioe1) {
393                         JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
394                         return;
395                 }
396                 Project newProject = new Project();
397                 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
398                 newProject.setInsertURI(keyPair[0]);
399                 newProject.setRequestURI(keyPair[1]);
400                 newProject.setEdition(1);
401                 projectListModel.add(newProject);
402                 projectList.setSelectedIndex(projectListModel.size() - 1);
403         }
404
405         protected void actionDelete() {
406                 int selectedIndex = projectList.getSelectedIndex();
407                 if (selectedIndex > -1) {
408                         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) {
409                                 projectListModel.remove(selectedIndex);
410                                 projectList.clearSelection();
411                                 if (projectListModel.getSize() != 0) {
412                                         projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
413                                 }
414                         }
415                 }
416         }
417
418         protected void actionClone() {
419                 int selectedIndex = projectList.getSelectedIndex();
420                 if (selectedIndex > -1) {
421                         Project newProject = new Project((Project) projectList.getSelectedValue());
422                         newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
423                         projectListModel.add(newProject);
424                         projectList.setSelectedIndex(projectListModel.indexOf(newProject));
425                 }
426         }
427         
428         protected void actionCopyURI() {
429                 int selectedIndex = projectList.getSelectedIndex();
430                 if (selectedIndex > -1) {
431                         Project selectedProject = (Project) projectList.getSelectedValue();
432                         Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
433                         clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
434                 }
435         }
436         
437         protected void actionGenerateNewKey() {
438                 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
439                         return;
440                 }
441                 int selectedIndex = projectList.getSelectedIndex();
442                 if (selectedIndex > -1) {
443                         Project selectedProject = (Project) projectList.getSelectedValue();
444                         String[] keyPair = null;
445                         try {
446                                 keyPair = freenetInterface.generateKeyPair();
447                         } catch (IOException ioe1) {
448                                 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
449                                 return;
450                         }
451                         selectedProject.setInsertURI(keyPair[0]);
452                         selectedProject.setRequestURI(keyPair[1]);
453                         projectPublicKeyTextField.setText(selectedProject.getRequestURI());
454                         projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
455                 }
456         }
457
458         //
459         // INTERFACE ListSelectionListener
460         //
461
462         /**
463          * {@inheritDoc}
464          */
465         public void valueChanged(ListSelectionEvent listSelectionEvent) {
466                 int selectedRow = projectList.getSelectedIndex();
467                 Project selectedProject = (Project) projectList.getSelectedValue();
468                 projectNameTextField.setEnabled(selectedRow > -1);
469                 projectDescriptionTextField.setEnabled(selectedRow > -1);
470                 projectLocalPathTextField.setEnabled(selectedRow > -1);
471                 projectPublicKeyTextField.setEnabled(selectedRow > -1);
472                 projectPrivateKeyTextField.setEnabled(selectedRow > -1);
473                 projectPathTextField.setEnabled(selectedRow > -1);
474                 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
475                 projectDeleteAction.setEnabled(selectedRow > -1);
476                 projectCloneAction.setEnabled(selectedRow > -1);
477                 projectCopyURIAction.setEnabled(selectedRow > -1);
478                 projectGenerateKeyAction.setEnabled(selectedRow > -1);
479                 if (selectedRow > -1) {
480                         projectNameTextField.setText(selectedProject.getName());
481                         projectDescriptionTextField.setText(selectedProject.getDescription());
482                         projectLocalPathTextField.setText(selectedProject.getLocalPath());
483                         projectPublicKeyTextField.setText(selectedProject.getRequestURI());
484                         projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
485                         projectPathTextField.setText(selectedProject.getPath());
486                 } else {
487                         projectNameTextField.setText("");
488                         projectDescriptionTextField.setText("");
489                         projectLocalPathTextField.setText("");
490                         projectPublicKeyTextField.setText("");
491                         projectPrivateKeyTextField.setText("");
492                         projectPathTextField.setText("");
493                 }
494         }
495
496         //
497         // INTERFACE ChangeListener
498         //
499
500         //
501         // INTERFACE DocumentListener
502         //
503
504         /**
505          * {@inheritDoc}
506          */
507         public void insertUpdate(DocumentEvent documentEvent) {
508                 setTextField(documentEvent);
509         }
510
511         /**
512          * {@inheritDoc}
513          */
514         public void removeUpdate(DocumentEvent documentEvent) {
515                 setTextField(documentEvent);
516         }
517
518         /**
519          * {@inheritDoc}
520          */
521         public void changedUpdate(DocumentEvent documentEvent) {
522                 setTextField(documentEvent);
523         }
524         
525         //
526         // INTERFACE ClipboardOwner
527         //
528
529         /**
530          * {@inheritDoc}
531          */
532         public void lostOwnership(Clipboard clipboard, Transferable contents) {
533         }
534
535 }