Fix calculation of project size.
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectPage.java
index 770828d..98ad847 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * jSite - a tool for uploading websites into Freenet
- * Copyright (C) 2006 David Roden
+ * jSite - ProjectPage.java - Copyright © 2006–2012 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -103,7 +102,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
        private JFileChooser pathChooser;
 
        /** The project list model. */
-       private SortedListModel projectListModel;
+       private SortedListModel<Project> projectListModel;
 
        /** The project list scroll pane. */
        private JScrollPane projectScrollPane;
@@ -158,13 +157,13 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                createActions();
 
                pathChooser = new JFileChooser();
-               projectListModel = new SortedListModel();
+               projectListModel = new SortedListModel<Project>();
                projectList = new JList(projectListModel);
                projectList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                projectList.addListSelectionListener(this);
-               projectList.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
 
                add(projectScrollPane = new JScrollPane(projectList), BorderLayout.LINE_START);
+               projectScrollPane.setPreferredSize(new Dimension(150, projectList.getPreferredSize().height));
                add(createInformationPanel(), BorderLayout.CENTER);
        }
 
@@ -367,16 +366,30 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                         * {@inheritDoc}
                         */
                        @Override
+                       @SuppressWarnings("synthetic-access")
                        public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
                                super.insertString(fb, offset, string.replaceAll("/", ""), attr);
+                               updateCompleteURI();
                        }
 
                        /**
                         * {@inheritDoc}
                         */
                        @Override
+                       @SuppressWarnings("synthetic-access")
                        public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
                                super.replace(fb, offset, length, text.replaceAll("/", ""), attrs);
+                               updateCompleteURI();
+                       }
+
+                       /**
+                        * {@inheritDoc}
+                        */
+                       @Override
+                       @SuppressWarnings("synthetic-access")
+                       public void remove(FilterBypass fb, int offset, int length) throws BadLocationException {
+                               super.remove(fb, offset, length);
+                               updateCompleteURI();
                        }
                });
                projectPathTextField.setEnabled(false);
@@ -427,7 +440,7 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
         * @return The list of projects
         */
        public Project[] getProjects() {
-               return (Project[]) projectListModel.toArray(new Project[projectListModel.size()]);
+               return projectListModel.toArray(new Project[projectListModel.size()]);
        }
 
        /**
@@ -595,8 +608,14 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                        keyDialog.setPublicKey(selectedProject.getRequestURI());
                        keyDialog.setVisible(true);
                        if (!keyDialog.wasCancelled()) {
+                               String originalPublicKey = selectedProject.getRequestURI();
+                               String originalPrivateKey = selectedProject.getInsertURI();
                                selectedProject.setInsertURI(keyDialog.getPrivateKey());
                                selectedProject.setRequestURI(keyDialog.getPublicKey());
+                               if (!originalPublicKey.equals(selectedProject.getRequestURI()) || !originalPrivateKey.equals(selectedProject.getInsertURI())) {
+                                       selectedProject.setEdition(-1);
+                               }
+                               updateCompleteURI();
                        }
                }
        }
@@ -612,6 +631,18 @@ public class ProjectPage extends TWizardPage implements ListSelectionListener, D
                if (selectedIndex > -1) {
                        Project selectedProject = (Project) projectList.getSelectedValue();
                        selectedProject.setEdition(-1);
+                       updateCompleteURI();
+               }
+       }
+
+       /**
+        * Updates the complete URI text field.
+        */
+       private void updateCompleteURI() {
+               int selectedIndex = projectList.getSelectedIndex();
+               if (selectedIndex > -1) {
+                       Project selectedProject = (Project) projectList.getSelectedValue();
+                       projectCompleteUriTextField.setText(selectedProject.getFinalRequestURI(0));
                }
        }