public static SizeFormatter get(final boolean decimal) { if(decimal) { return new ch.cyberduck.core.formatter.DecimalSizeFormatter(); } // Default is binary sizes return new ch.cyberduck.core.formatter.BinarySizeFormatter(); } }
public Speedometer(final long timestamp, final boolean decimal) { this.timestamp = timestamp; this.sizeFormatter = SizeFormatterFactory.get(decimal); }
@Override public String format(final long size) { return format(size, false); }
@Override public String getTooltip(final Path file) { return sizeFormatter.format(file.attributes().getSize(), true); } }
@Override public String format(final long size, final boolean plain) { if(size < 0) { return LocaleFactory.localizedString("--"); } if(size < kilo.multiple()) { return String.format("%d B", size); } StringBuilder formatted = new StringBuilder(); if(size < mega.multiple()) { formatted.append(new BigDecimal(size).divide(new BigDecimal(kilo.multiple()), 1, BigDecimal.ROUND_HALF_UP).toString()).append(" ").append(kilo.suffix()); } else if(size < giga.multiple()) { formatted.append(new BigDecimal(size).divide(new BigDecimal(mega.multiple()), 1, BigDecimal.ROUND_HALF_UP).toString()).append(" ").append(mega.suffix()); } else { formatted.append(new BigDecimal(size).divide(new BigDecimal(giga.multiple()), 1, BigDecimal.ROUND_HALF_UP).toString()).append(" ").append(giga.suffix()); } if(plain) { formatted.append(" (").append(NumberFormat.getInstance().format(size)).append(" bytes)"); } return formatted.toString(); } }
options.append(5 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(10 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(20 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(50 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(100 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(150 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(200 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(500 * DecimalSizeFormatter.KILO.multiple()).append(","); options.append(1 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(2 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(5 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(10 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(15 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(20 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(50 * DecimalSizeFormatter.MEGA.multiple()).append(","); options.append(100 * DecimalSizeFormatter.MEGA.multiple()).append(","); this.setDefault("queue.bandwidth.options", options.toString());
final StringBuilder b = new StringBuilder( MessageFormat.format(LocaleFactory.localizedString("{0} of {1}"), sizeFormatter.format(transferred, running), sizeFormatter.format(size)) ); if(running && transferred > 0) { b.append(", "); b.append(SizeFormatterFactory.get(true).format( new BigDecimal(speed * 1000).setScale(0, RoundingMode.UP).longValue())); b.append("/sec");
public synchronized TransferProgress getProgress() { long size = 0; for(Transfer t : this) { if(t.isRunning()) { size += t.getSize(); } } long transferred = 0; for(Transfer t : this) { if(t.isRunning()) { transferred += t.getTransferred(); } } return new TransferProgress(size, transferred, MessageFormat.format(LocaleFactory.localizedString("{0} of {1}"), sizeFormatter.format(transferred), sizeFormatter.format(size)), -1d); } }
public SizeTooltipService() { this(SizeFormatterFactory.get()); }
public void setDefaultDownloadThrottleCombobox(NSPopUpButton b) { this.defaultDownloadThrottleCombobox = b; this.defaultDownloadThrottleCombobox.setTarget(this.id()); this.defaultDownloadThrottleCombobox.setAction(Foundation.selector("defaultDownloadThrottleComboboxClicked:")); int bandwidth = (int) preferences.getDouble("queue.download.bandwidth.bytes"); final StringTokenizer options = new StringTokenizer(preferences.getProperty("queue.bandwidth.options"), ","); while(options.hasMoreTokens()) { final String bytes = options.nextToken(); this.defaultDownloadThrottleCombobox.addItemWithTitle(SizeFormatterFactory.get().format(Integer.parseInt(bytes)) + "/s"); this.defaultDownloadThrottleCombobox.lastItem().setRepresentedObject(bytes); } if(-1 == bandwidth) { this.defaultDownloadThrottleCombobox.selectItemWithTag(new NSInteger(-1)); } else { this.defaultDownloadThrottleCombobox.selectItemAtIndex( this.defaultDownloadThrottleCombobox.menu().indexOfItemWithRepresentedObject(String.valueOf(bandwidth))); } }
/** * Resets both the progress and status field */ @Override public void awakeFromNib() { this.setProgress(MessageFormat.format(LocaleFactory.localizedString("{0} of {1}"), sizeFormatter.format(transfer.getTransferred()), sizeFormatter.format(transfer.getSize()))); this.setMessage(StringUtils.EMPTY); this.setStatus(LocaleFactory.localizedString(transfer.isComplete() ? String.format("%s complete", StringUtils.capitalize(transfer.getType().name())) : "Transfer incomplete", "Status")); super.awakeFromNib(); }
public static SizeFormatter get() { return SizeFormatterFactory.get(PreferencesFactory.get().getBoolean("browser.filesize.decimal")); }
public void setDefaultUploadThrottleCombobox(NSPopUpButton b) { this.defaultUploadThrottleCombobox = b; this.defaultUploadThrottleCombobox.setTarget(this.id()); this.defaultUploadThrottleCombobox.setAction(Foundation.selector("defaultUploadThrottleComboboxClicked:")); int bandwidth = (int) preferences.getDouble("queue.upload.bandwidth.bytes"); final StringTokenizer options = new StringTokenizer(preferences.getProperty("queue.bandwidth.options"), ","); while(options.hasMoreTokens()) { final String bytes = options.nextToken(); this.defaultUploadThrottleCombobox.addItemWithTitle(SizeFormatterFactory.get().format(Integer.parseInt(bytes)) + "/s"); this.defaultUploadThrottleCombobox.lastItem().setRepresentedObject(bytes); } if(-1 == bandwidth) { this.defaultUploadThrottleCombobox.selectItemWithTag(new NSInteger(-1)); } else { this.defaultUploadThrottleCombobox.selectItemAtIndex( this.defaultUploadThrottleCombobox.menu().indexOfItemWithRepresentedObject(String.valueOf(bandwidth))); } }
@Override public void run() { progressBar.stopAnimation(null); progressBar.setIndeterminate(true); progressBar.setHidden(true); setMessage(StringUtils.EMPTY); setProgress(MessageFormat.format(LocaleFactory.localizedString("{0} of {1}"), sizeFormatter.format(transfer.getTransferred()), sizeFormatter.format(transfer.getSize()))); setStatus(LocaleFactory.localizedString(LocaleFactory.localizedString(transfer.isComplete() ? String.format("%s complete", StringUtils.capitalize(transfer.getType().name())) : "Transfer incomplete", "Status"), "Status")); statusIconView.setImage(transfer.isComplete() ? GREEN_ICON : RED_ICON); } });
protected NSObject objectValueForItem(final TransferItem file, final String identifier) { final TransferStatus status = this.getStatus(file); if(identifier.equals(Column.include.name())) { if(status.isRejected()) { return NSNumber.numberWithBoolean(false); } return NSNumber.numberWithBoolean(this.isSelected(file)); } if(identifier.equals(Column.filename.name())) { return NSAttributedString.attributedStringWithAttributes(file.remote.getName(), TableCellAttributes.browserFontLeftAlignment()); } if(identifier.equals(Column.size.name())) { return NSAttributedString.attributedStringWithAttributes( SizeFormatterFactory.get().format(status.getLength()), TableCellAttributes.browserFontRightAlignment()); } if(identifier.equals(Column.warning.name())) { if(file.remote.isFile()) { if(status.getLength() == 0) { return IconCacheFactory.<NSImage>get().iconNamed("alert.tiff"); } } return null; } throw new IllegalArgumentException(String.format("Unknown identifier %s", identifier)); }
sizeFormatter.format(item.attributes().getSize()), TableCellAttributes.browserFontRightAlignment());