Browse Source

Merge pull request #9497 in DESIGN/design from release/10.0 to bugfix/10.0

* commit 'dff0e8a38e1dbf79f15e0aa7d03c5e046b8a4d82':
  REPORT-38555 fix:数字控件中内容可以输入空格和减号
  REPORT-38555 fix:数字控件中内容可以输入空格和减号
  REPORT-38523 fix: 右侧单元格属性表鼠标事件有误,修改了mouseReleased事件
superman 2 years ago
parent
commit
ee9b349412
  1. 9
      designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java
  2. 11
      designer-base/src/main/java/com/fr/design/gui/itextfield/UINumberField.java
  3. 17
      designer-base/src/main/java/com/fr/design/widget/component/NumberEditorValidatePane.java
  4. 44
      designer-base/src/test/java/com/fr/design/gui/itextfield/UINumberFieldTest.java

9
designer-base/src/main/java/com/fr/design/gui/icontainer/UIEastResizableContainer.java

@ -296,10 +296,9 @@ public class UIEastResizableContainer extends JPanel {
model = UIConstants.MODEL_NORMAL;
refreshContainer();
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getX() <= ARROW_RANGE) {
public void mouseReleased(MouseEvent e) {
if (isInPane(e)) {
if (containerWidth == leftPaneWidth) {
showContainer();
} else {
@ -309,7 +308,9 @@ public class UIEastResizableContainer extends JPanel {
}
});
}
public boolean isInPane(MouseEvent e){
return e.getX() <= ARROW_RANGE && e.getX() >= 0 && e.getY() <= topToolPaneHeight && e.getY() >= 0;
}
@Override
public void paint(Graphics g) {
Image button;

11
designer-base/src/main/java/com/fr/design/gui/itextfield/UINumberField.java

@ -4,6 +4,7 @@ import com.fr.base.Utils;
import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
@ -164,10 +165,16 @@ public class UINumberField extends UITextField {
|| ComparatorUtils.equals(s, "D")
|| ComparatorUtils.equals(s, "d")
|| (ComparatorUtils.equals(str.trim(), "0") && !ComparatorUtils.equals(s.substring(0, 1), ".") && offset != 0)// 第一位是0时,第二位只能为小数点
|| (ComparatorUtils.equals(s, ".") && maxDecimalLength == 0));
|| (ComparatorUtils.equals(s, ".") && maxDecimalLength == 0))
|| s.contains(" ")//不允许空格
|| (ComparatorUtils.equals(s.substring(0, 1),"-") && offset != 0)//负号只允许出现在第一位
|| (ComparatorUtils.equals(s.substring(0, 1),".") && offset == 0)//小数点不能在第一位
|| s.contains("-.")
|| s.contains(".-")//不能包含-.或.-非法格式
|| (str.startsWith("-") && ComparatorUtils.equals(s.substring(0, 1), ".") && offset == 1 )//负号不能接小数点
|| (s.contains("-") && !ComparatorUtils.equals(s.substring(0,1), "-"));//输入的字符串如果包含负号,负号必须在第一位
}
public void insertString(int offset, String s, AttributeSet a) throws BadLocationException {
String str = getText(0, getLength());

17
designer-base/src/main/java/com/fr/design/widget/component/NumberEditorValidatePane.java

@ -26,6 +26,9 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
* Created by kerry on 2017/9/10.
@ -102,8 +105,20 @@ public class NumberEditorValidatePane extends JPanel {
int[][] rowCount = {{1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}};
JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_L2, IntervalConstants.INTERVAL_L1);
this.add(panel);
decimalLength.getTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
// Digit only
if (isDigit(e)) {
} else {
e.consume();
}
}
});
}
private boolean isDigit(KeyEvent e){
return e.getKeyChar() >= KeyEvent.VK_0 && e.getKeyChar() <= KeyEvent.VK_9;
}
private void initErrorMsgPane() {
TextFieldAdapterProvider provider = ExtraDesignClassManager.getInstance().getSingle(TextFieldAdapterProvider.XML_TAG);
if (provider != null) {

44
designer-base/src/test/java/com/fr/design/gui/itextfield/UINumberFieldTest.java

@ -0,0 +1,44 @@
package com.fr.design.gui.itextfield;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Destiny.Lin
* @version 10.0
* created by Destiny.Lin on 2022-07-11
*/
public class UINumberFieldTest {
@Test
public void testUINumberFieldTest(){
UINumberField uiNumberField = new UINumberField();
uiNumberField.setFieldDocument();
//异常输入测试
uiNumberField.setText("-.1");
Assert.assertEquals("",uiNumberField.getText());
uiNumberField.setText(".-1");
Assert.assertEquals("",uiNumberField.getText());
uiNumberField.setText("1-");
Assert.assertEquals("",uiNumberField.getText());
uiNumberField.setText("1-1");
Assert.assertEquals("",uiNumberField.getText());
uiNumberField.setText("1 ");
Assert.assertEquals("",uiNumberField.getText());
uiNumberField.setText(".1");
Assert.assertEquals("",uiNumberField.getText());
uiNumberField.setText("1 -");
Assert.assertEquals("",uiNumberField.getText());
//正常输入测试
uiNumberField.setText("0.1");
Assert.assertEquals("0.1",uiNumberField.getText());
uiNumberField.setText("1");
Assert.assertEquals("1",uiNumberField.getText());
uiNumberField.setText("-1.5");
Assert.assertEquals("-1.5",uiNumberField.getText());
uiNumberField.setText("-123.123");
Assert.assertEquals("-123.123",uiNumberField.getText());
}
}
Loading…
Cancel
Save