Browse Source

REPORT-50598 数字文本框输入有问题

final/10.0
kuangshuai 4 years ago
parent
commit
3660aba391
  1. 43
      designer-base/src/main/java/com/fr/design/gui/itextfield/UINumberField.java

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

@ -4,16 +4,11 @@ import com.fr.base.Utils;
import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.InputMethodEvent;
import java.awt.event.InputMethodListener;
/**
* Number Field.
@ -39,11 +34,6 @@ public class UINumberField extends UITextField {
private boolean isContentChanged = false;
private boolean fillNegativeNumber = true;
/**
* 输入法输入完成一个字符输入过程的标记开始输入的时候是true输入完矫正光标后为false
*/
private boolean isInputMethodOnceInserting = false;
private int insertOffset = 0;
public UINumberField() {
this(MAX_INTEGERLENGTH_32, MAX_DECIMALLENGTH);
@ -64,7 +54,6 @@ public class UINumberField extends UITextField {
this.minValue = minValue;
this.maxValue = maxValue;
setFieldDocument();
initFieldListener();
}
public void setFieldDocument() {
@ -72,31 +61,6 @@ public class UINumberField extends UITextField {
initListener();
}
private void initFieldListener() {
addInputMethodListener(new InputMethodListener() {
@Override
public void inputMethodTextChanged(InputMethodEvent event) {
isInputMethodOnceInserting = true;
}
@Override
public void caretPositionChanged(InputMethodEvent event) {
}
});
addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
if (isInputMethodOnceInserting) {
isInputMethodOnceInserting = false;
setCaretPosition(insertOffset);
} else {
insertOffset = e.getDot();
}
}
});
}
public void canFillNegativeNumber(boolean fillNegativeNumber) {
this.fillNegativeNumber = fillNegativeNumber;
}
@ -221,13 +185,6 @@ public class UINumberField extends UITextField {
super.insertString(offset, s, a);
}
public void remove(int offs, int len) throws BadLocationException {
if (isInputMethodOnceInserting) {
return;
}
super.remove(offs, len);
}
// kunsnat: 这种限制输入 有个不好的地方, 比如删除时: 10.1 最大值限定100, 那么就删除中间的小数点之后变为101, 超出了100.
// 但是直接限制不能删除中间类似小数点, 那么也可能遇到: 最小值10 , 从100变化到其中的19, 就很难..
private boolean notChange(String strNew) {

Loading…
Cancel
Save