You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2018/02/16 16:46:58 UTC
svn commit: r1824532 - in /pivot/trunk:
core/src/org/apache/pivot/text/FileSizeFormat.java
wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
Author: rwhitcomb
Date: Fri Feb 16 16:46:58 2018
New Revision: 1824532
URL: http://svn.apache.org/viewvc?rev=1824532&view=rev
Log:
PIVOT-1030: Update FileSizeFormat to allow for just byte values. Change
the formatting to put one fraction digit for scaled values less than 10,
and otherwise to use none. Code is simpler and shows small file sizes
as exact number of bytes, which was the point here.
Also changed the file browser skin to show blank size for directories
(as was already done in the VFS Browser skin).
Modified:
pivot/trunk/core/src/org/apache/pivot/text/FileSizeFormat.java
pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
Modified: pivot/trunk/core/src/org/apache/pivot/text/FileSizeFormat.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/text/FileSizeFormat.java?rev=1824532&r1=1824531&r2=1824532&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/text/FileSizeFormat.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/text/FileSizeFormat.java Fri Feb 16 16:46:58 2018
@@ -29,7 +29,7 @@ public class FileSizeFormat extends Form
private static final long serialVersionUID = 9126510513247641698L;
public static final int KILOBYTE = 1024;
- public static final String[] ABBREVIATIONS = { "K", "M", "G", "T", "P", "E", "Z", "Y" };
+ public static final String[] ABBREVIATIONS = { "", "K", "M", "G", "T", "P", "E", "Z", "Y" };
private static final FileSizeFormat FILE_SIZE_FORMAT = new FileSizeFormat();
@@ -54,15 +54,14 @@ public class FileSizeFormat extends Form
if (length >= 0) {
double size = length;
-
- int i = -1;
- do {
+ int i = 0;
+ while (size >= KILOBYTE) {
size /= KILOBYTE;
i++;
- } while (size > KILOBYTE);
+ }
NumberFormat numberFormat = NumberFormat.getNumberInstance();
- if (i == 0 && size > 1) {
+ if (i > 0 && size >= 10) {
numberFormat.setMaximumFractionDigits(0);
} else {
numberFormat.setMaximumFractionDigits(1);
Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java?rev=1824532&r1=1824531&r2=1824532&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraFileBrowserSkin.java Fri Feb 16 16:46:58 2018
@@ -294,7 +294,7 @@ public class TerraFileBrowserSkin extend
icon = getIcon(file);
getStyles().put(Style.horizontalAlignment, HorizontalAlignment.LEFT);
} else if (columnName.equals(SIZE_KEY)) {
- long length = file.length();
+ long length = file.isDirectory() ? -1 : file.length();
text = FileSizeFormat.getInstance().format(length);
getStyles().put(Style.horizontalAlignment, HorizontalAlignment.RIGHT);
} else if (columnName.equals(LAST_MODIFIED_KEY)) {
@@ -342,7 +342,7 @@ public class TerraFileBrowserSkin extend
if (columnName.equals(NAME_KEY)) {
string = file.getName();
} else if (columnName.equals(SIZE_KEY)) {
- long length = file.length();
+ long length = file.isDirectory() ? -1 : file.length();
string = FileSizeFormat.getInstance().format(length);
} else if (columnName.equals(LAST_MODIFIED_KEY)) {
long lastModified = file.lastModified();