Browse Source

REPORT-21800 水印密度框最小限制有问题,删掉进行输入的话,就是小于100,无法手动输入

research/11.0
Hugh.C 5 years ago
parent
commit
4f6f05becc
  1. 43
      designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java
  2. 22
      designer-base/src/main/java/com/fr/design/gui/itextfield/UIIntNumberField.java

43
designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java

@ -3,6 +3,9 @@ package com.fr.design.gui.ispinner;
import com.fr.design.gui.itextfield.UIIntNumberField;
import com.fr.design.gui.itextfield.UINumberField;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
/**
* Created by IntelliJ IDEA.
* Author : Hugh.C
@ -11,21 +14,59 @@ import com.fr.design.gui.itextfield.UINumberField;
*/
public class UnsignedIntUISpinner extends UISpinner {
private double minValue;
private double maxValue;
public UnsignedIntUISpinner(double minValue, double maxValue, double dierta) {
super(minValue, maxValue, dierta);
this.minValue = minValue;
this.maxValue = maxValue;
}
public UnsignedIntUISpinner(double minValue, double maxValue, double dierta, double defaultValue) {
super(minValue, maxValue, dierta, defaultValue);
this.minValue = minValue;
this.maxValue = maxValue;
}
@Override
protected UINumberField initNumberField() {
return new UIIntNumberField() {
final UIIntNumberField numberField = new UIIntNumberField() {
public boolean shouldResponseChangeListener() {
return false;
}
public NumberDocument createNumberDocument() {
return new NumberDocument() {
public boolean isContinueInsertWhenOverMaxOrMinValue() {
return true;
}
};
}
};
numberField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
/**
* 失去焦点后再做范围限制不然最小值为 100 输个 1 都不让....
* @param e
*/
@Override
public void focusLost(FocusEvent e) {
double value = numberField.getValue();
if (!isOverMaxOrMinValue(value)) {
return;
}
numberField.setValue(value < minValue ? minValue : maxValue);
}
private boolean isOverMaxOrMinValue(double value) {
return value < minValue || value > maxValue;
}
});
return numberField;
}
}

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

@ -1,11 +1,10 @@
package com.fr.design.gui.itextfield;
import com.fr.design.gui.itextfield.UINumberField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import java.awt.*;
import java.awt.Toolkit;
/**
* Created with IntelliJ IDEA.
@ -16,10 +15,10 @@ import java.awt.*;
*/
public class UIIntNumberField extends UINumberField {
public void setFieldDocument() {
setDocument(new NumberDocument());
setDocument(createNumberDocument());
}
class NumberDocument extends PlainDocument {
public class NumberDocument extends PlainDocument {
public NumberDocument() {
}
@ -33,7 +32,7 @@ public class UIIntNumberField extends UINumberField {
String strNew = str.substring(0, offset) + s + str.substring(offset, getLength());
if (isOverMaxOrMinValue(strNew)) {
if (isOverMaxOrMinValue(strNew) && !isContinueInsertWhenOverMaxOrMinValue()) {
Toolkit.getDefaultToolkit().beep();
return;
}
@ -42,8 +41,21 @@ public class UIIntNumberField extends UINumberField {
super.insertString(offset, s, a);
}
/**
* 是否继续插入输入的字符 - 当超出范围时
*
* @return true : 继续插入输入的字符
*/
public boolean isContinueInsertWhenOverMaxOrMinValue() {
return false;
}
private boolean isOverMaxOrMinValue( String strNew) {
return (Double.parseDouble(strNew)<getMinValue() || Double.parseDouble(strNew)>getMaxValue());
}
}
public NumberDocument createNumberDocument() {
return new NumberDocument();
}
}
Loading…
Cancel
Save