From a83ec1a9dcbeca420c30098056f095637fe9210a Mon Sep 17 00:00:00 2001 From: plough Date: Fri, 11 Jan 2019 14:13:28 +0800 Subject: [PATCH 1/5] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>26=20=E4=B8=8B=E6=8B=89=E6=A1=86=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cell/settingpane/CellOtherSetPane.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java index 4ac2aab9b..8d80b309d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java @@ -12,12 +12,12 @@ import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; -import com.fr.design.layout.*; +import com.fr.design.layout.TableLayout; +import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.design.mainframe.JTemplate; import com.fr.general.ComparatorUtils; - import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.cellattr.CellGUIAttr; @@ -26,10 +26,18 @@ import com.fr.report.cell.cellattr.CellPageAttr; import com.fr.report.elementcase.TemplateElementCase; import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JPanel; +import javax.swing.SwingConstants; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.CardLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.Rectangle; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -41,8 +49,7 @@ public class CellOtherSetPane extends AbstractCellAttrPane { private static final int HEAD_WDITH = 290; private static final int HEAD_HEIGTH = 24; - private static final Dimension NORMAL_DIMENSION = new Dimension(155, 20); - private static final Dimension SMALL_DIMENSION = new Dimension(150, 20); + private static final int COMBO_WIDTH = 154; // normal private UIButtonGroup autoshrik; @@ -187,28 +194,20 @@ public class CellOtherSetPane extends AbstractCellAttrPane { }; JPanel upPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_LARGE); - double[] downRowSize = {p, p, p, p, p, p}; - double[] downColumnSize = {p, f}; + double[] downRowSize = {p, p, p}; + double[] downColumnSize = {f, COMBO_WIDTH}; int[][] downRowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; - JPanel showContentPane = new JPanel(FRGUIPaneFactory.createRightZeroLayout()); - showContent.setPreferredSize(SMALL_DIMENSION); - showContentPane.add(showContent); fileNamePane.setBorder(BorderFactory.createEmptyBorder(0,12,0,0)); - JPanel tooltipTextFieldPane = new JPanel(FRGUIPaneFactory.createRightZeroLayout()); - tooltipTextField.setPreferredSize(NORMAL_DIMENSION); - tooltipTextFieldPane.add(tooltipTextField); - Component[][] downComponent = new Component[][]{ - new Component[]{null, null}, - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT), showContentPane}, - new Component[]{fileNamePane, null}, - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip"), SwingConstants.LEFT), tooltipTextFieldPane}, - new Component[]{null, null}, - new Component[]{null, null}, + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT), showContent}, + new Component[]{fileNamePane, null}, // 选择"用下载连接显示二进制内容"时,会显示这一行的面板 + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip"), SwingConstants.LEFT), tooltipTextField} }; JPanel downPane = TableLayoutHelper.createGapTableLayoutPane(downComponent, downRowSize, downColumnSize, downRowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); + downPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 12, 0)); + JPanel pane = new JPanel(new BorderLayout()); pane.add(upPane, BorderLayout.NORTH); pane.add(downPane, BorderLayout.CENTER); From fd7743d45a76c873b6b034c36dd5629570c26dad Mon Sep 17 00:00:00 2001 From: plough Date: Fri, 11 Jan 2019 14:32:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>=E7=AE=80=E5=8D=95=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cell/settingpane/CellOtherSetPane.java | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java index 8d80b309d..487f2babe 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java @@ -84,7 +84,7 @@ public class CellOtherSetPane extends AbstractCellAttrPane { private ValueEditorPane valueEditor; private CardLayout insertRowLayout; private JPanel insertRowPane; - private JPanel southContentPane; + private JPanel insertRowPolicyPane; private JPanel defaultValuePane; /** @@ -136,6 +136,15 @@ public class CellOtherSetPane extends AbstractCellAttrPane { } private JPanel seniorPane() { + initInsertRowPolicyPane(); + JPanel seniorPane = new JPanel(new BorderLayout()); + seniorPane.add(seniorUpPane(), BorderLayout.NORTH); + seniorPane.add(insertRowPolicyPane, BorderLayout.CENTER); + insertRowPolicyPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); + return seniorPane; + } + + private void initInsertRowPolicyPane() { // 插入行策略 insertRowPolicy = new UIButtonGroup(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_InsertRow_NULL"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Estate_Default_Text"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_InsertRow_COPY")}); @@ -168,16 +177,40 @@ public class CellOtherSetPane extends AbstractCellAttrPane { new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_InsertRow_Policy"), SwingConstants.LEFT), insertRowPolicy}, new Component[]{null, insertRowPane}, }; - southContentPane = TableLayoutHelper.createGapTableLayoutPane(components1, rowSize1, columnSize1, rowCount1, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); - JPanel seniorPane = new JPanel(new BorderLayout()); - seniorPane.add(seniorUpPane(), BorderLayout.NORTH); - seniorPane.add(southContentPane, BorderLayout.CENTER); - southContentPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); - return seniorPane; + insertRowPolicyPane = TableLayoutHelper.createGapTableLayoutPane(components1, rowSize1, columnSize1, rowCount1, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); } private JPanel seniorUpPane() { + JPanel pane = new JPanel(new BorderLayout()); + // TODO: 方法之间的耦合还比较严重。现在必须先执行 createShowContentPane,再执行 createSeniorCheckPane。否则出现 npe。 + pane.add(createShowContentPane(), BorderLayout.CENTER); + pane.add(createSeniorCheckPane(), BorderLayout.NORTH); + return pane; + } + + private JPanel createShowContentPane() { + double f = TableLayout.FILL; + double p = TableLayout.PREFERRED; + double[] rowSize = {p, p, p}; + double[] colSize = {f, COMBO_WIDTH}; + int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}}; + JPanel fileNamePane = createNormal(); + fileNamePane.setBorder(BorderFactory.createEmptyBorder(0,12,0,0)); + + Component[][] components = new Component[][]{ + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT), showContent}, + new Component[]{fileNamePane, null}, // 选择"用下载连接显示二进制内容"时,会显示这一行的面板 + new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip"), SwingConstants.LEFT), tooltipTextField} + }; + + JPanel showContentPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, colSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); + showContentPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 12, 0)); + + return showContentPane; + } + + private JPanel createSeniorCheckPane() { previewCellContent.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); printAndExportContent.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); printAndExportBackground.setBorder(UIConstants.CELL_ATTR_ZEROBORDER); @@ -192,26 +225,7 @@ public class CellOtherSetPane extends AbstractCellAttrPane { new Component[]{printAndExportContent, null}, new Component[]{printAndExportBackground, null}, }; - JPanel upPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_LARGE); - - double[] downRowSize = {p, p, p}; - double[] downColumnSize = {f, COMBO_WIDTH}; - int[][] downRowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}}; - - fileNamePane.setBorder(BorderFactory.createEmptyBorder(0,12,0,0)); - - Component[][] downComponent = new Component[][]{ - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT), showContent}, - new Component[]{fileNamePane, null}, // 选择"用下载连接显示二进制内容"时,会显示这一行的面板 - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip"), SwingConstants.LEFT), tooltipTextField} - }; - JPanel downPane = TableLayoutHelper.createGapTableLayoutPane(downComponent, downRowSize, downColumnSize, downRowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); - downPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 12, 0)); - - JPanel pane = new JPanel(new BorderLayout()); - pane.add(upPane, BorderLayout.NORTH); - pane.add(downPane, BorderLayout.CENTER); - return pane; + return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_MEDIUM, LayoutConstants.VGAP_LARGE); } private JPanel pagePane() { @@ -390,10 +404,10 @@ public class CellOtherSetPane extends AbstractCellAttrPane { insertRowLayout.show(insertRowPane, "none"); insertRowPane.setPreferredSize(new Dimension(0, 0)); } - southContentPane.setVisible(true); + insertRowPolicyPane.setVisible(true); JTemplate jTemplate = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (!jTemplate.isJWorkBook()) { //表单中报表块编辑屏蔽掉 插入行策略 - southContentPane.setVisible(false); + insertRowPolicyPane.setVisible(false); } } From 68bb1c340c70d67d5913bfdc8156212d2f895da2 Mon Sep 17 00:00:00 2001 From: plough Date: Fri, 11 Jan 2019 14:44:57 +0800 Subject: [PATCH 3/5] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>26=20=E4=B8=8B=E6=8B=89=E6=A1=86=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=85=A8=EF=BC=8C=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/cell/settingpane/CellOtherSetPane.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java index 487f2babe..aa8e72853 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java @@ -198,10 +198,17 @@ public class CellOtherSetPane extends AbstractCellAttrPane { JPanel fileNamePane = createNormal(); fileNamePane.setBorder(BorderFactory.createEmptyBorder(0,12,0,0)); + UILabel showContentLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT); + UILabel toolTipLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip")); + toolTipLabel.setLineWrap(); + + JPanel toolTipTextFieldWrapper = new JPanel(new BorderLayout()); + toolTipTextFieldWrapper.add(tooltipTextField, BorderLayout.NORTH); + Component[][] components = new Component[][]{ - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT), showContent}, + new Component[]{showContentLabel, showContent}, new Component[]{fileNamePane, null}, // 选择"用下载连接显示二进制内容"时,会显示这一行的面板 - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip"), SwingConstants.LEFT), tooltipTextField} + new Component[]{toolTipLabel, toolTipTextFieldWrapper} }; JPanel showContentPane = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, colSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); From 3f62f88bce84c7d73cd0b1a6365b5651c41714ca Mon Sep 17 00:00:00 2001 From: plough Date: Fri, 11 Jan 2019 17:42:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/actions/file/PreferencePane.java | 16 ++- .../fr/design/gui/core/UITextComponent.java | 10 ++ .../com/fr/design/gui/ibutton/UIButton.java | 35 +----- .../fr/design/gui/ibutton/UIHeadGroup.java | 3 +- .../com/fr/design/gui/ilable/UILabel.java | 27 +---- .../gradient/GradientBackgroundPane.java | 3 +- .../com/fr/design/utils/gui/GUICoreUtils.java | 51 ++++++-- .../fr/design/utils/gui/UIComponentUtils.java | 51 ++++++++ .../utils/gui/UIComponentUtilsTest.java | 109 ++++++++++++++++++ .../cell/settingpane/CellOtherSetPane.java | 3 +- .../fr/design/report/WriteShortCutsPane.java | 3 +- .../com/fr/design/webattr/WebCssPane.java | 3 +- .../java/com/fr/design/webattr/WebJsPane.java | 3 +- 13 files changed, 246 insertions(+), 71 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/gui/core/UITextComponent.java create mode 100644 designer-base/src/main/java/com/fr/design/utils/gui/UIComponentUtils.java create mode 100644 designer-base/src/test/java/com/fr/design/utils/gui/UIComponentUtilsTest.java diff --git a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java index 5ddd44b60..193a95d3f 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/PreferencePane.java @@ -23,6 +23,7 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.mainframe.DesignerContext; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.general.ComparatorUtils; import com.fr.general.FRFont; import com.fr.general.Inter; @@ -32,8 +33,17 @@ import com.fr.third.apache.log4j.Level; import com.fr.transaction.Configurations; import com.fr.transaction.Worker; -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; @@ -473,7 +483,7 @@ public class PreferencePane extends BasicPane { JPanel memoryPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Caching_Template")); UILabel memoryLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Max_Caching_Template")); UILabel memoryTipLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Preference_Caching_Template_Tip")); - memoryTipLabel.setLineWrap(MEMORY_TIP_LABEL_MAX_WIDTH); + UIComponentUtils.setLineWrap(memoryTipLabel, MEMORY_TIP_LABEL_MAX_WIDTH); memoryTipLabel.setBorder(BorderFactory.createEmptyBorder(0, CACHING_GAP, 0, 0)); cachingTemplateSpinner = new UISpinner(0, CACHING_MAX, 1, CACHING_DEFAULT); JPanel memorySpace = new JPanel(FRGUIPaneFactory.createLeftZeroLayout()); diff --git a/designer-base/src/main/java/com/fr/design/gui/core/UITextComponent.java b/designer-base/src/main/java/com/fr/design/gui/core/UITextComponent.java new file mode 100644 index 000000000..0cf2e1c3c --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/core/UITextComponent.java @@ -0,0 +1,10 @@ +package com.fr.design.gui.core; + +/** + * 这个接口说明一个基本组件可以设置文本 + * Created by plough on 2019/1/11. + */ +public interface UITextComponent { + String getText(); + void setText(String text); +} diff --git a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java index d70f06ea6..078bf692b 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java +++ b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButton.java @@ -6,6 +6,7 @@ import com.fr.base.GraphHelper; import com.fr.design.constants.UIConstants; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.core.UITextComponent; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.Constants; import com.fr.stable.StringUtils; @@ -28,7 +29,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.RoundRectangle2D; -public class UIButton extends JButton implements UIObserver { +public class UIButton extends JButton implements UIObserver, UITextComponent { private static final int TOOLTIP_INIT_DELAY = 300; // 延迟 0.3s 显示提示文字 public static final int OTHER_BORDER = 1; @@ -49,7 +50,6 @@ public class UIButton extends JButton implements UIObserver { private CellBorderStyle border = null; protected UIObserverListener uiObserverListener; - private boolean fixedHeight = true; // 是否将按钮的高度固定为 HEIGHT public UIButton() { this(StringUtils.EMPTY); @@ -340,36 +340,13 @@ public class UIButton extends JButton implements UIObserver { this.isBorderPaintedOnlyWhenPressed = value; } - /** - * 到达指定宽度后换行 - */ - public void setLineWrap(int width) { - insertPrefixToText(""); - } - - /** - * 自动换行 - */ - public void setLineWrap() { - insertPrefixToText(""); - } - - private void insertPrefixToText(String prefix) { + private boolean isFixedHeight() { String text = this.getText(); if (StringUtils.isEmpty(text)) { - return; + return true; } - this.setText(prefix + text); - // 如果文本过长,且允许换行的话,需要放开按钮高度的限制 - this.setFixedHeight(false); - } - - private boolean isFixedHeight() { - return fixedHeight; - } - - private void setFixedHeight(boolean fixedHeight) { - this.fixedHeight = fixedHeight; + // 如果允许换行,需要放开按钮高度的限制 + return !text.startsWith(""); } /** diff --git a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java index c9771b766..edbc01340 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java +++ b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIHeadGroup.java @@ -3,6 +3,7 @@ package com.fr.design.gui.ibutton; import com.fr.base.BaseUtils; import com.fr.design.constants.UIConstants; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.design.utils.gui.UIComponentUtils; import javax.swing.Icon; import javax.swing.JFrame; @@ -139,7 +140,7 @@ public class UIHeadGroup extends JPanel { labelButton.setRoundBorder(false); labelButton.setBorderPainted(false); labelButton.setPressedPainted(false); - labelButton.setLineWrap(); + UIComponentUtils.setLineWrap(labelButton); labelButtonList.add(labelButton); this.add(labelButton); } diff --git a/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java b/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java index 09e7ef0a7..d6a795275 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java +++ b/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java @@ -1,9 +1,9 @@ package com.fr.design.gui.ilable; +import com.fr.design.gui.core.UITextComponent; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.StringUtils; -import com.fr.stable.StringUtils; import javax.swing.Icon; import javax.swing.JFrame; import javax.swing.JLabel; @@ -19,7 +19,7 @@ import java.awt.Dimension; * Date: 13-1-23 * Time: 下午3:15 */ -public class UILabel extends JLabel { +public class UILabel extends JLabel implements UITextComponent { private static final int HTML_SHIFT_HEIGHT = 3; public UILabel(String text, Icon image, int horizontalAlignment) { @@ -64,29 +64,6 @@ public class UILabel extends JLabel { return preferredSize; } - /** - * 到达指定宽度后换行 - */ - public void setLineWrap(int width) { - insertPrefixToText(""); - } - - /** - * 自动换行 - */ - public void setLineWrap() { - insertPrefixToText(""); - } - - private void insertPrefixToText(String prefix) { - String text = this.getText(); - if (StringUtils.isEmpty(text)) { - return; - } - this.setText(prefix + text); - } - - public static void main(String[] args) { // UILabel label = new UILabel("shishi",SwingConstants.LEFT); JFrame frame = new JFrame("Test"); diff --git a/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBackgroundPane.java b/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBackgroundPane.java index 18c458963..a2f6e70d6 100644 --- a/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBackgroundPane.java +++ b/designer-base/src/main/java/com/fr/design/style/background/gradient/GradientBackgroundPane.java @@ -5,6 +5,7 @@ import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.style.background.BackgroundDetailPane; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.general.Background; import javax.swing.BorderFactory; @@ -43,7 +44,7 @@ public class GradientBackgroundPane extends BackgroundDetailPane { blankJp.add(gradientBar); UILabel jl = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Drag_To_Select_Gradient")); jl.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20)); - jl.setLineWrap(); + UIComponentUtils.setLineWrap(jl); jl.setHorizontalAlignment(SwingConstants.CENTER); gradientPanel.add(jl, BorderLayout.NORTH); gradientPanel.add(blankJp, BorderLayout.SOUTH); diff --git a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java index 21af9365d..c8c0561c9 100644 --- a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java @@ -6,7 +6,13 @@ package com.fr.design.utils.gui; import com.fr.base.BaseUtils; import com.fr.base.Style; import com.fr.base.background.ColorBackground; -import com.fr.data.util.function.*; +import com.fr.data.util.function.AverageFunction; +import com.fr.data.util.function.CountFunction; +import com.fr.data.util.function.DataFunction; +import com.fr.data.util.function.MaxFunction; +import com.fr.data.util.function.MinFunction; +import com.fr.data.util.function.NoneFunction; +import com.fr.data.util.function.SumFunction; import com.fr.design.actions.UpdateAction; import com.fr.design.actions.core.ActionFactory; import com.fr.design.border.UITitledBorder; @@ -25,20 +31,48 @@ import com.fr.design.style.color.ColorFactory; import com.fr.design.style.color.ColorSelectBox; import com.fr.design.style.color.ColorSelectable; import com.fr.general.FRFont; - import com.fr.stable.Constants; import com.fr.stable.OperatingSystem; import com.fr.stable.StringUtils; -import javax.swing.*; +import javax.swing.AbstractButton; +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.DefaultListModel; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JFormattedTextField; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JSeparator; +import javax.swing.JSlider; +import javax.swing.JSpinner; +import javax.swing.JTree; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.LineBorder; import javax.swing.border.TitledBorder; import javax.swing.event.ChangeListener; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; - -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -48,16 +82,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public abstract class GUICoreUtils{ +// Noninstantiable utility class +public final class GUICoreUtils { private static final int WINDOW_GAP = 20; private static final int HEIGHT_GAP = 28; private static final int WIN_LOCATION_Y=23; private static final int CASE_FOUR = 4; - - + // 覆盖缺省构造器,不可实例化 private GUICoreUtils() { + throw new AssertionError(); } /** diff --git a/designer-base/src/main/java/com/fr/design/utils/gui/UIComponentUtils.java b/designer-base/src/main/java/com/fr/design/utils/gui/UIComponentUtils.java new file mode 100644 index 000000000..676369e75 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/utils/gui/UIComponentUtils.java @@ -0,0 +1,51 @@ +package com.fr.design.utils.gui; + +import com.fr.design.gui.core.UITextComponent; +import com.fr.stable.StringUtils; + +/** + * 包含 UI 组件相关的工具方法 + * Created by plough on 2019/1/11. + */ + +// Noninstantiable utility class +public class UIComponentUtils { + private static final String HTML_TAG_TPL = ""; + private static final String HTML_BODY_TAG = ""; + private static final String HTML_TAG = ""; + private static final int MIN_WIDTH = 10; + + // 覆盖缺省构造器,不可实例化 + private UIComponentUtils() { + throw new AssertionError(); + } + + /** + * 到达指定宽度后换行 + */ + public static void setLineWrap(UITextComponent comp, int width) { + if (width < MIN_WIDTH) { + width = MIN_WIDTH; + } + insertPrefixToText(comp, String.format(HTML_TAG_TPL, width)); + } + + /** + * 自动换行 + */ + public static void setLineWrap(UITextComponent comp) { + insertPrefixToText(comp, HTML_BODY_TAG); + } + + private static void insertPrefixToText(UITextComponent comp, String prefix) { + if (comp == null) { + return; + } + String text = comp.getText(); + + if (StringUtils.isEmpty(comp.getText()) || text.startsWith(HTML_TAG)) { + return; + } + comp.setText(prefix + comp.getText()); + } +} diff --git a/designer-base/src/test/java/com/fr/design/utils/gui/UIComponentUtilsTest.java b/designer-base/src/test/java/com/fr/design/utils/gui/UIComponentUtilsTest.java new file mode 100644 index 000000000..256abeeca --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/utils/gui/UIComponentUtilsTest.java @@ -0,0 +1,109 @@ +package com.fr.design.utils.gui; + +import com.fr.design.gui.core.UITextComponent; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; +import com.fr.stable.StringUtils; +import org.junit.Before; +import org.junit.Test; + +import javax.swing.Icon; + +import java.awt.Component; +import java.awt.Graphics; + +import static org.junit.Assert.*; + +/** + * Created by plough on 2019/1/11. + */ +public class UIComponentUtilsTest { + private static final String HTML_TAG_TPL = ""; + private static final String HTML_TAG = ""; + private UIButton textButton; + private UIButton emptyTextButton; + private UIButton iconButton; + + private UILabel textLabel; + private UILabel emptyTextLabel; + private UILabel iconLabel; + + @Before + public void setUp() { + textButton = new UIButton("hello"); + emptyTextButton = new UIButton(StringUtils.EMPTY); + iconButton = new UIButton(createMockIcon()); + + textLabel = new UILabel("hello"); + emptyTextLabel = new UILabel(StringUtils.EMPTY); + iconLabel = new UILabel(createMockIcon()); + } + + @Test + public void testSetLineWrap() { + UITextComponent[] noWrapComps = {emptyTextButton, emptyTextLabel, iconButton, iconLabel}; + UITextComponent[] wrapComps = {textLabel, textButton}; + + for (UITextComponent comp : wrapComps) { + UIComponentUtils.setLineWrap(comp); + assertTrue(isLineWrapped(comp)); + } + + for (UITextComponent comp : noWrapComps) { + UIComponentUtils.setLineWrap(comp); + assertFalse(isLineWrapped(comp)); + } + } + + @Test + public void testSetLineWrapWithLineWidth() { + UILabel label1 = new UILabel("l1"); + UILabel label2 = new UILabel("l2"); + UILabel label3 = new UILabel("l3"); + UIComponentUtils.setLineWrap(label1, 50); + assertTrue(isLineWrappedWithLineWidth(label1, 50)); + + UIComponentUtils.setLineWrap(label2, 0); + assertTrue(isLineWrappedWithLineWidth(label2, 10)); + + UIComponentUtils.setLineWrap(label3, -10); + assertTrue(isLineWrappedWithLineWidth(label3, 10)); + } + + @Test + public void testAddHtmlTwice() { + UIComponentUtils.setLineWrap(textLabel, 50); + UIComponentUtils.setLineWrap(textLabel, 20); // 第二次应该不生效 + assertTrue(isLineWrappedWithLineWidth(textLabel, 50)); + } + + private boolean isLineWrapped(UITextComponent comp) { + String text = comp.getText(); + return StringUtils.isNotEmpty(text) && text.startsWith(HTML_TAG); + } + + private boolean isLineWrappedWithLineWidth(UITextComponent comp, int width) { + String text = comp.getText(); + return StringUtils.isNotEmpty(text) && text.startsWith(String.format(HTML_TAG_TPL, width)); + } + + + private Icon createMockIcon() { + return new Icon() { + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + // do nothing + } + + @Override + public int getIconWidth() { + return 0; + } + + @Override + public int getIconHeight() { + return 0; + } + }; + } +} \ No newline at end of file diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java index aa8e72853..b58456be7 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/CellOtherSetPane.java @@ -17,6 +17,7 @@ import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.VerticalFlowLayout; import com.fr.design.mainframe.EastRegionContainerPane; import com.fr.design.mainframe.JTemplate; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.general.ComparatorUtils; import com.fr.report.cell.DefaultTemplateCellElement; import com.fr.report.cell.TemplateCellElement; @@ -200,7 +201,7 @@ public class CellOtherSetPane extends AbstractCellAttrPane { UILabel showContentLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Show_Content"), SwingConstants.LEFT); UILabel toolTipLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CellWrite_ToolTip")); - toolTipLabel.setLineWrap(); + UIComponentUtils.setLineWrap(toolTipLabel); JPanel toolTipTextFieldWrapper = new JPanel(new BorderLayout()); toolTipTextFieldWrapper.add(tooltipTextField, BorderLayout.NORTH); diff --git a/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java b/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java index fa1948e9d..8cf891b92 100644 --- a/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java +++ b/designer-realize/src/main/java/com/fr/design/report/WriteShortCutsPane.java @@ -6,6 +6,7 @@ import com.fr.config.ServerPreferenceConfig; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.general.ComparatorUtils; import javax.swing.BorderFactory; @@ -69,7 +70,7 @@ public class WriteShortCutsPane extends JPanel{ UILabel nextCol = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Next_Column"), SwingConstants.CENTER); UILabel nextRow = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Cursor_To_Next_Row"), SwingConstants.CENTER); UILabel shortName = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Current_Keys"), SwingConstants.CENTER); - shortName.setLineWrap(MAX_LABEL_WIDTH); + UIComponentUtils.setLineWrap(shortName, MAX_LABEL_WIDTH); nextColHK = new UILabel(nextColString, SwingConstants.CENTER); JPanel switchBtnPane = getSwitchBtnPane(); nextRowHK = new UILabel(nextRowString, SwingConstants.CENTER); diff --git a/designer-realize/src/main/java/com/fr/design/webattr/WebCssPane.java b/designer-realize/src/main/java/com/fr/design/webattr/WebCssPane.java index 6f9866605..1f8ba57bb 100644 --- a/designer-realize/src/main/java/com/fr/design/webattr/WebCssPane.java +++ b/designer-realize/src/main/java/com/fr/design/webattr/WebCssPane.java @@ -6,6 +6,7 @@ import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; import com.fr.file.filter.ChooseFileFilter; @@ -46,7 +47,7 @@ public class WebCssPane extends BasicPane { northPane.add(chooseFile, FlowLayout.RIGHT); outnorth.add(northPane,BorderLayout.NORTH); UILabel infor = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_CSS_Warning")); - infor.setLineWrap(); + UIComponentUtils.setLineWrap(infor); infor.setForeground(new Color(207, 42, 39)); outnorth.add(infor,BorderLayout.CENTER); this.add(outnorth, BorderLayout.NORTH); diff --git a/designer-realize/src/main/java/com/fr/design/webattr/WebJsPane.java b/designer-realize/src/main/java/com/fr/design/webattr/WebJsPane.java index 292a9d9ba..4c0505201 100644 --- a/designer-realize/src/main/java/com/fr/design/webattr/WebJsPane.java +++ b/designer-realize/src/main/java/com/fr/design/webattr/WebJsPane.java @@ -8,6 +8,7 @@ import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; import com.fr.file.filter.ChooseFileFilter; @@ -96,7 +97,7 @@ public class WebJsPane extends BasicPane { northPane.add(chooseFile); firstnorth.add(northPane,BorderLayout.NORTH); infor1 = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_JS_WARNING1")); - infor1.setLineWrap(); + UIComponentUtils.setLineWrap(infor1); infor1.setForeground(new Color(207, 42, 39)); firstnorth.add(infor1,BorderLayout.CENTER); From f5e0713b8bf22b4a633b003a7a63ecb48a10d76f Mon Sep 17 00:00:00 2001 From: plough Date: Fri, 11 Jan 2019 17:50:05 +0800 Subject: [PATCH 5/5] =?UTF-8?q?REPORT-14057=2010.0=E6=97=A5=E6=96=87?= =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= =?UTF-8?q?=3D>28=20checkbox=E6=96=87=E5=AD=97=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/gui/icheckbox/UICheckBox.java | 3 ++- .../com/fr/design/widget/ui/MultiFileEditorPane.java | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java index 825dfc629..7489b4f59 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icheckbox/UICheckBox.java @@ -5,6 +5,7 @@ import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; +import com.fr.design.gui.core.UITextComponent; import com.fr.design.utils.gui.GUIPaintUtils; import com.fr.stable.Constants; import sun.swing.SwingUtilities2; @@ -29,7 +30,7 @@ import java.awt.RenderingHints; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObserver { +public class UICheckBox extends JCheckBox implements UIObserver, GlobalNameObserver, UITextComponent { private UIObserverListener uiObserverListener; private GlobalNameListener globalNameListener = null; private String checkboxName = ""; diff --git a/designer-realize/src/main/java/com/fr/design/widget/ui/MultiFileEditorPane.java b/designer-realize/src/main/java/com/fr/design/widget/ui/MultiFileEditorPane.java index ca84f5590..8b945f6f8 100644 --- a/designer-realize/src/main/java/com/fr/design/widget/ui/MultiFileEditorPane.java +++ b/designer-realize/src/main/java/com/fr/design/widget/ui/MultiFileEditorPane.java @@ -8,11 +8,14 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.utils.gui.UIComponentUtils; import com.fr.form.ui.MultiFileEditor; - -import javax.swing.*; -import java.awt.*; +import javax.swing.BorderFactory; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dimension; public class MultiFileEditorPane extends FieldEditorDefinePane { private DictionaryComboBox acceptType; @@ -34,6 +37,7 @@ public class MultiFileEditorPane extends FieldEditorDefinePane JPanel contenter = new JPanel(new BorderLayout()); singleFileCheckBox = new UICheckBox(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Single_File_Upload")); + UIComponentUtils.setLineWrap(singleFileCheckBox); singleFileCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); acceptType = new DictionaryComboBox(DictionaryConstants.acceptTypes, DictionaryConstants.fileTypeDisplays); // acceptType.setPreferredSize(new Dimension(100, 20));