make action methods private and add annotations
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectPage.java
index dcef26a..f7a46b3 100644 (file)
@@ -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,19 +68,18 @@ import de.todesbaum.util.swing.TWizard;
 import de.todesbaum.util.swing.TWizardPage;
 
 /**
- * @author David Roden <droden@gmail.com>
- * @version $Id$
+ * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class ProjectPage extends TWizardPage implements ListSelectionListener, DocumentListener, ClipboardOwner {
 
        private Freenet7Interface freenetInterface;
 
-       protected Action projectLocalPathBrowseAction;
-       protected Action projectAddAction;
-       protected Action projectDeleteAction;
-       protected Action projectCloneAction;
-       protected Action projectCopyURIAction;
-       protected Action projectGenerateKeyAction;
+       private Action projectLocalPathBrowseAction;
+       private Action projectAddAction;
+       private Action projectDeleteAction;
+       private Action projectCloneAction;
+       private Action projectCopyURIAction;
+       private Action projectGenerateKeyAction;
 
        private JFileChooser pathChooser;
        private SortedListModel projectListModel;
@@ -97,7 +98,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                dialogInit();
                setHeading(I18n.getMessage("jsite.project.heading"));
                setDescription(I18n.getMessage("jsite.project.description"));
-               
+
                I18nContainer.getInstance().registerRunnable(new Runnable() {
 
                        public void run() {
@@ -149,6 +150,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
        private void createActions() {
                projectLocalPathBrowseAction = new AbstractAction(I18n.getMessage("jsite.project.action.browse")) {
 
+                       @SuppressWarnings("synthetic-access")
                        public void actionPerformed(ActionEvent actionEvent) {
                                actionLocalPathBrowse();
                        }
@@ -159,6 +161,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 +171,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 +182,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 +193,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 +204,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 +212,10 @@ 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);
-               
+
                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,6 +229,7 @@ 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"));
+                               pathChooser.setApproveButtonText(I18n.getMessage("jsite.project.action.browse.choose"));
                        }
                });
        }
@@ -296,6 +305,24 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                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);
@@ -372,7 +399,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
        // ACTIONS
        //
 
-       protected void actionLocalPathBrowse() {
+       private void actionLocalPathBrowse() {
                Project project = (Project) projectList.getSelectedValue();
                if (project == null) {
                        return;
@@ -383,7 +410,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                }
        }
 
-       protected void actionAdd() {
+       private void actionAdd() {
                String[] keyPair = null;
                if (!freenetInterface.hasNode()) {
                        JOptionPane.showMessageDialog(this, I18n.getMessage("jsite.project-files.no-node-selected"), null, JOptionPane.ERROR_MESSAGE);
@@ -406,7 +433,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                projectList.setSelectedIndex(projectListModel.size() - 1);
        }
 
-       protected void actionDelete() {
+       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 +446,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                }
        }
 
-       protected void actionClone() {
+       private void actionClone() {
                int selectedIndex = projectList.getSelectedIndex();
                if (selectedIndex > -1) {
                        Project newProject = new Project((Project) projectList.getSelectedValue());
@@ -428,8 +455,8 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                        projectList.setSelectedIndex(projectListModel.indexOf(newProject));
                }
        }
-       
-       protected void actionCopyURI() {
+
+       private void actionCopyURI() {
                int selectedIndex = projectList.getSelectedIndex();
                if (selectedIndex > -1) {
                        Project selectedProject = (Project) projectList.getSelectedValue();
@@ -437,8 +464,8 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                        clipboard.setContents(new StringSelection(selectedProject.getFinalRequestURI(0)), this);
                }
        }
-       
-       protected void actionGenerateNewKey() {
+
+       private void actionGenerateNewKey() {
                if (JOptionPane.showConfirmDialog(this, I18n.getMessage("jsite.project.warning.generate-new-key"), null, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) {
                        return;
                }
@@ -525,7 +552,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
        public void changedUpdate(DocumentEvent documentEvent) {
                setTextField(documentEvent);
        }
-       
+
        //
        // INTERFACE ClipboardOwner
        //