X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fgui%2FProjectPage.java;h=086493ca19e2a9981e270446c4fdfa5cf104137f;hb=bfa8ea22740bd472403c67eb383e3fd25b8f93c8;hp=96a027d97150d16dba751f2343c2a52067c71c86;hpb=6f1a8216cfba28add0ef365b46a08d16d4eb87fe;p=jSite.git diff --git a/src/de/todesbaum/jsite/gui/ProjectPage.java b/src/de/todesbaum/jsite/gui/ProjectPage.java index 96a027d..086493c 100644 --- a/src/de/todesbaum/jsite/gui/ProjectPage.java +++ b/src/de/todesbaum/jsite/gui/ProjectPage.java @@ -25,6 +25,11 @@ import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.ClipboardOwner; +import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.Transferable; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.io.IOException; @@ -40,14 +45,9 @@ import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JSpinner; import javax.swing.JTextField; import javax.swing.ListSelectionModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.JSpinner.NumberEditor; import javax.swing.border.EmptyBorder; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; @@ -55,7 +55,6 @@ import javax.swing.event.ListSelectionListener; import javax.swing.text.BadLocationException; import javax.swing.text.Document; -import de.todesbaum.jsite.application.EditionProject; import de.todesbaum.jsite.application.Freenet7Interface; import de.todesbaum.jsite.application.Project; import de.todesbaum.jsite.i18n.I18n; @@ -66,9 +65,9 @@ import de.todesbaum.util.swing.TWizardPage; /** * @author David Roden <droden@gmail.com> - * @version $Id: ProjectPage.java 418 2006-03-29 17:49:16Z bombe $ + * @version $Id$ */ -public class ProjectPage extends TWizardPage implements ListSelectionListener, ChangeListener, DocumentListener { +public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner { private Freenet7Interface freenetInterface; @@ -76,6 +75,8 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C private Action projectAddAction; private Action projectDeleteAction; private Action projectCloneAction; + private Action projectCopyURIAction; + private Action projectGenerateKeyAction; private JFileChooser pathChooser; private SortedListModel projectListModel; @@ -86,7 +87,6 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C private JTextField projectPublicKeyTextField; private JTextField projectPrivateKeyTextField; private JTextField projectPathTextField; - private JSpinner projectEditionSpinner; public ProjectPage() { super(); @@ -171,6 +171,24 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C projectCloneAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.clone-project.tooltip")); projectCloneAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L); projectCloneAction.setEnabled(false); + + projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) { + public void actionPerformed(ActionEvent actionEvent) { + actionCopyURI(); + } + }; + projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip")); + projectCopyURIAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U); + projectCopyURIAction.setEnabled(false); + + projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) { + public void actionPerformed(ActionEvent actionEvent) { + actionGenerateNewKey(); + } + }; + projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip")); + projectGenerateKeyAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_G); + projectGenerateKeyAction.setEnabled(false); } private JComponent createInformationPanel() { @@ -183,6 +201,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C functionButtons.add(new JButton(projectAddAction)); functionButtons.add(new JButton(projectDeleteAction)); functionButtons.add(new JButton(projectCloneAction)); + functionButtons.add(new JButton(projectCopyURIAction)); informationPanel.add(functionButtons, BorderLayout.PAGE_START); informationPanel.add(informationTable, BorderLayout.CENTER); @@ -222,7 +241,8 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C projectPublicKeyTextField.setEnabled(false); informationTable.add(new TLabel(I18n.getMessage("jsite.project.project.public-key") + ":", KeyEvent.VK_U, projectPublicKeyTextField), new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0)); - informationTable.add(projectPublicKeyTextField, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); + informationTable.add(projectPublicKeyTextField, new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); + informationTable.add(new JButton(projectGenerateKeyAction), new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); projectPrivateKeyTextField = new JTextField(27); projectPrivateKeyTextField.getDocument().putProperty("name", "project.privatekey"); @@ -240,15 +260,6 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C informationTable.add(new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField), new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0)); informationTable.add(projectPathTextField, new GridBagConstraints(1, 7, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); - projectEditionSpinner = new JSpinner(new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1)); - ((NumberEditor) projectEditionSpinner.getEditor()).getTextField().setColumns(6); - projectEditionSpinner.setName("project.edition"); - projectEditionSpinner.addChangeListener(this); - projectEditionSpinner.setEnabled(false); - - informationTable.add(new TLabel(I18n.getMessage("jsite.project.project.edition") + ":", KeyEvent.VK_E, projectEditionSpinner), new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0)); - informationTable.add(projectEditionSpinner, new GridBagConstraints(1, 8, 2, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 6, 0, 0), 0, 0)); - return informationPanel; } @@ -308,8 +319,9 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C protected void actionLocalPathBrowse() { Project project = (Project) projectList.getSelectedValue(); - if (project == null) + if (project == null) { return; + } pathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (pathChooser.showDialog(this, I18n.getMessage("jsite.project.action.browse.choose")) == JFileChooser.APPROVE_OPTION) { projectLocalPathTextField.setText(pathChooser.getSelectedFile().getPath()); @@ -328,7 +340,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE); return; } - EditionProject newProject = new EditionProject(); + Project newProject = new Project(); newProject.setName(I18n.getMessage("jsite.project.new-project.name")); newProject.setInsertURI(keyPair[0]); newProject.setRequestURI(keyPair[1]); @@ -353,16 +365,42 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C protected void actionClone() { int selectedIndex = projectList.getSelectedIndex(); if (selectedIndex > -1) { - Project newProject = null; - Project selectedProject = (Project) projectList.getSelectedValue(); - if (selectedProject instanceof EditionProject) { - newProject = new EditionProject(selectedProject); - } // else { /* BUG! */ } + Project newProject = new Project((Project) projectList.getSelectedValue()); newProject.setName(MessageFormat.format(I18n.getMessage("jsite.project.action.clone-project.copy"), newProject.getName())); projectListModel.add(newProject); projectList.setSelectedIndex(projectListModel.indexOf(newProject)); } } + + protected void actionCopyURI() { + int selectedIndex = projectList.getSelectedIndex(); + if (selectedIndex > -1) { + Project selectedProject = (Project) projectList.getSelectedValue(); + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this); + } + } + + protected void actionGenerateNewKey() { + if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { + return; + } + int selectedIndex = projectList.getSelectedIndex(); + if (selectedIndex > -1) { + Project selectedProject = (Project) projectList.getSelectedValue(); + String[] keyPair = null; + try { + keyPair = freenetInterface.generateKeyPair(); + } catch (IOException ioe1) { + JOptionPane.showMessageDialog(this, MessageFormat.format(I18n.getMessage("jsite.project.keygen.io-error"), ioe1.getMessage()), null, JOptionPane.ERROR_MESSAGE); + return; + } + selectedProject.setInsertURI(keyPair[0]); + selectedProject.setRequestURI(keyPair[1]); + projectPublicKeyTextField.setText(selectedProject.getRequestURI()); + projectPrivateKeyTextField.setText(selectedProject.getInsertURI()); + } + } // // INTERFACE ListSelectionListener @@ -380,10 +418,11 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C projectPublicKeyTextField.setEnabled(selectedRow > -1); projectPrivateKeyTextField.setEnabled(selectedRow > -1); projectPathTextField.setEnabled(selectedRow > -1); - projectEditionSpinner.setEnabled(selectedRow > -1); projectLocalPathBrowseAction.setEnabled(selectedRow > -1); projectDeleteAction.setEnabled(selectedRow > -1); projectCloneAction.setEnabled(selectedRow > -1); + projectCopyURIAction.setEnabled(selectedRow > -1); + projectGenerateKeyAction.setEnabled(selectedRow > -1); if (selectedRow > -1) { projectNameTextField.setText(selectedProject.getName()); projectDescriptionTextField.setText(selectedProject.getDescription()); @@ -391,10 +430,6 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C projectPublicKeyTextField.setText(selectedProject.getRequestURI()); projectPrivateKeyTextField.setText(selectedProject.getInsertURI()); projectPathTextField.setText(selectedProject.getPath()); - if (selectedProject instanceof EditionProject) { - EditionProject editionProject = (EditionProject) selectedProject; - projectEditionSpinner.setValue(editionProject.getEdition()); - } } else { projectNameTextField.setText(""); projectDescriptionTextField.setText(""); @@ -402,7 +437,6 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C projectPublicKeyTextField.setText(""); projectPrivateKeyTextField.setText(""); projectPathTextField.setText(""); - projectEditionSpinner.setValue(0); } } @@ -410,23 +444,6 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C // INTERFACE ChangeListener // - /** - * {@inheritDoc} - */ - public void stateChanged(ChangeEvent changeEvent) { - Object source = changeEvent.getSource(); - if (source instanceof JSpinner) { - JSpinner spinner = (JSpinner) source; - Project currentProject = (Project) projectList.getSelectedValue(); - if (currentProject == null) { - return; - } - if ("project.edition".equals(spinner.getName())) { - ((EditionProject) currentProject).setEdition((Integer) spinner.getValue()); - } - } - } - // // INTERFACE DocumentListener // @@ -451,5 +468,15 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, C public void changedUpdate(DocumentEvent documentEvent) { setTextField(documentEvent); } + + // + // INTERFACE ClipboardOwner + // + + /** + * {@inheritDoc} + */ + public void lostOwnership(Clipboard clipboard, Transferable contents) { + } }