我无法在Scene Builder上看到自定义组件属性的旧值。 我想得到" Speed Unit Type"的旧值。相应地更改最小/最大值。
也许我可以使用静态最小/最大值并将它们绑定到"速度单位类型"。但只是想知道是否可以在SB上设计tima使用旧值。
public static enum SpeedUnitType {KILO_METERS_PER_HOUR,METERS_PER_SECOND,DATA_MILES_PER_HOUR}
public static final int SPEED_MAX_DEFAULT_VALUE = 1000;
public static final int SPEED_MAX_LIMIT_VALUE = 999;
public static final double SPEED_MIN_LIMIT_VALUE = -100;
private final IntegerProperty minValue = new SimpleIntegerProperty(0);
private final IntegerProperty maxValue = new SimpleIntegerProperty(Integer.MAX_VALUE);
private final IntegerProperty value = new SimpleIntegerProperty(0);
private SpeedUnitType _speedUnit = SpeedUnitType.KILO_METERS_PER_HOUR;
private ObjectProperty<SpeedUnitType> speedUnitTypeProperty ;
public final SpeedUnitType getSpeedUnitType() {
return null == speedUnitTypeProperty ? _speedUnit : speedUnitTypeProperty.get();
}
public final void setSpeedUnitType(final SpeedUnitType UNIT) {
if (null == speedUnitTypeProperty) {
_speedUnit = UNIT;
} else {
speedUnitTypeProperty.set(UNIT);
}
}
public final ObjectProperty<SpeedUnitType> speedUnitTypeProperty() {
if (null == speedUnitTypeProperty) {
speedUnitTypeProperty = new SimpleObjectProperty<>(this, "speedUnitTypeProperty", _speedUnit);
}
return speedUnitTypeProperty;
}
public Speed() {
this.construct();
}
public void setMinValue(int min){ this.minValue.set(min); }
public int getMinValue() { return this.minValue.get(); }
public IntegerProperty minValueProperty() { return this.minValue;}
public void setMaxValue(int max) { this.maxValue.set(max);}
public int getMaxValue(){ return this.maxValue.get();}
public IntegerProperty maxValueProperty() { return this.maxValue; }
public final int getValue() { return value.get(); }
public final void setValue(final int VALUE) { value.set(VALUE);}
public final IntegerProperty valueProperty() {return value;}
private void construct()
{
this.maxValueProperty().addListener((observable, oldValue, newValue) ->
{
try
{
System.out.println("maxValueProperty --> The value was changed from " + oldValue.toString() + " to " + newValue.toString());
}
catch (Exception e)
{
System.err.println("Exception: " + e.getLocalizedMessage());
setText("ERROR");
}
});
speedUnitTypeProperty().addListener((observable, oldValue, newValue) -> {
this.convertSpeedUnit(oldValue, newValue);
});
// this.maxValueProperty().bind(Bindings.add(10, this.minValueProperty())); test to bind property min to property max
}
// ********************实用方法*********************** ************
public void convertSpeedUnit(SpeedUnitType oldValue, SpeedUnitType newValue)
{
if (oldValue == null)
return;
if (oldValue == newValue){}
else{
switch (oldValue){
case KILO_METERS_PER_HOUR:
System.out.println("convertSpeedUnit::formerUnit - KILO_METERS_PER_HOUR");
switch (newValue){
case METERS_PER_SECOND:
System.out.println("convertSpeedUnit::currentUnit - METERS_PER_SECOND");
setMinValue(10);
setMaxValue(20);
break;
case DATA_MILES_PER_HOUR:
System.out.println("convertSpeedUnit::currentUnit - DATA_MILES_PER_HOUR");
setMinValue(11);
setMaxValue(21);
break;
}
break;
case METERS_PER_SECOND:
System.out.println("convertSpeedUnit::formerUnit - METERS_PER_SECOND");
switch (newValue){
case KILO_METERS_PER_HOUR:
System.out.println("convertSpeedUnit::currentUnit - KILO_METERS_PER_HOUR");
setMinValue(12);
setMaxValue(22);
break;
case DATA_MILES_PER_HOUR:
System.out.println("convertSpeedUnit::currentUnit - DATA_MILES_PER_HOUR");
setMinValue(13);
setMaxValue(23);
break;
}
break;
case DATA_MILES_PER_HOUR:
System.out.println("convertSpeedUnit::formerUnit - DATA_MILES_PER_HOUR");
switch (newValue){
case KILO_METERS_PER_HOUR:
System.out.println("convertSpeedUnit::currentUnit - KILO_METERS_PER_HOUR");
setMinValue(34);
setMaxValue(45);
break;
case METERS_PER_SECOND:
System.out.println("convertSpeedUnit::currentUnit - METERS_PER_SECOND");
setMinValue(56);
setMaxValue(67);
break;
}
break;
}
}
}