|
|
@ -4,6 +4,7 @@ import com.fanruan.workplace.http.debug.RequestInfo; |
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
|
|
|
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
|
|
|
import com.fr.design.gui.ibutton.UIToggleButton; |
|
|
|
import com.fr.event.Event; |
|
|
|
import com.fr.event.Event; |
|
|
|
import com.fr.event.EventDispatcher; |
|
|
|
import com.fr.event.EventDispatcher; |
|
|
|
import com.fr.event.Listener; |
|
|
|
import com.fr.event.Listener; |
|
|
@ -34,18 +35,22 @@ import static com.fanruan.workplace.http.debug.RemoteDesignDebugEvent.REMOTE_HTT |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
private static final int K = 1024; |
|
|
|
private static final int K = 1024; |
|
|
|
|
|
|
|
private static final int MS = 1000; |
|
|
|
private static final int TWO = 2; |
|
|
|
private static final int TWO = 2; |
|
|
|
private JTable uiTable; |
|
|
|
private JTable uiTable; |
|
|
|
private DefaultTableModel model; |
|
|
|
private DefaultTableModel model; |
|
|
|
|
|
|
|
private int count = 0; |
|
|
|
|
|
|
|
private boolean scrollRectToVisible = false; |
|
|
|
|
|
|
|
|
|
|
|
private final Listener<RequestInfo> remoteDesignDebugListener = new Listener<RequestInfo>() { |
|
|
|
private final Listener<RequestInfo> remoteDesignDebugListener = new Listener<RequestInfo>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void on(Event event, RequestInfo requestInfo) { |
|
|
|
public void on(Event event, RequestInfo requestInfo) { |
|
|
|
model.addRow(new Object[]{ |
|
|
|
model.addRow(new Object[]{ |
|
|
|
requestInfo.getStatus(), |
|
|
|
count++, |
|
|
|
dateFormat(requestInfo.getDate()), |
|
|
|
dateFormat(requestInfo.getDate()), |
|
|
|
requestInfo.getPath().substring(WorkContext.getCurrent().getPath().length() - 1), |
|
|
|
requestInfo.getPath().substring(WorkContext.getCurrent().getPath().length() - 1), |
|
|
|
requestInfo.getConsume() + "ms", |
|
|
|
requestInfo.getStatus(), |
|
|
|
|
|
|
|
simpleTime(requestInfo.getConsume()), |
|
|
|
simpleSize(requestInfo.getRequestSize()), |
|
|
|
simpleSize(requestInfo.getRequestSize()), |
|
|
|
simpleSize(requestInfo.getResponseSize()), |
|
|
|
simpleSize(requestInfo.getResponseSize()), |
|
|
|
requestInfo.getSendBody(), |
|
|
|
requestInfo.getSendBody(), |
|
|
@ -69,9 +74,10 @@ public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
|
|
|
|
|
|
|
|
private void initTable() { |
|
|
|
private void initTable() { |
|
|
|
model = new DefaultTableModel(); |
|
|
|
model = new DefaultTableModel(); |
|
|
|
model.addColumn("status"); |
|
|
|
model.addColumn("No."); |
|
|
|
model.addColumn("time"); |
|
|
|
model.addColumn("time"); |
|
|
|
model.addColumn("path"); |
|
|
|
model.addColumn("path"); |
|
|
|
|
|
|
|
model.addColumn("status"); |
|
|
|
model.addColumn("cost"); |
|
|
|
model.addColumn("cost"); |
|
|
|
model.addColumn("request size"); |
|
|
|
model.addColumn("request size"); |
|
|
|
model.addColumn("response size"); |
|
|
|
model.addColumn("response size"); |
|
|
@ -86,7 +92,8 @@ public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
jToolBar.setBorder(new EmptyBorder(5, 0, 10, 0)); |
|
|
|
jToolBar.setBorder(new EmptyBorder(5, 0, 10, 0)); |
|
|
|
UIButton run = new UIButton(new LazyIcon("run")); |
|
|
|
UIButton run = new UIButton(new LazyIcon("run")); |
|
|
|
UIButton forbid = new UIButton(new LazyIcon("forbid")); |
|
|
|
UIButton forbid = new UIButton(new LazyIcon("forbid")); |
|
|
|
UIButton refresh = new UIButton(new LazyIcon("remove")); |
|
|
|
UIButton remove = new UIButton(new LazyIcon("remove")); |
|
|
|
|
|
|
|
UIToggleButton refresh = new UIToggleButton(new LazyIcon("refresh")); |
|
|
|
run.setEnabled(false); |
|
|
|
run.setEnabled(false); |
|
|
|
run.setToolTipText("Start Record"); |
|
|
|
run.setToolTipText("Start Record"); |
|
|
|
run.addActionListener(e -> { |
|
|
|
run.addActionListener(e -> { |
|
|
@ -100,10 +107,16 @@ public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
run.setEnabled(true); |
|
|
|
run.setEnabled(true); |
|
|
|
forbid.setEnabled(false); |
|
|
|
forbid.setEnabled(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
refresh.setToolTipText("Clear Records"); |
|
|
|
remove.setToolTipText("Clear Records"); |
|
|
|
refresh.addActionListener(e -> model.setRowCount(0)); |
|
|
|
remove.addActionListener(e -> { |
|
|
|
|
|
|
|
model.setRowCount(0); |
|
|
|
|
|
|
|
count = 0; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
refresh.setToolTipText("Always Scroll To Visible"); |
|
|
|
|
|
|
|
refresh.addActionListener(e -> scrollRectToVisible = !scrollRectToVisible); |
|
|
|
jToolBar.add(run); |
|
|
|
jToolBar.add(run); |
|
|
|
jToolBar.add(forbid); |
|
|
|
jToolBar.add(forbid); |
|
|
|
|
|
|
|
jToolBar.add(remove); |
|
|
|
jToolBar.add(refresh); |
|
|
|
jToolBar.add(refresh); |
|
|
|
add(jToolBar, BorderLayout.NORTH); |
|
|
|
add(jToolBar, BorderLayout.NORTH); |
|
|
|
} |
|
|
|
} |
|
|
@ -120,20 +133,23 @@ public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
EventDispatcher.listen(REMOTE_HTTP_REQUEST, remoteDesignDebugListener); |
|
|
|
EventDispatcher.listen(REMOTE_HTTP_REQUEST, remoteDesignDebugListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void adjustColumnWidths(JTable table) { |
|
|
|
private void adjustColumnWidths(JTable table) { |
|
|
|
|
|
|
|
int row = table.getRowCount() - 1; |
|
|
|
|
|
|
|
// 从最后一行来调整大小
|
|
|
|
for (int column = 0; column < table.getColumnCount() - TWO; column++) { |
|
|
|
for (int column = 0; column < table.getColumnCount() - TWO; column++) { |
|
|
|
TableColumn tableColumn = table.getColumnModel().getColumn(column); |
|
|
|
TableColumn tableColumn = table.getColumnModel().getColumn(column); |
|
|
|
int preferredWidth = 20; |
|
|
|
int preferredWidth = 20; |
|
|
|
int maxWidth = tableColumn.getMaxWidth(); |
|
|
|
int maxWidth = tableColumn.getMaxWidth(); |
|
|
|
tableColumn.setMinWidth(0); |
|
|
|
tableColumn.setMinWidth(0); |
|
|
|
// 从最后一行来调整大小
|
|
|
|
|
|
|
|
int row = table.getRowCount() - 1; |
|
|
|
|
|
|
|
TableCellRenderer cellRenderer = table.getCellRenderer(row, column); |
|
|
|
TableCellRenderer cellRenderer = table.getCellRenderer(row, column); |
|
|
|
Component component = table.prepareRenderer(cellRenderer, row, column); |
|
|
|
Component component = table.prepareRenderer(cellRenderer, row, column); |
|
|
|
int width = component.getPreferredSize().width + table.getIntercellSpacing().width; |
|
|
|
int width = component.getPreferredSize().width + table.getIntercellSpacing().width; |
|
|
|
preferredWidth = Math.max(preferredWidth, Math.min(width, maxWidth)); |
|
|
|
preferredWidth = Math.max(preferredWidth, Math.min(width, maxWidth)); |
|
|
|
tableColumn.setPreferredWidth(preferredWidth); |
|
|
|
tableColumn.setPreferredWidth(preferredWidth); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (scrollRectToVisible) { |
|
|
|
|
|
|
|
table.scrollRectToVisible(table.getCellRect(row, 0, true)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String dateFormat(Date date) { |
|
|
|
private static String dateFormat(Date date) { |
|
|
@ -141,6 +157,17 @@ public class RemoteDesignNetWorkTablePane extends JPanel { |
|
|
|
return dateFormat.format(date); |
|
|
|
return dateFormat.format(date); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private 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"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String simpleSize(long bytes) { |
|
|
|
private static String simpleSize(long bytes) { |
|
|
|
if (bytes < 0) { |
|
|
|
if (bytes < 0) { |
|
|
|
return bytes + ""; |
|
|
|
return bytes + ""; |
|
|
|