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.KeyDialog;
63 import de.todesbaum.jsite.application.Project;
64 import de.todesbaum.jsite.i18n.I18n;
65 import de.todesbaum.jsite.i18n.I18nContainer;
66 import de.todesbaum.util.swing.SortedListModel;
67 import de.todesbaum.util.swing.TLabel;
68 import de.todesbaum.util.swing.TWizard;
69 import de.todesbaum.util.swing.TWizardPage;
72 * Wizard page that lets the user manage his projects and start inserts.
74 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
76 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
78 /** The freenet interface. */
79 private Freenet7Interface freenetInterface;
81 /** The “browse” action. */
82 private Action projectLocalPathBrowseAction;
84 /** The “add project” action. */
85 private Action projectAddAction;
87 /** The “delete project” action. */
88 private Action projectDeleteAction;
90 /** The “clone project” action. */
91 private Action projectCloneAction;
93 /** The “manage keys” action. */
94 private Action projectManageKeysAction;
96 /** The “copy URI” action. */
97 private Action projectCopyURIAction;
99 /** The “reset edition” action. */
100 private Action projectResetEditionAction;
102 /** The file chooser. */
103 private JFileChooser pathChooser;
105 /** The project list model. */
106 private SortedListModel<Project> projectListModel;
108 /** The project list scroll pane. */
109 private JScrollPane projectScrollPane;
111 /** The project list. */
112 private JList projectList;
114 /** The project name textfield. */
115 private JTextField projectNameTextField;
117 /** The project description textfield. */
118 private JTextField projectDescriptionTextField;
120 /** The local path textfield. */
121 private JTextField projectLocalPathTextField;
123 /** The textfield for the complete URI. */
124 private JTextField projectCompleteUriTextField;
126 /** The project path textfield. */
127 private JTextField projectPathTextField;
129 /** Whether the “copy URI to clipboard” action was used. */
130 private boolean uriCopied;
133 * Creates a new project page.
136 * The wizard this page belongs to
138 public ProjectPage(final TWizard wizard) {
140 setLayout(new BorderLayout(12, 12));
142 setHeading(I18n.getMessage("jsite.project.heading"));
143 setDescription(I18n.getMessage("jsite.project.description"));
145 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")) {
210 @SuppressWarnings("synthetic-access")
211 public void actionPerformed(ActionEvent actionEvent) {
212 actionLocalPathBrowse();
215 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
216 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
217 projectLocalPathBrowseAction.setEnabled(false);
219 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
221 @SuppressWarnings("synthetic-access")
222 public void actionPerformed(ActionEvent actionEvent) {
226 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
227 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
229 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
231 @SuppressWarnings("synthetic-access")
232 public void actionPerformed(ActionEvent actionEvent) {
236 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
237 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
238 projectDeleteAction.setEnabled(false);
240 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
242 @SuppressWarnings("synthetic-access")
243 public void actionPerformed(ActionEvent actionEvent) {
247 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
248 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
249 projectCloneAction.setEnabled(false);
251 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
253 @SuppressWarnings("synthetic-access")
254 public void actionPerformed(ActionEvent actionEvent) {
258 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
259 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
260 projectCopyURIAction.setEnabled(false);
262 projectManageKeysAction = new AbstractAction(I18n.getMessage("jsite.project.action.manage-keys")) {
264 @SuppressWarnings("synthetic-access")
265 public void actionPerformed(ActionEvent actionEvent) {
269 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
270 projectManageKeysAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
271 projectManageKeysAction.setEnabled(false);
273 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
275 @SuppressWarnings("synthetic-access")
276 public void actionPerformed(ActionEvent actionEvent) {
277 actionResetEdition();
280 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
281 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
282 projectResetEditionAction.setEnabled(false);
284 I18nContainer.getInstance().registerRunnable(new Runnable() {
286 @SuppressWarnings("synthetic-access")
288 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
289 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
290 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
291 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
292 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
293 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
294 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
295 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
296 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
297 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
298 projectManageKeysAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.manage-keys"));
299 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
300 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
301 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
302 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
308 * Creates the information panel.
310 * @return The information panel
312 private JComponent createInformationPanel() {
313 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
315 JPanel informationTable = new JPanel(new GridBagLayout());
317 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
318 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
319 functionButtons.add(new JButton(projectAddAction));
320 functionButtons.add(new JButton(projectDeleteAction));
321 functionButtons.add(new JButton(projectCloneAction));
322 functionButtons.add(new JButton(projectManageKeysAction));
324 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
325 informationPanel.add(informationTable, BorderLayout.CENTER);
327 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
328 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));
330 projectNameTextField = new JTextField();
331 projectNameTextField.getDocument().putProperty("name", "project.name");
332 projectNameTextField.getDocument().addDocumentListener(this);
333 projectNameTextField.setEnabled(false);
335 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
336 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));
337 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));
339 projectDescriptionTextField = new JTextField();
340 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
341 projectDescriptionTextField.getDocument().addDocumentListener(this);
342 projectDescriptionTextField.setEnabled(false);
344 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
345 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));
346 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));
348 projectLocalPathTextField = new JTextField();
349 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
350 projectLocalPathTextField.getDocument().addDocumentListener(this);
351 projectLocalPathTextField.setEnabled(false);
353 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
354 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));
355 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));
356 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));
358 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
359 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));
361 projectPathTextField = new JTextField();
362 projectPathTextField.getDocument().putProperty("name", "project.path");
363 projectPathTextField.getDocument().addDocumentListener(this);
364 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
370 @SuppressWarnings("synthetic-access")
371 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
372 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
380 @SuppressWarnings("synthetic-access")
381 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
382 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
390 @SuppressWarnings("synthetic-access")
391 public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
392 super.remove(fb, offset, length);
396 projectPathTextField.setEnabled(false);
398 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
399 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));
400 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));
402 projectCompleteUriTextField = new JTextField();
403 projectCompleteUriTextField.setEditable(false);
404 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
405 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));
406 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));
407 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));
409 I18nContainer.getInstance().registerRunnable(new Runnable() {
412 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
413 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
414 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
415 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
416 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
417 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
418 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
422 return informationPanel;
426 * Sets the project list.
429 * The list of projects
431 public void setProjects(Project[] projects) {
432 projectListModel.clear();
433 for (Project project : projects) {
434 projectListModel.add(project);
439 * Returns the list of projects.
441 * @return The list of projects
443 public Project[] getProjects() {
444 return projectListModel.toArray(new Project[projectListModel.size()]);
448 * Sets the freenet interface to use.
450 * @param freenetInterface
451 * The freenetInterface to use
453 public void setFreenetInterface(Freenet7Interface freenetInterface) {
454 this.freenetInterface = freenetInterface;
458 * Returns the currently selected project.
460 * @return The currently selected project
462 public Project getSelectedProject() {
463 return (Project) projectList.getSelectedValue();
467 * Returns whether the “copy URI to clipboard” button was used.
469 * @return {@code true} if the “copy URI to clipboard” button was used,
470 * {@code false} otherwise
472 public boolean wasUriCopied() {
477 * Updates the currently selected project with changed information from a
480 * @param documentEvent
481 * The document event to process
483 private void setTextField(DocumentEvent documentEvent) {
484 Document document = documentEvent.getDocument();
485 String propertyName = (String) document.getProperty("name");
486 Project project = (Project) projectList.getSelectedValue();
487 if (project == null) {
491 String text = document.getText(0, document.getLength()).trim();
492 if ("project.name".equals(propertyName)) {
493 project.setName(text);
494 projectList.repaint();
495 } else if ("project.description".equals(propertyName)) {
496 project.setDescription(text);
497 } else if ("project.localpath".equals(propertyName)) {
498 project.setLocalPath(text);
499 } else if ("project.privatekey".equals(propertyName)) {
500 project.setInsertURI(text);
501 } else if ("project.publickey".equals(propertyName)) {
502 project.setRequestURI(text);
503 } else if ("project.path".equals(propertyName)) {
504 project.setPath(text);
506 } catch (BadLocationException e) {
516 * Lets the user choose a local path for a project.
518 private void actionLocalPathBrowse() {
519 Project project = (Project) projectList.getSelectedValue();
520 if (project == null) {
523 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
524 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
525 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
530 * Adds a new project.
532 private void actionAdd() {
533 String[] keyPair = null;
534 if (!freenetInterface.hasNode()) {
535 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
539 keyPair = freenetInterface.generateKeyPair();
540 } catch (IOException ioe1) {
541 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
544 Project newProject = new Project();
545 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
546 newProject.setInsertURI(keyPair[0]);
547 newProject.setRequestURI(keyPair[1]);
548 newProject.setEdition(-1);
549 newProject.setPath("");
550 projectListModel.add(newProject);
551 projectScrollPane.revalidate();
552 projectScrollPane.repaint();
553 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
557 * Deletes the currently selected project.
559 private void actionDelete() {
560 int selectedIndex = projectList.getSelectedIndex();
561 if (selectedIndex > -1) {
562 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) {
563 projectListModel.remove(selectedIndex);
564 projectList.clearSelection();
565 if (projectListModel.getSize() != 0) {
566 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
573 * Clones the currently selected project.
575 private void actionClone() {
576 int selectedIndex = projectList.getSelectedIndex();
577 if (selectedIndex > -1) {
578 Project newProject = new Project((Project) projectList.getSelectedValue());
579 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
580 projectListModel.add(newProject);
581 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
586 * Copies the request URI of the currently selected project to the
589 private void actionCopyURI() {
590 int selectedIndex = projectList.getSelectedIndex();
591 if (selectedIndex > -1) {
592 Project selectedProject = (Project) projectList.getSelectedValue();
593 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
594 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
600 * Opens a {@link KeyDialog} and lets the user manipulate the keys of the
603 private void actionManageKeys() {
604 int selectedIndex = projectList.getSelectedIndex();
605 if (selectedIndex > -1) {
606 Project selectedProject = (Project) projectList.getSelectedValue();
607 KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard);
608 keyDialog.setPrivateKey(selectedProject.getInsertURI());
609 keyDialog.setPublicKey(selectedProject.getRequestURI());
610 keyDialog.setVisible(true);
611 if (!keyDialog.wasCancelled()) {
612 selectedProject.setInsertURI(keyDialog.getPrivateKey());
613 selectedProject.setRequestURI(keyDialog.getPublicKey());
620 * Resets the edition of the currently selected project.
622 private void actionResetEdition() {
623 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
626 int selectedIndex = projectList.getSelectedIndex();
627 if (selectedIndex > -1) {
628 Project selectedProject = (Project) projectList.getSelectedValue();
629 selectedProject.setEdition(-1);
635 * Updates the complete URI text field.
637 private void updateCompleteURI() {
638 int selectedIndex = projectList.getSelectedIndex();
639 if (selectedIndex > -1) {
640 Project selectedProject = (Project) projectList.getSelectedValue();
641 projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
646 // INTERFACE ListSelectionListener
652 public void valueChanged(ListSelectionEvent listSelectionEvent) {
653 int selectedRow = projectList.getSelectedIndex();
654 Project selectedProject = (Project) projectList.getSelectedValue();
655 projectNameTextField.setEnabled(selectedRow > -1);
656 projectDescriptionTextField.setEnabled(selectedRow > -1);
657 projectLocalPathTextField.setEnabled(selectedRow > -1);
658 projectPathTextField.setEnabled(selectedRow > -1);
659 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
660 projectDeleteAction.setEnabled(selectedRow > -1);
661 projectCloneAction.setEnabled(selectedRow > -1);
662 projectCopyURIAction.setEnabled(selectedRow > -1);
663 projectManageKeysAction.setEnabled(selectedRow > -1);
664 projectResetEditionAction.setEnabled(selectedRow > -1);
665 if (selectedRow > -1) {
666 projectNameTextField.setText(selectedProject.getName());
667 projectDescriptionTextField.setText(selectedProject.getDescription());
668 projectLocalPathTextField.setText(selectedProject.getLocalPath());
669 projectPathTextField.setText(selectedProject.getPath());
670 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
672 projectNameTextField.setText("");
673 projectDescriptionTextField.setText("");
674 projectLocalPathTextField.setText("");
675 projectPathTextField.setText("");
676 projectCompleteUriTextField.setText("");
681 // INTERFACE ChangeListener
685 // INTERFACE DocumentListener
691 public void insertUpdate(DocumentEvent documentEvent) {
692 setTextField(documentEvent);
698 public void removeUpdate(DocumentEvent documentEvent) {
699 setTextField(documentEvent);
705 public void changedUpdate(DocumentEvent documentEvent) {
706 setTextField(documentEvent);
710 // INTERFACE ClipboardOwner
716 public void lostOwnership(Clipboard clipboard, Transferable contents) {