2 * jSite - a tool for uploading websites into Freenet
3 * Copyright (C) 2006 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package de.todesbaum.jsite.gui;
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.Toolkit;
29 import java.awt.datatransfer.Clipboard;
30 import java.awt.datatransfer.ClipboardOwner;
31 import java.awt.datatransfer.StringSelection;
32 import java.awt.datatransfer.Transferable;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.KeyEvent;
35 import java.io.IOException;
36 import java.text.MessageFormat;
38 import javax.swing.AbstractAction;
39 import javax.swing.Action;
40 import javax.swing.JButton;
41 import javax.swing.JComponent;
42 import javax.swing.JFileChooser;
43 import javax.swing.JLabel;
44 import javax.swing.JList;
45 import javax.swing.JOptionPane;
46 import javax.swing.JPanel;
47 import javax.swing.JScrollPane;
48 import javax.swing.JTextField;
49 import javax.swing.ListSelectionModel;
50 import javax.swing.border.EmptyBorder;
51 import javax.swing.event.DocumentEvent;
52 import javax.swing.event.DocumentListener;
53 import javax.swing.event.ListSelectionEvent;
54 import javax.swing.event.ListSelectionListener;
55 import javax.swing.text.AbstractDocument;
56 import javax.swing.text.AttributeSet;
57 import javax.swing.text.BadLocationException;
58 import javax.swing.text.Document;
59 import javax.swing.text.DocumentFilter;
61 import de.todesbaum.jsite.application.Freenet7Interface;
62 import de.todesbaum.jsite.application.Project;
63 import de.todesbaum.jsite.i18n.I18n;
64 import de.todesbaum.jsite.i18n.I18nContainer;
65 import de.todesbaum.util.swing.SortedListModel;
66 import de.todesbaum.util.swing.TLabel;
67 import de.todesbaum.util.swing.TWizard;
68 import de.todesbaum.util.swing.TWizardPage;
71 * Wizard page that lets the user manage his projects and start inserts.
73 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
75 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
77 /** The freenet interface. */
78 private Freenet7Interface freenetInterface;
80 /** The “browse” action. */
81 private Action projectLocalPathBrowseAction;
83 /** The “add project” action. */
84 private Action projectAddAction;
86 /** The “delete project” action. */
87 private Action projectDeleteAction;
89 /** The “clone project” action. */
90 private Action projectCloneAction;
92 /** The “copy URI” action. */
93 private Action projectCopyURIAction;
95 /** The “generate key” action. */
96 private Action projectGenerateKeyAction;
98 /** The “reset edition” action. */
99 private Action projectResetEditionAction;
101 /** The file chooser. */
102 private JFileChooser pathChooser;
104 /** The project list model. */
105 private SortedListModel projectListModel;
107 /** The project list scroll pane. */
108 private JScrollPane projectScrollPane;
110 /** The project list. */
111 private JList projectList;
113 /** The project name textfield. */
114 private JTextField projectNameTextField;
116 /** The project description textfield. */
117 private JTextField projectDescriptionTextField;
119 /** The local path textfield. */
120 private JTextField projectLocalPathTextField;
122 /** The public key textfield. */
123 private JTextField projectPublicKeyTextField;
125 /** The private key textfield. */
126 private JTextField projectPrivateKeyTextField;
128 /** The project path textfield. */
129 private JTextField projectPathTextField;
132 * Creates a new project page.
135 * The wizard this page belongs to
137 public ProjectPage(final TWizard wizard) {
139 setLayout(new BorderLayout(12, 12));
141 setHeading(I18n.getMessage("jsite.project.heading"));
142 setDescription(I18n.getMessage("jsite.project.description"));
144 I18nContainer.getInstance().registerRunnable(new Runnable() {
147 setHeading(I18n.getMessage("jsite.project.heading"));
148 setDescription(I18n.getMessage("jsite.project.description"));
154 * Initializes the page.
156 private void dialogInit() {
159 pathChooser = new JFileChooser();
160 projectListModel = new SortedListModel();
161 projectList = new JList(projectListModel);
162 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
163 projectList.addListSelectionListener(this);
164 projectList.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
166 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
167 add(createInformationPanel(), BorderLayout.CENTER);
174 public void pageAdded(TWizard wizard) {
175 super.pageAdded(wizard);
176 projectList.clearSelection();
177 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
178 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
179 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
180 this.wizard.setNextEnabled(false);
184 * Adds the given listener to the list of listeners.
187 * The listener to add
189 public void addListSelectionListener(ListSelectionListener listener) {
190 projectList.addListSelectionListener(listener);
194 * Removes the given listener from the list of listeners.
197 * The listener to remove
199 public void removeListSelectionListener(ListSelectionListener listener) {
200 projectList.removeListSelectionListener(listener);
204 * Creates all actions.
206 private void createActions() {
207 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
209 @SuppressWarnings("synthetic-access")
210 public void actionPerformed(ActionEvent actionEvent) {
211 actionLocalPathBrowse();
214 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
215 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
216 projectLocalPathBrowseAction.setEnabled(false);
218 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
220 @SuppressWarnings("synthetic-access")
221 public void actionPerformed(ActionEvent actionEvent) {
225 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
226 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
228 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
230 @SuppressWarnings("synthetic-access")
231 public void actionPerformed(ActionEvent actionEvent) {
235 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
236 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
237 projectDeleteAction.setEnabled(false);
239 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
241 @SuppressWarnings("synthetic-access")
242 public void actionPerformed(ActionEvent actionEvent) {
246 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
247 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
248 projectCloneAction.setEnabled(false);
250 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
252 @SuppressWarnings("synthetic-access")
253 public void actionPerformed(ActionEvent actionEvent) {
257 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
258 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
259 projectCopyURIAction.setEnabled(false);
261 projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) {
263 @SuppressWarnings("synthetic-access")
264 public void actionPerformed(ActionEvent actionEvent) {
265 actionGenerateNewKey();
268 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
269 projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G);
270 projectGenerateKeyAction.setEnabled(false);
272 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
274 @SuppressWarnings("synthetic-access")
275 public void actionPerformed(ActionEvent actionEvent) {
276 actionResetEdition();
279 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
280 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
281 projectResetEditionAction.setEnabled(false);
283 I18nContainer.getInstance().registerRunnable(new Runnable() {
285 @SuppressWarnings("synthetic-access")
287 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
288 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
289 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
290 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
291 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
292 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
293 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
294 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
295 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
296 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
297 projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key"));
298 projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip"));
299 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
300 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
301 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
307 * Creates the information panel.
309 * @return The information panel
311 private JComponent createInformationPanel() {
312 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
314 JPanel informationTable = new JPanel(new GridBagLayout());
316 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
317 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
318 functionButtons.add(new JButton(projectAddAction));
319 functionButtons.add(new JButton(projectDeleteAction));
320 functionButtons.add(new JButton(projectCloneAction));
321 functionButtons.add(new JButton(projectCopyURIAction));
323 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
324 informationPanel.add(informationTable, BorderLayout.CENTER);
326 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
327 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));
329 projectNameTextField = new JTextField();
330 projectNameTextField.getDocument().putProperty("name", "project.name");
331 projectNameTextField.getDocument().addDocumentListener(this);
332 projectNameTextField.setEnabled(false);
334 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
335 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));
336 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));
338 projectDescriptionTextField = new JTextField();
339 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
340 projectDescriptionTextField.getDocument().addDocumentListener(this);
341 projectDescriptionTextField.setEnabled(false);
343 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
344 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));
345 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));
347 projectLocalPathTextField = new JTextField();
348 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
349 projectLocalPathTextField.getDocument().addDocumentListener(this);
350 projectLocalPathTextField.setEnabled(false);
352 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
353 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));
354 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));
355 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));
357 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
358 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));
360 projectPublicKeyTextField = new JTextField(27);
361 projectPublicKeyTextField.getDocument().putProperty("name", "project.publickey");
362 projectPublicKeyTextField.getDocument().addDocumentListener(this);
363 projectPublicKeyTextField.setEnabled(false);
365 final TLabel projectPublicKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.public-key") + ":", KeyEvent.VK_U, projectPublicKeyTextField);
366 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));
367 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));
368 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));
370 projectPrivateKeyTextField = new JTextField(27);
371 projectPrivateKeyTextField.getDocument().putProperty("name", "project.privatekey");
372 projectPrivateKeyTextField.getDocument().addDocumentListener(this);
373 projectPrivateKeyTextField.setEnabled(false);
375 final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField);
376 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));
377 informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
378 informationTable.add(new JButton(projectResetEditionAction), new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
380 projectPathTextField = new JTextField();
381 projectPathTextField.getDocument().putProperty("name", "project.path");
382 projectPathTextField.getDocument().addDocumentListener(this);
383 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
389 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
390 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
397 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
398 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
401 projectPathTextField.setEnabled(false);
403 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
404 I18nContainer.getInstance().registerRunnable(new Runnable() {
407 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
408 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
409 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
410 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
411 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
412 projectPublicKeyLabel.setText(I18n.getMessage("jsite.project.project.public-key") + ":");
413 projectPrivateKeyLabel.setText(I18n.getMessage("jsite.project.project.private-key") + ":");
414 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
417 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));
418 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));
420 return informationPanel;
424 * Sets the project list.
427 * The list of projects
429 public void setProjects(Project[] projects) {
430 projectListModel.clear();
431 for (Project project : projects) {
432 projectListModel.add(project);
437 * Returns the list of projects.
439 * @return The list of projects
441 public Project[] getProjects() {
442 return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]);
446 * Sets the freenet interface to use.
448 * @param freenetInterface
449 * The freenetInterface to use
451 public void setFreenetInterface(Freenet7Interface freenetInterface) {
452 this.freenetInterface = freenetInterface;
456 * Returns the currently selected project.
458 * @return The currently selected project
460 public Project getSelectedProject() {
461 return (Project) projectList.getSelectedValue();
465 * Updates the currently selected project with changed information from a
468 * @param documentEvent
469 * The document event to process
471 private void setTextField(DocumentEvent documentEvent) {
472 Document document = documentEvent.getDocument();
473 String propertyName = (String) document.getProperty("name");
474 Project project = (Project) projectList.getSelectedValue();
475 if (project == null) {
479 String text = document.getText(0, document.getLength()).trim();
480 if ("project.name".equals(propertyName)) {
481 project.setName(text);
482 projectList.repaint();
483 } else if ("project.description".equals(propertyName)) {
484 project.setDescription(text);
485 } else if ("project.localpath".equals(propertyName)) {
486 project.setLocalPath(text);
487 } else if ("project.privatekey".equals(propertyName)) {
488 project.setInsertURI(text);
489 } else if ("project.publickey".equals(propertyName)) {
490 project.setRequestURI(text);
491 } else if ("project.path".equals(propertyName)) {
492 project.setPath(text);
494 } catch (BadLocationException e) {
504 * Lets the user choose a local path for a project.
506 private void actionLocalPathBrowse() {
507 Project project = (Project) projectList.getSelectedValue();
508 if (project == null) {
511 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
512 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
513 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
518 * Adds a new project.
520 private void actionAdd() {
521 String[] keyPair = null;
522 if (!freenetInterface.hasNode()) {
523 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
527 keyPair = freenetInterface.generateKeyPair();
528 } catch (IOException ioe1) {
529 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
532 Project newProject = new Project();
533 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
534 newProject.setInsertURI(keyPair[0]);
535 newProject.setRequestURI(keyPair[1]);
536 newProject.setEdition(-1);
537 newProject.setPath("");
538 projectListModel.add(newProject);
539 projectScrollPane.revalidate();
540 projectScrollPane.repaint();
541 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
545 * Deletes the currently selected project.
547 private void actionDelete() {
548 int selectedIndex = projectList.getSelectedIndex();
549 if (selectedIndex > -1) {
550 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) {
551 projectListModel.remove(selectedIndex);
552 projectList.clearSelection();
553 if (projectListModel.getSize() != 0) {
554 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
561 * Clones the currently selected project.
563 private void actionClone() {
564 int selectedIndex = projectList.getSelectedIndex();
565 if (selectedIndex > -1) {
566 Project newProject = new Project((Project) projectList.getSelectedValue());
567 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
568 projectListModel.add(newProject);
569 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
574 * Copies the request URI of the currently selected project to the
577 private void actionCopyURI() {
578 int selectedIndex = projectList.getSelectedIndex();
579 if (selectedIndex > -1) {
580 Project selectedProject = (Project) projectList.getSelectedValue();
581 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
582 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
587 * Generates a new key for the currently selected project.
589 private void actionGenerateNewKey() {
590 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
593 int selectedIndex = projectList.getSelectedIndex();
594 if (selectedIndex > -1) {
595 Project selectedProject = (Project) projectList.getSelectedValue();
596 String[] keyPair = null;
598 keyPair = freenetInterface.generateKeyPair();
599 } catch (IOException ioe1) {
600 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
603 selectedProject.setInsertURI(keyPair[0]);
604 selectedProject.setRequestURI(keyPair[1]);
605 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
606 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
611 * Resets the edition of the currently selected project.
613 private void actionResetEdition() {
614 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
617 int selectedIndex = projectList.getSelectedIndex();
618 if (selectedIndex > -1) {
619 Project selectedProject = (Project) projectList.getSelectedValue();
620 selectedProject.setEdition(-1);
625 // INTERFACE ListSelectionListener
631 public void valueChanged(ListSelectionEvent listSelectionEvent) {
632 int selectedRow = projectList.getSelectedIndex();
633 Project selectedProject = (Project) projectList.getSelectedValue();
634 projectNameTextField.setEnabled(selectedRow > -1);
635 projectDescriptionTextField.setEnabled(selectedRow > -1);
636 projectLocalPathTextField.setEnabled(selectedRow > -1);
637 projectPublicKeyTextField.setEnabled(selectedRow > -1);
638 projectPrivateKeyTextField.setEnabled(selectedRow > -1);
639 projectPathTextField.setEnabled(selectedRow > -1);
640 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
641 projectDeleteAction.setEnabled(selectedRow > -1);
642 projectCloneAction.setEnabled(selectedRow > -1);
643 projectCopyURIAction.setEnabled(selectedRow > -1);
644 projectGenerateKeyAction.setEnabled(selectedRow > -1);
645 projectResetEditionAction.setEnabled(selectedRow > -1);
646 if (selectedRow > -1) {
647 projectNameTextField.setText(selectedProject.getName());
648 projectDescriptionTextField.setText(selectedProject.getDescription());
649 projectLocalPathTextField.setText(selectedProject.getLocalPath());
650 projectPublicKeyTextField.setText(selectedProject.getRequestURI());
651 projectPrivateKeyTextField.setText(selectedProject.getInsertURI());
652 projectPathTextField.setText(selectedProject.getPath());
654 projectNameTextField.setText("");
655 projectDescriptionTextField.setText("");
656 projectLocalPathTextField.setText("");
657 projectPublicKeyTextField.setText("");
658 projectPrivateKeyTextField.setText("");
659 projectPathTextField.setText("");
664 // INTERFACE ChangeListener
668 // INTERFACE DocumentListener
674 public void insertUpdate(DocumentEvent documentEvent) {
675 setTextField(documentEvent);
681 public void removeUpdate(DocumentEvent documentEvent) {
682 setTextField(documentEvent);
688 public void changedUpdate(DocumentEvent documentEvent) {
689 setTextField(documentEvent);
693 // INTERFACE ClipboardOwner
699 public void lostOwnership(Clipboard clipboard, Transferable contents) {