Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-03-08 18:06:20 -0500
committerspingel2008-03-08 18:06:20 -0500
commit49e8b58dd3c22446a0cbe342de45546f57bfde67 (patch)
tree6b1c34bddc105e2b673480d9672683213554323b
parent43dd0a958bf214c26eb7329c9605d48ce3164bc1 (diff)
downloadorg.eclipse.mylyn.tasks-49e8b58dd3c22446a0cbe342de45546f57bfde67.tar.gz
org.eclipse.mylyn.tasks-49e8b58dd3c22446a0cbe342de45546f57bfde67.tar.xz
org.eclipse.mylyn.tasks-49e8b58dd3c22446a0cbe342de45546f57bfde67.zip
NEW - bug 221721: [patch] AttachmentSizeFormatterTest fails id decimalpoint = ","
https://bugs.eclipse.org/bugs/show_bug.cgi?id=221721
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentSizeFormatterTest.java45
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentSizeFormatter.java35
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java4
3 files changed, 61 insertions, 23 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentSizeFormatterTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentSizeFormatterTest.java
index 7c966a338..818a14463 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentSizeFormatterTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AttachmentSizeFormatterTest.java
@@ -5,9 +5,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
-
package org.eclipse.mylyn.tasks.tests;
+import java.util.Locale;
+
import junit.framework.TestCase;
import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentSizeFormatter;
@@ -19,37 +20,55 @@ import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentSizeFormatter;
* change your locale to en_US or append the following parameter to program arguments on JUnit plug-in test: "-nl en_US"</strong>
*
* @author Willian Mitsuda
+ * @author Frank Becker
*/
public class AttachmentSizeFormatterTest extends TestCase {
public void testInvalidString() {
- assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, AttachmentSizeFormatter.format(null));
- assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, AttachmentSizeFormatter.format("x"));
+ AttachmentSizeFormatter formatter = AttachmentSizeFormatter.getInstance();
+ assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format(null));
+ assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format("x"));
}
public void testNotAValidNumber() {
- assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, AttachmentSizeFormatter.format("-5"));
- assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, AttachmentSizeFormatter.format("1.0"));
+ AttachmentSizeFormatter formatter = AttachmentSizeFormatter.getInstance();
+ assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format("-5"));
+ assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format("1.0"));
}
public void testByteFormatter() {
- assertEquals("1 byte", AttachmentSizeFormatter.format("1"));
- assertEquals("2 bytes", AttachmentSizeFormatter.format("2"));
- assertEquals("1023 bytes", AttachmentSizeFormatter.format("1023"));
+ AttachmentSizeFormatter formatter = new AttachmentSizeFormatter(Locale.ENGLISH);
+ assertEquals("1 byte", formatter.format("1"));
+ assertEquals("2 bytes", formatter.format("2"));
+ assertEquals("1023 bytes", formatter.format("1023"));
}
public void testKBFormatter() {
- assertEquals("1.00 KB", AttachmentSizeFormatter.format("1024"));
- assertEquals("1024.00 KB", AttachmentSizeFormatter.format("1048575"));
+ AttachmentSizeFormatter formatterEnglish = new AttachmentSizeFormatter(Locale.ENGLISH);
+ assertEquals("1.00 KB", formatterEnglish.format("1024"));
+ assertEquals("1024.00 KB", formatterEnglish.format("1048575"));
+
+ AttachmentSizeFormatter formatterGerman = new AttachmentSizeFormatter(Locale.GERMAN);
+ assertEquals("1,00 KB", formatterGerman.format("1024"));
+ assertEquals("1024,00 KB", formatterGerman.format("1048575"));
}
public void testMBFormatter() {
- assertEquals("1.00 MB", AttachmentSizeFormatter.format("1048576"));
- assertEquals("1024.00 MB", AttachmentSizeFormatter.format("1073741823"));
+ AttachmentSizeFormatter formatterEnglish = new AttachmentSizeFormatter(Locale.ENGLISH);
+ assertEquals("1.00 MB", formatterEnglish.format("1048576"));
+ assertEquals("1024.00 MB", formatterEnglish.format("1073741823"));
+
+ AttachmentSizeFormatter formatterGerman = new AttachmentSizeFormatter(Locale.GERMAN);
+ assertEquals("1,00 MB", formatterGerman.format("1048576"));
+ assertEquals("1024,00 MB", formatterGerman.format("1073741823"));
}
public void testGBFormatter() {
- assertEquals("1.00 GB", AttachmentSizeFormatter.format("1073741824"));
+ AttachmentSizeFormatter formatterEnglish = new AttachmentSizeFormatter(Locale.ENGLISH);
+ assertEquals("1.00 GB", formatterEnglish.format("1073741824"));
+
+ AttachmentSizeFormatter formatterGerman = new AttachmentSizeFormatter(Locale.GERMAN);
+ assertEquals("1,00 GB", formatterGerman.format("1073741824"));
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentSizeFormatter.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentSizeFormatter.java
index 9a588d6cd..d8473e3eb 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentSizeFormatter.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentSizeFormatter.java
@@ -9,9 +9,11 @@
package org.eclipse.mylyn.internal.tasks.ui.editors;
import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
/**
- * Format attachment size values originally in bytes to nice messages
+ * Format attachment size values originally in bytes to nice messages.
* <p>
* This formatter tries to use the most applicable measure unit based on size magnitude, i.e.:
* <p>
@@ -30,6 +32,7 @@ import java.text.DecimalFormat;
* decoded, for any reason, it returns {@link #UNKNOWN_SIZE}
*
* @author Willian Mitsuda
+ * @author Frank Becker
*/
public class AttachmentSizeFormatter {
@@ -38,7 +41,21 @@ public class AttachmentSizeFormatter {
*/
public static final String UNKNOWN_SIZE = "-";
- public static String format(String sizeInBytes) {
+ public final static AttachmentSizeFormatter getInstance() {
+ return new AttachmentSizeFormatter();
+ }
+
+ private final DecimalFormat decimalFormat;
+
+ public AttachmentSizeFormatter() {
+ this(Locale.getDefault());
+ }
+
+ public AttachmentSizeFormatter(Locale locale) {
+ this.decimalFormat = (DecimalFormat) NumberFormat.getInstance(locale);
+ }
+
+ public String format(String sizeInBytes) {
// Ensures it can be converted to an int
if (sizeInBytes == null) {
return UNKNOWN_SIZE;
@@ -64,19 +81,19 @@ public class AttachmentSizeFormatter {
} else if (size >= 1024 && size <= 1048575) {
// Format as KB
double formattedValue = size / 1024.0;
- DecimalFormat fmt = new DecimalFormat("0.00 KB");
- return fmt.format(formattedValue);
+ decimalFormat.applyPattern("0.00 KB");
+ return decimalFormat.format(formattedValue);
} else if (size >= 1048576 && size <= 1073741823) {
// Format as MB
double formattedValue = size / 1048576.0;
- DecimalFormat fmt = new DecimalFormat("0.00 MB");
- return fmt.format(formattedValue);
+ decimalFormat.applyPattern("0.00 MB");
+ return decimalFormat.format(formattedValue);
}
// Format as GB
double formattedValue = size / 1073741824.0;
- DecimalFormat fmt = new DecimalFormat("0.00 GB");
- return fmt.format(formattedValue);
+ decimalFormat.applyPattern("0.00 GB");
+ return decimalFormat.format(formattedValue);
}
-} \ No newline at end of file
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java
index d422c50c6..1ae5bb316 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java
@@ -34,6 +34,8 @@ public class AttachmentTableLabelProvider extends ColumnLabelProvider {
private final AbstractRepositoryTaskEditor AbstractTaskEditor;
+ private final AttachmentSizeFormatter sizeFormatter = AttachmentSizeFormatter.getInstance();
+
private final IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
private static final String[] IMAGE_EXTENSIONS = { "jpg", "gif", "png", "tiff", "tif", "bmp" };
@@ -96,7 +98,7 @@ public class AttachmentTableLabelProvider extends ColumnLabelProvider {
return attachment.getContentType();
// }
case 3:
- return AttachmentSizeFormatter.format(attachment.getSize());
+ return sizeFormatter.format(attachment.getSize());
case 4:
return attachment.getCreator();
case 5:

Back to the top