Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public class MixStatusCell extends TreeTableCell<Entry, UtxoEntry.MixStatus> {
private static final int ERROR_DISPLAY_MILLIS = 5 * 60 * 1000;
private static int maxMixesDoneDigitCount = 0;

public MixStatusCell() {
super();
Expand All @@ -40,7 +41,7 @@ protected void updateItem(UtxoEntry.MixStatus mixStatus, boolean empty) {
setText(null);
setGraphic(null);
} else {
setText(Integer.toString(mixStatus.getMixesDone()));
setText(formatMixesDone(mixStatus.getMixesDone()));
if(mixStatus.getNextMixUtxo() == null) {
setContextMenu(new MixStatusContextMenu(mixStatus.getUtxoEntry(), mixStatus.getMixProgress() != null && mixStatus.getMixProgress().getMixStep() != MixStep.FAIL));
} else {
Expand Down Expand Up @@ -211,4 +212,65 @@ public MixStatusContextMenu(UtxoEntry utxoEntry, boolean isMixing) {
}
}
}

/**
* Provides an equal length for all displayed mixesDone cell texts by reserving enough space to hold the largest
* mix count.
* @param mixesDone
* @return A string representation of <code>mixesDone</code> but of the same string length as the greatest mix
* count in the column.
*/
private String formatMixesDone(int mixesDone) {
int mixesDoneDigits = calcDigitCount(mixesDone);
if (mixesDoneDigits > maxMixesDoneDigitCount) maxMixesDoneDigitCount = mixesDoneDigits;
String formattingString = "%1$" + maxMixesDoneDigitCount + "s";

return String.format(formattingString, mixesDone);
}

/**
* Util method to count the digits of a number excluding its sign by a divide and conquer algorithm.
* @param number
* @return An integer representing the number of digits in the provided integer.
*/
private int calcDigitCount(int number) {
number = Math.abs(number);
if (number < 100000) {
if (number < 100) {
if (number < 10) {
return 1;
} else {
return 2;
}
} else {
if (number < 1000) {
return 3;
} else {
if (number < 10000) {
return 4;
} else {
return 5;
}
}
}
} else {
if (number < 10000000) {
if (number < 1000000) {
return 6;
} else {
return 7;
}
} else {
if (number < 100000000) {
return 8;
} else {
if (number < 1000000000) {
return 9;
} else {
return 10;
}
}
}
}
}
}