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. 24
      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.UIIntNumberField;
import com.fr.design.gui.itextfield.UINumberField; import com.fr.design.gui.itextfield.UINumberField;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
* Author : Hugh.C * Author : Hugh.C
@ -11,21 +14,59 @@ import com.fr.design.gui.itextfield.UINumberField;
*/ */
public class UnsignedIntUISpinner extends UISpinner { public class UnsignedIntUISpinner extends UISpinner {
private double minValue;
private double maxValue;
public UnsignedIntUISpinner(double minValue, double maxValue, double dierta) { public UnsignedIntUISpinner(double minValue, double maxValue, double dierta) {
super(minValue, maxValue, dierta); super(minValue, maxValue, dierta);
this.minValue = minValue;
this.maxValue = maxValue;
} }
public UnsignedIntUISpinner(double minValue, double maxValue, double dierta, double defaultValue) { public UnsignedIntUISpinner(double minValue, double maxValue, double dierta, double defaultValue) {
super(minValue, maxValue, dierta, defaultValue); super(minValue, maxValue, dierta, defaultValue);
this.minValue = minValue;
this.maxValue = maxValue;
} }
@Override @Override
protected UINumberField initNumberField() { protected UINumberField initNumberField() {
return new UIIntNumberField() { final UIIntNumberField numberField = new UIIntNumberField() {
public boolean shouldResponseChangeListener() { public boolean shouldResponseChangeListener() {
return false; 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;
} }
} }

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

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