Browse Source

Pull request #14913: REPORT-135687 修复框体大小&添加清理

Merge in DESIGN/design from ~VITO/c-design:fbp/release to fbp/release

* commit 'cd67e9b355f7b3cb2137d21abca23efc482efb43':
  无jira任务 代码质量
  REPORT-135687 修复框体大小&添加清理
fbp/merge
vito-刘恒霖 3 months ago
parent
commit
d4ab9a8d7b
  1. 23
      designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java
  2. 80
      designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java

23
designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java

@ -1,7 +1,7 @@
package com.fr.design.remote.ui.debug;
import com.fine.theme.utils.FineUIScale;
import com.fr.design.actions.UpdateAction;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.DesignerFrame;
import com.fr.design.utils.gui.GUICoreUtils;
@ -10,6 +10,11 @@ import com.fr.workspace.WorkContext;
import javax.swing.JDialog;
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()) {
FineJOptionPane.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));
}
}

80
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<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();
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<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) {

Loading…
Cancel
Save