value = ((FurnitureCategory)value).getName();
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
this.categoryComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setCategory((FurnitureCategory)ev.getItem());
}
});
controller.addPropertyChangeListener(FurnitureController.Property.CATEGORY,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If category changes update category combo box
FurnitureCategory category = controller.getCategory();
if (category != null) {
categoryComboBox.setSelectedItem(category);
}
}
});
if (this.categoryComboBox.getItemCount() > 0) {
this.categoryComboBox.setSelectedItem(controller.getCategory());
}
this.categoryComboBox.setMaximumRowCount(15);
// 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);
if (width != null) {
widthSpinnerModel.setMinimum(Math.min(width, minimumLength));
}
}
};
widthChangeListener.propertyChange(null);
controller.addPropertyChangeListener(FurnitureController.Property.WIDTH, widthChangeListener);
widthSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
controller.removePropertyChangeListener(FurnitureController.Property.WIDTH, widthChangeListener);
controller.setWidth(widthSpinnerModel.getLength());
if (!controller.isProportional()) {
resetIcon(false);
}
controller.addPropertyChangeListener(FurnitureController.Property.WIDTH, widthChangeListener);
}
});
// Create depth label and its spinner bound to DEPTH controller property
this.depthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
FurniturePanel.class, "depthLabel.text", unitName));
final NullableSpinner.NullableSpinnerLengthModel depthSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
this.depthSpinner = new NullableSpinner(depthSpinnerModel);
final PropertyChangeListener depthChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
Float depth = controller.getDepth();
depthSpinnerModel.setNullable(depth == null);
depthSpinnerModel.setLength(depth);
if (depth != null) {
depthSpinnerModel.setMinimum(Math.min(depth, minimumLength));
}
}
};
depthChangeListener.propertyChange(null);
controller.addPropertyChangeListener(FurnitureController.Property.DEPTH, depthChangeListener);
depthSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
controller.removePropertyChangeListener(FurnitureController.Property.DEPTH, depthChangeListener);
controller.setDepth(depthSpinnerModel.getLength());
if (!controller.isProportional()) {
resetIcon(false);
}
controller.addPropertyChangeListener(FurnitureController.Property.DEPTH, depthChangeListener);
}
});
// Create height label and its spinner bound to HEIGHT controller property
this.heightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
FurniturePanel.class, "heightLabel.text", unitName));
final NullableSpinner.NullableSpinnerLengthModel heightSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, minimumLength, 100000f);
this.heightSpinner = new NullableSpinner(heightSpinnerModel);
final PropertyChangeListener heightChangeListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
Float height = controller.getHeight();
heightSpinnerModel.setNullable(height == null);
heightSpinnerModel.setLength(height);
if (height != null) {
heightSpinnerModel.setMinimum(Math.min(height, minimumLength));
}
}
};
heightChangeListener.propertyChange(null);
controller.addPropertyChangeListener(FurnitureController.Property.HEIGHT, heightChangeListener);
heightSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
controller.removePropertyChangeListener(FurnitureController.Property.HEIGHT, heightChangeListener);
controller.setHeight(heightSpinnerModel.getLength());
if (!controller.isProportional()) {
resetIcon(false);
}
controller.addPropertyChangeListener(FurnitureController.Property.HEIGHT, heightChangeListener);
}
});
this.keepProportionsCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
FurniturePanel.class, "keepProportionsCheckBox.text"), controller.isProportional());
this.keepProportionsCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setProportional(keepProportionsCheckBox.isSelected());
}
});
controller.addPropertyChangeListener(FurnitureController.Property.PROPORTIONAL,