network speed added
This commit is contained in:
parent
8b4048fad4
commit
dc68d66159
|
@ -1,5 +1,6 @@
|
||||||
package com.luoboduner.moo.info.ui.form;
|
package com.luoboduner.moo.info.ui.form;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import cn.hutool.log.LogFactory;
|
import cn.hutool.log.LogFactory;
|
||||||
import com.intellij.uiDesigner.core.GridConstraints;
|
import com.intellij.uiDesigner.core.GridConstraints;
|
||||||
|
@ -23,7 +24,6 @@ import javax.swing.table.TableModel;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -152,8 +152,8 @@ public class NetworkForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkForm networkForm = getInstance();
|
NetworkForm networkForm = getInstance();
|
||||||
networkForm.getUploadSpeedLabel().setText("↓: " + formatSize((downloadNow - downloadBefore) / (timestampNow - timestampBefore)) + "/s");
|
networkForm.getUploadSpeedLabel().setText("↓: " + DataSizeUtil.format((downloadNow - downloadBefore) / (timestampNow - timestampBefore) * 1000) + "/s");
|
||||||
networkForm.getDownloadSpeedLabel().setText("↑: " + formatSize((uploadNow - uploadBefore) / (timestampNow - timestampBefore)) + "/s");
|
networkForm.getDownloadSpeedLabel().setText("↑: " + DataSizeUtil.format((uploadNow - uploadBefore) / (timestampNow - timestampBefore) * 1000) + "/s");
|
||||||
|
|
||||||
downloadBefore = downloadNow;
|
downloadBefore = downloadNow;
|
||||||
uploadBefore = uploadNow;
|
uploadBefore = uploadNow;
|
||||||
|
@ -250,30 +250,6 @@ public class NetworkForm {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* this functions converts byte to KB, MB, GB, TB with 3 decimal places
|
|
||||||
*
|
|
||||||
* @param size number to convert
|
|
||||||
* @return coverted number with unit size (ex. 1,234 KB)
|
|
||||||
*/
|
|
||||||
private static String formatSize(long size) {
|
|
||||||
double m = size / 1024.0;
|
|
||||||
double g = size / 1048576.0;
|
|
||||||
double t = size / 1073741824.0;
|
|
||||||
|
|
||||||
DecimalFormat dec = new DecimalFormat("0.000");
|
|
||||||
String formattedSize;
|
|
||||||
if (t > 1) {
|
|
||||||
formattedSize = dec.format(t).concat(" TB");
|
|
||||||
} else if (g > 1) {
|
|
||||||
formattedSize = dec.format(g).concat(" GB");
|
|
||||||
} else if (m > 1) {
|
|
||||||
formattedSize = dec.format(m).concat(" MB");
|
|
||||||
} else {
|
|
||||||
formattedSize = size + " KB";
|
|
||||||
}
|
|
||||||
return formattedSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
// GUI initializer generated by IntelliJ IDEA GUI Designer
|
// GUI initializer generated by IntelliJ IDEA GUI Designer
|
||||||
|
|
Loading…
Reference in New Issue