<commit_before>package framework.editors;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ImageIcon;

import framework.Sound;
import framework.generators.Generator;
import framework.generators.GeneratorPrototyper;
import framework.parameters.Parameter;
import framework.modifiers.Modifier;
import framework.modifiers.ModifierPrototyper;

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

        getContentPane().setLayout(new BoxLayout(
            this.getContentPane(),
            BoxLayout.Y_AXIS));

        ////////////////////////////
        // Basic parameters panel //
        ////////////////////////////
        add(new JLabel("General"));

        JPanel basicPanel = new JPanel();

        // Generator selector
        final JComboBox generatorsList = new JComboBox(GeneratorPrototyper.getPrototypes());
        // Set the selected item to be the current Sound Generator
        for(Generator g : GeneratorPrototyper.getPrototypes()) {
            if(g.getClass().getName() == sound.getGenerator().getClass().getName())
                generatorsList.setSelectedItem(g);
        }
        generatorsList.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Get selected Generator
                Generator sg = (Generator) generatorsList.getSelectedItem();

                // Clone it and give it to the Sound object
                sound.setGenerator((Generator) sg.clone());
            }
        });
        basicPanel.add(generatorsList);

        // Generic parameters
        for(Parameter p : s.getParameters()) {
            basicPanel.add(p.attachEditor());
        }

        add(basicPanel);


        /////////////////////
        // Modifiers panel //
        /////////////////////
        final JPanel modifPanel = new JPanel();
        modifPanel.setLayout(new BoxLayout(modifPanel, BoxLayout.Y_AXIS));

        modifPanel.add(new JLabel("Modifiers"));

        // New modif panel
        final JPanel newModifPanel = new JPanel();
        final JComboBox modifiersList = new JComboBox(ModifierPrototyper.getPrototypes());
        JButton newModifButton = new JButton(new ImageIcon("framework/editors/icons/plus.png"));
        newModifButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Get selected Modifier
                Modifier sm = (Modifier) modifiersList.getSelectedItem();

                // Clone it
                Modifier m = (Modifier) sm.clone();

                // Add to the sound
                sound.addModifier(m);

                // Attach editor and add to the JPanel
                modifPanel.add(m.attachEditor());
            }
        });
        newModifPanel.add(modifiersList);
        newModifPanel.add(newModifButton);
        modifPanel.add(newModifPanel);
<commit_msg>Repack the JFrame when a ModifierEditor is added.<commit_after>package framework.editors;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.ImageIcon;

import framework.Sound;
import framework.generators.Generator;
import framework.generators.GeneratorPrototyper;
import framework.parameters.Parameter;
import framework.modifiers.Modifier;
import framework.modifiers.ModifierPrototyper;

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

        getContentPane().setLayout(new BoxLayout(
            this.getContentPane(),
            BoxLayout.Y_AXIS));

        ////////////////////////////
        // Basic parameters panel //
        ////////////////////////////
        add(new JLabel("General"));

        JPanel basicPanel = new JPanel();

        // Generator selector
        final JComboBox generatorsList = new JComboBox(GeneratorPrototyper.getPrototypes());
        // Set the selected item to be the current Sound Generator
        for(Generator g : GeneratorPrototyper.getPrototypes()) {
            if(g.getClass().getName() == sound.getGenerator().getClass().getName())
                generatorsList.setSelectedItem(g);
        }
        generatorsList.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Get selected Generator
                Generator sg = (Generator) generatorsList.getSelectedItem();

                // Clone it and give it to the Sound object
                sound.setGenerator((Generator) sg.clone());
            }
        });
        basicPanel.add(generatorsList);

        // Generic parameters
        for(Parameter p : s.getParameters()) {
            basicPanel.add(p.attachEditor());
        }

        add(basicPanel);


        /////////////////////
        // Modifiers panel //
        /////////////////////
        final JPanel modifPanel = new JPanel();
        modifPanel.setLayout(new BoxLayout(modifPanel, BoxLayout.Y_AXIS));

        modifPanel.add(new JLabel("Modifiers"));

        // New modif panel
        final JPanel newModifPanel = new JPanel();
        final JComboBox modifiersList = new JComboBox(ModifierPrototyper.getPrototypes());
        JButton newModifButton = new JButton(new ImageIcon("framework/editors/icons/plus.png"));
        newModifButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Get selected Modifier
                Modifier sm = (Modifier) modifiersList.getSelectedItem();

                // Clone it
                Modifier m = (Modifier) sm.clone();

                // Add to the sound
                sound.addModifier(m);

                // Attach editor and add to the JPanel
                modifPanel.add(m.attachEditor());
                pack();
            }
        });
        newModifPanel.add(modifiersList);
        newModifPanel.add(newModifButton);
        modifPanel.add(newModifPanel);

{'fraction_non_alphanumeric': 0.12208787968150987, 'fraction_numerical': 0.0, 'mean_word_length': 2.08879781420765, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '800818', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1713, 'n_words': 406}