Mercurial > hg > release > thermostat-0.11
changeset 1113:58d1c5979ddd
PR1440: Better numbers formatting on Memory panel
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-May/006767.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Mon, 27 May 2013 13:22:58 -0400 |
parents | 6640492c1733 |
children | 9c1ebac8d0b9 |
files | vm-memory/client-core/src/main/java/com/redhat/thermostat/vm/memory/client/core/MemoryMeter.java vm-memory/client-core/src/main/java/com/redhat/thermostat/vm/memory/client/core/internal/MemoryStatsController.java vm-memory/client-core/src/test/java/com/redhat/thermostat/vm/memory/client/core/internal/MemoryStatsControllerTest.java |
diffstat | 3 files changed, 12 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/vm-memory/client-core/src/main/java/com/redhat/thermostat/vm/memory/client/core/MemoryMeter.java Mon May 27 12:27:22 2013 -0400 +++ b/vm-memory/client-core/src/main/java/com/redhat/thermostat/vm/memory/client/core/MemoryMeter.java Mon May 27 13:22:58 2013 -0400 @@ -209,7 +209,7 @@ bounds.height, 6, 6); graphics.fill(frame); - String value = String.valueOf(getPrimaryModel().getValue()) + " " + primaryUnit; + String value = String.format("%.2f", getPrimaryModel().getValue()) + " " + primaryUnit; Rectangle2D fontBounds = font.getStringBounds(value, graphics.getFontRenderContext()); int width = (int) (bounds.width/2 - fontBounds.getWidth()/2) - 1; @@ -298,28 +298,28 @@ // top bar min value FontMetrics fm = SwingUtilities2.getFontMetrics(this, font); - String value = String.valueOf(getPrimaryModel().getMinimum()) + " " + primaryUnit; + String value = String.format("%.2f", getPrimaryModel().getMinimum()) + " " + primaryUnit; int height = top + fm.getAscent()/2; SwingUtilities2.drawString(this, graphics, value, 1, height); - value = String.valueOf(getSecondaryModel().getMinimum()) + " " + secondaryUnit; + value = String.format("%.2f", getSecondaryModel().getMinimum()) + " " + secondaryUnit; height = bottom; SwingUtilities2.drawString(this, graphics, value, 1, height); - value = String.valueOf(getPrimaryModel().getMaximum()) + " " + primaryUnit; + value = String.format("%.2f", getPrimaryModel().getMaximum()) + " " + primaryUnit; height = top + fm.getAscent()/2; int width = (int) (right - font.getStringBounds(value, graphics.getFontRenderContext()).getWidth()) - 1; SwingUtilities2.drawString(this, graphics, value, width, height); - value = String.valueOf(getSecondaryModel().getMaximum()) + " " + secondaryUnit; + value = String.format("%.2f", getSecondaryModel().getMaximum()) + " " + secondaryUnit; height = bottom; width = (int) (right - font.getStringBounds(value, graphics.getFontRenderContext()).getWidth()) - 1; SwingUtilities2.drawString(this, graphics, value, width, height); // now draw the actual value for the bottom bar, the top bar is drawn in // its fill method - value = String.valueOf(getSecondaryModel().getValue()) + " " + secondaryUnit; + value = String.format("%.2f", getSecondaryModel().getValue()) + " " + secondaryUnit; width = right/2; Rectangle2D bounds = font.getStringBounds(value, graphics.getFontRenderContext()); width = (int) (width - bounds.getWidth()/2) - 1;
--- a/vm-memory/client-core/src/main/java/com/redhat/thermostat/vm/memory/client/core/internal/MemoryStatsController.java Mon May 27 12:27:22 2013 -0400 +++ b/vm-memory/client-core/src/main/java/com/redhat/thermostat/vm/memory/client/core/internal/MemoryStatsController.java Mon May 27 13:22:58 2013 -0400 @@ -122,9 +122,9 @@ payload.setMaxCapacity(maxCapacity); payload.setCapacityUnit(maxScale); - String tooltip = space.getName() + ": used: " + used + " " + usedScale + - ", capacity: " + capacity + " " + maxScale + - ", max capacity: " + maxCapacity + " " + maxScale; + String tooltip = space.getName() + ": used: " + String.format("%.2f", used) + " " + usedScale + + ", capacity: " + String.format("%.2f", capacity) + " " + maxScale + + ", max capacity: " + String.format("%.2f", maxCapacity) + " " + maxScale; payload.setTooltip(tooltip);
--- a/vm-memory/client-core/src/test/java/com/redhat/thermostat/vm/memory/client/core/internal/MemoryStatsControllerTest.java Mon May 27 12:27:22 2013 -0400 +++ b/vm-memory/client-core/src/test/java/com/redhat/thermostat/vm/memory/client/core/internal/MemoryStatsControllerTest.java Mon May 27 13:22:58 2013 -0400 @@ -244,10 +244,10 @@ assertEquals(1, payload.getUsed(), 0); // the value above all ensure the same scale is used - String tooltip = payload.getName() + ": used: " + payload.getUsed() + " " + + String tooltip = payload.getName() + ": used: " + String.format("%.2f", payload.getUsed()) + " " + payload.getUsedUnit() + ", capacity: " + - payload.getCapacity() + " " + payload.getUsedUnit() + - ", max capacity: " + payload.getMaxCapacity() + " " + + String.format("%.2f", payload.getCapacity()) + " " + payload.getUsedUnit() + + ", max capacity: " + String.format("%.2f", payload.getMaxCapacity()) + " " + payload.getUsedUnit(); assertEquals(tooltip, payload.getTooltip());