package framework.editors;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.util.Observable;
import java.util.Observer;
import framework.Sound;

/**
 * Editor for Sound object.
 *
 * Allow the user to modify the frequency, duration and amplitude.
 */
public class SoundEditor extends JPanel implements Observer {
    /**
     * Create a SoundEditor object.
     * @param  s the associated Sound
     */
    public SoundEditor(Sound s) {
        sound = s;

        // Frequency input
        add(new JLabel("Frequency:"));
        frequencyField  = new JTextField(sound.getFrequency().toString());
        frequencyField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sound.setFrequency(Double.parseDouble(frequencyField.getText()));
            }
        });
        add(frequencyField);

        // Duration input
        add(new JLabel("Duration:"));
        durationField   = new JTextField(sound.getDuration().toString());
        durationField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sound.setDuration(Double.parseDouble(durationField.getText()));
            }
        });
        add(durationField);

        // Amplitude input
        add(new JLabel("Amplitude:"));
        amplitudeField  = new JTextField(sound.getAmplitude().toString());
        amplitudeField.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sound.setAmplitude(Double.parseDouble(amplitudeField.getText()));
            }
        });
        add(amplitudeField);
    }

    public void update(Observable o, Object arg) {
        if(o == sound) {
            frequencyField.setText(sound.getFrequency().toString());
            durationField.setText(sound.getDuration().toString());
            amplitudeField.setText(sound.getAmplitude().toString());
        }
    }

    private Sound sound;
    private JTextField frequencyField;
    private JTextField durationField;
    private JTextField amplitudeField;
}
@@ -179,16 +179,46 @@
 tField;%0A
+import javax.swing.JComboBox;%0A
 import j
@@ -238,16 +238,16 @@
 rvable;%0A
-
 import j
@@ -261,24 +261,25 @@
 l.Observer;%0A
+%0A
 import frame
@@ -289,16 +289,55 @@
 k.Sound;
+%0Aimport framework.generators.Generator;
 %0A%0A/**%0A *
@@ -618,24 +618,24 @@
 (Sound s) %7B%0A
-
         soun
@@ -642,16 +642,432 @@
 d = s;%0A%0A
+        // Generator selector%0A        JComboBox generatorsList = new JComboBox(Generator.getPrototypes());%0A        generatorsList.setSelectedItem(sound.getGenerator());%0A        generatorsList.addActionListener(new ActionListener() %7B%0A            public void actionPerformed(ActionEvent e) %7B%0A                sound.setGenerator(generatorsList.getSelectedItem());%0A            %7D%0A        %7D);%0A        add(generatorsList);%0A%0A
         

Add a Generator selector to the SoundEditor.