<commit_before>package etomica.graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Iterator;
import java.util.LinkedList;

import etomica.Action;
import etomica.Controller;
import etomica.Default;
import etomica.EtomicaElement;
import etomica.EtomicaInfo;
import etomica.Integrator;
import etomica.simulations.HSMD3D;
import etomica.units.PrefixedUnit;

/**
 * Permits selection of temperature from a discrete set of values.  Also has option
 * to select adiabatic.  Enforces selection by manipulating properties of integrator.
 * By default, last integrator added to simulation is the only one controlled by this device.
 *
 * @author <NAME>
 */
public class DeviceThermoSelector extends Device implements EtomicaElement {
    
     public DeviceThermoSelector(Controller controller, final Integrator integrator) {
        this();
        setController(controller);
        setIntegrator(integrator);
     }
     
     public DeviceThermoSelector() {
        super();
        selector = new javax.swing.JComboBox(new Object[] {new Object()});
        setTemperatures(new double[] {200.0, 400.0, 600.0});
        selector.setEditable(false);
        label = new javax.swing.JLabel("");
        setUnit(Default.UNIT_SYSTEM.temperature());

        panel = new javax.swing.JPanel(new java.awt.BorderLayout(0,1));
        panel.add(label, java.awt.BorderLayout.NORTH);
        panel.add(selector, java.awt.BorderLayout.SOUTH);
        panel.setBorder(new javax.swing.border.EmptyBorder(3,3,3,3));

        
        //listener to combo box gets value and initiates action
        selector.addItemListener( new ItemListener() {
            public void itemStateChanged(ItemEvent event) {
                Object item = event.getItem();
                if(item==adiabaticString) {
                    isothermal = false;
                } else {
                    isothermal = true;
                    temperature = unit.toSim(((Double)item).doubleValue());
                }
                doAction(targetAction);
            }
        });
       
    }//end of constructor
    
    /**
     * set the integrator's temperature to the selected value
     */
    public void updateIntegrator() {
        Object item = selector.getSelectedItem();
        if(item==adiabaticString) {
            isothermal = false;
        } else {
            isothermal = true;
            temperature = unit.toSim(((Double)item).doubleValue());
        }
        doAction(targetAction);
    }

    public void setIntegrator(final Integrator integrator) {
        targetAction = new Action() {
            public void actionPerformed() {
                if(integrator == null) return;
                integrator.setIsothermal(isothermal);
                if(isothermal) {
                    integrator.setTemperature(temperature);
                }
            }
            public String getLabel() {
                return DeviceThermoSelector.this.getLabel().toString();
            }
        };
    }
    
    public static EtomicaInfo getEtomicaInfo() {
        EtomicaInfo info = new EtomicaInfo();
        info.setDescription("Select isothermal at a set of temperatures, or adiabatic");
        return info;
    }
    
    public javax.swing.JComboBox getSelector() {return selector;}
    public javax.swing.JLabel getLabel() {return label;}
    
    public final void setIncludeAdiabatic(boolean b) {
        if(selector.getItemCount() == 0) includeAdiabatic = false;
        if(includeAdiabatic && !b) selector.removeItem(adiabaticString);//remove if was there and removing
        else if(!includeAdiabatic && b) selector.addItem(adiabaticString);//add if wasn't there and adding
        includeAdiabatic = b;
    }
    public boolean isIncludeAdiabatic() {return includeAdiabatic;}
    
    /**
     * Sets the i-th item (counting from 0) in the list as the one currently selected.
     * Argument outside bounds is interpreted as first or last item on list.
     */<commit_msg>reset integrator after setting temperature<commit_after>package etomica.graphics;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Iterator;
import java.util.LinkedList;

import etomica.Action;
import etomica.Controller;
import etomica.Default;
import etomica.EtomicaElement;
import etomica.EtomicaInfo;
import etomica.Integrator;
import etomica.simulations.HSMD3D;
import etomica.units.PrefixedUnit;

/**
 * Permits selection of temperature from a discrete set of values.  Also has option
 * to select adiabatic.  Enforces selection by manipulating properties of integrator.
 * By default, last integrator added to simulation is the only one controlled by this device.
 *
 * @author <NAME>
 */
public class DeviceThermoSelector extends Device implements EtomicaElement {
    
     public DeviceThermoSelector(Controller controller, final Integrator integrator) {
        this();
        setController(controller);
        setIntegrator(integrator);
     }
     
     public DeviceThermoSelector() {
        super();
        selector = new javax.swing.JComboBox(new Object[] {new Object()});
        setTemperatures(new double[] {200.0, 400.0, 600.0});
        selector.setEditable(false);
        label = new javax.swing.JLabel("");
        setUnit(Default.UNIT_SYSTEM.temperature());

        panel = new javax.swing.JPanel(new java.awt.BorderLayout(0,1));
        panel.add(label, java.awt.BorderLayout.NORTH);
        panel.add(selector, java.awt.BorderLayout.SOUTH);
        panel.setBorder(new javax.swing.border.EmptyBorder(3,3,3,3));

        
        //listener to combo box gets value and initiates action
        selector.addItemListener( new ItemListener() {
            public void itemStateChanged(ItemEvent event) {
                Object item = event.getItem();
                if(item==adiabaticString) {
                    isothermal = false;
                } else {
                    isothermal = true;
                    temperature = unit.toSim(((Double)item).doubleValue());
                }
                doAction(targetAction);
            }
        });
       
    }//end of constructor
    
    /**
     * set the integrator's temperature to the selected value
     */
    public void updateIntegrator() {
        Object item = selector.getSelectedItem();
        if(item==adiabaticString) {
            isothermal = false;
        } else {
            isothermal = true;
            temperature = unit.toSim(((Double)item).doubleValue());
        }
        doAction(targetAction);
    }

    public void setIntegrator(final Integrator integrator) {
        targetAction = new Action() {
            public void actionPerformed() {
                if(integrator == null) return;
                integrator.setIsothermal(isothermal);
                if(isothermal) {
                    integrator.setTemperature(temperature);
                }
                integrator.reset();
            }
            public String getLabel() {
                return DeviceThermoSelector.this.getLabel().toString();
            }
        };
    }
    
    public static EtomicaInfo getEtomicaInfo() {
        EtomicaInfo info = new EtomicaInfo();
        info.setDescription("Select isothermal at a set of temperatures, or adiabatic");
        return info;
    }
    
    public javax.swing.JComboBox getSelector() {return selector;}
    public javax.swing.JLabel getLabel() {return label;}
    
    public final void setIncludeAdiabatic(boolean b) {
        if(selector.getItemCount() == 0) includeAdiabatic = false;
        if(includeAdiabatic && !b) selector.removeItem(adiabaticString);//remove if was there and removing
        else if(!includeAdiabatic && b) selector.addItem(adiabaticString);//add if wasn't there and adding
        includeAdiabatic = b;
    }
    public boolean isIncludeAdiabatic() {return includeAdiabatic;}
    
    /**
     * Sets the i-th item (counting from 0) in the list as the one currently selected.
     * Argument outside bounds is interpreted as first or last item on list.
     */
{'fraction_non_alphanumeric': 0.09390831582849377, 'fraction_numerical': 0.0051896700852588655, 'mean_word_length': 2.4022698612862547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3508660', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2104, 'n_words': 557}