use of com.biglybt.ui.swt.config.actionperformer.ChangeSelectionActionPerformer 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();
}
Aggregations