use of com.biglybt.ui.swt.config.IntSwtParameter in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method addTemporaryRates.
private void addTemporaryRates(Composite composite) {
Group temp_rates = new Group(composite, SWT.NULL);
Messages.setLanguageText(temp_rates, "label.temporary.rates");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
temp_rates.setLayoutData(gridData);
GridLayout layout = new GridLayout(10, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
temp_rates.setLayout(layout);
// label = new Label(temp_rates, SWT.NULL);
// Messages.setLanguageText( label, "label.temporary.rates" );
Label label = new Label(temp_rates, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 4;
label.setLayoutData(gridData);
Messages.setLanguageText(label, "label.upload.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final IntSwtParameter tempULRate = new IntSwtParameter(temp_rates, "global.download.rate.temp.kbps", null, null, 0, Integer.MAX_VALUE, null);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.download.kbps", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final IntSwtParameter tempDLRate = new IntSwtParameter(temp_rates, "global.upload.rate.temp.kbps", null, null, 0, Integer.MAX_VALUE, null);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.duration.mins");
final IntSwtParameter tempMins = new IntSwtParameter(temp_rates, "global.rate.temp.min", null, null, 0, Integer.MAX_VALUE, null);
final Button activate = new Button(temp_rates, SWT.TOGGLE);
Messages.setLanguageText(activate, "label.activate");
final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 150;
remLabel.setLayoutData(gridData);
activate.addSelectionListener(new SelectionAdapter() {
private CoreLifecycleAdapter listener;
private TimerEventPeriodic event;
private boolean auto_up_enabled;
private boolean auto_up_seeding_enabled;
private boolean seeding_limits_enabled;
private int up_limit;
private int down_limit;
private long end_time;
@Override
public void widgetSelected(SelectionEvent e) {
if (activate.getSelection()) {
listener = new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
deactivate(true);
}
};
CoreFactory.getSingleton().addLifecycleListener(listener);
Messages.setLanguageText(activate, "FileView.BlockView.Active");
tempDLRate.setEnabled(false);
tempULRate.setEnabled(false);
tempMins.setEnabled(false);
auto_up_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY);
auto_up_seeding_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY);
seeding_limits_enabled = COConfigurationManager.getBooleanParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY);
up_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY);
down_limit = COConfigurationManager.getIntParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, tempULRate.getValue());
COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, tempDLRate.getValue());
end_time = SystemTime.getCurrentTime() + tempMins.getValue() * 60 * 1000;
event = SimpleTimer.addPeriodicEvent("TempRates", 1000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (event == null) {
return;
}
long now = SystemTime.getCurrentTime();
long rem = end_time - now;
if (rem < 1000 || composite.isDisposed()) {
deactivate(false);
} else {
remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatTime(rem));
}
}
});
}
});
} else {
deactivate(false);
}
}
private void deactivate(boolean closing) {
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, auto_up_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, auto_up_seeding_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_ENABLED_CONFIGKEY, seeding_limits_enabled);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, up_limit);
COConfigurationManager.setParameter(TransferSpeedValidator.DOWNLOAD_CONFIGKEY, down_limit);
if (!closing) {
if (listener != null) {
CoreFactory.getSingleton().removeLifecycleListener(listener);
listener = null;
}
if (!composite.isDisposed()) {
Messages.setLanguageText(activate, "label.activate");
activate.setSelection(false);
tempDLRate.setEnabled(true);
tempULRate.setEnabled(true);
tempMins.setEnabled(true);
remLabel.setText("");
}
}
if (event != null) {
event.cancel();
event = null;
}
}
});
tempMins.addAndFireChangeListener(p -> Utils.execSWTThread(() -> activate.setEnabled(p.getValue() > 0)));
}
use of com.biglybt.ui.swt.config.IntSwtParameter in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method addTemporaryData.
private void addTemporaryData(Composite composite) {
Group temp_rates = new Group(composite, SWT.NULL);
Messages.setLanguageText(temp_rates, "label.temporary.data");
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
temp_rates.setLayoutData(gridData);
GridLayout layout = new GridLayout(10, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
temp_rates.setLayout(layout);
// label = new Label(temp_rates, SWT.NULL);
// Messages.setLanguageText( label, "label.temporary.rates" );
Label label = new Label(temp_rates, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 4;
label.setLayoutData(gridData);
Messages.setLanguageText(label, "label.upload.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
final IntSwtParameter tempULLimit = new IntSwtParameter(temp_rates, "global.upload.limit.temp.mb", null, null, 0, Integer.MAX_VALUE, null);
label = new Label(temp_rates, SWT.NULL);
Messages.setLanguageText(label, "label.download.mb", new String[] { DisplayFormatters.getUnit(DisplayFormatters.UNIT_MB) });
final IntSwtParameter tempDLLimit = new IntSwtParameter(temp_rates, "global.download.limit.temp.mb", null, null, 0, Integer.MAX_VALUE, null);
final Button activate = new Button(temp_rates, SWT.TOGGLE);
Messages.setLanguageText(activate, "label.activate");
final BufferedLabel remLabel = new BufferedLabel(temp_rates, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 200;
remLabel.setLayoutData(gridData);
activate.addSelectionListener(new SelectionAdapter() {
private CoreLifecycleAdapter listener;
private TimerEventPeriodic event;
private long end_upload;
private long end_download;
@Override
public void widgetSelected(SelectionEvent e) {
if (activate.getSelection()) {
listener = new CoreLifecycleAdapter() {
@Override
public void stopping(Core core) {
deactivate(true);
}
};
Core core = CoreFactory.getSingleton();
core.addLifecycleListener(listener);
Messages.setLanguageText(activate, "FileView.BlockView.Active");
final GlobalManagerStats stats = core.getGlobalManager().getStats();
tempULLimit.setEnabled(false);
tempDLLimit.setEnabled(false);
long u_limit = tempULLimit.getValue();
if (u_limit > 0) {
end_upload = stats.getTotalDataProtocolBytesSent() + u_limit * DisplayFormatters.getMinB();
} else {
end_upload = 0;
}
long d_limit = tempDLLimit.getValue();
if (d_limit > 0) {
end_download = stats.getTotalDataProtocolBytesReceived() + d_limit * DisplayFormatters.getMinB();
} else {
end_download = 0;
}
event = SimpleTimer.addPeriodicEvent("TempData", 5000, new TimerEventPerformer() {
@Override
public void perform(TimerEvent e) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (event == null) {
return;
}
long rem_up = 0;
long rem_down = 0;
if (end_upload > 0) {
rem_up = end_upload - stats.getTotalDataProtocolBytesSent();
}
if (end_download > 0) {
rem_down = end_download - stats.getTotalDataProtocolBytesReceived();
}
if (end_upload > 0 && rem_up <= 0) {
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
if (!dm.isForceStart()) {
int state = dm.getState();
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
ManagerUtils.stop(dm, null);
dm.setStopReason(MessageText.getString("label.temporary.data"));
}
}
}
}
if (end_download > 0 && rem_down <= 0) {
java.util.List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
if (!dm.isForceStart()) {
int state = dm.getState();
if (state != DownloadManager.STATE_STOPPED && state != DownloadManager.STATE_ERROR && !dm.isPaused()) {
if (!dm.isDownloadComplete(false)) {
ManagerUtils.stop(dm, null);
dm.setStopReason(MessageText.getString("label.temporary.data"));
}
}
}
}
}
if ((rem_up <= 0 && rem_down <= 0) || composite.isDisposed()) {
deactivate(false);
} else {
remLabel.setText(MessageText.getString("TableColumn.header.remaining") + ": " + DisplayFormatters.formatByteCountToKiBEtc(rem_up < 0 ? 0 : rem_up) + "/" + DisplayFormatters.formatByteCountToKiBEtc(rem_down < 0 ? 0 : rem_down));
temp_rates.layout(new Control[] { remLabel.getControl() });
}
}
});
}
});
} else {
deactivate(false);
}
}
private void deactivate(boolean closing) {
if (!closing) {
if (listener != null) {
CoreFactory.getSingleton().removeLifecycleListener(listener);
listener = null;
}
if (!composite.isDisposed()) {
Messages.setLanguageText(activate, "label.activate");
activate.setSelection(false);
tempULLimit.setEnabled(true);
tempDLLimit.setEnabled(true);
remLabel.setText("");
temp_rates.layout(true);
}
}
if (event != null) {
event.cancel();
event = null;
}
}
});
activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0);
ParameterChangeListener adapter = p -> Utils.execSWTThread(() -> activate.setEnabled(tempULLimit.getValue() > 0 || tempDLLimit.getValue() > 0));
tempULLimit.addChangeListener(adapter);
tempDLLimit.addChangeListener(adapter);
}
use of com.biglybt.ui.swt.config.IntSwtParameter in project BiglyBT by BiglySoftware.
the class ViewQuickConfig method initialize.
private void initialize(Composite ooparent) {
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
ooparent.setLayout(layout);
// if you put the border on the scrolled composite parent then on every resize the computedSize
// grows by 4 pixels :( So stick in extra composite for the border
final Composite oparent = new Composite(ooparent, SWT.BORDER);
GridData gridData = new GridData(GridData.FILL_BOTH);
oparent.setLayoutData(gridData);
layout = new GridLayout(1, false);
layout.marginWidth = 0;
layout.marginHeight = 0;
oparent.setLayout(layout);
final Composite parent = new Composite(oparent, SWT.NULL);
gridData = new GridData(GridData.FILL_BOTH);
parent.setLayoutData(gridData);
composite = Utils.createScrolledComposite(parent);
gridData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gridData);
layout = new GridLayout(4, false);
composite.setLayout(layout);
// done downloading - 2
addDoneDownloadingOption(composite, false);
// max simul down - 2
Label label = new Label(composite, SWT.NULL);
gridData = new GridData();
gridData.horizontalIndent = 8;
label.setLayoutData(gridData);
Messages.setLanguageText(label, "ConfigView.label.maxdownloads.short");
IntSwtParameter maxDLs = new IntSwtParameter(composite, "max downloads", null, null, null);
maxDLs.addChangeListener(p -> COConfigurationManager.setDirty());
addTemporaryRates(composite);
addTemporaryData(composite);
}
use of com.biglybt.ui.swt.config.IntSwtParameter in project BiglyBT by BiglySoftware.
the class TorrentOptionsView method initialize.
private void initialize(Composite composite) {
this.parent = composite;
GridLayout layout;
// I don't want to waste my time :) [tux]
if (sc != null && !sc.isDisposed()) {
sc.dispose();
}
sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
sc.getVerticalBar().setIncrement(16);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
sc.setLayoutData(gridData);
Composite panel = new Composite(sc, SWT.NULL);
sc.setContent(panel);
layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 1;
panel.setLayout(layout);
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof FormLayout) {
panel.setLayoutData(Utils.getFilledFormData());
} else {
panel.setLayoutData(new GridData(GridData.FILL_BOTH));
}
if (managers == null) {
return;
}
int userMode = COConfigurationManager.getIntParameter("User Mode");
// header
boolean showHeader = true;
if (swtView instanceof TabbedEntry) {
showHeader = ((TabbedEntry) swtView).getMDI().getAllowSubViews();
}
if (showHeader) {
Composite cHeader = new Composite(panel, SWT.BORDER);
GridLayout configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
cHeader.setLayoutData(gridData);
Display d = panel.getDisplay();
cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
Label lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
FontData[] fontData = lHeader.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
int fontHeight = (int) (fontData[0].getHeight() * 1.2);
fontData[0].setHeight(fontHeight);
headerFont = new Font(d, fontData);
lHeader.setFont(headerFont);
if (managers.length == 1) {
if (managers[0].getDownloadManager() == null) {
lHeader.setText(" " + managers[0].getName().replaceAll("&", "&&"));
} else {
lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + managers[0].getName().replaceAll("&", "&&"));
}
} else {
String str = "";
for (int i = 0; i < Math.min(3, managers.length); i++) {
str += (i == 0 ? "" : ", ") + managers[i].getName().replaceAll("&", "&&");
}
if (managers.length > 3) {
str += "...";
}
lHeader.setText(" " + managers.length + " " + MessageText.getString("ConfigView.section.torrents") + " : " + str);
}
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
lHeader.setLayoutData(gridData);
}
Group gTorrentOptions = new Group(panel, SWT.NULL);
Messages.setLanguageText(gTorrentOptions, "ConfigView.section.transfer");
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
gTorrentOptions.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 2;
gTorrentOptions.setLayout(layout);
// Disabled for release. Need to convert from user-specified units to
// KB/s before restoring the following line
// String k_unit = DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB).trim()
String k_unit = DisplayFormatters.getRateUnitBase10(DisplayFormatters.UNIT_KB).trim();
// max upload speed
Label label;
IntSwtParameter max_upload = new IntSwtParameter(gTorrentOptions, MAX_UPLOAD, "", null, adhoc_param_adapter);
max_upload.setLabelText(k_unit + " " + MessageText.getString("GeneralView.label.maxuploadspeed.tooltip"));
adhoc_parameters.put(MAX_UPLOAD, max_upload);
if (userMode > 0) {
// max upload when busy
IntSwtParameter max_upload_when_busy = new IntSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_MAX_UPLOAD_WHEN_BUSY, "TorrentOptionsView.param.max.uploads.when.busy", null, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOAD_WHEN_BUSY, max_upload_when_busy);
}
// max download speed
IntSwtParameter max_download = new IntSwtParameter(gTorrentOptions, MAX_DOWNLOAD, "", null, adhoc_param_adapter);
max_download.setLabelText(k_unit + " " + MessageText.getString("GeneralView.label.maxdownloadspeed.tooltip"));
adhoc_parameters.put(MAX_DOWNLOAD, max_download);
if (userMode > 0) {
IntSwtParameter max_uploads = new IntSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_MAX_UPLOADS, "TorrentOptionsView.param.max.uploads", null, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOADS, max_uploads);
max_uploads.setMinimumValue(2);
// max uploads when seeding enabled
final Composite cMaxUploadsOptionsArea = new Composite(gTorrentOptions, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 3;
layout.marginWidth = 0;
layout.marginHeight = 0;
cMaxUploadsOptionsArea.setLayout(layout);
gridData = new GridData();
gridData.horizontalSpan = 2;
cMaxUploadsOptionsArea.setLayoutData(gridData);
BooleanSwtParameter max_uploads_when_seeding_enabled = new BooleanSwtParameter(cMaxUploadsOptionsArea, DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED, "TorrentOptionsView.param.alternative.value.enable", null, ds_boolparam_adapter);
max_uploads_when_seeding_enabled.setIndent(1, true);
ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING_ENABLED, max_uploads_when_seeding_enabled);
IntSwtParameter max_uploads_when_seeding = new IntSwtParameter(cMaxUploadsOptionsArea, DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING, null, null, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING, max_uploads_when_seeding);
max_uploads_when_seeding.setMinimumValue(2);
max_uploads_when_seeding_enabled.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(max_uploads_when_seeding));
// max peers
IntSwtParameter max_peers = new IntSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_MAX_PEERS, "TorrentOptionsView.param.max.peers", null, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_PEERS, max_peers);
// max peers when seeding
final Composite cMaxPeersOptionsArea = new Composite(gTorrentOptions, SWT.NULL);
layout = new GridLayout();
layout.numColumns = 3;
layout.marginWidth = 0;
layout.marginHeight = 0;
cMaxPeersOptionsArea.setLayout(layout);
gridData = new GridData();
gridData.horizontalSpan = 2;
cMaxPeersOptionsArea.setLayoutData(gridData);
BooleanSwtParameter max_peers_when_seeding_enabled = new BooleanSwtParameter(cMaxPeersOptionsArea, DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED, "TorrentOptionsView.param.alternative.value.enable", null, ds_boolparam_adapter);
max_peers_when_seeding_enabled.setIndent(1, true);
ds_parameters.put(DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING_ENABLED, max_peers_when_seeding_enabled);
IntSwtParameter max_peers_when_seeding = new IntSwtParameter(cMaxPeersOptionsArea, DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING, null, null, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_PEERS_WHEN_SEEDING, max_peers_when_seeding);
max_peers_when_seeding_enabled.setAdditionalActionPerformer(new ChangeSelectionActionPerformer(max_peers_when_seeding));
// max seeds
IntSwtParameter max_seeds = new IntSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_MAX_SEEDS, "TorrentOptionsView.param.max.seeds", null, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_SEEDS, max_seeds);
}
if (userMode > 0) {
IntSwtParameter upload_priority_enabled = new IntSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_UPLOAD_PRIORITY, "TorrentOptionsView.param.upload.priority", null, 0, 1, ds_intparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_UPLOAD_PRIORITY, upload_priority_enabled);
// min sr
FloatSwtParameter min_sr = new FloatSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_MIN_SHARE_RATIO, "TableColumn.header.min_sr", null, 0, Float.MAX_VALUE, true, 3, ds_floatparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MIN_SHARE_RATIO, min_sr);
// max sr
FloatSwtParameter max_sr = new FloatSwtParameter(gTorrentOptions, DownloadManagerState.PARAM_MAX_SHARE_RATIO, "TableColumn.header.max_sr", null, 0, Float.MAX_VALUE, true, 3, ds_floatparam_adapter);
ds_parameters.put(DownloadManagerState.PARAM_MAX_SHARE_RATIO, max_sr);
}
// reset
Label reset_label = new Label(gTorrentOptions, SWT.NULL);
Messages.setLanguageText(reset_label, "TorrentOptionsView.param.reset.to.default");
Button reset_button = new Button(gTorrentOptions, SWT.PUSH);
Messages.setLanguageText(reset_button, "TorrentOptionsView.param.reset.button");
reset_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
setDefaults();
}
});
for (int i = 0; i < managers.length; i++) {
managers[i].addListener(this);
}
Group gTorrentInfo = new Group(panel, SWT.NULL);
Messages.setLanguageText(gTorrentInfo, "label.aggregate.info");
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
gTorrentInfo.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 2;
gTorrentInfo.setLayout(layout);
// total size
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("TableColumn.header.size") + ": ");
agg_size = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_size.setLayoutData(gridData);
// remaining
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("TableColumn.header.remaining") + ": ");
agg_remaining = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_remaining.setLayoutData(gridData);
// uploaded
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("MyTracker.column.uploaded") + ": ");
agg_uploaded = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_uploaded.setLayoutData(gridData);
// downloaded
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("MyTracker.column.downloaded") + ": ");
agg_downloaded = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_downloaded.setLayoutData(gridData);
// upload speed
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("SpeedView.uploadSpeed.title") + ": ");
agg_upload_speed = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_upload_speed.setLayoutData(gridData);
// download speed
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("SpeedView.downloadSpeed.title") + ": ");
agg_download_speed = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_download_speed.setLayoutData(gridData);
// share ratio
label = new Label(gTorrentInfo, SWT.NULL);
label.setText(MessageText.getString("TableColumn.header.shareRatio") + ": ");
agg_share_ratio = new BufferedLabel(gTorrentInfo, SWT.LEFT | SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
agg_share_ratio.setLayoutData(gridData);
// reset
Label stats_reset_label = new Label(gTorrentInfo, SWT.NULL);
Messages.setLanguageText(stats_reset_label, "TorrentOptionsView.param.reset.stats");
Button stats_reset_button = new Button(gTorrentInfo, SWT.PUSH);
Messages.setLanguageText(stats_reset_button, "TorrentOptionsView.param.reset.button");
stats_reset_button.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (DownloadManagerOptionsHandler dm : managers) {
if (dm.getDownloadManager() != null) {
dm.getDownloadManager().getStats().resetTotalBytesSentReceived(0, 0);
}
}
}
});
sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
composite.layout();
}
use of com.biglybt.ui.swt.config.IntSwtParameter in project BiglyBT by BiglySoftware.
the class TorrentOptionsView method setDefaults.
protected void setDefaults() {
Iterator<Entry<String, BaseSwtParameter<?, ?>>> it = ds_parameters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, BaseSwtParameter<?, ?>> entry = it.next();
String key = entry.getKey();
for (int i = 0; i < managers.length; i++) {
managers[i].setParameterDefault(key);
}
// we need an explicit refresh here because of the way the reset works - by the time to code
// runs to see if the displayed value has changed from the parameter value the value has been
// reset and appears not to have changed (even though the parameter has...)
entry.getValue().refreshControl();
}
it = adhoc_parameters.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, BaseSwtParameter<?, ?>> entry = it.next();
BaseSwtParameter<?, ?> param = entry.getValue();
if (param instanceof IntSwtParameter) {
IntSwtParameter int_param = (IntSwtParameter) param;
int_param.setValue(0);
} else {
Debug.out("Unknown parameter type: " + param.getClass());
}
}
}
Aggregations