// Create price label and its spinner bound to PRICE controller property
this.priceLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
FurniturePanel.class, "priceLabel.text"));
final NullableSpinner.NullableSpinnerNumberModel priceSpinnerModel =
new NullableSpinner.NullableSpinnerNumberModel(1, 0.00999f, 1000000f, 1f);
this.priceSpinner = new AutoCommitSpinner(priceSpinnerModel);
priceSpinnerModel.setNullable(controller.getPrice() == null);
priceSpinnerModel.setValue(controller.getPrice());
final PropertyChangeListener priceChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
priceSpinnerModel.setNullable(ev.getNewValue() == null);
priceSpinnerModel.setValue((Float)ev.getNewValue());
}
};
controller.addPropertyChangeListener(FurnitureController.Property.PRICE, priceChangeListener);
priceSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
controller.removePropertyChangeListener(FurnitureController.Property.PRICE, priceChangeListener);
Object value = priceSpinnerModel.getValue();
controller.setPrice(value != null
? new BigDecimal((Float)value).setScale(2, BigDecimal.ROUND_HALF_UP)
: (BigDecimal)value);
controller.addPropertyChangeListener(FurnitureController.Property.PRICE, priceChangeListener);
}
});
// Create VAT % label and its spinner bound to VALUE_ADDED_TAX_PERCENTAGE controller property
this.valueAddedTaxPercentageLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
FurniturePanel.class, "valueAddedTaxPercentageLabel.text"));
final NullableSpinner.NullableSpinnerNumberModel valueAddedTaxPercentageSpinnerModel =
new NullableSpinner.NullableSpinnerNumberModel(0, 0, 100f, 0.1f);
this.valueAddedTaxPercentageSpinner = new AutoCommitSpinner(valueAddedTaxPercentageSpinnerModel);
valueAddedTaxPercentageSpinnerModel.setNullable(controller.getValueAddedTaxPercentage() == null);
valueAddedTaxPercentageSpinnerModel.setValue(controller.getValueAddedTaxPercentage() == null
? null
: controller.getValueAddedTaxPercentage().floatValue() * 100);
final PropertyChangeListener valueAddedTaxPercentageChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
valueAddedTaxPercentageSpinnerModel.setNullable(ev.getNewValue() == null);
valueAddedTaxPercentageSpinnerModel.setValue(ev.getNewValue() == null
? null
: ((Float)ev.getNewValue()) * 100);
}
};
controller.addPropertyChangeListener(FurnitureController.Property.VALUE_ADDED_TAX_PERCENTAGE, valueAddedTaxPercentageChangeListener);
valueAddedTaxPercentageSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
controller.removePropertyChangeListener(FurnitureController.Property.VALUE_ADDED_TAX_PERCENTAGE, valueAddedTaxPercentageChangeListener);
Object value = valueAddedTaxPercentageSpinnerModel.getValue();
controller.setValueAddedTaxPercentage(value != null
? new BigDecimal((Float)value / 100).setScale(3, BigDecimal.ROUND_HALF_UP)
: (BigDecimal)value);
controller.addPropertyChangeListener(FurnitureController.Property.VALUE_ADDED_TAX_PERCENTAGE, valueAddedTaxPercentageChangeListener);
}
});
// Create width label and its spinner bound to WIDTH controller property
this.widthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
FurniturePanel.class, "widthLabel.text", unitName));
final float minimumLength = preferences.getLengthUnit().getMinimumLength();
final NullableSpinner.NullableSpinnerLengthModel widthSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
this.widthSpinner = new AutoCommitSpinner(widthSpinnerModel);
final PropertyChangeListener widthChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
Float width = controller.getWidth();
widthSpinnerModel.setNullable(width == null);
widthSpinnerModel.setLength(width);