From d6e49b13a2167ff00dd43be64faf0598f1f967ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 22 Sep 2012 09:53:56 +0200 Subject: [PATCH] Add list of projects to copy keys from to key dialog. --- .../java/de/todesbaum/jsite/gui/KeyDialog.java | 86 +++++++++++++++++++--- .../java/de/todesbaum/jsite/gui/ProjectPage.java | 1 + .../de/todesbaum/jsite/i18n/jSite.properties | 5 +- .../de/todesbaum/jsite/i18n/jSite_de.properties | 5 +- .../de/todesbaum/jsite/i18n/jSite_fr.properties | 5 +- 5 files changed, 90 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/todesbaum/jsite/gui/KeyDialog.java b/src/main/java/de/todesbaum/jsite/gui/KeyDialog.java index 732bb6e..ae8cea4 100644 --- a/src/main/java/de/todesbaum/jsite/gui/KeyDialog.java +++ b/src/main/java/de/todesbaum/jsite/gui/KeyDialog.java @@ -59,6 +59,7 @@ import javax.swing.SwingConstants; import net.pterodactylus.util.swing.ComboBoxModelList; import de.todesbaum.jsite.application.Freenet7Interface; +import de.todesbaum.jsite.application.Project; import de.todesbaum.jsite.i18n.I18n; import de.todesbaum.jsite.i18n.I18nContainer; import de.todesbaum.util.freenet.fcp2.wot.OwnIdentity; @@ -88,6 +89,9 @@ public class KeyDialog extends JDialog { /** The “Regenerate” button’s action. */ private Action generateAction; + /** The “Copy from Project” action. */ + private Action copyFromProjectAction; + /** The “Copy from Identity” action. */ private Action copyFromIdentityAction; @@ -97,12 +101,18 @@ public class KeyDialog extends JDialog { /** The text field for the public key. */ private JTextField publicKeyTextField; + /** The select box for the projects. */ + private JComboBox projectsComboBox; + /** The select box for the own identities. */ private JComboBox ownIdentitiesComboBox; /** Whether the dialog was cancelled. */ private boolean cancelled; + /** The list of projects. */ + private final List projects = new ArrayList(); + /** The list of own identities. */ private final List ownIdentities = new ArrayList(); @@ -184,6 +194,20 @@ public class KeyDialog extends JDialog { } /** + * Sets the projects to display and copy URIs from. + * + * @param projects + * The list of projects + */ + public void setProjects(Collection projects) { + synchronized (this.projects) { + this.projects.clear(); + this.projects.addAll(projects); + } + projectsComboBox.setSelectedIndex(-1); + } + + /** * Sets the own identities to display and copy URIs from. * * @param ownIdentities @@ -256,6 +280,18 @@ public class KeyDialog extends JDialog { cancelAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.key-dialog.button.cancel.tooltip")); cancelAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_ESCAPE); + copyFromProjectAction = new AbstractAction(I18n.getMessage("jsite.key-dialog.button.copy-from-project")) { + + @Override + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionevent) { + actionCopyFromProject(); + } + }; + copyFromProjectAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.key-dialog.button.copy-from-project.tooltip")); + copyFromProjectAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_P); + copyFromProjectAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)); + copyFromIdentityAction = new AbstractAction(I18n.getMessage("jsite.key-dialog.button.copy-from-identity")) { @Override @@ -265,7 +301,8 @@ public class KeyDialog extends JDialog { } }; copyFromIdentityAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.key-dialog.button.copy-from-identity.tooltip")); - copyFromIdentityAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK)); + copyFromIdentityAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_I); + copyFromIdentityAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK)); generateAction = new AbstractAction(I18n.getMessage("jsite.key-dialog.button.generate")) { @@ -305,11 +342,29 @@ public class KeyDialog extends JDialog { publicKeyTextField = new JTextField(); contentPanel.add(publicKeyTextField, new GridBagConstraints(1, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 12, 0, 0), 0, 0)); - final JLabel identitiesLabel = new JLabel(I18n.getMessage("jsite.key-dialog.label.identities")); - contentPanel.add(identitiesLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0)); + final JLabel copyKeysLabel = new JLabel(I18n.getMessage("jsite.key-dialog.label.copy-keys")); + contentPanel.add(copyKeysLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0)); + + final JLabel projectLabel = new JLabel(I18n.getMessage("jsite.key-dialog.label.project")); + contentPanel.add(projectLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 18, 0, 0), 0, 0)); + + projectsComboBox = new JComboBox(new ComboBoxModelList(projects)); + projectsComboBox.addActionListener(new ActionListener() { + + @Override + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + copyFromProjectAction.setEnabled(projectsComboBox.getSelectedIndex() > -1); + } + + }); + contentPanel.add(projectsComboBox, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 12, 0, 0), 0, 0)); + + JButton copyFromProjectButton = new JButton(copyFromProjectAction); + contentPanel.add(copyFromProjectButton, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(6, 12, 0, 0), 0, 0)); final JLabel identityLabel = new JLabel(I18n.getMessage("jsite.key-dialog.label.identity")); - contentPanel.add(identityLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 18, 0, 0), 0, 0)); + contentPanel.add(identityLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 18, 0, 0), 0, 0)); ownIdentitiesComboBox = new JComboBox(new ComboBoxModelList(ownIdentities)); ownIdentitiesComboBox.addActionListener(new ActionListener() { @@ -334,17 +389,17 @@ public class KeyDialog extends JDialog { return this; } }); - contentPanel.add(ownIdentitiesComboBox, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 12, 0, 0), 0, 0)); + contentPanel.add(ownIdentitiesComboBox, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 12, 0, 0), 0, 0)); JButton copyFromIdentityButton = new JButton(copyFromIdentityAction); - contentPanel.add(copyFromIdentityButton, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(6, 12, 0, 0), 0, 0)); + contentPanel.add(copyFromIdentityButton, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.HORIZONTAL, new Insets(6, 12, 0, 0), 0, 0)); final JLabel actionsLabel = new JLabel(I18n.getMessage("jsite.key-dialog.label.actions")); - contentPanel.add(actionsLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0)); + contentPanel.add(actionsLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0)); JPanel actionButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 12, 12)); actionButtonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12)); - contentPanel.add(actionButtonPanel, new GridBagConstraints(0, 6, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 18, 0, 0), 0, 0)); + contentPanel.add(actionButtonPanel, new GridBagConstraints(0, 7, 3, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 18, 0, 0), 0, 0)); actionButtonPanel.add(new JButton(generateAction)); @@ -365,8 +420,9 @@ public class KeyDialog extends JDialog { keysLabel.setText(I18n.getMessage("jsite.key-dialog.label.keys")); privateKeyLabel.setText(I18n.getMessage("jsite.key-dialog.label.private-key")); publicKeyLabel.setText(I18n.getMessage("jsite.key-dialog.label.public-key")); - identitiesLabel.setText(I18n.getMessage("jsite.key-dialog.label.identities")); + copyKeysLabel.setText(I18n.getMessage("jsite.key-dialog.label.copy-keys")); identityLabel.setText(I18n.getMessage("jsite.key-dialog.label.identity")); + projectLabel.setText(I18n.getMessage("jsite.key-dialog.label.project")); actionsLabel.setText(I18n.getMessage("jsite.key-dialog.label.actions")); } }); @@ -399,6 +455,18 @@ public class KeyDialog extends JDialog { } /** + * Copies the public and private key from the selected project. + */ + private void actionCopyFromProject() { + Project project = (Project) projectsComboBox.getSelectedItem(); + if (project == null) { + return; + } + setPublicKey(project.getRequestURI()); + setPrivateKey(project.getInsertURI()); + } + + /** * Copies the public and private key from the selected identity. */ private void actionCopyFromIdentity() { diff --git a/src/main/java/de/todesbaum/jsite/gui/ProjectPage.java b/src/main/java/de/todesbaum/jsite/gui/ProjectPage.java index 5d96436..ceee143 100644 --- a/src/main/java/de/todesbaum/jsite/gui/ProjectPage.java +++ b/src/main/java/de/todesbaum/jsite/gui/ProjectPage.java @@ -632,6 +632,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D KeyDialog keyDialog = new KeyDialog(freenetInterface, wizard); keyDialog.setPrivateKey(selectedProject.getInsertURI()); keyDialog.setPublicKey(selectedProject.getRequestURI()); + keyDialog.setProjects(getProjects()); keyDialog.setOwnIdentities(webOfTrustInterface.getOwnIdentities()); keyDialog.setVisible(true); if (!keyDialog.wasCancelled()) { diff --git a/src/main/resources/de/todesbaum/jsite/i18n/jSite.properties b/src/main/resources/de/todesbaum/jsite/i18n/jSite.properties index e483ce7..19ea78d 100644 --- a/src/main/resources/de/todesbaum/jsite/i18n/jSite.properties +++ b/src/main/resources/de/todesbaum/jsite/i18n/jSite.properties @@ -177,6 +177,8 @@ jsite.update-checker.latest-version.okay.message=You are currently running jsite.key-dialog.title=Manage Project Keys jsite.key-dialog.button.ok.tooltip=Accepts the changes jsite.key-dialog.button.cancel.tooltip=Discards the changes +jsite.key-dialog.button.copy-from-project=Copy from Project +jsite.key-dialog.button.copy-from-project.tooltip=Copies the public and private keys from the selected project jsite.key-dialog.button.copy-from-identity=Copy from Identity jsite.key-dialog.button.copy-from-identity.tooltip=Copies the public and private keys from the selected identity jsite.key-dialog.button.generate=Regenerate Keys @@ -184,7 +186,8 @@ jsite.key-dialog.button.generate.tooltip=Create a new key pair jsite.key-dialog.label.keys=Keys jsite.key-dialog.label.private-key=Private Key jsite.key-dialog.label.public-key=Public Key -jsite.key-dialog.label.identities=Identities +jsite.key-dialog.label.copy-keys=Copy Keys +jsite.key-dialog.label.project=Project jsite.key-dialog.label.identity=Identity jsite.key-dialog.label.actions=Actions diff --git a/src/main/resources/de/todesbaum/jsite/i18n/jSite_de.properties b/src/main/resources/de/todesbaum/jsite/i18n/jSite_de.properties index 0752114..7f82138 100644 --- a/src/main/resources/de/todesbaum/jsite/i18n/jSite_de.properties +++ b/src/main/resources/de/todesbaum/jsite/i18n/jSite_de.properties @@ -177,6 +177,8 @@ jsite.update-checker.latest-version.okay.message=Es l\u00e4uft momentan Ve jsite.key-dialog.title=Projektschl\u00fcsselverwaltung jsite.key-dialog.button.ok.tooltip=\u00c4nderungen akzeptieren jsite.key-dialog.button.cancel.tooltip=\u00c4nderungen verwerfen +jsite.key-dialog.button.copy-from-project=Von Projekt kopieren +jsite.key-dialog.button.copy-from-project.tooltip=Kopiert das Schl\u00fcsselpaar des ausgew\u00e4hlten Projekts jsite.key-dialog.button.copy-from-identity=Von Identit\u00e4t kopieren jsite.key-dialog.button.copy-from-identity.tooltip=Kopiert das Schl\u00fcsselpaar der ausgew\u00e4hlten Identit\u00e4t jsite.key-dialog.button.generate=Schl\u00fcssel neu generieren @@ -184,7 +186,8 @@ jsite.key-dialog.button.generate.tooltip=Generiert ein neues Schl\u00fcsselpaar jsite.key-dialog.label.keys=Schl\u00fcssel jsite.key-dialog.label.private-key=Privater Schl\u00fcssel jsite.key-dialog.label.public-key=\u00d6ffentlicher Schl\u00fcssel -jsite.key-dialog.label.identities=Identit\u00e4ten +jsite.key-dialog.label.copy-keys=Schl\u00fcssel kopieren +jsite.key-dialog.label.project=Projekt jsite.key-dialog.label.identity=Identit\u00e4t jsite.key-dialog.label.actions=Aktionen diff --git a/src/main/resources/de/todesbaum/jsite/i18n/jSite_fr.properties b/src/main/resources/de/todesbaum/jsite/i18n/jSite_fr.properties index 80d3fc5..b50ce99 100644 --- a/src/main/resources/de/todesbaum/jsite/i18n/jSite_fr.properties +++ b/src/main/resources/de/todesbaum/jsite/i18n/jSite_fr.properties @@ -177,6 +177,8 @@ jsite.update-checker.latest-version.okay.message=Vous utilisez la version jsite.key-dialog.title=G\u00e9rer les cl\u00e9s des projets jsite.key-dialog.button.ok.tooltip=Accepter les changements jsite.key-dialog.button.cancel.tooltip=Annuler les changements +jsite.key-dialog.button.copy-from-project=Copy from Project +jsite.key-dialog.button.copy-from-project.tooltip=Copies the public and private keys from the selected project jsite.key-dialog.button.copy-from-identity=Copy from Identity jsite.key-dialog.button.copy-from-identity.tooltip=Copies the public and private keys from the selected identity jsite.key-dialog.button.generate=Reg\u00e9n\u00e9rer les cl\u00e9s @@ -184,7 +186,8 @@ jsite.key-dialog.button.generate.tooltip=Cr\u00e9er une nouvelle paire de cl\u00 jsite.key-dialog.label.keys=Cl\u00e9s jsite.key-dialog.label.private-key=Cl\u00e9 priv\u00e9e jsite.key-dialog.label.public-key=Cl\u00e9 publique -jsite.key-dialog.label.identities=Identities +jsite.key-dialog.label.copy-keys=Copy Keys +jsite.key-dialog.label.project=Project jsite.key-dialog.label.identity=Identity jsite.key-dialog.label.actions=Actions -- 2.7.4