2 * jSite - ProjectPage.java - Copyright © 2006–2012 David Roden
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 package de.todesbaum.jsite.gui;
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.FlowLayout;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.Toolkit;
28 import java.awt.datatransfer.Clipboard;
29 import java.awt.datatransfer.ClipboardOwner;
30 import java.awt.datatransfer.StringSelection;
31 import java.awt.datatransfer.Transferable;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.KeyEvent;
34 import java.io.IOException;
35 import java.text.MessageFormat;
36 import java.util.Map.Entry;
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 net.pterodactylus.util.swing.SortedListModel;
62 import de.todesbaum.jsite.application.FileOption;
63 import de.todesbaum.jsite.application.Freenet7Interface;
64 import de.todesbaum.jsite.application.Project;
65 import de.todesbaum.jsite.application.WebOfTrustInterface;
66 import de.todesbaum.jsite.i18n.I18n;
67 import de.todesbaum.jsite.i18n.I18nContainer;
68 import de.todesbaum.util.swing.TLabel;
69 import de.todesbaum.util.swing.TWizard;
70 import de.todesbaum.util.swing.TWizardPage;
73 * Wizard page that lets the user manage his projects and start inserts.
75 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
77 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
79 /** The freenet interface. */
80 private Freenet7Interface freenetInterface;
82 /** The web of trust interface. */
83 private WebOfTrustInterface webOfTrustInterface;
85 /** The “browse” action. */
86 private Action projectLocalPathBrowseAction;
88 /** The “add project” action. */
89 private Action projectAddAction;
91 /** The “delete project” action. */
92 private Action projectDeleteAction;
94 /** The “clone project” action. */
95 private Action projectCloneAction;
97 /** The “manage keys” action. */
98 private Action projectManageKeysAction;
100 /** The “copy URI” action. */
101 private Action projectCopyURIAction;
103 /** The “reset edition” action. */
104 private Action projectResetEditionAction;
106 /** The file chooser. */
107 private JFileChooser pathChooser;
109 /** The project list model. */
110 private SortedListModel<Project> projectListModel;
112 /** The project list scroll pane. */
113 private JScrollPane projectScrollPane;
115 /** The project list. */
116 private JList projectList;
118 /** The project name textfield. */
119 private JTextField projectNameTextField;
121 /** The project description textfield. */
122 private JTextField projectDescriptionTextField;
124 /** The local path textfield. */
125 private JTextField projectLocalPathTextField;
127 /** The textfield for the complete URI. */
128 private JTextField projectCompleteUriTextField;
130 /** The project path textfield. */
131 private JTextField projectPathTextField;
133 /** Whether the “copy URI to clipboard” action was used. */
134 private boolean uriCopied;
137 * Creates a new project page.
140 * The wizard this page belongs to
142 public ProjectPage(final TWizard wizard) {
144 setLayout(new BorderLayout(12, 12));
146 setHeading(I18n.getMessage("jsite.project.heading"));
147 setDescription(I18n.getMessage("jsite.project.description"));
149 I18nContainer.getInstance().registerRunnable(new Runnable() {
153 setHeading(I18n.getMessage("jsite.project.heading"));
154 setDescription(I18n.getMessage("jsite.project.description"));
160 * Initializes the page.
162 private void dialogInit() {
165 pathChooser = new JFileChooser();
166 projectListModel = new SortedListModel<Project>();
167 projectList = new JList(projectListModel);
168 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
169 projectList.addListSelectionListener(this);
171 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
172 projectScrollPane.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
173 add(createInformationPanel(), BorderLayout.CENTER);
180 public void pageAdded(TWizard wizard) {
181 super.pageAdded(wizard);
182 projectList.clearSelection();
183 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
184 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
185 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
186 this.wizard.setNextEnabled(false);
190 * Adds the given listener to the list of listeners.
193 * The listener to add
195 public void addListSelectionListener(ListSelectionListener listener) {
196 projectList.addListSelectionListener(listener);
200 * Removes the given listener from the list of listeners.
203 * The listener to remove
205 public void removeListSelectionListener(ListSelectionListener listener) {
206 projectList.removeListSelectionListener(listener);
210 * Creates all actions.
212 private void createActions() {
213 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
216 @SuppressWarnings("synthetic-access")
217 public void actionPerformed(ActionEvent actionEvent) {
218 actionLocalPathBrowse();
221 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
222 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
223 projectLocalPathBrowseAction.setEnabled(false);
225 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
228 @SuppressWarnings("synthetic-access")
229 public void actionPerformed(ActionEvent actionEvent) {
233 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
234 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
236 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
239 @SuppressWarnings("synthetic-access")
240 public void actionPerformed(ActionEvent actionEvent) {
244 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
245 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
246 projectDeleteAction.setEnabled(false);
248 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
251 @SuppressWarnings("synthetic-access")
252 public void actionPerformed(ActionEvent actionEvent) {
256 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
257 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
258 projectCloneAction.setEnabled(false);
260 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
263 @SuppressWarnings("synthetic-access")
264 public void actionPerformed(ActionEvent actionEvent) {
268 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
269 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
270 projectCopyURIAction.setEnabled(false);
272 projectManageKeysAction = new AbstractAction(I18n.getMessage("jsite.project.action.manage-keys")) {
275 @SuppressWarnings("synthetic-access")
276 public void actionPerformed(ActionEvent actionEvent) {
280 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
281 projectManageKeysAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
282 projectManageKeysAction.setEnabled(false);
284 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
287 @SuppressWarnings("synthetic-access")
288 public void actionPerformed(ActionEvent actionEvent) {
289 actionResetEdition();
292 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
293 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
294 projectResetEditionAction.setEnabled(false);
296 I18nContainer.getInstance().registerRunnable(new Runnable() {
299 @SuppressWarnings("synthetic-access")
301 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
302 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
303 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
304 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
305 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
306 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
307 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
308 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
309 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
310 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
311 projectManageKeysAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.manage-keys"));
312 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
313 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
314 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
315 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
321 * Creates the information panel.
323 * @return The information panel
325 private JComponent createInformationPanel() {
326 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
328 JPanel informationTable = new JPanel(new GridBagLayout());
330 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
331 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
332 functionButtons.add(new JButton(projectAddAction));
333 functionButtons.add(new JButton(projectDeleteAction));
334 functionButtons.add(new JButton(projectCloneAction));
335 functionButtons.add(new JButton(projectManageKeysAction));
337 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
338 informationPanel.add(informationTable, BorderLayout.CENTER);
340 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
341 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));
343 projectNameTextField = new JTextField();
344 projectNameTextField.getDocument().putProperty("name", "project.name");
345 projectNameTextField.getDocument().addDocumentListener(this);
346 projectNameTextField.setEnabled(false);
348 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
349 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));
350 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));
352 projectDescriptionTextField = new JTextField();
353 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
354 projectDescriptionTextField.getDocument().addDocumentListener(this);
355 projectDescriptionTextField.setEnabled(false);
357 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
358 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));
359 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));
361 projectLocalPathTextField = new JTextField();
362 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
363 projectLocalPathTextField.getDocument().addDocumentListener(this);
364 projectLocalPathTextField.setEnabled(false);
366 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
367 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));
368 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));
369 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));
371 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
372 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));
374 projectPathTextField = new JTextField();
375 projectPathTextField.getDocument().putProperty("name", "project.path");
376 projectPathTextField.getDocument().addDocumentListener(this);
377 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
383 @SuppressWarnings("synthetic-access")
384 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
385 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
393 @SuppressWarnings("synthetic-access")
394 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
395 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
403 @SuppressWarnings("synthetic-access")
404 public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
405 super.remove(fb, offset, length);
409 projectPathTextField.setEnabled(false);
411 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
412 informationTable.add(projectPathLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
413 informationTable.add(projectPathTextField, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
415 projectCompleteUriTextField = new JTextField();
416 projectCompleteUriTextField.setEditable(false);
417 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
418 informationTable.add(projectUriLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
419 informationTable.add(projectCompleteUriTextField, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
420 informationTable.add(new JButton(projectCopyURIAction), new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
422 I18nContainer.getInstance().registerRunnable(new Runnable() {
426 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
427 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
428 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
429 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
430 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
431 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
432 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
436 return informationPanel;
440 * Sets the project list.
443 * The list of projects
445 public void setProjects(Project[] projects) {
446 projectListModel.clear();
447 for (Project project : projects) {
448 projectListModel.add(project);
453 * Returns the list of projects.
455 * @return The list of projects
457 public Project[] getProjects() {
458 return projectListModel.toArray(new Project[projectListModel.size()]);
462 * Sets the freenet interface to use.
464 * @param freenetInterface
465 * The freenetInterface to use
467 public void setFreenetInterface(Freenet7Interface freenetInterface) {
468 this.freenetInterface = freenetInterface;
472 * Sets the web of trust interface to use.
474 * @param webOfTrustInterface
475 * The web of trust interface to use
477 public void setWebOfTrustInterface(WebOfTrustInterface webOfTrustInterface) {
478 this.webOfTrustInterface = webOfTrustInterface;
482 * Returns the currently selected project.
484 * @return The currently selected project
486 public Project getSelectedProject() {
487 return (Project) projectList.getSelectedValue();
491 * Returns whether the “copy URI to clipboard” button was used.
493 * @return {@code true} if the “copy URI to clipboard” button was used,
494 * {@code false} otherwise
496 public boolean wasUriCopied() {
501 * Updates the currently selected project with changed information from a
504 * @param documentEvent
505 * The document event to process
507 private void setTextField(DocumentEvent documentEvent) {
508 Document document = documentEvent.getDocument();
509 String propertyName = (String) document.getProperty("name");
510 Project project = (Project) projectList.getSelectedValue();
511 if (project == null) {
515 String text = document.getText(0, document.getLength()).trim();
516 if ("project.name".equals(propertyName)) {
517 project.setName(text);
518 projectList.repaint();
519 } else if ("project.description".equals(propertyName)) {
520 project.setDescription(text);
521 } else if ("project.localpath".equals(propertyName)) {
522 project.setLocalPath(text);
523 } else if ("project.privatekey".equals(propertyName)) {
524 project.setInsertURI(text);
525 } else if ("project.publickey".equals(propertyName)) {
526 project.setRequestURI(text);
527 } else if ("project.path".equals(propertyName)) {
528 project.setPath(text);
530 } catch (BadLocationException e) {
540 * Lets the user choose a local path for a project.
542 private void actionLocalPathBrowse() {
543 Project project = (Project) projectList.getSelectedValue();
544 if (project == null) {
547 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
548 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
549 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
554 * Adds a new project.
556 private void actionAdd() {
557 String[] keyPair = null;
558 if (!freenetInterface.hasNode()) {
559 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
563 keyPair = freenetInterface.generateKeyPair();
564 } catch (IOException ioe1) {
565 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
568 Project newProject = new Project();
569 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
570 newProject.setInsertURI(keyPair[0]);
571 newProject.setRequestURI(keyPair[1]);
572 newProject.setEdition(-1);
573 newProject.setPath("");
574 projectListModel.add(newProject);
575 projectScrollPane.revalidate();
576 projectScrollPane.repaint();
577 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
581 * Deletes the currently selected project.
583 private void actionDelete() {
584 int selectedIndex = projectList.getSelectedIndex();
585 if (selectedIndex > -1) {
586 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) {
587 projectListModel.remove(selectedIndex);
588 projectList.clearSelection();
589 if (projectListModel.getSize() != 0) {
590 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
597 * Clones the currently selected project.
599 private void actionClone() {
600 int selectedIndex = projectList.getSelectedIndex();
601 if (selectedIndex > -1) {
602 Project newProject = new Project((Project) projectList.getSelectedValue());
603 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
604 projectListModel.add(newProject);
605 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
610 * Copies the request URI of the currently selected project to the
613 private void actionCopyURI() {
614 int selectedIndex = projectList.getSelectedIndex();
615 if (selectedIndex > -1) {
616 Project selectedProject = (Project) projectList.getSelectedValue();
617 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
618 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
624 * Opens a {@link KeyDialog} and lets the user manipulate the keys of the
627 private void actionManageKeys() {
628 int selectedIndex = projectList.getSelectedIndex();
629 if (selectedIndex > -1) {
630 Project selectedProject = (Project) projectList.getSelectedValue();
631 KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard);
632 keyDialog.setPrivateKey(selectedProject.getInsertURI());
633 keyDialog.setPublicKey(selectedProject.getRequestURI());
634 keyDialog.setOwnIdentities(webOfTrustInterface.getOwnIdentities());
635 keyDialog.setVisible(true);
636 if (!keyDialog.wasCancelled()) {
637 String originalPublicKey = selectedProject.getRequestURI();
638 String originalPrivateKey = selectedProject.getInsertURI();
639 selectedProject.setInsertURI(keyDialog.getPrivateKey());
640 selectedProject.setRequestURI(keyDialog.getPublicKey());
641 if (!originalPublicKey.equals(selectedProject.getRequestURI()) || !originalPrivateKey.equals(selectedProject.getInsertURI())) {
642 selectedProject.setEdition(-1);
643 for (Entry<String, FileOption> fileOption : selectedProject.getFileOptions().entrySet()) {
644 fileOption.getValue().setLastInsertHash(null);
653 * Resets the edition of the currently selected project.
655 private void actionResetEdition() {
656 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
659 int selectedIndex = projectList.getSelectedIndex();
660 if (selectedIndex > -1) {
661 Project selectedProject = (Project) projectList.getSelectedValue();
662 selectedProject.setEdition(-1);
668 * Updates the complete URI text field.
670 private void updateCompleteURI() {
671 int selectedIndex = projectList.getSelectedIndex();
672 if (selectedIndex > -1) {
673 Project selectedProject = (Project) projectList.getSelectedValue();
674 projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
679 // INTERFACE ListSelectionListener
686 public void valueChanged(ListSelectionEvent listSelectionEvent) {
687 int selectedRow = projectList.getSelectedIndex();
688 Project selectedProject = (Project) projectList.getSelectedValue();
689 projectNameTextField.setEnabled(selectedRow > -1);
690 projectDescriptionTextField.setEnabled(selectedRow > -1);
691 projectLocalPathTextField.setEnabled(selectedRow > -1);
692 projectPathTextField.setEnabled(selectedRow > -1);
693 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
694 projectDeleteAction.setEnabled(selectedRow > -1);
695 projectCloneAction.setEnabled(selectedRow > -1);
696 projectCopyURIAction.setEnabled(selectedRow > -1);
697 projectManageKeysAction.setEnabled(selectedRow > -1);
698 projectResetEditionAction.setEnabled(selectedRow > -1);
699 if (selectedRow > -1) {
700 projectNameTextField.setText(selectedProject.getName());
701 projectDescriptionTextField.setText(selectedProject.getDescription());
702 projectLocalPathTextField.setText(selectedProject.getLocalPath());
703 projectPathTextField.setText(selectedProject.getPath());
704 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
706 projectNameTextField.setText("");
707 projectDescriptionTextField.setText("");
708 projectLocalPathTextField.setText("");
709 projectPathTextField.setText("");
710 projectCompleteUriTextField.setText("");
715 // INTERFACE ChangeListener
719 // INTERFACE DocumentListener
726 public void insertUpdate(DocumentEvent documentEvent) {
727 setTextField(documentEvent);
734 public void removeUpdate(DocumentEvent documentEvent) {
735 setTextField(documentEvent);
742 public void changedUpdate(DocumentEvent documentEvent) {
743 setTextField(documentEvent);
747 // INTERFACE ClipboardOwner
754 public void lostOwnership(Clipboard clipboard, Transferable contents) {