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 net.pterodactylus.util.swing.SortedListModel;
61 import de.todesbaum.jsite.application.Freenet7Interface;
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.TLabel;
66 import de.todesbaum.util.swing.TWizard;
67 import de.todesbaum.util.swing.TWizardPage;
70 * Wizard page that lets the user manage his projects and start inserts.
72 * @author David âBombeâ Roden <bombe@freenetproject.org>
74 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
76 /** The freenet interface. */
77 private Freenet7Interface freenetInterface;
79 /** The âbrowseâ action. */
80 private Action projectLocalPathBrowseAction;
82 /** The âadd projectâ action. */
83 private Action projectAddAction;
85 /** The âdelete projectâ action. */
86 private Action projectDeleteAction;
88 /** The âclone projectâ action. */
89 private Action projectCloneAction;
91 /** The âmanage keysâ action. */
92 private Action projectManageKeysAction;
94 /** The âcopy URIâ action. */
95 private Action projectCopyURIAction;
97 /** The âreset editionâ action. */
98 private Action projectResetEditionAction;
100 /** The file chooser. */
101 private JFileChooser pathChooser;
103 /** The project list model. */
104 private SortedListModel<Project> projectListModel;
106 /** The project list scroll pane. */
107 private JScrollPane projectScrollPane;
109 /** The project list. */
110 private JList projectList;
112 /** The project name textfield. */
113 private JTextField projectNameTextField;
115 /** The project description textfield. */
116 private JTextField projectDescriptionTextField;
118 /** The local path textfield. */
119 private JTextField projectLocalPathTextField;
121 /** The textfield for the complete URI. */
122 private JTextField projectCompleteUriTextField;
124 /** The project path textfield. */
125 private JTextField projectPathTextField;
127 /** Whether the âcopy URI to clipboardâ action was used. */
128 private boolean uriCopied;
131 * Creates a new project page.
134 * The wizard this page belongs to
136 public ProjectPage(final TWizard wizard) {
138 setLayout(new BorderLayout(12, 12));
140 setHeading(I18n.getMessage("jsite.project.heading"));
141 setDescription(I18n.getMessage("jsite.project.description"));
143 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")) {
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")) {
222 @SuppressWarnings("synthetic-access")
223 public void actionPerformed(ActionEvent actionEvent) {
227 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
228 projectAddAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
230 projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) {
233 @SuppressWarnings("synthetic-access")
234 public void actionPerformed(ActionEvent actionEvent) {
238 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
239 projectDeleteAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
240 projectDeleteAction.setEnabled(false);
242 projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) {
245 @SuppressWarnings("synthetic-access")
246 public void actionPerformed(ActionEvent actionEvent) {
250 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
251 projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
252 projectCloneAction.setEnabled(false);
254 projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) {
257 @SuppressWarnings("synthetic-access")
258 public void actionPerformed(ActionEvent actionEvent) {
262 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
263 projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U);
264 projectCopyURIAction.setEnabled(false);
266 projectManageKeysAction = new AbstractAction(I18n.getMessage("jsite.project.action.manage-keys")) {
269 @SuppressWarnings("synthetic-access")
270 public void actionPerformed(ActionEvent actionEvent) {
274 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
275 projectManageKeysAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
276 projectManageKeysAction.setEnabled(false);
278 projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) {
281 @SuppressWarnings("synthetic-access")
282 public void actionPerformed(ActionEvent actionEvent) {
283 actionResetEdition();
286 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
287 projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R);
288 projectResetEditionAction.setEnabled(false);
290 I18nContainer.getInstance().registerRunnable(new Runnable() {
293 @SuppressWarnings("synthetic-access")
295 projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse"));
296 projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip"));
297 projectAddAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.add-project"));
298 projectAddAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.add-project.tooltip"));
299 projectDeleteAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.delete-project"));
300 projectDeleteAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.delete-project.tooltip"));
301 projectCloneAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.clone-project"));
302 projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip"));
303 projectCopyURIAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.copy-uri"));
304 projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip"));
305 projectManageKeysAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.manage-keys"));
306 projectManageKeysAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.manage-keys.tooltip"));
307 projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition"));
308 projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip"));
309 pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
315 * Creates the information panel.
317 * @return The information panel
319 private JComponent createInformationPanel() {
320 JPanel informationPanel = new JPanel(new BorderLayout(12, 12));
322 JPanel informationTable = new JPanel(new GridBagLayout());
324 JPanel functionButtons = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12));
325 functionButtons.setBorder(new EmptyBorder(-12, -12, -12, -12));
326 functionButtons.add(new JButton(projectAddAction));
327 functionButtons.add(new JButton(projectDeleteAction));
328 functionButtons.add(new JButton(projectCloneAction));
329 functionButtons.add(new JButton(projectManageKeysAction));
331 informationPanel.add(functionButtons, BorderLayout.PAGE_START);
332 informationPanel.add(informationTable, BorderLayout.CENTER);
334 final JLabel projectInformationLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
335 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));
337 projectNameTextField = new JTextField();
338 projectNameTextField.getDocument().putProperty("name", "project.name");
339 projectNameTextField.getDocument().addDocumentListener(this);
340 projectNameTextField.setEnabled(false);
342 final TLabel projectNameLabel = new TLabel(I18n.getMessage("jsite.project.project.name") + ":", KeyEvent.VK_N, projectNameTextField);
343 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));
344 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));
346 projectDescriptionTextField = new JTextField();
347 projectDescriptionTextField.getDocument().putProperty("name", "project.description");
348 projectDescriptionTextField.getDocument().addDocumentListener(this);
349 projectDescriptionTextField.setEnabled(false);
351 final TLabel projectDescriptionLabel = new TLabel(I18n.getMessage("jsite.project.project.description") + ":", KeyEvent.VK_D, projectDescriptionTextField);
352 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));
353 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));
355 projectLocalPathTextField = new JTextField();
356 projectLocalPathTextField.getDocument().putProperty("name", "project.localpath");
357 projectLocalPathTextField.getDocument().addDocumentListener(this);
358 projectLocalPathTextField.setEnabled(false);
360 final TLabel projectLocalPathLabel = new TLabel(I18n.getMessage("jsite.project.project.local-path") + ":", KeyEvent.VK_L, projectLocalPathTextField);
361 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));
362 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));
363 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));
365 final JLabel projectAddressLabel = new JLabel("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
366 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));
368 projectPathTextField = new JTextField();
369 projectPathTextField.getDocument().putProperty("name", "project.path");
370 projectPathTextField.getDocument().addDocumentListener(this);
371 ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() {
377 @SuppressWarnings("synthetic-access")
378 public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
379 super.insertString(fb, offset, string.replaceAll("/", ""), attr);
387 @SuppressWarnings("synthetic-access")
388 public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
389 super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
397 @SuppressWarnings("synthetic-access")
398 public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
399 super.remove(fb, offset, length);
403 projectPathTextField.setEnabled(false);
405 final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField);
406 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));
407 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));
409 projectCompleteUriTextField = new JTextField();
410 projectCompleteUriTextField.setEditable(false);
411 final TLabel projectUriLabel = new TLabel(I18n.getMessage("jsite.project.project.uri") + ":", KeyEvent.VK_U, projectCompleteUriTextField);
412 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));
413 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));
414 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));
416 I18nContainer.getInstance().registerRunnable(new Runnable() {
420 projectInformationLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.information") + "</b></html>");
421 projectNameLabel.setText(I18n.getMessage("jsite.project.project.name") + ":");
422 projectDescriptionLabel.setText(I18n.getMessage("jsite.project.project.description") + ":");
423 projectLocalPathLabel.setText(I18n.getMessage("jsite.project.project.local-path") + ":");
424 projectAddressLabel.setText("<html><b>" + I18n.getMessage("jsite.project.project.address") + "</b></html>");
425 projectPathLabel.setText(I18n.getMessage("jsite.project.project.path") + ":");
426 projectUriLabel.setText(I18n.getMessage("jsite.project.project.uri") + ":");
430 return informationPanel;
434 * Sets the project list.
437 * The list of projects
439 public void setProjects(Project[] projects) {
440 projectListModel.clear();
441 for (Project project : projects) {
442 projectListModel.add(project);
447 * Returns the list of projects.
449 * @return The list of projects
451 public Project[] getProjects() {
452 return projectListModel.toArray(new Project[projectListModel.size()]);
456 * Sets the freenet interface to use.
458 * @param freenetInterface
459 * The freenetInterface to use
461 public void setFreenetInterface(Freenet7Interface freenetInterface) {
462 this.freenetInterface = freenetInterface;
466 * Returns the currently selected project.
468 * @return The currently selected project
470 public Project getSelectedProject() {
471 return (Project) projectList.getSelectedValue();
475 * Returns whether the âcopy URI to clipboardâ button was used.
477 * @return {@code true} if the âcopy URI to clipboardâ button was used,
478 * {@code false} otherwise
480 public boolean wasUriCopied() {
485 * Updates the currently selected project with changed information from a
488 * @param documentEvent
489 * The document event to process
491 private void setTextField(DocumentEvent documentEvent) {
492 Document document = documentEvent.getDocument();
493 String propertyName = (String) document.getProperty("name");
494 Project project = (Project) projectList.getSelectedValue();
495 if (project == null) {
499 String text = document.getText(0, document.getLength()).trim();
500 if ("project.name".equals(propertyName)) {
501 project.setName(text);
502 projectList.repaint();
503 } else if ("project.description".equals(propertyName)) {
504 project.setDescription(text);
505 } else if ("project.localpath".equals(propertyName)) {
506 project.setLocalPath(text);
507 } else if ("project.privatekey".equals(propertyName)) {
508 project.setInsertURI(text);
509 } else if ("project.publickey".equals(propertyName)) {
510 project.setRequestURI(text);
511 } else if ("project.path".equals(propertyName)) {
512 project.setPath(text);
514 } catch (BadLocationException e) {
524 * Lets the user choose a local path for a project.
526 private void actionLocalPathBrowse() {
527 Project project = (Project) projectList.getSelectedValue();
528 if (project == null) {
531 pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
532 if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) {
533 projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath());
538 * Adds a new project.
540 private void actionAdd() {
541 String[] keyPair = null;
542 if (!freenetInterface.hasNode()) {
543 JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
547 keyPair = freenetInterface.generateKeyPair();
548 } catch (IOException ioe1) {
549 JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE);
552 Project newProject = new Project();
553 newProject.setName(I18n.getMessage("jsite.project.new-project.name"));
554 newProject.setInsertURI(keyPair[0]);
555 newProject.setRequestURI(keyPair[1]);
556 newProject.setEdition(-1);
557 newProject.setPath("");
558 projectListModel.add(newProject);
559 projectScrollPane.revalidate();
560 projectScrollPane.repaint();
561 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
565 * Deletes the currently selected project.
567 private void actionDelete() {
568 int selectedIndex = projectList.getSelectedIndex();
569 if (selectedIndex > -1) {
570 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) {
571 projectListModel.remove(selectedIndex);
572 projectList.clearSelection();
573 if (projectListModel.getSize() != 0) {
574 projectList.setSelectedIndex(Math.min(selectedIndex, projectListModel.getSize() - 1));
581 * Clones the currently selected project.
583 private void actionClone() {
584 int selectedIndex = projectList.getSelectedIndex();
585 if (selectedIndex > -1) {
586 Project newProject = new Project((Project) projectList.getSelectedValue());
587 newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName()));
588 projectListModel.add(newProject);
589 projectList.setSelectedIndex(projectListModel.indexOf(newProject));
594 * Copies the request URI of the currently selected project to the
597 private void actionCopyURI() {
598 int selectedIndex = projectList.getSelectedIndex();
599 if (selectedIndex > -1) {
600 Project selectedProject = (Project) projectList.getSelectedValue();
601 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
602 clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
608 * Opens a {@link KeyDialog} and lets the user manipulate the keys of the
611 private void actionManageKeys() {
612 int selectedIndex = projectList.getSelectedIndex();
613 if (selectedIndex > -1) {
614 Project selectedProject = (Project) projectList.getSelectedValue();
615 KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard);
616 keyDialog.setPrivateKey(selectedProject.getInsertURI());
617 keyDialog.setPublicKey(selectedProject.getRequestURI());
618 keyDialog.setVisible(true);
619 if (!keyDialog.wasCancelled()) {
620 String originalPublicKey = selectedProject.getRequestURI();
621 String originalPrivateKey = selectedProject.getInsertURI();
622 selectedProject.setInsertURI(keyDialog.getPrivateKey());
623 selectedProject.setRequestURI(keyDialog.getPublicKey());
624 if (!originalPublicKey.equals(selectedProject.getRequestURI()) || !originalPrivateKey.equals(selectedProject.getInsertURI())) {
625 selectedProject.setEdition(-1);
633 * Resets the edition of the currently selected project.
635 private void actionResetEdition() {
636 if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
639 int selectedIndex = projectList.getSelectedIndex();
640 if (selectedIndex > -1) {
641 Project selectedProject = (Project) projectList.getSelectedValue();
642 selectedProject.setEdition(-1);
648 * Updates the complete URI text field.
650 private void updateCompleteURI() {
651 int selectedIndex = projectList.getSelectedIndex();
652 if (selectedIndex > -1) {
653 Project selectedProject = (Project) projectList.getSelectedValue();
654 projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
659 // INTERFACE ListSelectionListener
666 public void valueChanged(ListSelectionEvent listSelectionEvent) {
667 int selectedRow = projectList.getSelectedIndex();
668 Project selectedProject = (Project) projectList.getSelectedValue();
669 projectNameTextField.setEnabled(selectedRow > -1);
670 projectDescriptionTextField.setEnabled(selectedRow > -1);
671 projectLocalPathTextField.setEnabled(selectedRow > -1);
672 projectPathTextField.setEnabled(selectedRow > -1);
673 projectLocalPathBrowseAction.setEnabled(selectedRow > -1);
674 projectDeleteAction.setEnabled(selectedRow > -1);
675 projectCloneAction.setEnabled(selectedRow > -1);
676 projectCopyURIAction.setEnabled(selectedRow > -1);
677 projectManageKeysAction.setEnabled(selectedRow > -1);
678 projectResetEditionAction.setEnabled(selectedRow > -1);
679 if (selectedRow > -1) {
680 projectNameTextField.setText(selectedProject.getName());
681 projectDescriptionTextField.setText(selectedProject.getDescription());
682 projectLocalPathTextField.setText(selectedProject.getLocalPath());
683 projectPathTextField.setText(selectedProject.getPath());
684 projectCompleteUriTextField.setText("freenet:" + selectedProject.getFinalRequestURI(0));
686 projectNameTextField.setText("");
687 projectDescriptionTextField.setText("");
688 projectLocalPathTextField.setText("");
689 projectPathTextField.setText("");
690 projectCompleteUriTextField.setText("");
695 // INTERFACE ChangeListener
699 // INTERFACE DocumentListener
706 public void insertUpdate(DocumentEvent documentEvent) {
707 setTextField(documentEvent);
714 public void removeUpdate(DocumentEvent documentEvent) {
715 setTextField(documentEvent);
722 public void changedUpdate(DocumentEvent documentEvent) {
723 setTextField(documentEvent);
727 // INTERFACE ClipboardOwner
734 public void lostOwnership(Clipboard clipboard, Transferable contents) {