|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |