Add method to format numbers.
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectInsertPage.java
index 563ef3c..7a3ccac 100644 (file)
@@ -57,7 +57,7 @@ import de.todesbaum.util.swing.TWizardPage;
 
 /**
  * Wizard page that shows the progress of an insert.
- * 
+ *
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
  */
 public class ProjectInsertPage extends TWizardPage implements InsertListener, ClipboardOwner {
@@ -82,7 +82,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
 
        /**
         * Creates a new progress insert wizard page.
-        * 
+        *
         * @param wizard
         *            The wizard this page belongs to
         */
@@ -138,7 +138,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
 
        /**
         * Creates the main panel.
-        * 
+        *
         * @return The main panel
         */
        private JComponent createProjectInsertPanel() {
@@ -210,7 +210,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
 
        /**
         * Sets whether to activate the debug mode.
-        * 
+        *
         * @param debug
         *            <code>true</code> to activate the debug mode,
         *            <code>false</code> to deactivate.
@@ -221,7 +221,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
 
        /**
         * Sets the project to insert.
-        * 
+        *
         * @param project
         *            The project to insert
         */
@@ -238,7 +238,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
 
        /**
         * Sets the freenet interface to use.
-        * 
+        *
         * @param freenetInterface
         *            The freenet interface to use
         */
@@ -338,6 +338,28 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
                clipboard.setContents(new StringSelection(requestURITextField.getText()), this);
        }
 
+       /**
+        * Formats the given number so that it always has the the given number of
+        * fractional digits.
+        *
+        * @param number
+        *            The number to format
+        * @param digits
+        *            The number of fractional digits
+        * @return The formatted number
+        */
+       private String formatNumber(double number, int digits) {
+               int multiplier = (int) Math.pow(10, digits);
+               String formattedNumber = String.valueOf((int) (number * multiplier) / (double) multiplier);
+               if (formattedNumber.indexOf('.') == -1) {
+                       formattedNumber += '.';
+                       for (int digit = 0; digit < digits; digit++) {
+                               formattedNumber += "0";
+                       }
+               }
+               return formattedNumber;
+       }
+
        //
        // INTERFACE ClipboardOwner
        //