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