Browse Source

Merge pull request #1104 in DESIGN/design from ~HUGH.C/design:feature/10.0 to feature/10.0

* commit '9757a58c68275946036e9d296a1a216785894032':
  REPORT-21800 水印密度框最小限制有问题,删掉进行输入的话,就是小于100,无法手动输入
research/11.0
Hugh.C 5 years ago
parent
commit
a3efd32a97
  1. 43
      designer-base/src/main/java/com/fr/design/gui/ispinner/UnsignedIntUISpinner.java
  2. 26
      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;
}
}

26
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.
@ -15,11 +14,11 @@ import java.awt.*;
* To change this template use File | Settings | File Templates.
*/
public class UIIntNumberField extends UINumberField {
public void setFieldDocument(){
setDocument(new NumberDocument());
public void setFieldDocument() {
setDocument(createNumberDocument());
}
class NumberDocument extends PlainDocument {
public class NumberDocument extends PlainDocument {
public NumberDocument() {
}
@ -33,17 +32,30 @@ 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;
}
setisContentChanged(true);
setisContentChanged(true);
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