protected void operationChanged(Operation operation) {
super.operationChanged(operation);
this.op = (GenericOperation) operation;
Box box = Box.createVerticalBox();
box.add(Box.createVerticalStrut(6));
// Add all the sliders:
// A special layout that aligns the GenericSlider pieces in rows
// and columns:
GenericSliderContainer sliderContainer = new GenericSliderContainer();
List sliderKeys = op.getSliderKeys();
for (Iterator i=sliderKeys.iterator(); i.hasNext(); ) {
final String key = (String) i.next();
final String userKey = getUserPresentableKey(key);
final SliderConfig config = op.getSliderConfig(key);
final GenericSlider slider = new GenericSlider(userKey, config);
slider.addChangeListener(
new ChangeListener() {
public void stateChanged(ChangeEvent event) {
double value = slider.getConfiguredValue();
op.setSliderValue(key, value);
}
}
);
GenericSlider oldSlider = (GenericSlider) sliders.get(key);
if (oldSlider != null) {
slider.setConfiguredValue(oldSlider.getConfiguredValue());
}
slider.addSliderMouseListener(
new MouseAdapter() {
public void mousePressed(MouseEvent event) {
op.changeBatchStarted();
}
public void mouseReleased(MouseEvent event) {
op.changeBatchEnded();
undoSupport.postEdit(key + " Slider");
}
}
);
slider.setBackgroundRecurse(Background);
slider.setFontRecurse(ControlFont);
sliderContainer.addGenericSlider(slider);
sliders.put(key, slider);
}
sliderContainer.setBackground(Background);
box.add(sliderContainer);
// Add all the checkboxes:
List checkboxKeys = op.getCheckboxKeys();
for (Iterator i=checkboxKeys.iterator(); i.hasNext(); ) {
final String key = (String) i.next();
final String userKey = getUserPresentableKey(key);
final JCheckBox checkbox = new JCheckBox(userKey);
checkbox.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent event) {
boolean value = checkbox.isSelected();
op.setCheckboxValue(key, value);
undoSupport.postEdit(key + " Checkbox");
}
}
);
JCheckBox oldCheckbox = (JCheckBox) checkboxes.get(key);
if (oldCheckbox != null) {
checkbox.setSelected(oldCheckbox.isSelected());
}
checkbox.setBackground(Background);
checkbox.setFont(ControlFont);
box.add(checkbox);
checkboxes.put(key, checkbox);
}
// Add all the choices:
List choiceKeys = op.getChoiceKeys();
for (Iterator i=choiceKeys.iterator(); i.hasNext(); ) {
final String key = (String) i.next();
Vector values = new Vector(op.getChoiceValues(key));
final JComboBox choice = new JComboBox(values);
choice.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
String value = (String) choice.getSelectedItem();
op.setChoiceValue(key, value);
undoSupport.postEdit(key + " Choice");
}
}
);
JComboBox oldChoice = (JComboBox) choices.get(key);
if (oldChoice != null) {
choice.setSelectedItem(oldChoice.getSelectedItem());
}
choice.setBackground(Background);
choice.setFont(ControlFont);
box.add(choice);
choices.put(key, choice);
}
box.add(Box.createVerticalStrut(6));
setContent(box);
undoSupport.initialize();
}