2 * jSite - ProjectPage.java - Copyright © 2006–2019 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.List;
37 import java.util.Map.Entry;
39 import javax.swing.AbstractAction;
40 import javax.swing.Action;
41 import javax.swing.JButton;
42 import javax.swing.JComponent;
43 import javax.swing.JFileChooser;
44 import javax.swing.JLabel;
45 import javax.swing.JList;
46 import javax.swing.JOptionPane;
47 import javax.swing.JPanel;
48 import javax.swing.JScrollPane;
49 import javax.swing.JTextField;
50 import javax.swing.ListSelectionModel;
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.AbstractDocument;
57 import javax.swing.text.AttributeSet;
58 import javax.swing.text.BadLocationException;
59 import javax.swing.text.Document;
60 import javax.swing.text.DocumentFilter;
62 import net.pterodactylus.util.swing.SortedListModel;
63 import de.todesbaum.jsite.application.FileOption;
64 import de.todesbaum.jsite.application.Freenet7Interface;
65 import de.todesbaum.jsite.application.Project;
66 import de.todesbaum.jsite.application.WebOfTrustInterface;
67 import de.todesbaum.jsite.i18n.I18n;
68 import de.todesbaum.jsite.i18n.I18nContainer;
69 import de.todesbaum.util.swing.TLabel;
70 import de.todesbaum.util.swing.TWizard;
71 import de.todesbaum.util.swing.TWizardPage;
74 * Wizard page that lets the user manage his projects and start inserts.
76 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
78 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
80 /** The freenet interface. */
81 private Freenet7Interface freenetInterface;
83 /** The web of trust interface. */
84 private WebOfTrustInterface webOfTrustInterface;
86 /** The “browse” action. */
87 private Action projectLocalPathBrowseAction;
89 /** The “add project” action. */
90 private Action projectAddAction;
92 /** The “delete project” action. */
93 private Action projectDeleteAction;
95 /** The “clone project” action. */
96 private Action projectCloneAction;
98 /** The “manage keys” action. */
99 private Action projectManageKeysAction;
101 /** The “copy URI” action. */
102 private Action projectCopyURIAction;
104 /** The “reset edition” action. */
105 private Action projectResetEditionAction;
107 /** The file chooser. */
108 private JFileChooser pathChooser;
110 /** The project list model. */
111 private SortedListModel<Project> projectListModel;
113 /** The project list scroll pane. */
114 private JScrollPane projectScrollPane;
116 /** The project list. */
117 private JList projectList;
119 /** The project name textfield. */
120 private JTextField projectNameTextField;
122 /** The project description textfield. */
123 private JTextField projectDescriptionTextField;
125 /** The local path textfield. */
126 private JTextField projectLocalPathTextField;
128 /** The textfield for the complete URI. */
129 private JTextField projectCompleteUriTextField;
131 /** The project path textfield. */
132 private JTextField projectPathTextField;
134 /** Whether the “copy URI to clipboard” action was used. */
135 private boolean uriCopied;
138 * Creates a new project page.
141 * The wizard this page belongs to
143 public ProjectPage(final TWizard wizard) {
145 setLayout(new BorderLayout(12, 12));
147 setHeading(I18n.getMessage("jsite.project.heading"));
148 setDescription(I18n.getMessage("jsite.project.description"));
150 I18nContainer.getInstance().registerRunnable(new Runnable() {
154 setHeading(I18n.getMessage("jsite.project.heading"));
155 setDescription(I18n.getMessage("jsite.project.description"));
161 * Initializes the page.
163 private void dialogInit() {
166 pathChooser = new JFileChooser();
167 projectListModel = new SortedListModel<Project>();
168 projectList = new JList(projectListModel);
169 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
170 projectList.addListSelectionListener(this);
172 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
173 projectScrollPane.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
174 add(createInformationPanel(), BorderLayout.CENTER);
181 public void pageAdded(TWizard wizard) {
182 super.pageAdded(wizard);
183 projectList.clearSelection();
184 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
185 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
186 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
187 this.wizard.setNextEnabled(false);
191 * Adds the given listener to the list of listeners.
194 * The listener to add
196 public void addListSelectionListener(ListSelectionListener listener) {
197 projectList.addListSelectionListener(listener);
201 * Removes the given listener from the list of listeners.
204 * The listener to remove
206 public void removeListSelectionListener(ListSelectionListener listener) {
207 projectList.removeListSelectionListener(listener);
211 * Creates all actions.
213 private void createActions() {
214 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
217 @SuppressWarnings("synthetic-access")
218 public void actionPerformed(ActionEvent actionEvent) {
219 actionLocalPathBrowse();
222 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
223 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
224 projectLocalPathBrowseAction.setEnabled(false);
226 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
229 @SuppressWarnings("synthetic-access")
230 public void actionPerformed(ActionEvent actionEvent) {
234 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
235 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
237 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
240 @SuppressWarnings("synthetic-access")
241 public void actionPerformed(ActionEvent actionEvent) {
245 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
246 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
247 projectDeleteAction.setEnabled(false);
249 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
252 @SuppressWarnings("synthetic-access")
253 public void actionPerformed(ActionEvent actionEvent) {
257 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
258 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
259 projectCloneAction.setEnabled(false);
261 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
264 @SuppressWarnings("synthetic-access")
265 public void actionPerformed(ActionEvent actionEvent) {
269 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
270 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
271 projectCopyURIAction.setEnabled(false);
273 projectManageKeysAction = new AbstractAction(I18n.getMessage("jsite.project.action.manage-keys")) {
276 @SuppressWarnings("synthetic-access")
277 public void actionPerformed(ActionEvent actionEvent) {
281 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
282 projectManageKeysAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
283 projectManageKeysAction.setEnabled(false);
285 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
288 @SuppressWarnings("synthetic-access")
289 public void actionPerformed(ActionEvent actionEvent) {
290 actionResetEdition();
293 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
294 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
295 projectResetEditionAction.setEnabled(false);
297 I18nContainer.getInstance().registerRunnable(new Runnable() {
300 @SuppressWarnings("synthetic-access")
302 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
303 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
304 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
305 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
306 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
307 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
308 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
309 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
310 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
311 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
312 projectManageKeysAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.manage-keys"));
313 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
314 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
315 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
316 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
322 * Creates the information panel.
324 * @return The information panel
326 private JComponent createInformationPanel() {
327 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
329 JPanel informationTable = new JPanel(new GridBagLayout());
331 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
332 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
333 functionButtons.add(new JButton(projectAddAction));
334 functionButtons.add(new JButton(projectDeleteAction));
335 functionButtons.add(new JButton(projectCloneAction));
336 functionButtons.add(new JButton(projectManageKeysAction));
338 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
339 informationPanel.add(informationTable, BorderLayout.CENTER);
341 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
342 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));
344 projectNameTextField = new JTextField();
345 projectNameTextField.getDocument().putProperty("name", "project.name");
346 projectNameTextField.getDocument().addDocumentListener(this);
347 projectNameTextField.setEnabled(false);
349 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
350 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));
351 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));
353 projectDescriptionTextField = new JTextField();
354 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
355 projectDescriptionTextField.getDocument().addDocumentListener(this);
356 projectDescriptionTextField.setEnabled(false);
358 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
359 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));
360 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));
362 projectLocalPathTextField = new JTextField();
363 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
364 projectLocalPathTextField.getDocument().addDocumentListener(this);
365 projectLocalPathTextField.setEnabled(false);
367 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
368 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));
369 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));
370 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));
372 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
373 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));
375 projectPathTextField = new JTextField();
376 projectPathTextField.getDocument().putProperty("name", "project.path");
377 projectPathTextField.getDocument().addDocumentListener(this);
378 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
384 @SuppressWarnings("synthetic-access")
385 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
386 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
394 @SuppressWarnings("synthetic-access")
395 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
396 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
404 @SuppressWarnings("synthetic-access")
405 public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
406 super.remove(fb, offset, length);
410 projectPathTextField.setEnabled(false);
412 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
413 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));
414 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));
416 projectCompleteUriTextField = new JTextField();
417 projectCompleteUriTextField.setEditable(false);
418 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
419 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));
420 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));
421 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));
423 I18nContainer.getInstance().registerRunnable(new Runnable() {
427 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
428 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
429 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
430 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
431 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
432 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
433 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
437 return informationPanel;
441 * Sets the project list.
444 * The list of projects
446 public void setProjects(List<Project> projects) {
447 projectListModel.clear();
448 for (Project project : projects) {
449 projectListModel.add(project);
454 * Returns the list of projects.
456 * @return The list of projects
458 public List<Project> getProjects() {
459 return projectListModel;
463 * Sets the freenet interface to use.
465 * @param freenetInterface
466 * The freenetInterface to use
468 public void setFreenetInterface(Freenet7Interface freenetInterface) {
469 this.freenetInterface = freenetInterface;
473 * Sets the web of trust interface to use.
475 * @param webOfTrustInterface
476 * The web of trust interface to use
478 public void setWebOfTrustInterface(WebOfTrustInterface webOfTrustInterface) {
479 this.webOfTrustInterface = webOfTrustInterface;
483 * Returns the currently selected project.
485 * @return The currently selected project
487 public Project getSelectedProject() {
488 return (Project) projectList.getSelectedValue();
492 * Returns whether the “copy URI to clipboard” button was used.
494 * @return {@code true} if the “copy URI to clipboard” button was used,
495 * {@code false} otherwise
497 public boolean wasUriCopied() {
502 * Updates the currently selected project with changed information from a
505 * @param documentEvent
506 * The document event to process
508 private void setTextField(DocumentEvent documentEvent) {
509 Document document = documentEvent.getDocument();
510 String propertyName = (String) document.getProperty("name");
511 Project project = (Project) projectList.getSelectedValue();
512 if (project == null) {
516 String text = document.getText(0, document.getLength()).trim();
517 if ("project.name".equals(propertyName)) {
518 project.setName(text);
519 projectList.repaint();
520 } else if ("project.description".equals(propertyName)) {
521 project.setDescription(text);
522 } else if ("project.localpath".equals(propertyName)) {
523 project.setLocalPath(text);
524 } else if ("project.privatekey".equals(propertyName)) {
525 project.setInsertURI(text);
526 } else if ("project.publickey".equals(propertyName)) {
527 project.setRequestURI(text);
528 } else if ("project.path".equals(propertyName)) {
529 project.setPath(text);
531 } catch (BadLocationException e) {
541 * Lets the user choose a local path for a project.
543 private void actionLocalPathBrowse() {
544 Project project = (Project) projectList.getSelectedValue();
545 if (project == null) {
548 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
549 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
550 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
555 * Adds a new project.
557 private void actionAdd() {
558 String[] keyPair = null;
559 if (!freenetInterface.hasNode()) {
560 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
564 keyPair = freenetInterface.generateKeyPair();
565 } catch (IOException ioe1) {
566 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
569 Project newProject = new Project();
570 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
571 newProject.setInsertURI(keyPair[0]);
572 newProject.setRequestURI(keyPair[1]);
573 newProject.setEdition(-1);
574 newProject.setPath("");
575 projectListModel.add(newProject);
576 projectScrollPane.revalidate();
577 projectScrollPane.repaint();
578 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
582 * Deletes the currently selected project.
584 private void actionDelete() {
585 int selectedIndex = projectList.getSelectedIndex();
586 if (selectedIndex > -1) {
587 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) {
588 projectListModel.remove(selectedIndex);
589 projectList.clearSelection();
590 if (projectListModel.getSize() != 0) {
591 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
598 * Clones the currently selected project.
600 private void actionClone() {
601 int selectedIndex = projectList.getSelectedIndex();
602 if (selectedIndex > -1) {
603 Project newProject = new Project((Project) projectList.getSelectedValue());
604 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
605 projectListModel.add(newProject);
606 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
611 * Copies the request URI of the currently selected project to the
614 private void actionCopyURI() {
615 int selectedIndex = projectList.getSelectedIndex();
616 if (selectedIndex > -1) {
617 Project selectedProject = (Project) projectList.getSelectedValue();
618 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
619 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
625 * Opens a {@link KeyDialog} and lets the user manipulate the keys of the
628 private void actionManageKeys() {
629 int selectedIndex = projectList.getSelectedIndex();
630 if (selectedIndex > -1) {
631 Project selectedProject = (Project) projectList.getSelectedValue();
632 KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard);
633 keyDialog.setPrivateKey(selectedProject.getInsertURI());
634 keyDialog.setPublicKey(selectedProject.getRequestURI());
635 keyDialog.setProjects(getProjects());
636 keyDialog.setOwnIdentities(webOfTrustInterface.getOwnIdentities());
637 keyDialog.setVisible(true);
638 if (!keyDialog.wasCancelled()) {
639 String originalPublicKey = selectedProject.getRequestURI();
640 String originalPrivateKey = selectedProject.getInsertURI();
641 selectedProject.setInsertURI(keyDialog.getPrivateKey());
642 selectedProject.setRequestURI(keyDialog.getPublicKey());
643 if (!originalPublicKey.equals(selectedProject.getRequestURI()) || !originalPrivateKey.equals(selectedProject.getInsertURI())) {
644 selectedProject.setEdition(-1);
645 for (Entry<String, FileOption> fileOption : selectedProject.getFileOptions().entrySet()) {
646 fileOption.getValue().setLastInsertHash(null);
655 * Resets the edition of the currently selected project.
657 private void actionResetEdition() {
658 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
661 int selectedIndex = projectList.getSelectedIndex();
662 if (selectedIndex > -1) {
663 Project selectedProject = (Project) projectList.getSelectedValue();
664 selectedProject.setEdition(-1);
670 * Updates the complete URI text field.
672 private void updateCompleteURI() {
673 int selectedIndex = projectList.getSelectedIndex();
674 if (selectedIndex > -1) {
675 Project selectedProject = (Project) projectList.getSelectedValue();
676 projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
681 // INTERFACE ListSelectionListener
688 public void valueChanged(ListSelectionEvent listSelectionEvent) {
689 int selectedRow = projectList.getSelectedIndex();
690 Project selectedProject = (Project) projectList.getSelectedValue();
691 projectNameTextField.setEnabled(selectedRow > -1);
692 projectDescriptionTextField.setEnabled(selectedRow > -1);
693 projectLocalPathTextField.setEnabled(selectedRow > -1);
694 projectPathTextField.setEnabled(selectedRow > -1);
695 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
696 projectDeleteAction.setEnabled(selectedRow > -1);
697 projectCloneAction.setEnabled(selectedRow > -1);
698 projectCopyURIAction.setEnabled(selectedRow > -1);
699 projectManageKeysAction.setEnabled(selectedRow > -1);
700 projectResetEditionAction.setEnabled(selectedRow > -1);
701 if (selectedRow > -1) {
702 projectNameTextField.setText(selectedProject.getName());
703 projectDescriptionTextField.setText(selectedProject.getDescription());
704 projectLocalPathTextField.setText(selectedProject.getLocalPath());
705 projectPathTextField.setText(selectedProject.getPath());
706 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
708 projectNameTextField.setText("");
709 projectDescriptionTextField.setText("");
710 projectLocalPathTextField.setText("");
711 projectPathTextField.setText("");
712 projectCompleteUriTextField.setText("");
717 // INTERFACE ChangeListener
721 // INTERFACE DocumentListener
728 public void insertUpdate(DocumentEvent documentEvent) {
729 setTextField(documentEvent);
736 public void removeUpdate(DocumentEvent documentEvent) {
737 setTextField(documentEvent);
744 public void changedUpdate(DocumentEvent documentEvent) {
745 setTextField(documentEvent);
749 // INTERFACE ClipboardOwner
756 public void lostOwnership(Clipboard clipboard, Transferable contents) {