use of com.biglybt.core.networkmanager.admin.NetworkAdminSpeedTesterResult in project BiglyBT by BiglySoftware.
the class SpeedTestSetLimitPanel method show.
/**
* Panel has text at the top explaining the result.
* Then under that it has a label the measured upload value and the recommended value.
* Then a button with apply.
*/
@Override
public void show() {
wizard.setTitle(MessageText.getString("SpeedTestWizard.set.upload.title"));
wizard.setCurrentInfo(MessageText.getString("SpeedTestWizard.set.upload.hint"));
Composite rootPanel = wizard.getPanel();
GridLayout layout = new GridLayout();
layout.numColumns = 1;
rootPanel.setLayout(layout);
Composite panel = new Composite(rootPanel, SWT.NULL);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
Utils.setLayoutData(panel, gridData);
layout = new GridLayout();
layout.numColumns = 4;
panel.setLayout(layout);
Label explain = new Label(panel, SWT.WRAP);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 4;
Utils.setLayoutData(explain, gridData);
Messages.setLanguageText(explain, "SpeedTestWizard.set.upload.panel.explain");
// spacer line
Label spacer = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 4;
Utils.setLayoutData(spacer, gridData);
Label spacer1 = new Label(panel, SWT.NULL);
gridData = new GridData();
spacer1.setLayoutData(gridData);
Label bytesCol = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.widthHint = 80;
Utils.setLayoutData(bytesCol, gridData);
Messages.setLanguageText(bytesCol, "SpeedTestWizard.set.upload.bytes.per.sec");
Label bitsCol = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.widthHint = 80;
Utils.setLayoutData(bitsCol, gridData);
Messages.setLanguageText(bitsCol, "SpeedTestWizard.set.upload.bits.per.sec");
Label confLevel = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.widthHint = 80;
Utils.setLayoutData(confLevel, gridData);
Messages.setLanguageText(confLevel, "SpeedTestWizard.set.limit.conf.level");
// upload limit label.
Label ul = new Label(panel, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(ul, gridData);
Messages.setLanguageText(ul, "SpeedView.stats.estupcap", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final Text uploadLimitSetting = new Text(panel, SWT.BORDER);
gridData = new GridData(GridData.BEGINNING);
gridData.widthHint = 80;
Utils.setLayoutData(uploadLimitSetting, gridData);
int uploadCapacity = determineRateSettingEx(measuredUploadKbps, uploadTestRan, true);
// don't accept any value less the 20 kb/s
if (uploadCapacity < 20)
uploadCapacity = 20;
uploadLimitSetting.setText("" + uploadCapacity);
uploadLimitSetting.addListener(SWT.Verify, new NumberListener(uploadLimitSetting));
// echo
final Label echo = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.widthHint = 80;
Utils.setLayoutData(echo, gridData);
echo.setText(DisplayFormatters.formatByteCountToBitsPerSec(uploadCapacity * 1024));
// This space has a change listener the updates in bits/sec.
// want a change listener to update the echo label which has the value in bits/sec.
uploadLimitSetting.addListener(SWT.Modify, new ByteConversionListener(echo, uploadLimitSetting));
// confidence setting.
final String[] confName = helper.getSettableTypes();
final String[] confValue = helper.getSettableTypes();
// upload confidence setting.
int uploadDropIndex = setDefaultConfidenceLevelEx(measuredUploadKbps, uploadTestRan, true, confValue);
upConfLevelCombo = new Combo(panel, SWT.READ_ONLY);
addDropElements(upConfLevelCombo, confName);
upConfLevelCombo.select(uploadDropIndex);
// download limit label.
Label dl = new Label(panel, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(dl, gridData);
Messages.setLanguageText(dl, "SpeedView.stats.estdowncap", new String[] { DisplayFormatters.getRateUnit(DisplayFormatters.UNIT_KB) });
final Text downloadLimitSetting = new Text(panel, SWT.BORDER);
gridData = new GridData(GridData.BEGINNING);
gridData.widthHint = 80;
Utils.setLayoutData(downloadLimitSetting, gridData);
int bestDownloadSetting = determineRateSettingEx(measuredDownloadKbps, downloadTestRan, false);
downloadLimitSetting.setText("" + bestDownloadSetting);
downloadLimitSetting.addListener(SWT.Verify, new NumberListener(downloadLimitSetting));
// echo
final Label downEcho = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.widthHint = 80;
Utils.setLayoutData(downEcho, gridData);
downEcho.setText(DisplayFormatters.formatByteCountToBitsPerSec(bestDownloadSetting * 1024));
// convert bytes to bits on the fly for user.
downloadLimitSetting.addListener(SWT.Modify, new ByteConversionListener(downEcho, downloadLimitSetting));
int downIndex = setDefaultConfidenceLevelEx(measuredDownloadKbps, downloadTestRan, false, confValue);
downConfLevelCombo = new Combo(panel, SWT.READ_ONLY);
addDropElements(downConfLevelCombo, confName);
downConfLevelCombo.select(downIndex);
// spacer col
Label c1 = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.widthHint = 80;
c1.setLayoutData(gridData);
SpeedManager sm = CoreFactory.getSingleton().getSpeedManager();
if (uploadTestRan) {
// Since cable modems can over estimate upload need to drop type setting to estimate.
sm.setEstimatedUploadCapacityBytesPerSec(measuredUploadKbps * 1024, // parg: as far as I can tell this stuff is deliberate, probably because the 'measured' conf settings screwed things up
uploadHitLimit ? SpeedManagerLimitEstimate.TYPE_ESTIMATED : SpeedManagerLimitEstimate.TYPE_ESTIMATED);
}
if (downloadTestRan) {
sm.setEstimatedDownloadCapacityBytesPerSec(measuredDownloadKbps * 1024, downloadHitLimit ? SpeedManagerLimitEstimate.TYPE_MEASURED_MIN : SpeedManagerLimitEstimate.TYPE_MEASURED);
}
apply = new Button(panel, SWT.PUSH);
Messages.setLanguageText(apply, "SpeedTestWizard.set.upload.button.apply");
gridData = new GridData();
gridData.widthHint = 70;
Utils.setLayoutData(apply, gridData);
apply.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
// Turn the string into an int and make it kbps.
int uploadLimitKBPS = Integer.parseInt(uploadLimitSetting.getText());
int downlaodLimitKBPS = Integer.parseInt(downloadLimitSetting.getText());
// No value less then 20 kpbs should be allowed.
if (uploadLimitKBPS < 20) {
uploadLimitKBPS = 20;
}
// download value can never be less then upload.
if (downlaodLimitKBPS < uploadLimitKBPS) {
downlaodLimitKBPS = uploadLimitKBPS;
}
// turn off auto-speed!
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY, false);
COConfigurationManager.setParameter(TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY, false);
// set upload limits
COConfigurationManager.setParameter("AutoSpeed Max Upload KBs", uploadLimitKBPS);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_CONFIGKEY, uploadLimitKBPS);
COConfigurationManager.setParameter(TransferSpeedValidator.UPLOAD_SEEDING_CONFIGKEY, uploadLimitKBPS);
if (downloadTestRan) {
int dIndex = downConfLevelCombo.getSelectionIndex();
float downEstType = helper.textToType(confValue[dIndex]);
speedManager.setEstimatedUploadCapacityBytesPerSec(downlaodLimitKBPS, downEstType);
}
if (uploadTestRan) {
int uIndex = upConfLevelCombo.getSelectionIndex();
float upEstType = helper.textToType(confValue[uIndex]);
speedManager.setEstimatedUploadCapacityBytesPerSec(uploadLimitKBPS, upEstType);
}
wizard.setFinishEnabled(true);
wizard.setPreviousEnabled(false);
}
});
// spacer col
Label c3 = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 1;
c3.setLayoutData(gridData);
// spacer line
Label spacer2 = new Label(panel, SWT.NULL);
gridData = new GridData();
gridData.horizontalSpan = 3;
spacer2.setLayoutData(gridData);
// switch column width to 5 columns.
Composite resultsPanel = new Composite(rootPanel, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_END | GridData.FILL_HORIZONTAL);
Utils.setLayoutData(resultsPanel, gridData);
layout = new GridLayout();
layout.numColumns = 5;
layout.makeColumnsEqualWidth = true;
resultsPanel.setLayout(layout);
// display last test result
NetworkAdminSpeedTesterResult result = SpeedTestData.getInstance().getLastResult();
if (result.hadError()) {
// error
String error = result.getLastError();
createResultLabels(resultsPanel, true);
createErrorDesc(resultsPanel, error);
createTestDesc(resultsPanel);
} else {
// no error
// print out the last result format.
int upload = result.getUploadSpeed();
int download = result.getDownloadSpeed();
createResultLabels(resultsPanel, false);
createResultData(resultsPanel, MessageText.getString("GeneralView.label.uploadspeed"), upload);
createResultData(resultsPanel, MessageText.getString("GeneralView.label.downloadspeed"), download);
createTestDesc(resultsPanel);
}
}
Aggregations