2 * jSite - ProjectPage.java - Copyright © 2006â2011 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() {
147 setHeading(I18n.getMessage("jsite.project.heading"));
148 setDescription(I18n.getMessage("jsite.project.description"));
154 * Initializes the page.
156 private void dialogInit() {
159 pathChooser = new JFileChooser();
160 projectListModel = new SortedListModel<Project>();
161 projectList = new JList(projectListModel);
162 projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
163 projectList.addListSelectionListener(this);
165 add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
166 projectScrollPane.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
167 add(createInformationPanel(), BorderLayout.CENTER);
174 public void pageAdded(TWizard wizard) {
175 super.pageAdded(wizard);
176 projectList.clearSelection();
177 this.wizard.setPreviousName(I18n.getMessage("jsite.menu.nodes.manage-nodes"));
178 this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
179 this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
180 this.wizard.setNextEnabled(false);
184 * Adds the given listener to the list of listeners.
187 * The listener to add
189 public void addListSelectionListener(ListSelectionListener listener) {
190 projectList.addListSelectionListener(listener);
194 * Removes the given listener from the list of listeners.
197 * The listener to remove
199 public void removeListSelectionListener(ListSelectionListener listener) {
200 projectList.removeListSelectionListener(listener);
204 * Creates all actions.
206 private void createActions() {
207 projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
209 @SuppressWarnings("synthetic-access")
210 public void actionPerformed(ActionEvent actionEvent) {
211 actionLocalPathBrowse();
214 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
215 projectLocalPathBrowseAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B);
216 projectLocalPathBrowseAction.setEnabled(false);
218 projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) {
220 @SuppressWarnings("synthetic-access")
221 public void actionPerformed(ActionEvent actionEvent) {
225 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
226 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
228 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
230 @SuppressWarnings("synthetic-access")
231 public void actionPerformed(ActionEvent actionEvent) {
235 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
236 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
237 projectDeleteAction.setEnabled(false);
239 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
241 @SuppressWarnings("synthetic-access")
242 public void actionPerformed(ActionEvent actionEvent) {
246 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
247 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
248 projectCloneAction.setEnabled(false);
250 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
252 @SuppressWarnings("synthetic-access")
253 public void actionPerformed(ActionEvent actionEvent) {
257 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
258 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
259 projectCopyURIAction.setEnabled(false);
261 projectManageKeysAction = new AbstractAction(I18n.getMessage("jsite.project.action.manage-keys")) {
263 @SuppressWarnings("synthetic-access")
264 public void actionPerformed(ActionEvent actionEvent) {
268 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
269 projectManageKeysAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
270 projectManageKeysAction.setEnabled(false);
272 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
274 @SuppressWarnings("synthetic-access")
275 public void actionPerformed(ActionEvent actionEvent) {
276 actionResetEdition();
279 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
280 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
281 projectResetEditionAction.setEnabled(false);
283 I18nContainer.getInstance().registerRunnable(new Runnable() {
285 @SuppressWarnings("synthetic-access")
287 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
288 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
289 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
290 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
291 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
292 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
293 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
294 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
295 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
296 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
297 projectManageKeysAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.manage-keys"));
298 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
299 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
300 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
301 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
307 * Creates the information panel.
309 * @return The information panel
311 private JComponent createInformationPanel() {
312 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
314 JPanel informationTable = new JPanel(new GridBagLayout());
316 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
317 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
318 functionButtons.add(new JButton(projectAddAction));
319 functionButtons.add(new JButton(projectDeleteAction));
320 functionButtons.add(new JButton(projectCloneAction));
321 functionButtons.add(new JButton(projectManageKeysAction));
323 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
324 informationPanel.add(informationTable, BorderLayout.CENTER);
326 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
327 informationTable.add(projectInformationLabel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
329 projectNameTextField = new JTextField();
330 projectNameTextField.getDocument().putProperty("name", "project.name");
331 projectNameTextField.getDocument().addDocumentListener(this);
332 projectNameTextField.setEnabled(false);
334 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
335 informationTable.add(projectNameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
336 informationTable.add(projectNameTextField, new GridBagConstraints(1, 1, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
338 projectDescriptionTextField = new JTextField();
339 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
340 projectDescriptionTextField.getDocument().addDocumentListener(this);
341 projectDescriptionTextField.setEnabled(false);
343 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
344 informationTable.add(projectDescriptionLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
345 informationTable.add(projectDescriptionTextField, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
347 projectLocalPathTextField = new JTextField();
348 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
349 projectLocalPathTextField.getDocument().addDocumentListener(this);
350 projectLocalPathTextField.setEnabled(false);
352 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
353 informationTable.add(projectLocalPathLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0));
354 informationTable.add(projectLocalPathTextField, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
355 informationTable.add(new JButton(projectLocalPathBrowseAction), new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0));
357 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
358 informationTable.add(projectAddressLabel, new GridBagConstraints(0, 4, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
360 projectPathTextField = new JTextField();
361 projectPathTextField.getDocument().putProperty("name", "project.path");
362 projectPathTextField.getDocument().addDocumentListener(this);
363 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
369 @SuppressWarnings("synthetic-access")
370 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
371 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
379 @SuppressWarnings("synthetic-access")
380 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
381 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
389 @SuppressWarnings("synthetic-access")
390 public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
391 super.remove(fb, offset, length);
395 projectPathTextField.setEnabled(false);
397 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
398 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));
399 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));
401 projectCompleteUriTextField = new JTextField();
402 projectCompleteUriTextField.setEditable(false);
403 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
404 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));
405 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));
406 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));
408 I18nContainer.getInstance().registerRunnable(new Runnable() {
411 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
412 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
413 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
414 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
415 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
416 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
417 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
421 return informationPanel;
425 * Sets the project list.
428 * The list of projects
430 public void setProjects(Project[] projects) {
431 projectListModel.clear();
432 for (Project project : projects) {
433 projectListModel.add(project);
438 * Returns the list of projects.
440 * @return The list of projects
442 public Project[] getProjects() {
443 return projectListModel.toArray(new Project[projectListModel.size()]);
447 * Sets the freenet interface to use.
449 * @param freenetInterface
450 * The freenetInterface to use
452 public void setFreenetInterface(Freenet7Interface freenetInterface) {
453 this.freenetInterface = freenetInterface;
457 * Returns the currently selected project.
459 * @return The currently selected project
461 public Project getSelectedProject() {
462 return (Project) projectList.getSelectedValue();
466 * Returns whether the âcopy URI to clipboardâ button was used.
468 * @return {@code true} if the âcopy URI to clipboardâ button was used,
469 * {@code false} otherwise
471 public boolean wasUriCopied() {
476 * Updates the currently selected project with changed information from a
479 * @param documentEvent
480 * The document event to process
482 private void setTextField(DocumentEvent documentEvent) {
483 Document document = documentEvent.getDocument();
484 String propertyName = (String) document.getProperty("name");
485 Project project = (Project) projectList.getSelectedValue();
486 if (project == null) {
490 String text = document.getText(0, document.getLength()).trim();
491 if ("project.name".equals(propertyName)) {
492 project.setName(text);
493 projectList.repaint();
494 } else if ("project.description".equals(propertyName)) {
495 project.setDescription(text);
496 } else if ("project.localpath".equals(propertyName)) {
497 project.setLocalPath(text);
498 } else if ("project.privatekey".equals(propertyName)) {
499 project.setInsertURI(text);
500 } else if ("project.publickey".equals(propertyName)) {
501 project.setRequestURI(text);
502 } else if ("project.path".equals(propertyName)) {
503 project.setPath(text);
505 } catch (BadLocationException e) {
515 * Lets the user choose a local path for a project.
517 private void actionLocalPathBrowse() {
518 Project project = (Project) projectList.getSelectedValue();
519 if (project == null) {
522 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
523 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
524 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
529 * Adds a new project.
531 private void actionAdd() {
532 String[] keyPair = null;
533 if (!freenetInterface.hasNode()) {
534 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
538 keyPair = freenetInterface.generateKeyPair();
539 } catch (IOException ioe1) {
540 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
543 Project newProject = new Project();
544 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
545 newProject.setInsertURI(keyPair[0]);
546 newProject.setRequestURI(keyPair[1]);
547 newProject.setEdition(-1);
548 newProject.setPath("");
549 projectListModel.add(newProject);
550 projectScrollPane.revalidate();
551 projectScrollPane.repaint();
552 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
556 * Deletes the currently selected project.
558 private void actionDelete() {
559 int selectedIndex = projectList.getSelectedIndex();
560 if (selectedIndex > -1) {
561 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) {
562 projectListModel.remove(selectedIndex);
563 projectList.clearSelection();
564 if (projectListModel.getSize() != 0) {
565 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
572 * Clones the currently selected project.
574 private void actionClone() {
575 int selectedIndex = projectList.getSelectedIndex();
576 if (selectedIndex > -1) {
577 Project newProject = new Project((Project) projectList.getSelectedValue());
578 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
579 projectListModel.add(newProject);
580 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
585 * Copies the request URI of the currently selected project to the
588 private void actionCopyURI() {
589 int selectedIndex = projectList.getSelectedIndex();
590 if (selectedIndex > -1) {
591 Project selectedProject = (Project) projectList.getSelectedValue();
592 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
593 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
599 * Opens a {@link KeyDialog} and lets the user manipulate the keys of the
602 private void actionManageKeys() {
603 int selectedIndex = projectList.getSelectedIndex();
604 if (selectedIndex > -1) {
605 Project selectedProject = (Project) projectList.getSelectedValue();
606 KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard);
607 keyDialog.setPrivateKey(selectedProject.getInsertURI());
608 keyDialog.setPublicKey(selectedProject.getRequestURI());
609 keyDialog.setVisible(true);
610 if (!keyDialog.wasCancelled()) {
611 String originalPublicKey = selectedProject.getRequestURI();
612 String originalPrivateKey = selectedProject.getInsertURI();
613 selectedProject.setInsertURI(keyDialog.getPrivateKey());
614 selectedProject.setRequestURI(keyDialog.getPublicKey());
615 if (!originalPublicKey.equals(selectedProject.getRequestURI()) || !originalPrivateKey.equals(selectedProject.getInsertURI())) {
616 selectedProject.setEdition(-1);
624 * Resets the edition of the currently selected project.
626 private void actionResetEdition() {
627 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
630 int selectedIndex = projectList.getSelectedIndex();
631 if (selectedIndex > -1) {
632 Project selectedProject = (Project) projectList.getSelectedValue();
633 selectedProject.setEdition(-1);
639 * Updates the complete URI text field.
641 private void updateCompleteURI() {
642 int selectedIndex = projectList.getSelectedIndex();
643 if (selectedIndex > -1) {
644 Project selectedProject = (Project) projectList.getSelectedValue();
645 projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
650 // INTERFACE ListSelectionListener
656 public void valueChanged(ListSelectionEvent listSelectionEvent) {
657 int selectedRow = projectList.getSelectedIndex();
658 Project selectedProject = (Project) projectList.getSelectedValue();
659 projectNameTextField.setEnabled(selectedRow > -1);
660 projectDescriptionTextField.setEnabled(selectedRow > -1);
661 projectLocalPathTextField.setEnabled(selectedRow > -1);
662 projectPathTextField.setEnabled(selectedRow > -1);
663 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
664 projectDeleteAction.setEnabled(selectedRow > -1);
665 projectCloneAction.setEnabled(selectedRow > -1);
666 projectCopyURIAction.setEnabled(selectedRow > -1);
667 projectManageKeysAction.setEnabled(selectedRow > -1);
668 projectResetEditionAction.setEnabled(selectedRow > -1);
669 if (selectedRow > -1) {
670 projectNameTextField.setText(selectedProject.getName());
671 projectDescriptionTextField.setText(selectedProject.getDescription());
672 projectLocalPathTextField.setText(selectedProject.getLocalPath());
673 projectPathTextField.setText(selectedProject.getPath());
674 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
676 projectNameTextField.setText("");
677 projectDescriptionTextField.setText("");
678 projectLocalPathTextField.setText("");
679 projectPathTextField.setText("");
680 projectCompleteUriTextField.setText("");
685 // INTERFACE ChangeListener
689 // INTERFACE DocumentListener
695 public void insertUpdate(DocumentEvent documentEvent) {
696 setTextField(documentEvent);
702 public void removeUpdate(DocumentEvent documentEvent) {
703 setTextField(documentEvent);
709 public void changedUpdate(DocumentEvent documentEvent) {
710 setTextField(documentEvent);
714 // INTERFACE ClipboardOwner
720 public void lostOwnership(Clipboard clipboard, Transferable contents) {