From 047c262f72024600a6008b08a7ec86390d4bec08 Mon Sep 17 00:00:00 2001 From: "Richard.Fang" Date: Tue, 24 Sep 2024 15:45:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-135499=20fix:fbp=E5=9B=9E=E5=BD=92?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9A=E8=B6=85=E7=BA=A7=E9=93=BE=E6=8E=A5?= =?UTF-8?q?-=E7=A7=BB=E5=8A=A8=E7=AB=AF=E5=BC=B9=E7=AA=97=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../popup/MobilePopupRegularPane.java | 49 +++++++++-------- .../hyperlink/popup/StyleSettingPane.java | 54 ++++++++----------- .../parameter/RootDesignDefinePane.java | 6 +-- 3 files changed, 48 insertions(+), 61 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/hyperlink/popup/MobilePopupRegularPane.java b/designer-base/src/main/java/com/fr/design/hyperlink/popup/MobilePopupRegularPane.java index bc10b89144..7978159c1c 100644 --- a/designer-base/src/main/java/com/fr/design/hyperlink/popup/MobilePopupRegularPane.java +++ b/designer-base/src/main/java/com/fr/design/hyperlink/popup/MobilePopupRegularPane.java @@ -1,11 +1,13 @@ package com.fr.design.hyperlink.popup; +import com.fine.theme.utils.FineUIStyle; +import com.formdev.flatlaf.util.ScaledEmptyBorder; +import com.fr.design.constants.LayoutConstants; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.i18n.Toolkit; -import com.fr.design.layout.VerticalFlowLayout; import com.fr.stable.StringUtils; import javax.swing.*; @@ -13,6 +15,11 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import static com.fine.swing.ui.layout.Layouts.column; +import static com.fine.swing.ui.layout.Layouts.cell; +import static com.fine.swing.ui.layout.Layouts.row; +import static com.fine.swing.ui.layout.Layouts.flex; + public class MobilePopupRegularPane extends BasicPane { private String label; @@ -35,13 +42,15 @@ public class MobilePopupRegularPane extends BasicPane { private void initComponent() { this.setLayout(new BorderLayout()); - this.add(this.createRadioButtonGroupPane(), BorderLayout.NORTH); spinnerGroupPane = this.createSpinnerPane(); - this.add(spinnerGroupPane, BorderLayout.CENTER); + this.add(column(LayoutConstants.VERTICAL_GAP, + cell(this.createRadioButtonGroupPane()), + row(flex(1), cell(spinnerGroupPane).weight(3)) + ).getComponent()); } private JPanel createRadioButtonGroupPane() { - radiosPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 5)); + radiosPane = new JPanel(new BorderLayout()); customRadio = new UIRadioButton(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Custom")); customRadio.addActionListener(radioActionListener); @@ -52,10 +61,8 @@ public class MobilePopupRegularPane extends BasicPane { radioButtons.add(customRadio); radioButtons.add(autoRadio); - radiosPane.add(customRadio); - radiosPane.add(autoRadio); - - return MobilePopupUIUtils.createLeftTileRightContentPanel(this.label, radiosPane, Color.GRAY, 20); + radiosPane.add(row(30, cell(customRadio), cell(autoRadio), flex()).getComponent()); + return row(cell(new UILabel(this.label, FineUIStyle.LABEL_SECONDARY)).weight(1), cell(radiosPane).weight(3)).getComponent(); } private ActionListener radioActionListener = new ActionListener() { @@ -66,40 +73,32 @@ public class MobilePopupRegularPane extends BasicPane { }; private JPanel createSpinnerPane() { - JPanel spinnerPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 5)); - spinnerPane.setBorder(BorderFactory.createEmptyBorder(0, MobilePopupUIUtils.Left_Title_width, 0, 0)); + JPanel spinnerPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 0)); + spinnerPane.setBorder(new ScaledEmptyBorder(0, 0, 0, 0)); widthSpinner = new UISpinner(0, 100, 1, 95); widthSpinnerPane = this.createSpinnerLabelPane(widthSpinner, Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Width")); heightSpinner = new UISpinner(0, 100, 1, 95); heightSpinnerPane = this.createSpinnerLabelPane(heightSpinner, Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Height")); - - spinnerPane.add(widthSpinnerPane); - spinnerPane.add(heightSpinnerPane); - + spinnerPane.add(row(cell(widthSpinnerPane), cell(heightSpinnerPane)).getComponent()); return spinnerPane; } private JPanel createSpinnerLabelPane(UISpinner spinner, String labelText) { - JPanel spinnerLabelPane = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 5)); - - JPanel spinnerPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 2,0)); + JPanel spinnerLabelPane = new JPanel(new BorderLayout()); UILabel percent = new UILabel("%"); - spinnerPane.add(spinner); - spinnerPane.add(percent); - UILabel label = new UILabel(labelText); label.setHorizontalAlignment(SwingConstants.CENTER); - - spinnerLabelPane.add(spinnerPane); - spinnerLabelPane.add(label); - + spinnerLabelPane.add(column(LayoutConstants.VGAP_SMALL, + row(cell(spinner).weight(1), cell(percent)).weight(1), + cell(label) + ).getComponent()); return spinnerLabelPane; } private void resetSpinnerGroupPane(boolean showHeightSpinnerPane) { spinnerGroupPane.removeAll(); spinnerGroupPane.add(widthSpinnerPane); - if(showHeightSpinnerPane) { + if (showHeightSpinnerPane) { spinnerGroupPane.add(heightSpinnerPane); } spinnerGroupPane.revalidate(); diff --git a/designer-base/src/main/java/com/fr/design/hyperlink/popup/StyleSettingPane.java b/designer-base/src/main/java/com/fr/design/hyperlink/popup/StyleSettingPane.java index 3073203496..701594bf12 100644 --- a/designer-base/src/main/java/com/fr/design/hyperlink/popup/StyleSettingPane.java +++ b/designer-base/src/main/java/com/fr/design/hyperlink/popup/StyleSettingPane.java @@ -1,6 +1,8 @@ package com.fr.design.hyperlink.popup; +import com.fine.theme.utils.FineUIStyle; import com.fr.design.beans.BasicBeanPane; +import com.fr.design.constants.LayoutConstants; import com.fr.design.gui.frpane.UINumberDragPane; import com.fr.design.gui.icombobox.LineComboBox; import com.fr.design.gui.ilable.UILabel; @@ -57,14 +59,11 @@ public class StyleSettingPane extends BasicBeanPane { JPanel typePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); popupTypeLabel = new UILabel(""); UILabel typeLabel = new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Type")); - typePane.add(row(44, - cell(typeLabel), - cell(popupTypeLabel) - ).getComponent()); + typePane.add(row(cell(typeLabel).weight(1), row(cell(popupTypeLabel), flex()).weight(6)).getComponent()); return typePane; } - private JPanel createStylePane() { + private JPanel createStylePane() { JPanel stylePane = FRGUIPaneFactory.createBorderLayout_S_Pane(); stylePane.add(column(10, cell(this.createBorderSettingPane()), @@ -82,14 +81,11 @@ public class StyleSettingPane extends BasicBeanPane { borderColor = new NewColorSelectBox(100); borderRadiusSpinner = new UISpinner(0, maxBorderRadius, 1, 20); UILabel borderLabel = new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Border")); - borderPane.add(row(44, - column(10, - cell(borderLabel).weight(0.3), - flex().weight(0.7)), - column(10, - cell(MobilePopupUIUtils.createLeftTileRightContentPanel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Line"), borderType, Color.GRAY, 64)), - cell(MobilePopupUIUtils.createLeftTileRightContentPanel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Colors"), borderColor, Color.GRAY, 64)), - cell(MobilePopupUIUtils.createLeftTileRightContentPanel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Radius"), borderRadiusSpinner, Color.GRAY, 64))) + + borderPane.add(column(LayoutConstants.VERTICAL_GAP, + row(cell(borderLabel).weight(1), cell(new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Line"), FineUIStyle.LABEL_SECONDARY)).weight(1), cell(borderType).weight(2), flex(3)), + row(flex(1), cell(new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Colors"), FineUIStyle.LABEL_SECONDARY)).weight(1), cell(borderColor).weight(2), flex(3)), + row(flex(1), cell(new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Radius"), FineUIStyle.LABEL_SECONDARY)).weight(1), cell(borderRadiusSpinner).weight(2), flex(3)) ).getComponent()); return borderPane; } @@ -99,39 +95,31 @@ public class StyleSettingPane extends BasicBeanPane { bgPane.setLayout(new BorderLayout()); bgColor = new NewColorSelectBox(100); - JPanel transparencyPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); - this.numberDragPane = new UINumberDragPane(0,100); + this.numberDragPane = new UINumberDragPane(0, 100); transparencyPane.add(numberDragPane, BorderLayout.CENTER); transparencyPane.add(new UILabel(" %"), BorderLayout.EAST); JLabel bgLabel = new JLabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Background")); - bgPane.add(row(44, - column(10, - cell(bgLabel).weight(0.6), - flex().weight(0.4)), - column(10, - cell(MobilePopupUIUtils.createLeftTileRightContentPanel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Colors"), bgColor, Color.GRAY, 64)), - cell(MobilePopupUIUtils.createLeftTileRightContentPanel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Opacity"), transparencyPane, Color.GRAY, 64)) - ) + + bgPane.add(column(LayoutConstants.VERTICAL_GAP, + row(cell(bgLabel).weight(1), cell(new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Colors"), FineUIStyle.LABEL_SECONDARY)).weight(1), cell(bgColor).weight(2), flex(3)), + row(flex(1), cell(new UILabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Opacity"), FineUIStyle.LABEL_SECONDARY)).weight(1), cell(transparencyPane).weight(3), flex(2)) ).getComponent()); return bgPane; } private JPanel createPopupSizePane() { JPanel sizePane = new JPanel(new BorderLayout()); - mobileRegularPane = new MobilePopupRegularPane(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Mobile_Rules")); padRegularPane = new MobilePopupRegularPane(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Pad_Rules")); JLabel sizeLabel = new JLabel(Toolkit.i18nText("FR-Plugin-Designer_Mobile_Popup_Size")); - sizePane.add(row(20, - column(10, - cell(sizeLabel).weight(0.16), - flex().weight(0.84)), - column(10, - cell(mobileRegularPane), - cell(padRegularPane) - ) + sizePane.add(column(LayoutConstants.VERTICAL_GAP, + row( + column(LayoutConstants.VERTICAL_GAP, cell(sizeLabel), flex()).weight(1), + cell(mobileRegularPane).weight(4), flex(2) + ), + row(flex(1), cell(padRegularPane).weight(4), flex(2)) ).getComponent()); return sizePane; } @@ -204,7 +192,7 @@ public class StyleSettingPane extends BasicBeanPane { private void updateBackgroundSettingBean(MobilePopupHyperlink link) { link.setBgColor(bgColor.getSelectObject()); - link.setBgOpacity((float)(numberDragPane.updateBean() / maxNumber)); + link.setBgOpacity((float) (numberDragPane.updateBean() / maxNumber)); } private void populatePopupSizeBean(MobilePopupHyperlink link) { diff --git a/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java b/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java index b6fbaea532..ee9ea9909a 100644 --- a/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java +++ b/designer-form/src/main/java/com/fr/design/parameter/RootDesignDefinePane.java @@ -182,9 +182,9 @@ public class RootDesignDefinePane extends AbstractDataModify { cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Background"))).weight(LEFT_WEIGHT), cell(backgroundPane).weight(RIGHT_WEIGHT) ), - cell(displayReport), - cell(useParamsTemplate), - cell(fireAfterEditor), + row(cell(displayReport)), + row(cell(useParamsTemplate)), + row(cell(fireAfterEditor)), row( cell(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Display_Position"))).weight(LEFT_WEIGHT), cell(hAlignmentPane).weight(RIGHT_WEIGHT) From 80a6cb0f4f072c739b7f2ebf5937bd96d298ef93 Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 24 Sep 2024 16:52:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-135687=20=E6=96=B0=E5=A2=9E=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E7=95=8C=E9=9D=A2-=E8=BF=9C=E7=A8=8B=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/toolbar/DebugModeMenuDef.java | 51 ++++++++ .../mainframe/toolbar/ToolBarMenuDock.java | 19 +-- .../ui/debug/RemoteDesignNetWorkAction.java | 46 ++++++++ .../debug/RemoteDesignNetWorkTablePane.java | 109 ++++++++++++++++++ 4 files changed, 207 insertions(+), 18 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/toolbar/DebugModeMenuDef.java create mode 100644 designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java create mode 100644 designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/DebugModeMenuDef.java b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/DebugModeMenuDef.java new file mode 100644 index 0000000000..989e88b5c5 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/DebugModeMenuDef.java @@ -0,0 +1,51 @@ +package com.fr.design.mainframe.toolbar; + +import com.fanruan.gui.UiInspector; +import com.fine.theme.light.ui.laf.FineDarkLaf; +import com.fine.theme.light.ui.laf.FineLightLaf; +import com.fr.design.actions.UpdateAction; +import com.fr.design.gui.UILookAndFeel; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.menu.MenuDef; +import com.fr.design.remote.ui.debug.RemoteDesignNetWorkAction; + +import java.awt.event.ActionEvent; + +/** + * 调试模式菜单 + * + * @author vito + * @since 11.0 + * Created on 2024/9/24 + */ +public class DebugModeMenuDef extends MenuDef { + + public DebugModeMenuDef() { + super("Debug"); + addLookAndFeelMenu(); + addRemotePane(); + } + + private void addUIInspect() { + this.addShortCut(new UpdateAction() { + @Override + public void actionPerformed(ActionEvent e) { + new UiInspector().showInspector(DesignerContext.getDesignerFrame()); + } + }); + } + + private void addLookAndFeelMenu() { + MenuDef lookAndFeel = new MenuDef("Look And Feel", 'L'); + lookAndFeel.addShortCut( + new LookAndFeelAction(new FineLightLaf()), + new LookAndFeelAction(new FineDarkLaf()), + new LookAndFeelAction(new UILookAndFeel()) + ); + this.addShortCut(lookAndFeel); + } + + private void addRemotePane() { + this.addShortCut(new RemoteDesignNetWorkAction()); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java index e74ffc708b..fec6fdc9e5 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java @@ -3,8 +3,6 @@ */ package com.fr.design.mainframe.toolbar; -import com.fine.theme.light.ui.laf.FineDarkLaf; -import com.fine.theme.light.ui.laf.FineLightLaf; import com.fr.base.FRContext; import com.fr.base.vcs.DesignerMode; import com.fr.design.DesignState; @@ -34,7 +32,6 @@ import com.fr.design.actions.file.SwitchExistEnv; import com.fr.design.actions.help.AboutAction; import com.fr.design.actions.help.FineUIAction; import com.fr.design.actions.help.TutorialAction; -import com.fr.design.actions.help.WebDemoAction; import com.fr.design.actions.help.alphafine.AlphaFineAction; import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; import com.fr.design.actions.server.ConnectionListAction; @@ -49,7 +46,6 @@ import com.fr.design.fun.MenuHandler; import com.fr.design.fun.OemProcessor; import com.fr.design.fun.PluginManagerProvider; import com.fr.design.fun.TableDataPaneProcessor; -import com.fr.design.gui.UILookAndFeel; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UICombinationButton; import com.fr.design.gui.ilable.UILabel; @@ -66,9 +62,7 @@ import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; import com.fr.design.os.impl.SupportOSImpl; import com.fr.design.remote.action.RemoteDesignAuthManagerAction; -import com.fr.design.update.actions.SoftwareUpdateAction; import com.fr.design.utils.ThemeUtils; -import com.fr.env.detect.ui.EnvDetectorAction; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.locale.LocaleAction; @@ -298,7 +292,7 @@ public abstract class ToolBarMenuDock { // 当前仅UI开发者模式显示外观配置选项 if (DesignerUIModeConfig.getInstance().isUIDevMode()) { - menuList.add(createLookAndFeel()); + menuList.add(new DebugModeMenuDef()); } // 添加全部UpdateAction到actionmanager中 @@ -668,17 +662,6 @@ public abstract class ToolBarMenuDock { return menuDef; } - public MenuDef createLookAndFeel() { - MenuDef menuDef = new MenuDef("外观", 'H'); - menuDef.addShortCut( - new LookAndFeelAction(new FineLightLaf()), - new LookAndFeelAction(new FineDarkLaf()), - new LookAndFeelAction(new UILookAndFeel()) - ); - insertMenu(menuDef, "laf"); - return menuDef; - } - public MenuDef createCommunityMenuDef() { 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 new file mode 100644 index 0000000000..29f149eed8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkAction.java @@ -0,0 +1,46 @@ +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; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.workspace.WorkContext; + +import javax.swing.JDialog; +import java.awt.Dimension; +import java.awt.event.ActionEvent; + +/** + * 远程设计网络调试 + * + * @author vito + * @since 11.0 + * Created on 2024/9/24 + */ +public class RemoteDesignNetWorkAction extends UpdateAction { + public static final String TITLE = "Remote Design NetWork"; + + public RemoteDesignNetWorkAction() { + setName(TITLE); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (WorkContext.getCurrent().isLocal()) { + return; + } + JDialog jDialog = new JDialog(DesignerContext.getDesignerFrame(), TITLE); + jDialog.setSize(calculatePaneDimension()); + jDialog.add(new RemoteDesignNetWorkTablePane()); + 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)); + } +} + 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 new file mode 100644 index 0000000000..456d6266d4 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/remote/ui/debug/RemoteDesignNetWorkTablePane.java @@ -0,0 +1,109 @@ +package com.fr.design.remote.ui.debug; + +import com.fanruan.workplace.http.debug.RequestInfo; +import com.formdev.flatlaf.util.ScaledEmptyBorder; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.workspace.WorkContext; + +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import java.awt.BorderLayout; +import java.awt.Component; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import static com.fanruan.workplace.http.debug.RemoteDesignDebugEvent.REMOTE_HTTP_REQUEST; + +/** + * 远程设计网络调试面板 + * + * @author vito + * @since 11.0 + * Created on 2024/9/24 + */ +public class RemoteDesignNetWorkTablePane extends JPanel { + private static final int K = 1024; + private static final int TWO = 2; + private JTable uiTable; + private DefaultTableModel model; + + public RemoteDesignNetWorkTablePane() { + setLayout(new BorderLayout()); + setBorder(new ScaledEmptyBorder(10, 10, 10, 10)); + initComponent(); + initListener(); + } + + private void initComponent() { + model = new DefaultTableModel(); + model.addColumn("status"); + model.addColumn("time"); + model.addColumn("path"); + model.addColumn("cost"); + model.addColumn("request size"); + model.addColumn("response size"); + model.addColumn("request"); + model.addColumn("response"); + uiTable = new JTable(model); + 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 static void adjustColumnWidths(JTable table) { + for (int column = 0; column < table.getColumnCount() - TWO; column++) { + TableColumn tableColumn = table.getColumnModel().getColumn(column); + int preferredWidth = 20; + int maxWidth = tableColumn.getMaxWidth(); + tableColumn.setMinWidth(0); + // 从最后一行来调整大小 + int row = table.getRowCount() - 1; + TableCellRenderer cellRenderer = table.getCellRenderer(row, column); + Component component = table.prepareRenderer(cellRenderer, row, column); + int width = component.getPreferredSize().width + table.getIntercellSpacing().width; + preferredWidth = Math.max(preferredWidth, Math.min(width, maxWidth)); + tableColumn.setPreferredWidth(preferredWidth); + } + } + + private static String dateFormat(Date date) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return dateFormat.format(date); + } + + private static String simpleSize(long bytes) { + if (bytes < 0) { + return bytes + ""; + } else if (bytes < K) { + return bytes + " B"; + } else { + DecimalFormat df = new DecimalFormat("#.00"); + return df.format((float) bytes / K) + " K"; + } + } + +}