vito
2 months ago
3 changed files with 137 additions and 45 deletions
@ -0,0 +1,83 @@
|
||||
package com.fr.design.remote.ui.debug; |
||||
|
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import java.text.DecimalFormat; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* 帮助类 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/10/11 |
||||
*/ |
||||
public class RemoteDesignNetWorkHelper { |
||||
private static final int UNIT = 1000; |
||||
private static final int UNIT_BYTES = 1024; |
||||
private static final String SECOND = "s"; |
||||
private static final int K = 1024; |
||||
private static final int MS = 1000; |
||||
|
||||
static String dateFormat(Date date) { |
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); |
||||
return dateFormat.format(date); |
||||
} |
||||
|
||||
static String simpleTime(long time) { |
||||
if (time < 0) { |
||||
return time + ""; |
||||
} else if (time < MS) { |
||||
return time + " ms"; |
||||
} else { |
||||
DecimalFormat df = new DecimalFormat("#.0"); |
||||
return df.format((float) time / MS) + " s"; |
||||
} |
||||
} |
||||
|
||||
static String simpleSize(long bytes) { |
||||
if (bytes < 0) { |
||||
return bytes + ""; |
||||
} else if (bytes < K) { |
||||
return bytes + " B"; |
||||
} else { |
||||
DecimalFormat df = new DecimalFormat("#.00"); |
||||
return df.format((float) bytes / K) + " K"; |
||||
} |
||||
} |
||||
|
||||
static long parseCostToMS(String timeStr) { |
||||
String[] split = timeStr.split(" "); |
||||
if (split.length > 1) { |
||||
double number = Double.parseDouble(split[0]); |
||||
String unit = split[1].toLowerCase(); |
||||
|
||||
if (StringUtils.equals(unit, SECOND)) { |
||||
return (long) (number * UNIT); |
||||
} |
||||
return (long) number; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static long parseSizeToBytes(String sizeStr) { |
||||
String[] split = sizeStr.split(" "); |
||||
if (split.length > 1) { |
||||
double number = Double.parseDouble(split[0]); |
||||
String unit = split[1].toUpperCase(); |
||||
|
||||
switch (unit) { |
||||
case "K": |
||||
return (long) (number * UNIT_BYTES); |
||||
case "M": |
||||
return (long) (number * UNIT_BYTES * UNIT_BYTES); |
||||
case "G": |
||||
return (long) (number * UNIT_BYTES * UNIT_BYTES * UNIT_BYTES); |
||||
default: |
||||
return (long) number; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
package com.fr.design.remote.ui.debug; |
||||
|
||||
import javax.swing.table.DefaultTableModel; |
||||
import javax.swing.table.TableRowSorter; |
||||
import java.util.Comparator; |
||||
|
||||
/** |
||||
* 行排序器 |
||||
* |
||||
* @author vito |
||||
* @since 11.0 |
||||
* Created on 2024/10/11 |
||||
*/ |
||||
public class RemoteDesignNetWorkTableRowSorter extends TableRowSorter<DefaultTableModel> { |
||||
|
||||
public RemoteDesignNetWorkTableRowSorter(DefaultTableModel model) { |
||||
super(model); |
||||
setComparator(0, (Comparator<Long>) Long::compareTo); |
||||
setComparator(4, Comparator.comparingLong(RemoteDesignNetWorkHelper::parseCostToMS)); |
||||
setComparator(5, Comparator.comparingLong(RemoteDesignNetWorkHelper::parseSizeToBytes)); |
||||
setComparator(6, Comparator.comparingLong(RemoteDesignNetWorkHelper::parseSizeToBytes)); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isSortable(int column) { |
||||
return column == 0 |
||||
|| column == 4 |
||||
|| column == 5 |
||||
|| column == 6; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue