📄 speedtestsetlimitpanel.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: SpeedTestSetLimitPanel.java
package org.gudy.azureus2.ui.swt.speedtest;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.core.networkmanager.admin.NetworkAdminSpeedTesterResult;
import com.aelitis.azureus.core.speedmanager.SpeedManager;
import com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimate;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.DisplayFormatters;
import org.gudy.azureus2.ui.swt.Messages;
import org.gudy.azureus2.ui.swt.views.stats.TransferStatsView;
import org.gudy.azureus2.ui.swt.wizard.*;
// Referenced classes of package org.gudy.azureus2.ui.swt.speedtest:
// SpeedTestData, SpeedTestFinishPanel
public class SpeedTestSetLimitPanel extends AbstractWizardPanel
{
class ByteConversionListener
implements Listener
{
final Label echoLbl;
final Text setting;
final SpeedTestSetLimitPanel this$0;
public void handleEvent(Event e)
{
String newVal = setting.getText();
try
{
int newValInt = Integer.parseInt(newVal);
if (echoLbl != null)
echoLbl.setText(DisplayFormatters.formatByteCountToBitsPerSec(newValInt * 1024));
}
catch (Throwable t) { }
}
public ByteConversionListener(Label _echoLbl, Text _setting)
{
this$0 = SpeedTestSetLimitPanel.this;
super();
echoLbl = _echoLbl;
setting = _setting;
}
}
class NumberListener
implements Listener
{
final Text setting;
final SpeedTestSetLimitPanel this$0;
public void handleEvent(Event e)
{
String text = e.text;
char chars[] = new char[text.length()];
text.getChars(0, chars.length, chars, 0);
for (int i = 0; i < chars.length; i++)
if ('0' > chars[i] || chars[i] > '9')
{
e.doit = false;
return;
}
}
public NumberListener(Text _setting)
{
this$0 = SpeedTestSetLimitPanel.this;
super();
setting = _setting;
}
}
int measuredUploadKbps;
int measuredDownloadKbps;
boolean downloadTestRan;
boolean uploadTestRan;
boolean downloadHitLimit;
boolean uploadHitLimit;
Label explain;
Label downloadLabel;
Label uploadLabel;
Text uploadText;
Button apply;
Combo downConfLevelCombo;
Combo upConfLevelCombo;
SpeedManager speedManager;
org.gudy.azureus2.ui.swt.views.stats.TransferStatsView.limitToTextHelper helper;
public SpeedTestSetLimitPanel(Wizard wizard, IWizardPanel previousPanel, int upload, long maxup, int download, long maxdown)
{
super(wizard, previousPanel);
uploadTestRan = true;
downloadHitLimit = (long)download > maxdown - 20480L;
uploadHitLimit = (long)upload > maxup - 20480L;
measuredUploadKbps = upload / 1024;
if (measuredUploadKbps < 5)
uploadTestRan = false;
measuredDownloadKbps = download / 1024;
if (measuredDownloadKbps < 5)
downloadTestRan = false;
speedManager = AzureusCoreFactory.getSingleton().getSpeedManager();
helper = new org.gudy.azureus2.ui.swt.views.stats.TransferStatsView.limitToTextHelper();
}
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, 0);
GridData gridData = new GridData(768);
panel.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 4;
panel.setLayout(layout);
Label explain = new Label(panel, 64);
gridData = new GridData(768);
gridData.horizontalSpan = 4;
explain.setLayoutData(gridData);
Messages.setLanguageText(explain, "SpeedTestWizard.set.upload.panel.explain");
Label spacer = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 4;
spacer.setLayoutData(gridData);
Label spacer1 = new Label(panel, 0);
gridData = new GridData();
spacer1.setLayoutData(gridData);
Label bytesCol = new Label(panel, 0);
gridData = new GridData();
gridData.widthHint = 80;
bytesCol.setLayoutData(gridData);
Messages.setLanguageText(bytesCol, "SpeedTestWizard.set.upload.bytes.per.sec");
Label bitsCol = new Label(panel, 0);
gridData = new GridData();
gridData.widthHint = 80;
bitsCol.setLayoutData(gridData);
Messages.setLanguageText(bitsCol, "SpeedTestWizard.set.upload.bits.per.sec");
Label confLevel = new Label(panel, 0);
gridData = new GridData();
gridData.widthHint = 80;
confLevel.setLayoutData(gridData);
Messages.setLanguageText(confLevel, "SpeedTestWizard.set.limit.conf.level");
Label ul = new Label(panel, 0);
gridData = new GridData();
ul.setLayoutData(gridData);
Messages.setLanguageText(ul, "SpeedView.stats.estupcap", new String[] {
DisplayFormatters.getRateUnit(1)
});
final Text uploadLimitSetting = new Text(panel, 2048);
gridData = new GridData(1);
gridData.widthHint = 80;
uploadLimitSetting.setLayoutData(gridData);
int uploadCapacity = determineRateSettingEx(measuredUploadKbps, uploadTestRan, true);
if (uploadCapacity < 20)
uploadCapacity = 20;
uploadLimitSetting.setText((new StringBuilder()).append("").append(uploadCapacity).toString());
uploadLimitSetting.addListener(25, new NumberListener(uploadLimitSetting));
Label echo = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.widthHint = 80;
echo.setLayoutData(gridData);
echo.setText(DisplayFormatters.formatByteCountToBitsPerSec(uploadCapacity * 1024));
uploadLimitSetting.addListener(24, new ByteConversionListener(echo, uploadLimitSetting));
String confName[] = helper.getSettableTypes();
final String confValue[] = helper.getSettableTypes();
int uploadDropIndex = setDefaultConfidenceLevelEx(measuredUploadKbps, uploadTestRan, true, confValue);
upConfLevelCombo = new Combo(panel, 8);
addDropElements(upConfLevelCombo, confName);
upConfLevelCombo.select(uploadDropIndex);
Label dl = new Label(panel, 0);
gridData = new GridData();
dl.setLayoutData(gridData);
Messages.setLanguageText(dl, "SpeedView.stats.estdowncap", new String[] {
DisplayFormatters.getRateUnit(1)
});
final Text downloadLimitSetting = new Text(panel, 2048);
gridData = new GridData(1);
gridData.widthHint = 80;
downloadLimitSetting.setLayoutData(gridData);
int bestDownloadSetting = determineRateSettingEx(measuredDownloadKbps, downloadTestRan, false);
downloadLimitSetting.setText((new StringBuilder()).append("").append(bestDownloadSetting).toString());
downloadLimitSetting.addListener(25, new NumberListener(downloadLimitSetting));
Label downEcho = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.widthHint = 80;
downEcho.setLayoutData(gridData);
downEcho.setText(DisplayFormatters.formatByteCountToBitsPerSec(bestDownloadSetting * 1024));
downloadLimitSetting.addListener(24, new ByteConversionListener(downEcho, downloadLimitSetting));
int downIndex = setDefaultConfidenceLevelEx(measuredDownloadKbps, downloadTestRan, false, confValue);
downConfLevelCombo = new Combo(panel, 8);
addDropElements(downConfLevelCombo, confName);
downConfLevelCombo.select(downIndex);
Label c1 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.widthHint = 80;
c1.setLayoutData(gridData);
SpeedManager sm = AzureusCoreFactory.getSingleton().getSpeedManager();
if (uploadTestRan)
sm.setEstimatedUploadCapacityBytesPerSec(measuredUploadKbps * 1024, uploadHitLimit ? 0.0F : 0.0F);
if (downloadTestRan)
sm.setEstimatedDownloadCapacityBytesPerSec(measuredDownloadKbps * 1024, downloadHitLimit ? 0.8F : 0.9F);
apply = new Button(panel, 8);
Messages.setLanguageText(apply, "SpeedTestWizard.set.upload.button.apply");
gridData = new GridData();
gridData.widthHint = 70;
apply.setLayoutData(gridData);
apply.addListener(13, new Listener() );
Label c3 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
c3.setLayoutData(gridData);
Label spacer2 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 3;
spacer2.setLayoutData(gridData);
Composite resultsPanel = new Composite(rootPanel, 0);
gridData = new GridData(776);
resultsPanel.setLayoutData(gridData);
layout = new GridLayout();
layout.numColumns = 5;
layout.makeColumnsEqualWidth = true;
resultsPanel.setLayout(layout);
NetworkAdminSpeedTesterResult result = SpeedTestData.getInstance().getLastResult();
if (result.hadError())
{
String error = result.getLastError();
createResultLabels(resultsPanel, true);
createErrorDesc(resultsPanel, error);
createTestDesc(resultsPanel);
} else
{
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);
}
}
private void addDropElements(Combo combo, String elements[])
{
if (elements == null)
return;
int n = elements.length;
for (int i = 0; i < n; i++)
combo.add(elements[i]);
}
private int setDefaultConfidenceLevelEx(int transferRateKBPS, boolean testRan, boolean isUpload, String values[])
{
SpeedManagerLimitEstimate est;
if (isUpload)
est = speedManager.getEstimatedUploadCapacityBytesPerSec();
else
est = speedManager.getEstimatedDownloadCapacityBytesPerSec();
float originalEstType = est.getEstimateType();
float retValType;
if (originalEstType == 1.0F)
retValType = originalEstType;
else
if (!testRan)
retValType = originalEstType;
else
if (isUpload)
retValType = 0.0F;
else
if (transferRateKBPS < 550 && transferRateKBPS > 450)
retValType = 0.0F;
else
retValType = 0.9F;
String cType = helper.typeToText(retValType);
if (cType == null)
return -1;
for (int i = 0; i < values.length; i++)
if (cType.equalsIgnoreCase(values[i]))
return i;
return -1;
}
private void createResultLabels(Composite panel, boolean hadError)
{
Label c1 = new Label(panel, 0);
GridData gridData = new GridData();
gridData.horizontalSpan = 1;
c1.setLayoutData(gridData);
Label c2 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.horizontalAlignment = 3;
c2.setLayoutData(gridData);
c2.setText(MessageText.getString("SpeedTestWizard.set.upload.result"));
Label c3 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.horizontalAlignment = 2;
c3.setLayoutData(gridData);
if (!hadError)
c3.setText(MessageText.getString("SpeedTestWizard.set.upload.bytes.per.sec"));
Label c4 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.horizontalAlignment = 2;
c4.setLayoutData(gridData);
if (!hadError)
c4.setText(MessageText.getString("SpeedTestWizard.set.upload.bits.per.sec"));
Label c5 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
c5.setLayoutData(gridData);
}
private void createResultData(Composite panel, String label, int rate)
{
Label c1 = new Label(panel, 0);
GridData gridData = new GridData();
gridData.horizontalSpan = 1;
c1.setLayoutData(gridData);
Label c2 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.horizontalAlignment = 3;
c2.setLayoutData(gridData);
c2.setText(label);
Label c3 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.horizontalAlignment = 2;
c3.setLayoutData(gridData);
c3.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(rate));
Label c4 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.horizontalAlignment = 2;
c4.setLayoutData(gridData);
c4.setText(DisplayFormatters.formatByteCountToBitsPerSec(rate));
Label c5 = new Label(panel, 0);
gridData = new GridData();
gridData.horizontalSpan = 1;
c5.setLayoutData(gridData);
}
private void createTestDesc(Composite composite)
{
}
private void createErrorDesc(Composite composite, String s)
{
}
public int determineRateSettingEx(int measuredRate, boolean testRan, boolean isUpload)
{
int retVal = measuredRate;
SpeedManagerLimitEstimate est;
if (isUpload)
est = speedManager.getEstimatedUploadCapacityBytesPerSec();
else
est = speedManager.getEstimatedDownloadCapacityBytesPerSec();
if (!testRan)
retVal = est.getBytesPerSec() / 1024;
if (est.getEstimateType() == 1.0F)
retVal = est.getBytesPerSec() / 1024;
return retVal;
}
public void finish()
{
wizard.switchToClose();
}
public IWizardPanel getFinishPanel()
{
return new SpeedTestFinishPanel(wizard, this);
}
public boolean isFinishEnabled()
{
return true;
}
public boolean isNextEnabled()
{
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -