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;
37 import javax.swing.AbstractAction;
38 import javax.swing.Action;
39 import javax.swing.JButton;
40 import javax.swing.JComponent;
41 import javax.swing.JFileChooser;
42 import javax.swing.JLabel;
43 import javax.swing.JList;
44 import javax.swing.JOptionPane;
45 import javax.swing.JPanel;
46 import javax.swing.JScrollPane;
47 import javax.swing.JTextField;
48 import javax.swing.ListSelectionModel;
49 import javax.swing.border.EmptyBorder;
50 import javax.swing.event.DocumentEvent;
51 import javax.swing.event.DocumentListener;
52 import javax.swing.event.ListSelectionEvent;
53 import javax.swing.event.ListSelectionListener;
54 import javax.swing.text.AbstractDocument;
55 import javax.swing.text.AttributeSet;
56 import javax.swing.text.BadLocationException;
57 import javax.swing.text.Document;
58 import javax.swing.text.DocumentFilter;
60 import de.todesbaum.jsite.application.Freenet7Interface;
61 import de.todesbaum.jsite.application.KeyDialog;
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 “manage keys” action. */
93 private Action projectManageKeysAction;
95 /** The “copy URI” action. */
96 private Action projectCopyURIAction;
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<Project> 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 textfield for the complete URI. */
123 private JTextField projectCompleteUriTextField;
125 /** The project path textfield. */
126 private JTextField projectPathTextField;
128 /** Whether the “copy URI to clipboard” action was used. */
129 private boolean uriCopied;
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() {
148 setHeading(I18n.getMessage("jsite.project.heading"));
149 setDescription(I18n.getMessage("jsite.project.description"));
155 * Initializes the page.
157 private void dialogInit() {
160 pathChooser = new JFileChooser();
161 projectListModel = new SortedListModel<Project>();
162 projectList = new JList(projectListModel);
163 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
164 projectList.addListSelectionListener(this);
166 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
167 projectScrollPane.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
168 add(createInformationPanel(), BorderLayout.CENTER);
175 public void pageAdded(TWizard wizard) {
176 super.pageAdded(wizard);
177 projectList.clearSelection();
178 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
179 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
180 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
181 this.wizard.setNextEnabled(false);
185 * Adds the given listener to the list of listeners.
188 * The listener to add
190 public void addListSelectionListener(ListSelectionListener listener) {
191 projectList.addListSelectionListener(listener);
195 * Removes the given listener from the list of listeners.
198 * The listener to remove
200 public void removeListSelectionListener(ListSelectionListener listener) {
201 projectList.removeListSelectionListener(listener);
205 * Creates all actions.
207 private void createActions() {
208 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
211 @SuppressWarnings("synthetic-access")
212 public void actionPerformed(ActionEvent actionEvent) {
213 actionLocalPathBrowse();
216 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
217 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
218 projectLocalPathBrowseAction.setEnabled(false);
220 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
223 @SuppressWarnings("synthetic-access")
224 public void actionPerformed(ActionEvent actionEvent) {
228 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
229 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
231 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
234 @SuppressWarnings("synthetic-access")
235 public void actionPerformed(ActionEvent actionEvent) {
239 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
240 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
241 projectDeleteAction.setEnabled(false);
243 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
246 @SuppressWarnings("synthetic-access")
247 public void actionPerformed(ActionEvent actionEvent) {
251 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
252 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
253 projectCloneAction.setEnabled(false);
255 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
258 @SuppressWarnings("synthetic-access")
259 public void actionPerformed(ActionEvent actionEvent) {
263 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
264 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
265 projectCopyURIAction.setEnabled(false);
267 projectManageKeysAction = new AbstractAction(I18n.getMessage("jsite.project.action.manage-keys")) {
270 @SuppressWarnings("synthetic-access")
271 public void actionPerformed(ActionEvent actionEvent) {
275 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
276 projectManageKeysAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
277 projectManageKeysAction.setEnabled(false);
279 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
282 @SuppressWarnings("synthetic-access")
283 public void actionPerformed(ActionEvent actionEvent) {
284 actionResetEdition();
287 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
288 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
289 projectResetEditionAction.setEnabled(false);
291 I18nContainer.getInstance().registerRunnable(new Runnable() {
294 @SuppressWarnings("synthetic-access")
296 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
297 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
298 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
299 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
300 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
301 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
302 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
303 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
304 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
305 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
306 projectManageKeysAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.manage-keys"));
307 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
308 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
309 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
310 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
316 * Creates the information panel.
318 * @return The information panel
320 private JComponent createInformationPanel() {
321 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
323 JPanel informationTable = new JPanel(new GridBagLayout());
325 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
326 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
327 functionButtons.add(new JButton(projectAddAction));
328 functionButtons.add(new JButton(projectDeleteAction));
329 functionButtons.add(new JButton(projectCloneAction));
330 functionButtons.add(new JButton(projectManageKeysAction));
332 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
333 informationPanel.add(informationTable, BorderLayout.CENTER);
335 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
336 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));
338 projectNameTextField = new JTextField();
339 projectNameTextField.getDocument().putProperty("name", "project.name");
340 projectNameTextField.getDocument().addDocumentListener(this);
341 projectNameTextField.setEnabled(false);
343 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
344 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));
345 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));
347 projectDescriptionTextField = new JTextField();
348 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
349 projectDescriptionTextField.getDocument().addDocumentListener(this);
350 projectDescriptionTextField.setEnabled(false);
352 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
353 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));
354 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));
356 projectLocalPathTextField = new JTextField();
357 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
358 projectLocalPathTextField.getDocument().addDocumentListener(this);
359 projectLocalPathTextField.setEnabled(false);
361 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
362 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));
363 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));
364 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));
366 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
367 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));
369 projectPathTextField = new JTextField();
370 projectPathTextField.getDocument().putProperty("name", "project.path");
371 projectPathTextField.getDocument().addDocumentListener(this);
372 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
378 @SuppressWarnings("synthetic-access")
379 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
380 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
388 @SuppressWarnings("synthetic-access")
389 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
390 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
398 @SuppressWarnings("synthetic-access")
399 public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
400 super.remove(fb, offset, length);
404 projectPathTextField.setEnabled(false);
406 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
407 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));
408 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));
410 projectCompleteUriTextField = new JTextField();
411 projectCompleteUriTextField.setEditable(false);
412 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
413 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));
414 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));
415 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));
417 I18nContainer.getInstance().registerRunnable(new Runnable() {
421 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
422 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
423 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
424 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
425 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
426 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
427 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
431 return informationPanel;
435 * Sets the project list.
438 * The list of projects
440 public void setProjects(Project[] projects) {
441 projectListModel.clear();
442 for (Project project : projects) {
443 projectListModel.add(project);
448 * Returns the list of projects.
450 * @return The list of projects
452 public Project[] getProjects() {
453 return projectListModel.toArray(new Project[projectListModel.size()]);
457 * Sets the freenet interface to use.
459 * @param freenetInterface
460 * The freenetInterface to use
462 public void setFreenetInterface(Freenet7Interface freenetInterface) {
463 this.freenetInterface = freenetInterface;
467 * Returns the currently selected project.
469 * @return The currently selected project
471 public Project getSelectedProject() {
472 return (Project) projectList.getSelectedValue();
476 * Returns whether the “copy URI to clipboard” button was used.
478 * @return {@code true} if the “copy URI to clipboard” button was used,
479 * {@code false} otherwise
481 public boolean wasUriCopied() {
486 * Updates the currently selected project with changed information from a
489 * @param documentEvent
490 * The document event to process
492 private void setTextField(DocumentEvent documentEvent) {
493 Document document = documentEvent.getDocument();
494 String propertyName = (String) document.getProperty("name");
495 Project project = (Project) projectList.getSelectedValue();
496 if (project == null) {
500 String text = document.getText(0, document.getLength()).trim();
501 if ("project.name".equals(propertyName)) {
502 project.setName(text);
503 projectList.repaint();
504 } else if ("project.description".equals(propertyName)) {
505 project.setDescription(text);
506 } else if ("project.localpath".equals(propertyName)) {
507 project.setLocalPath(text);
508 } else if ("project.privatekey".equals(propertyName)) {
509 project.setInsertURI(text);
510 } else if ("project.publickey".equals(propertyName)) {
511 project.setRequestURI(text);
512 } else if ("project.path".equals(propertyName)) {
513 project.setPath(text);
515 } catch (BadLocationException e) {
525 * Lets the user choose a local path for a project.
527 private void actionLocalPathBrowse() {
528 Project project = (Project) projectList.getSelectedValue();
529 if (project == null) {
532 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
533 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
534 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
539 * Adds a new project.
541 private void actionAdd() {
542 String[] keyPair = null;
543 if (!freenetInterface.hasNode()) {
544 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
548 keyPair = freenetInterface.generateKeyPair();
549 } catch (IOException ioe1) {
550 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
553 Project newProject = new Project();
554 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
555 newProject.setInsertURI(keyPair[0]);
556 newProject.setRequestURI(keyPair[1]);
557 newProject.setEdition(-1);
558 newProject.setPath("");
559 projectListModel.add(newProject);
560 projectScrollPane.revalidate();
561 projectScrollPane.repaint();
562 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
566 * Deletes the currently selected project.
568 private void actionDelete() {
569 int selectedIndex = projectList.getSelectedIndex();
570 if (selectedIndex > -1) {
571 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) {
572 projectListModel.remove(selectedIndex);
573 projectList.clearSelection();
574 if (projectListModel.getSize() != 0) {
575 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
582 * Clones the currently selected project.
584 private void actionClone() {
585 int selectedIndex = projectList.getSelectedIndex();
586 if (selectedIndex > -1) {
587 Project newProject = new Project((Project) projectList.getSelectedValue());
588 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
589 projectListModel.add(newProject);
590 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
595 * Copies the request URI of the currently selected project to the
598 private void actionCopyURI() {
599 int selectedIndex = projectList.getSelectedIndex();
600 if (selectedIndex > -1) {
601 Project selectedProject = (Project) projectList.getSelectedValue();
602 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
603 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
609 * Opens a {@link KeyDialog} and lets the user manipulate the keys of the
612 private void actionManageKeys() {
613 int selectedIndex = projectList.getSelectedIndex();
614 if (selectedIndex > -1) {
615 Project selectedProject = (Project) projectList.getSelectedValue();
616 KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard);
617 keyDialog.setPrivateKey(selectedProject.getInsertURI());
618 keyDialog.setPublicKey(selectedProject.getRequestURI());
619 keyDialog.setVisible(true);
620 if (!keyDialog.wasCancelled()) {
621 String originalPublicKey = selectedProject.getRequestURI();
622 String originalPrivateKey = selectedProject.getInsertURI();
623 selectedProject.setInsertURI(keyDialog.getPrivateKey());
624 selectedProject.setRequestURI(keyDialog.getPublicKey());
625 if (!originalPublicKey.equals(selectedProject.getRequestURI()) || !originalPrivateKey.equals(selectedProject.getInsertURI())) {
626 selectedProject.setEdition(-1);
634 * Resets the edition of the currently selected project.
636 private void actionResetEdition() {
637 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
640 int selectedIndex = projectList.getSelectedIndex();
641 if (selectedIndex > -1) {
642 Project selectedProject = (Project) projectList.getSelectedValue();
643 selectedProject.setEdition(-1);
649 * Updates the complete URI text field.
651 private void updateCompleteURI() {
652 int selectedIndex = projectList.getSelectedIndex();
653 if (selectedIndex > -1) {
654 Project selectedProject = (Project) projectList.getSelectedValue();
655 projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
660 // INTERFACE ListSelectionListener
667 public void valueChanged(ListSelectionEvent listSelectionEvent) {
668 int selectedRow = projectList.getSelectedIndex();
669 Project selectedProject = (Project) projectList.getSelectedValue();
670 projectNameTextField.setEnabled(selectedRow > -1);
671 projectDescriptionTextField.setEnabled(selectedRow > -1);
672 projectLocalPathTextField.setEnabled(selectedRow > -1);
673 projectPathTextField.setEnabled(selectedRow > -1);
674 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
675 projectDeleteAction.setEnabled(selectedRow > -1);
676 projectCloneAction.setEnabled(selectedRow > -1);
677 projectCopyURIAction.setEnabled(selectedRow > -1);
678 projectManageKeysAction.setEnabled(selectedRow > -1);
679 projectResetEditionAction.setEnabled(selectedRow > -1);
680 if (selectedRow > -1) {
681 projectNameTextField.setText(selectedProject.getName());
682 projectDescriptionTextField.setText(selectedProject.getDescription());
683 projectLocalPathTextField.setText(selectedProject.getLocalPath());
684 projectPathTextField.setText(selectedProject.getPath());
685 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
687 projectNameTextField.setText("");
688 projectDescriptionTextField.setText("");
689 projectLocalPathTextField.setText("");
690 projectPathTextField.setText("");
691 projectCompleteUriTextField.setText("");
696 // INTERFACE ChangeListener
700 // INTERFACE DocumentListener
707 public void insertUpdate(DocumentEvent documentEvent) {
708 setTextField(documentEvent);
715 public void removeUpdate(DocumentEvent documentEvent) {
716 setTextField(documentEvent);
723 public void changedUpdate(DocumentEvent documentEvent) {
724 setTextField(documentEvent);
728 // INTERFACE ClipboardOwner
735 public void lostOwnership(Clipboard clipboard, Transferable contents) {