From 92825af427883c4e7b7e84c67ce37741d25a4f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E7=A3=8A?= <294531121@qq.com> Date: Tue, 17 Aug 2021 17:21:19 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-56926=20=E3=80=90FRM=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E6=8E=A8=E8=8D=90=E3=80=91=E7=BB=84=E4=BB=B6=E5=A4=8D=E7=94=A8?= =?UTF-8?q?-=E6=89=8B=E5=8A=A8=E9=97=B4=E8=B7=9D=E7=9B=AE=E5=89=8D?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E8=BE=93=E5=85=A5=E5=B0=8F=E6=95=B0?= =?UTF-8?q?=EF=BC=88=E5=85=81=E8=AE=B8=E8=BE=93=E5=85=A5=E5=B0=8F=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E8=87=AA=E5=8A=A8=E5=8F=96=E6=95=B4=E5=A4=84?= =?UTF-8?q?=E7=90=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UIPositiveAndNegativeIntNumberField.java | 76 ------------------- .../widget/ui/FormMultiWidgetCardPane.java | 25 +++--- 2 files changed, 14 insertions(+), 87 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java 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 deleted file mode 100644 index 6f903d5cb7..0000000000 --- a/designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java +++ /dev/null @@ -1,76 +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; - -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-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 b053ea6337..a49d719d26 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 @@ -4,7 +4,7 @@ import com.fr.design.designer.beans.events.DesignerEvent; import com.fr.design.gui.frpane.AttributeChangeListener; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.gui.itextfield.UIPositiveAndNegativeIntNumberField; +import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.TableLayout; @@ -157,31 +157,34 @@ public class FormMultiWidgetCardPane extends FormWidgetCardPane { return createTitleLayout(Toolkit.i18nText("Fine-Design_Multi_Selection_Manual_Spacing"), centerPane); } - private UIPositiveAndNegativeIntNumberField createIntNumberField(boolean isVertical) { - final UIPositiveAndNegativeIntNumberField intNumberField = new UIPositiveAndNegativeIntNumberField(); - intNumberField.addFocusListener(new FocusAdapter() { + private UINumberField createIntNumberField(boolean isVertical) { + final UINumberField numberField = new UINumberField(); + numberField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { - distributionDoChange(intNumberField.getText(), isVertical); + distributionDoChange(numberField, isVertical); } }); - intNumberField.addKeyListener(new KeyAdapter() { + numberField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { - distributionDoChange(intNumberField.getText(), isVertical); + distributionDoChange(numberField, isVertical); } } }); - return intNumberField; + return numberField; } - private void distributionDoChange(String text, boolean isVertical) { + private void distributionDoChange(UINumberField numberField, boolean isVertical) { + String text = numberField.getText(); if (StringUtils.isNotEmpty(text) && StableUtils.isNumber(text)) { + int gap = (int) Math.floor(Float.parseFloat(text)); + numberField.setValue(gap); if (isVertical) { - arrangement.verticalManualDistribution(Math.round(Float.parseFloat(text))); + arrangement.verticalManualDistribution(gap); } else { - arrangement.horizontalManualDistribution(Math.round(Float.parseFloat(text))); + arrangement.horizontalManualDistribution(gap); } attributeChanged(); }