public void itemStateChanged(ItemEvent ev) {
controller.setBackFaceShown(backFaceShownCheckBox.isSelected());
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.BACK_FACE_SHOWN,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If back face shown changes update back face shown check box
backFaceShownCheckBox.setSelected(controller.isBackFaceShown());
}
});
this.rotationPreviewComponent = new RotationPreviewComponent(preferences, controller);
// Attributes panel components
this.attributesLabel = new JLabel(preferences.getLocalizedString(
ImportedFurnitureWizardStepsPanel.class, "attributesLabel.text"));
this.nameLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "nameLabel.text"));
this.nameTextField = new JTextField(10);
if (!OperatingSystem.isMacOSXLeopardOrSuperior()) {
SwingTools.addAutoSelectionOnFocusGain(this.nameTextField);
}
final Color defaultNameTextFieldColor = this.nameTextField.getForeground();
DocumentListener nameListener = new DocumentListener() {
public void changedUpdate(DocumentEvent ev) {
nameTextField.getDocument().removeDocumentListener(this);
controller.setName(nameTextField.getText().trim());
nameTextField.getDocument().addDocumentListener(this);
}
public void insertUpdate(DocumentEvent ev) {
changedUpdate(ev);
}
public void removeUpdate(DocumentEvent ev) {
changedUpdate(ev);
}
};
this.nameTextField.getDocument().addDocumentListener(nameListener);
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.NAME,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If name changes update name text field
if (!nameTextField.getText().trim().equals(controller.getName())) {
nameTextField.setText(controller.getName());
}
updateNameTextFieldForeground(defaultNameTextFieldColor);
}
});
this.addToCatalogCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "addToCatalogCheckBox.text"));
// Propose the add to catalog option only for home furniture import
this.addToCatalogCheckBox.setVisible(importHomePiece);
this.addToCatalogCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
if (addToCatalogCheckBox.isSelected()) {
categoryComboBox.setEnabled(true);
controller.setCategory((FurnitureCategory)categoryComboBox.getSelectedItem());
} else {
categoryComboBox.setEnabled(false);
controller.setCategory(null);
}
}
});
this.categoryLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "categoryLabel.text"));
this.categoryComboBox = new JComboBox(preferences.getFurnitureCatalog().getCategories().toArray());
// The piece category isn't enabled by default for home furniture import
this.categoryComboBox.setEnabled(!importHomePiece);
this.categoryComboBox.setEditable(true);
final ComboBoxEditor defaultEditor = this.categoryComboBox.getEditor();
// Change editor to edit category name
this.categoryComboBox.setEditor(new ComboBoxEditor() {
public Object getItem() {
String name = (String)defaultEditor.getItem();
name = name.trim();
// If category is empty, replace it by the last selected item
if (name.length() == 0) {
setItem(categoryComboBox.getSelectedItem());
}
FurnitureCategory category = new FurnitureCategory(name);
// Search an existing category
List<FurnitureCategory> categories = preferences.getFurnitureCatalog().getCategories();
int categoryIndex = Collections.binarySearch(categories, category);
if (categoryIndex >= 0) {
return categories.get(categoryIndex);
}
// If no existing category was found, return a new one
return category;
}
public void setItem(Object value) {
if (value != null) {
FurnitureCategory category = (FurnitureCategory)value;
defaultEditor.setItem(category.getName());
}
}
public void addActionListener(ActionListener l) {
defaultEditor.addActionListener(l);
}
public Component getEditorComponent() {
return defaultEditor.getEditorComponent();
}
public void removeActionListener(ActionListener l) {
defaultEditor.removeActionListener(l);
}
public void selectAll() {
defaultEditor.selectAll();
}
});
this.categoryComboBox.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
FurnitureCategory category = (FurnitureCategory)value;
return super.getListCellRendererComponent(list, category.getName(), index, isSelected, cellHasFocus);
}
});
this.categoryComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setCategory((FurnitureCategory)ev.getItem());
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.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);
}
updateNameTextFieldForeground(defaultNameTextFieldColor);
}
});
if (this.categoryComboBox.getItemCount() > 0) {
this.categoryComboBox.setSelectedIndex(0);
}
this.widthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "widthLabel.text", unitName));
final float minimumLength = preferences.getLengthUnit().getMinimumLength();
final NullableSpinner.NullableSpinnerLengthModel widthSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, Math.min(controller.getWidth(), minimumLength), 100000f);
this.widthSpinner = new NullableSpinner(widthSpinnerModel);
widthSpinnerModel.addChangeListener(new ChangeListener () {
public void stateChanged(ChangeEvent ev) {
widthSpinnerModel.removeChangeListener(this);
// If width spinner value changes update controller
controller.setWidth(widthSpinnerModel.getLength());
widthSpinnerModel.addChangeListener(this);
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.WIDTH,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If width changes update width spinner
widthSpinnerModel.setLength(controller.getWidth());
widthSpinnerModel.setMinimum(Math.min(controller.getWidth(), minimumLength));
}
});
this.depthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "depthLabel.text", unitName));
final NullableSpinner.NullableSpinnerLengthModel depthSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, Math.min(controller.getDepth(), minimumLength), 100000f);
this.depthSpinner = new NullableSpinner(depthSpinnerModel);
depthSpinnerModel.addChangeListener(new ChangeListener () {
public void stateChanged(ChangeEvent ev) {
depthSpinnerModel.removeChangeListener(this);
// If depth spinner value changes update controller
controller.setDepth(depthSpinnerModel.getLength());
depthSpinnerModel.addChangeListener(this);
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.DEPTH,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If depth changes update depth spinner
depthSpinnerModel.setLength(controller.getDepth());
depthSpinnerModel.setMinimum(Math.min(controller.getDepth(), minimumLength));
}
});
this.heightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "heightLabel.text", unitName));
final NullableSpinner.NullableSpinnerLengthModel heightSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, Math.min(controller.getHeight(), minimumLength), 100000f);
this.heightSpinner = new NullableSpinner(heightSpinnerModel);
heightSpinnerModel.addChangeListener(new ChangeListener () {
public void stateChanged(ChangeEvent ev) {
heightSpinnerModel.removeChangeListener(this);
// If width spinner value changes update controller
controller.setHeight(heightSpinnerModel.getLength());
heightSpinnerModel.addChangeListener(this);
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.HEIGHT,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If height changes update height spinner
heightSpinnerModel.setLength(controller.getHeight());
heightSpinnerModel.setMinimum(Math.min(controller.getHeight(), minimumLength));
}
});
this.keepProportionsCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "keepProportionsCheckBox.text"));
this.keepProportionsCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setProportional(keepProportionsCheckBox.isSelected());
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.PROPORTIONAL,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If proportional property changes update keep proportions check box
keepProportionsCheckBox.setSelected(controller.isProportional());
}
});
this.elevationLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "elevationLabel.text", unitName));
final NullableSpinner.NullableSpinnerLengthModel elevationSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, 0f, 2500f);
this.elevationSpinner = new NullableSpinner(elevationSpinnerModel);
elevationSpinnerModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ev) {
widthSpinnerModel.removeChangeListener(this);
controller.setElevation(elevationSpinnerModel.getLength());
widthSpinnerModel.addChangeListener(this);
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.ELEVATION,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If elevation changes update elevation spinner
elevationSpinnerModel.setLength(controller.getElevation());
}
});
this.movableCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "movableCheckBox.text"));
this.movableCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setMovable(movableCheckBox.isSelected());
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.MOVABLE,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If movable changes update movable check box
movableCheckBox.setSelected(controller.isMovable());
}
});
this.doorOrWindowCheckBox = new JCheckBox(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "doorOrWindowCheckBox.text"));
this.doorOrWindowCheckBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setDoorOrWindow(doorOrWindowCheckBox.isSelected());
}
});
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.DOOR_OR_WINDOW,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If door or window changes update door or window check box
boolean doorOrWindow = controller.isDoorOrWindow();
doorOrWindowCheckBox.setSelected(doorOrWindow);
movableCheckBox.setEnabled(!doorOrWindow);
}
});
this.colorLabel = new JLabel(
String.format(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "colorLabel.text"), unitName));
this.colorButton = new ColorButton();
this.colorButton.setColorDialogTitle(preferences.getLocalizedString(
ImportedFurnitureWizardStepsPanel.class, "colorDialog.title"));
this.colorButton.addPropertyChangeListener(ColorButton.COLOR_PROPERTY,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
controller.setColor(colorButton.getColor());
}
});
this.clearColorButton = new JButton(SwingTools.getLocalizedLabelText(preferences,
ImportedFurnitureWizardStepsPanel.class, "clearColorButton.text"));
this.clearColorButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ev) {
controller.setColor(null);
}
});
this.clearColorButton.setEnabled(false);
controller.addPropertyChangeListener(ImportedFurnitureWizardController.Property.COLOR,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If color changes update color buttons
colorButton.setColor(controller.getColor());
clearColorButton.setEnabled(controller.getColor() != null);
}