@Override public Object getPreviousValue() { final Object ret = this.getValue(); final long num = ((Number) ret).longValue(); final Unit unit = SizeFormatter.getBestUnit(num); long add = getStep(num, unit); long nv; if (this.nm.getMinimum() != null) { nv = (long) Math.max(((Number) this.nm.getMinimum()).longValue(), num - add); } else { nv = (long) (num - add); } final Unit nunit = SizeFormatter.getBestUnit(nv); if (nunit == unit) { if (nv == num) { this.beep(); } return nv; } nv = nunit.getBytes1024() * 1000; if (nv == num) { this.beep(); } return nv; }
@Override public Object getNextValue() { Object ret = getValue(); long num = ((Number) ret).longValue(); Unit unit = SizeFormatter.getBestUnit(num); long add = getStep(num, unit); long newV; if (nm.getMaximum() != null) { newV = (long) Math.min(((Number) nm.getMaximum()).longValue(), num + add); } else { newV = (long) (num + add); } Unit newUnit = SizeFormatter.getBestUnit((long) newV); if (newUnit == unit) { if (newV == num) { beep(); } return newV; } newV = newUnit.getBytes1024() * 1; if (newV == num) { beep(); } return newV; }
public long getStep(long num, Unit unit) { long display = num / unit.getBytes1024(); int log = display < 1 ? 0 : (int) Math.log10(display); log -= 1; long add = 0; if (log < 0) { add = (long) ((unit.getBytes1024() / 1024) * 100); } else { add = (long) (Math.pow(10, log) * unit.getBytes1024()); } return Math.max(1, add); }