Browse Source

Pull request #5359: REPORT-56906 自定义一个输入框,只支持输入整数

Merge in DESIGN/design from ~FANGLEI/design10.0:feature/10.0 to feature/10.0

* commit '6ed7588b7b04ed56f94c666ead775713e6db34e3':
  REPORT-56906  由于UIIntNumberField被引用的地方太多了,所以还原这个类的重命名
  REPORT-56906&REPORT-56926 修正一个笔误
  REPORT-56906&REPORT-56926 自定义一个输入框,只支持输入整数
feature/10.0
fanglei 3 years ago
parent
commit
cea7b647cd
  1. 1
      designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java
  2. 76
      designer-base/src/main/java/com/fr/design/gui/itextfield/UIPositiveAndNegativeIntNumberField.java
  3. 6
      designer-form/src/main/java/com/fr/design/mainframe/widget/ui/FormMultiWidgetCardPane.java

1
designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java

@ -12,6 +12,7 @@ import java.awt.Toolkit;
* Date: 13-3-29
* Time: 下午12:02
* To change this template use File | Settings | File Templates.
* fanglei: 这个类名字虽然叫整数输入框但是里面的业务仅支持输入正整数由于被引用的地方太多无法更改知道就行
*/
public class UIIntNumberField extends UINumberField {
public void setFieldDocument() {

76
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();
}
}

6
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) {

Loading…
Cancel
Save