From 6ed7588b7b04ed56f94c666ead775713e6db34e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Mon, 16 Aug 2021 14:28:09 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-56906=20=20=E7=94=B1=E4=BA=8EUIIntNumber?= =?UTF-8?q?Field=E8=A2=AB=E5=BC=95=E7=94=A8=E7=9A=84=E5=9C=B0=E6=96=B9?= =?UTF-8?q?=E5=A4=AA=E5=A4=9A=E4=BA=86=EF=BC=8C=E6=89=80=E4=BB=A5=E8=BF=98?= =?UTF-8?q?=E5=8E=9F=E8=BF=99=E4=B8=AA=E7=B1=BB=E7=9A=84=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/ispinner/UnsignedIntUISpinner.java | 4 +- .../gui/itextfield/UIIntNumberField.java | 66 +++++++--------- .../UIPositiveAndNegativeIntNumberField.java | 76 +++++++++++++++++++ .../itextfield/UIPositiveIntNumberField.java | 61 --------------- .../ui/MobileCollapsedStyleExpandPane.java | 4 +- .../widget/ui/FormMultiWidgetCardPane.java | 6 +- .../fr/design/report/freeze/RowSpinner.java | 4 +- .../GlobalNativePrintSettingPane.java | 4 +- 8 files changed, 113 insertions(+), 112 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java delete mode 100644 designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveIntNumberField.java diff --git a/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java b/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java index 4d4e2794b1..42a40cd79e 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java +++ b/designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java @@ -1,6 +1,6 @@ package com.fr.design.gui.ispinner; -import com.fr.design.gui.itextfield.UIPositiveIntNumberField; +import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UINumberField; @@ -29,7 +29,7 @@ public class UnsignedIntUISpinner extends UISpinner { @Override protected UINumberField initNumberField() { - return new UIPositiveIntNumberField() { + return new UIIntNumberField() { public boolean shouldResponseChangeListener() { return false; } diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java index e81694d267..862eedaff0 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java +++ b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java @@ -1,32 +1,39 @@ package com.fr.design.gui.itextfield; + import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; import java.awt.Toolkit; +/** + * Created with IntelliJ IDEA. + * User: Lenovo + * Date: 13-3-29 + * Time: 下午12:02 + * To change this template use File | Settings | File Templates. + * fanglei: 这个类名字虽然叫整数输入框,但是里面的业务仅支持输入正整数,由于被引用的地方太多无法更改,知道就行 + */ public class UIIntNumberField extends UINumberField { - private static final long serialVersionUID = 4946379346015964509L; - public void setFieldDocument() { setDocument(createNumberDocument()); } public class NumberDocument extends PlainDocument { - private static final long serialVersionUID = 1024213269275179172L; - public NumberDocument() { } - public boolean checkString(int offset, String s, String str) { - String strNew = str.substring(0, offset) + s + str.substring(offset, getLength()); - return isMinusSignOnly(strNew) || (isIntNumber(strNew) && isInputIllegalNumber(strNew) && !isOverMaxOrMinValue(strNew)); - - } - public void insertString(int offset, String s, AttributeSet a) throws BadLocationException { String str = getText(0, getLength()); - if (!checkString(offset, s, str)) { + + if (!s.matches("^[0-9]+$")) { + Toolkit.getDefaultToolkit().beep(); + return; + } + + String strNew = str.substring(0, offset) + s + str.substring(offset, getLength()); + + if (isOverMaxOrMinValue(strNew) && !isContinueInsertWhenOverMaxOrMinValue()) { Toolkit.getDefaultToolkit().beep(); return; } @@ -35,42 +42,21 @@ public class UIIntNumberField extends UINumberField { super.insertString(offset, s, a); } - private boolean isMinusSignOnly(String s) { - return s.contains("-") && s.length() == 1; - } - /** - * 输入字符是否是不合法数字 - * @param s 输入的字符串 - * @return 是否不合法 + * 是否继续插入输入的字符 - 当超出范围时 + * + * @return true : 继续插入输入的字符 */ - private boolean isInputIllegalNumber(String s) { - try { - Integer.parseInt(s); - } catch (Exception e) { - return false; - } - return true; - } - - private boolean isIntNumber(String s) { - boolean result = true; - for (int i = 0; i < s.length(); i++) { - String ch = s.charAt(i) + ""; - if (!ch.matches("^[0-9\\-]+$")) { - result = false; - } - } - return result; + public boolean isContinueInsertWhenOverMaxOrMinValue() { + return false; } - private boolean isOverMaxOrMinValue(String s) { - int value = Integer.parseInt(s); - return (value < getMinValue() || value > getMaxValue()); + private boolean isOverMaxOrMinValue( String strNew) { + return (Double.parseDouble(strNew)getMaxValue()); } } public NumberDocument createNumberDocument() { return new NumberDocument(); } -} +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java new file mode 100644 index 0000000000..6f903d5cb7 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java @@ -0,0 +1,76 @@ +package com.fr.design.gui.itextfield; + +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; +import java.awt.Toolkit; + +public class UIPositiveAndNegativeIntNumberField extends UINumberField { + private static final long serialVersionUID = 4946379346015964509L; + + public void setFieldDocument() { + setDocument(createNumberDocument()); + } + + public class NumberDocument extends PlainDocument { + private static final long serialVersionUID = 1024213269275179172L; + + public NumberDocument() { + } + + public boolean checkString(int offset, String s, String str) { + String strNew = str.substring(0, offset) + s + str.substring(offset, getLength()); + return isMinusSignOnly(strNew) || (isIntNumber(strNew) && isInputIllegalNumber(strNew) && !isOverMaxOrMinValue(strNew)); + + } + + public void insertString(int offset, String s, AttributeSet a) throws BadLocationException { + String str = getText(0, getLength()); + if (!checkString(offset, s, str)) { + Toolkit.getDefaultToolkit().beep(); + return; + } + + setisContentChanged(true); + super.insertString(offset, s, a); + } + + private boolean isMinusSignOnly(String s) { + return s.contains("-") && s.length() == 1; + } + + /** + * 输入字符是否是不合法数字 + * @param s 输入的字符串 + * @return 是否不合法 + */ + private boolean isInputIllegalNumber(String s) { + try { + Integer.parseInt(s); + } catch (Exception e) { + return false; + } + return true; + } + + private boolean isIntNumber(String s) { + boolean result = true; + for (int i = 0; i < s.length(); i++) { + String ch = s.charAt(i) + ""; + if (!ch.matches("^[0-9\\-]+$")) { + result = false; + } + } + return result; + } + + private boolean isOverMaxOrMinValue(String s) { + int value = Integer.parseInt(s); + return (value < getMinValue() || value > getMaxValue()); + } + } + + public NumberDocument createNumberDocument() { + return new NumberDocument(); + } +} diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveIntNumberField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveIntNumberField.java deleted file mode 100644 index ec99777d7b..0000000000 --- a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveIntNumberField.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.fr.design.gui.itextfield; - - -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.PlainDocument; -import java.awt.Toolkit; - -/** - * Created with IntelliJ IDEA. - * User: Lenovo - * Date: 13-3-29 - * Time: 下午12:02 - * To change this template use File | Settings | File Templates. - */ -public class UIPositiveIntNumberField extends UINumberField { - public void setFieldDocument() { - setDocument(createNumberDocument()); - } - - public class NumberDocument extends PlainDocument { - public NumberDocument() { - } - - public void insertString(int offset, String s, AttributeSet a) throws BadLocationException { - String str = getText(0, getLength()); - - if (!s.matches("^[0-9]+$")) { - Toolkit.getDefaultToolkit().beep(); - return; - } - - String strNew = str.substring(0, offset) + s + str.substring(offset, getLength()); - - if (isOverMaxOrMinValue(strNew) && !isContinueInsertWhenOverMaxOrMinValue()) { - Toolkit.getDefaultToolkit().beep(); - return; - } - - setisContentChanged(true); - super.insertString(offset, s, a); - } - - /** - * 是否继续插入输入的字符 - 当超出范围时 - * - * @return true : 继续插入输入的字符 - */ - public boolean isContinueInsertWhenOverMaxOrMinValue() { - return false; - } - - private boolean isOverMaxOrMinValue( String strNew) { - return (Double.parseDouble(strNew)getMaxValue()); - } - } - - public NumberDocument createNumberDocument() { - return new NumberDocument(); - } -} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileCollapsedStyleExpandPane.java b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileCollapsedStyleExpandPane.java index 531a946b7e..8fd34d4524 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileCollapsedStyleExpandPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/mobile/ui/MobileCollapsedStyleExpandPane.java @@ -2,7 +2,7 @@ package com.fr.design.mainframe.mobile.ui; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ispinner.UISpinner; -import com.fr.design.gui.itextfield.UIPositiveIntNumberField; +import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; @@ -39,7 +39,7 @@ public class MobileCollapsedStyleExpandPane extends MobileCollapsedStylePane { this.rowSpinner = new UISpinner(1, Integer.MAX_VALUE, 1, 1) { @Override protected UINumberField initNumberField(){ - return new UIPositiveIntNumberField(); + return new UIIntNumberField(); } }; this.rowSpinner.setPreferredSize(new Dimension(62, COMPONENT_HEIGHT)); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java index c1dda9cc95..fa9a9bd0bc 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java @@ -2,7 +2,7 @@ package com.fr.design.mainframe.widget.ui; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itextfield.UIIntNumberField; +import com.fr.design.gui.itextfield.UIPositiveAndNegativeIntNumberField; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; @@ -129,14 +129,14 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { TableLayout.PREFERRED, TableLayout.FILL }; - UITextField horizontalSpacingNumberField = new UIIntNumberField(); + UITextField horizontalSpacingNumberField = new UIPositiveAndNegativeIntNumberField(); horizontalSpacingNumberField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { distributionDoChange(horizontalSpacingNumberField.getText(), false); } }); - UITextField verticalSpacingNumberField = new UIIntNumberField(); + UITextField verticalSpacingNumberField = new UIPositiveAndNegativeIntNumberField(); verticalSpacingNumberField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { diff --git a/designer-realize/src/main/java/com/fr/design/report/freeze/RowSpinner.java b/designer-realize/src/main/java/com/fr/design/report/freeze/RowSpinner.java index 961b05cfc1..da652a0e44 100644 --- a/designer-realize/src/main/java/com/fr/design/report/freeze/RowSpinner.java +++ b/designer-realize/src/main/java/com/fr/design/report/freeze/RowSpinner.java @@ -1,7 +1,7 @@ package com.fr.design.report.freeze; import com.fr.design.gui.ispinner.UISpinner; -import com.fr.design.gui.itextfield.UIPositiveIntNumberField; +import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UINumberField; /** @@ -25,7 +25,7 @@ public class RowSpinner extends UISpinner { @Override protected UINumberField initNumberField(){ - return new UIPositiveIntNumberField(); + return new UIIntNumberField(); } diff --git a/designer-realize/src/main/java/com/fr/design/webattr/printsettings/GlobalNativePrintSettingPane.java b/designer-realize/src/main/java/com/fr/design/webattr/printsettings/GlobalNativePrintSettingPane.java index e9877b2514..7b3643899a 100644 --- a/designer-realize/src/main/java/com/fr/design/webattr/printsettings/GlobalNativePrintSettingPane.java +++ b/designer-realize/src/main/java/com/fr/design/webattr/printsettings/GlobalNativePrintSettingPane.java @@ -3,7 +3,7 @@ package com.fr.design.webattr.printsettings; import com.fr.base.print.NativePrintAttr; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itextfield.UIPositiveIntNumberField; +import com.fr.design.gui.itextfield.UIIntNumberField; import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.layout.FRGUIPaneFactory; @@ -89,7 +89,7 @@ public class GlobalNativePrintSettingPane extends AbstractNativePrintSettingPane } private JPanel getPrintPortFieldPane() { - printPortField = new UIPositiveIntNumberField(); + printPortField = new UIIntNumberField(); printPortField.setMaxValue(NativePrintAttr.MAX_PRINT_PORT_VALUE); printPortField.setColumns(PRINT_PORT_FIELD_COLUMNS); JPanel panel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane();