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