changedUpdate(ev);
}
};
this.nameTextField.getDocument().addDocumentListener(nameListener);
controller.addPropertyChangeListener(ImportedTextureWizardController.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.categoryLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedTextureWizardStepsPanel.class, "categoryLabel.text"));
this.categoryComboBox = new JComboBox(preferences.getTexturesCatalog().getCategories().toArray());
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());
}
TexturesCategory category = new TexturesCategory(name);
// Search an existing category
List<TexturesCategory> categories = preferences.getTexturesCatalog().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) {
TexturesCategory category = (TexturesCategory)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) {
TexturesCategory category = (TexturesCategory)value;
return super.getListCellRendererComponent(list, category.getName(), index, isSelected, cellHasFocus);
}
});
this.categoryComboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent ev) {
controller.setCategory((TexturesCategory)ev.getItem());
}
});
controller.addPropertyChangeListener(ImportedTextureWizardController.Property.CATEGORY,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If category changes update category combo box
TexturesCategory category = controller.getCategory();
if (category != null) {
categoryComboBox.setSelectedItem(category);
}
updateNameTextFieldForeground(defaultNameTextFieldColor);
}
});
this.widthLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedTextureWizardStepsPanel.class, "widthLabel.text", unitName));
float minimumLength = preferences.getLengthUnit().getMinimumLength();
final NullableSpinner.NullableSpinnerLengthModel widthSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, 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(ImportedTextureWizardController.Property.WIDTH,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If width changes update width spinner
widthSpinnerModel.setLength(controller.getWidth());
}
});
this.heightLabel = new JLabel(SwingTools.getLocalizedLabelText(preferences,
ImportedTextureWizardStepsPanel.class, "heightLabel.text", unitName));
final NullableSpinner.NullableSpinnerLengthModel heightSpinnerModel =
new NullableSpinner.NullableSpinnerLengthModel(preferences, 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(ImportedTextureWizardController.Property.HEIGHT,
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
// If height changes update height spinner
heightSpinnerModel.setLength(controller.getHeight());
}
});
this.attributesPreviewComponent = new ScaledImageComponent();
PropertyChangeListener imageAttributesListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent ev) {
updateAttributesPreviewImage();
}
};
controller.addPropertyChangeListener(ImportedTextureWizardController.Property.IMAGE, imageAttributesListener);