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