X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Fjsite%2Fgui%2FProjectPage.java;h=4089364c706d7869418a6da2fcb3839ea6e66585;hb=6ab16b098b2380c0bb196fd3360ea1fd44a331bc;hp=dcef26a95525573e7bb9b7831937678ac4ee7438;hpb=0347aab6d7792820022b523deb6bc974745c386b;p=jSite.git diff --git a/src/de/todesbaum/jsite/gui/ProjectPage.java b/src/de/todesbaum/jsite/gui/ProjectPage.java index dcef26a..4089364 100644 --- a/src/de/todesbaum/jsite/gui/ProjectPage.java +++ b/src/de/todesbaum/jsite/gui/ProjectPage.java @@ -47,14 +47,16 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.ListSelectionModel; -import javax.swing.ScrollPaneConstants; import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import javax.swing.text.AbstractDocument; +import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import javax.swing.text.DocumentFilter; import de.todesbaum.jsite.application.Freenet7Interface; import de.todesbaum.jsite.application.Project; @@ -66,38 +68,79 @@ import de.todesbaum.util.swing.TWizard; import de.todesbaum.util.swing.TWizardPage; /** - * @author David Roden <droden@gmail.com> - * @version $Id$ + * Wizard page that lets the user manage his projects and start inserts. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner { + /** The freenet interface. */ private Freenet7Interface freenetInterface; - protected Action projectLocalPathBrowseAction; - protected Action projectAddAction; - protected Action projectDeleteAction; - protected Action projectCloneAction; - protected Action projectCopyURIAction; - protected Action projectGenerateKeyAction; + /** The “browse” action. */ + private Action projectLocalPathBrowseAction; + + /** The “add project” action. */ + private Action projectAddAction; + + /** The “delete project” action. */ + private Action projectDeleteAction; + + /** The “clone project” action. */ + private Action projectCloneAction; + + /** The “copy URI” action. */ + private Action projectCopyURIAction; + /** The “generate key” action. */ + private Action projectGenerateKeyAction; + + /** The “reset edition” action. */ + private Action projectResetEditionAction; + + /** The file chooser. */ private JFileChooser pathChooser; + + /** The project list model. */ private SortedListModel projectListModel; + + /** The project list scroll pane. */ private JScrollPane projectScrollPane; + + /** The project list. */ private JList projectList; + + /** The project name textfield. */ private JTextField projectNameTextField; + + /** The project description textfield. */ private JTextField projectDescriptionTextField; + + /** The local path textfield. */ private JTextField projectLocalPathTextField; + + /** The public key textfield. */ private JTextField projectPublicKeyTextField; + + /** The private key textfield. */ private JTextField projectPrivateKeyTextField; + + /** The project path textfield. */ private JTextField projectPathTextField; + /** + * Creates a new project page. + * + * @param wizard + * The wizard this page belongs to + */ public ProjectPage(final TWizard wizard) { super(wizard); setLayout(new BorderLayout(12, 12)); dialogInit(); setHeading(I18n.getMessage("jsite.project.heading")); setDescription(I18n.getMessage("jsite.project.description")); - + I18nContainer.getInstance().registerRunnable(new Runnable() { public void run() { @@ -107,7 +150,10 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D }); } - protected void dialogInit() { + /** + * Initializes the page. + */ + private void dialogInit() { createActions(); pathChooser = new JFileChooser(); @@ -135,20 +181,32 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D } /** + * Adds the given listener to the list of listeners. + * + * @param listener + * The listener to add */ public void addListSelectionListener(ListSelectionListener listener) { projectList.addListSelectionListener(listener); } /** + * Removes the given listener from the list of listeners. + * + * @param listener + * The listener to remove */ public void removeListSelectionListener(ListSelectionListener listener) { projectList.removeListSelectionListener(listener); } + /** + * Creates all actions. + */ private void createActions() { projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) { + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { actionLocalPathBrowse(); } @@ -159,6 +217,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectAddAction = new AbstractAction(I18n.getMessage("jsite.project.action.add-project")) { + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { actionAdd(); } @@ -168,6 +227,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectDeleteAction = new AbstractAction(I18n.getMessage("jsite.project.action.delete-project")) { + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { actionDelete(); } @@ -178,6 +238,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectCloneAction = new AbstractAction(I18n.getMessage("jsite.project.action.clone-project")) { + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { actionClone(); } @@ -188,6 +249,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectCopyURIAction = new AbstractAction(I18n.getMessage("jsite.project.action.copy-uri")) { + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { actionCopyURI(); } @@ -198,6 +260,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectGenerateKeyAction = new AbstractAction(I18n.getMessage("jsite.project.action.generate-new-key")) { + @SuppressWarnings("synthetic-access") public void actionPerformed(ActionEvent actionEvent) { actionGenerateNewKey(); } @@ -205,9 +268,21 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D 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); - + + projectResetEditionAction = new AbstractAction(I18n.getMessage("jsite.project.action.reset-edition")) { + + @SuppressWarnings("synthetic-access") + public void actionPerformed(ActionEvent actionEvent) { + actionResetEdition(); + } + }; + projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip")); + projectResetEditionAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_R); + projectResetEditionAction.setEnabled(false); + I18nContainer.getInstance().registerRunnable(new Runnable() { + @SuppressWarnings("synthetic-access") public void run() { projectLocalPathBrowseAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.browse")); projectLocalPathBrowseAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.browse.tooltip")); @@ -221,10 +296,18 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectCopyURIAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.copy-uri.tooltip")); projectGenerateKeyAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.generate-new-key")); projectGenerateKeyAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.generate-new-key.tooltip")); + projectResetEditionAction.putValue(Action.NAME, I18n.getMessage("jsite.project.action.reset-edition")); + projectResetEditionAction.putValue(Action.SHORT_DESCRIPTION, I18n.getMessage("jsite.project.action.reset-edition.tooltip")); + pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose")); } }); } + /** + * Creates the information panel. + * + * @return The information panel + */ private JComponent createInformationPanel() { JPanel informationPanel = new JPanel(new BorderLayout(12, 12)); @@ -291,11 +374,30 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D final TLabel projectPrivateKeyLabel = new TLabel(I18n.getMessage("jsite.project.project.private-key") + ":", KeyEvent.VK_R, projectPrivateKeyTextField); informationTable.add(projectPrivateKeyLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(6, 18, 0, 0), 0, 0)); - informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); + informationTable.add(projectPrivateKeyTextField, new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); + informationTable.add(new JButton(projectResetEditionAction), new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(6, 6, 0, 0), 0, 0)); projectPathTextField = new JTextField(); projectPathTextField.getDocument().putProperty("name", "project.path"); projectPathTextField.getDocument().addDocumentListener(this); + ((AbstractDocument) projectPathTextField.getDocument()).setDocumentFilter(new DocumentFilter() { + + /** + * {@inheritDoc} + */ + @Override + public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { + super.insertString(fb, offset, string.replaceAll("/", ""), attr); + } + + /** + * {@inheritDoc} + */ + @Override + public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { + super.replace(fb, offset, length, text.replaceAll("/", ""), attrs); + } + }); projectPathTextField.setEnabled(false); final TLabel projectPathLabel = new TLabel(I18n.getMessage("jsite.project.project.path") + ":", KeyEvent.VK_P, projectPathTextField); @@ -318,29 +420,54 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D return informationPanel; } + /** + * Sets the project list. + * + * @param projects + * The list of projects + */ public void setProjects(Project[] projects) { projectListModel.clear(); - for (Project project: projects) { + for (Project project : projects) { projectListModel.add(project); } } + /** + * Returns the list of projects. + * + * @return The list of projects + */ public Project[] getProjects() { return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]); } /** + * Sets the freenet interface to use. + * * @param freenetInterface - * The freenetInterface to set. + * The freenetInterface to use */ public void setFreenetInterface(Freenet7Interface freenetInterface) { this.freenetInterface = freenetInterface; } + /** + * Returns the currently selected project. + * + * @return The currently selected project + */ public Project getSelectedProject() { return (Project) projectList.getSelectedValue(); } + /** + * Updates the currently selected project with changed information from a + * textfield. + * + * @param documentEvent + * The document event to process + */ private void setTextField(DocumentEvent documentEvent) { Document document = documentEvent.getDocument(); String propertyName = (String) document.getProperty("name"); @@ -365,6 +492,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D project.setPath(text); } } catch (BadLocationException e) { + /* ignore. */ } } @@ -372,7 +500,10 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D // ACTIONS // - protected void actionLocalPathBrowse() { + /** + * Lets the user choose a local path for a project. + */ + private void actionLocalPathBrowse() { Project project = (Project) projectList.getSelectedValue(); if (project == null) { return; @@ -383,7 +514,10 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D } } - protected void actionAdd() { + /** + * Adds a new project. + */ + private void actionAdd() { String[] keyPair = null; if (!freenetInterface.hasNode()) { JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE); @@ -399,14 +533,18 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D newProject.setName(I18n.getMessage("jsite.project.new-project.name")); newProject.setInsertURI(keyPair[0]); newProject.setRequestURI(keyPair[1]); - newProject.setEdition(0); + newProject.setEdition(-1); + newProject.setPath(""); projectListModel.add(newProject); projectScrollPane.revalidate(); projectScrollPane.repaint(); - projectList.setSelectedIndex(projectListModel.size() - 1); + projectList.setSelectedIndex(projectListModel.indexOf(newProject)); } - protected void actionDelete() { + /** + * Deletes the currently selected project. + */ + private void actionDelete() { int selectedIndex = projectList.getSelectedIndex(); if (selectedIndex > -1) { 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) { @@ -419,7 +557,10 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D } } - protected void actionClone() { + /** + * Clones the currently selected project. + */ + private void actionClone() { int selectedIndex = projectList.getSelectedIndex(); if (selectedIndex > -1) { Project newProject = new Project((Project) projectList.getSelectedValue()); @@ -428,8 +569,12 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectList.setSelectedIndex(projectListModel.indexOf(newProject)); } } - - protected void actionCopyURI() { + + /** + * Copies the request URI of the currently selected project to the + * clipboard. + */ + private void actionCopyURI() { int selectedIndex = projectList.getSelectedIndex(); if (selectedIndex > -1) { Project selectedProject = (Project) projectList.getSelectedValue(); @@ -437,8 +582,11 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this); } } - - protected void actionGenerateNewKey() { + + /** + * Generates a new key for the currently selected project. + */ + private void actionGenerateNewKey() { if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { return; } @@ -459,6 +607,20 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D } } + /** + * Resets the edition of the currently selected project. + */ + private void actionResetEdition() { + if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.reset-edition"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { + return; + } + int selectedIndex = projectList.getSelectedIndex(); + if (selectedIndex > -1) { + Project selectedProject = (Project) projectList.getSelectedValue(); + selectedProject.setEdition(-1); + } + } + // // INTERFACE ListSelectionListener // @@ -480,6 +642,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D projectCloneAction.setEnabled(selectedRow > -1); projectCopyURIAction.setEnabled(selectedRow > -1); projectGenerateKeyAction.setEnabled(selectedRow > -1); + projectResetEditionAction.setEnabled(selectedRow > -1); if (selectedRow > -1) { projectNameTextField.setText(selectedProject.getName()); projectDescriptionTextField.setText(selectedProject.getDescription()); @@ -525,7 +688,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D public void changedUpdate(DocumentEvent documentEvent) { setTextField(documentEvent); } - + // // INTERFACE ClipboardOwner // @@ -534,6 +697,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D * {@inheritDoc} */ public void lostOwnership(Clipboard clipboard, Transferable contents) { + /* ignore. */ } }