@ -1,7 +1,9 @@
package com.fr.design.remote.ui.debug ;
import com.fanruan.workplace.http.debug.RequestInfo ;
import com.fine.theme.icon.LazyIcon ;
import com.formdev.flatlaf.util.ScaledEmptyBorder ;
import com.fr.design.gui.ibutton.UIButton ;
import com.fr.event.Event ;
import com.fr.event.EventDispatcher ;
import com.fr.event.Listener ;
@ -10,6 +12,8 @@ import com.fr.workspace.WorkContext;
import javax.swing.JPanel ;
import javax.swing.JScrollPane ;
import javax.swing.JTable ;
import javax.swing.JToolBar ;
import javax.swing.border.EmptyBorder ;
import javax.swing.table.DefaultTableModel ;
import javax.swing.table.TableCellRenderer ;
import javax.swing.table.TableColumn ;
@ -34,14 +38,36 @@ public class RemoteDesignNetWorkTablePane extends JPanel {
private JTable uiTable ;
private DefaultTableModel model ;
private final Listener < RequestInfo > remoteDesignDebugListener = new Listener < RequestInfo > ( ) {
@Override
public void on ( Event event , RequestInfo requestInfo ) {
model . addRow ( new Object [ ] {
requestInfo . getStatus ( ) ,
dateFormat ( requestInfo . getDate ( ) ) ,
requestInfo . getPath ( ) . substring ( WorkContext . getCurrent ( ) . getPath ( ) . length ( ) - 1 ) ,
requestInfo . getConsume ( ) + "ms" ,
simpleSize ( requestInfo . getRequestSize ( ) ) ,
simpleSize ( requestInfo . getResponseSize ( ) ) ,
requestInfo . getSendBody ( ) ,
requestInfo . getReturnBody ( ) ,
} ) ;
adjustColumnWidths ( uiTable ) ;
}
} ;
public RemoteDesignNetWorkTablePane ( ) {
setLayout ( new BorderLayout ( ) ) ;
setBorder ( new ScaledEmptyBorder ( 10 , 10 , 10 , 10 ) ) ;
initComponent ( ) ;
initListener ( ) ;
add Listener( ) ;
}
private void initComponent ( ) {
initTable ( ) ;
initToolBar ( ) ;
}
private void initTable ( ) {
model = new DefaultTableModel ( ) ;
model . addColumn ( "status" ) ;
model . addColumn ( "time" ) ;
@ -55,23 +81,43 @@ public class RemoteDesignNetWorkTablePane extends JPanel {
add ( new JScrollPane ( uiTable ) , BorderLayout . CENTER ) ;
}
private void initListener ( ) {
EventDispatcher . listen ( REMOTE_HTTP_REQUEST , new Listener < RequestInfo > ( ) {
@Override
public void on ( Event event , RequestInfo requestInfo ) {
model . addRow ( new Object [ ] {
requestInfo . getStatus ( ) ,
dateFormat ( requestInfo . getDate ( ) ) ,
requestInfo . getPath ( ) . substring ( WorkContext . getCurrent ( ) . getPath ( ) . length ( ) - 1 ) ,
requestInfo . getConsume ( ) + "ms" ,
simpleSize ( requestInfo . getRequestSize ( ) ) ,
simpleSize ( requestInfo . getResponseSize ( ) ) ,
requestInfo . getSendBody ( ) ,
requestInfo . getReturnBody ( ) ,
} ) ;
adjustColumnWidths ( uiTable ) ;
}
private void initToolBar ( ) {
JToolBar jToolBar = new JToolBar ( ) ;
jToolBar . setBorder ( new EmptyBorder ( 5 , 0 , 10 , 0 ) ) ;
UIButton run = new UIButton ( new LazyIcon ( "run" ) ) ;
UIButton forbid = new UIButton ( new LazyIcon ( "forbid" ) ) ;
UIButton refresh = new UIButton ( new LazyIcon ( "remove" ) ) ;
run . setEnabled ( false ) ;
run . setToolTipText ( "Start Record" ) ;
run . addActionListener ( e - > {
addListener ( ) ;
run . setEnabled ( false ) ;
forbid . setEnabled ( true ) ;
} ) ;
forbid . setToolTipText ( "Stop Record" ) ;
forbid . addActionListener ( e - > {
EventDispatcher . stopListen ( remoteDesignDebugListener ) ;
run . setEnabled ( true ) ;
forbid . setEnabled ( false ) ;
} ) ;
refresh . setToolTipText ( "Clear Records" ) ;
refresh . addActionListener ( e - > model . setRowCount ( 0 ) ) ;
jToolBar . add ( run ) ;
jToolBar . add ( forbid ) ;
jToolBar . add ( refresh ) ;
add ( jToolBar , BorderLayout . NORTH ) ;
}
/ * *
* 清理监听
* /
public void clear ( ) {
EventDispatcher . stopListen ( remoteDesignDebugListener ) ;
}
private void addListener ( ) {
EventDispatcher . listen ( REMOTE_HTTP_REQUEST , remoteDesignDebugListener ) ;
}
private static void adjustColumnWidths ( JTable table ) {