From f1eadc89e2e55c8803e3e604af2fde40bc648013 Mon Sep 17 00:00:00 2001 From: vito Date: Wed, 25 Sep 2024 17:30:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-135687=20=E4=BF=AE=E5=A4=8D=E6=A1=86?= =?UTF-8?q?=E4=BD=93=E5=A4=A7=E5=B0=8F&=E6=B7=BB=E5=8A=A0=E6=B8=85?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/debug/RemoteDesignNetWorkAction.java | 23 +++++- .../debug/RemoteDesignNetWorkTablePane.java | 80 +++++++++++++++---- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java b/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java index 29f149eed8..7e4147f759 100644 --- a/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java +++ b/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java @@ -1,6 +1,5 @@ package com.fr.design.remote.ui.debug; -import com.fine.theme.utils.FineUIScale; import com.fr.design.actions.UpdateAction; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrame; @@ -8,8 +7,14 @@ import com.fr.design.utils.gui.GUICoreUtils; import com.fr.workspace.WorkContext; import javax.swing.JDialog; +import javax.swing.JOptionPane; import java.awt.Dimension; import java.awt.event.ActionEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import static com.fine.theme.utils.FineUIScale.createScaleDimension; +import static com.fine.theme.utils.FineUIScale.unscale; /** * 远程设计网络调试 @@ -28,19 +33,29 @@ public class RemoteDesignNetWorkAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { if (WorkContext.getCurrent().isLocal()) { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + "Remote Design NetWork can't show on local environment."); return; } JDialog jDialog = new JDialog(DesignerContext.getDesignerFrame(), TITLE); jDialog.setSize(calculatePaneDimension()); - jDialog.add(new RemoteDesignNetWorkTablePane()); + RemoteDesignNetWorkTablePane netWorkPane = new RemoteDesignNetWorkTablePane(); + jDialog.add(netWorkPane); + jDialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + netWorkPane.clear(); + super.windowClosing(e); + } + }); GUICoreUtils.centerWindow(jDialog); jDialog.setVisible(true); } private static Dimension calculatePaneDimension() { DesignerFrame parent = DesignerContext.getDesignerFrame(); - return new Dimension((int) (FineUIScale.unscale(parent.getWidth()) * 0.8), - (int) (FineUIScale.unscale(parent.getHeight()) * 0.6)); + return createScaleDimension((int) (unscale(parent.getWidth()) * 0.8), + (int) (unscale(parent.getHeight()) * 0.6)); } } diff --git a/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java b/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java index 456d6266d4..21cb2ab049 100644 --- a/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java +++ b/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java @@ -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 remoteDesignDebugListener = new Listener() { + @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(); + addListener(); } 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() { - @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) {