<commit_before>package etomica.graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import etomica.action.Action;
import etomica.action.ResetAccumulators;
import etomica.action.SimulationDataAction;
import etomica.action.SimulationRestart;
import etomica.action.activity.Controller;
import etomica.simulation.Simulation;
import etomica.simulation.prototypes.HSMD2D;

/**
 * Device comprising three buttons: (1) attaches to a controller to toggle its pause/resume state; 
 * (2)causes a reset (restart) action of simulation to be performed; (3) causes reset of meter averages
 * only.
 *
 * @author <NAME>
 */
 
public class DeviceTrioControllerButton extends Device {
    
    private JPanel jp;
    private DeviceControllerButton startButton;
    private Simulation simulation;
    private DeviceButton reinitButton;
    private DeviceButton resetButton;
	private double width;
	private boolean firstResized = true;
	private String shape;
	private SimulationRestart simRestart;

    /**
     * Contructs device with buttons that affect the given simulation.
     */
    public DeviceTrioControllerButton(Simulation simulation) {
        this();
        setSimulation(simulation);
    }
    
    /**
     * No-argument contructor gives device that performs no action until
     * setSimulation is used to specify the target simulation.
     */
    public DeviceTrioControllerButton() {
        super();
        jp = new JPanel(new java.awt.GridLayout(1,0)); //default shape of panel
        jp.setBorder(new TitledBorder(null, "Control", TitledBorder.CENTER, TitledBorder.TOP));
        jp.setOpaque(false);

        startButton = new DeviceControllerButton(null);
        reinitButton = new DeviceButton(null);
        resetButton = new DeviceButton(null);
        reinitButton.setLabel("Reinitialize");
        resetButton.setLabel("Reset averages");
        
        jp.add(startButton.graphic()); 
        jp.add(reinitButton.graphic());  
        jp.add(resetButton.graphic());
                       
        setShape("VERTICAL");
    }
        
    /**
     * Sets the controller that is toggled by this device.
     */
    public void setSimulation(Simulation sim) {
        simulation = sim;
        simRestart = new SimulationRestart(sim);
        final Controller c = sim.getController();
        setController(c);
        startButton.setController(c);
        reinitButton.setPreAction(new Action() {
            public void actionPerformed() {
                if (c.isActive()) {
                    c.halt();
                    DeviceTrioControllerButton.this.reset();
                }
                c.reset();
            }
        });
        resetButton.setController(c);
        reinitButton.setAction(simRestart);
        resetButton.setAction(new SimulationDataAction(sim,new ResetAccumulators()));
    }
    
    /**
     * Returns the simulation affected by the buttons.
     */
    public Simulation getSimulation() {
        return simulation;
    }

    /**
     * Returns the JPanel that contains the buttons.
     */
    public java.awt.Component graphic(Object obj) {
        return jp;
    }
    
    public DeviceControllerButton getControllerButton() {return startButton;}
    public DeviceButton getReinitButton() {return reinitButton;}
    public DeviceButton getResetAveragesButton() {return resetButton;}
    
    /**
     * Sets controller toggle button to read "Start"
     */
    public void reset() {startButton.reset();}
    
    /**
     * Sets display shape of the device.  The argument must be a string having
     * one of the following values:<ul>
     * <li>"HORIZONTAL" causes buttons to be laid out in a row.
     * <li>"VERTICAL" causes buttons to be laid out in a column (default)
     * <li>"AUTOMATIC" causes buttons to adopt layout based on size of available space
     * </ul>
     * Any other value is ignored.
     */
    public void setShape(String s){
        shape = s;
        if(s=="HORIZONTAL"){jp.setLayout(new java.awt.GridLayout(1,0));jp.updateUI();}
        if(s=="VERTICAL"){jp.setLayout(new java.awt.GridLayout(0,1));jp.updateUI();}
        if(s=="AUTOMATIC"){jp.getParent().addComponentListener(new ComponentEventControllerButton());}
    }
    public String getShape() {return shape;}

    public SimulationRestart getSimRestart() {
    	return(simRestart);
    }

    /**
     * Inner class that catches action of simulation panel 
     */        
    protected class ComponentEventControllerButton implements ComponentListener {
  
        public void componentHidden(ComponentEvent e){}<commit_msg>Added some spacing between the buttons of a DeviceTrioControllerButton.<commit_after>package etomica.graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import etomica.action.Action;
import etomica.action.ResetAccumulators;
import etomica.action.SimulationDataAction;
import etomica.action.SimulationRestart;
import etomica.action.activity.Controller;
import etomica.simulation.Simulation;
import etomica.simulation.prototypes.HSMD2D;

/**
 * Device comprising three buttons: (1) attaches to a controller to toggle its pause/resume state; 
 * (2)causes a reset (restart) action of simulation to be performed; (3) causes reset of meter averages
 * only.
 *
 * @author <NAME>
 */
 
public class DeviceTrioControllerButton extends Device {
    
    private JPanel jp;
    private DeviceControllerButton startButton;
    private Simulation simulation;
    private DeviceButton reinitButton;
    private DeviceButton resetButton;
	private double width;
	private boolean firstResized = true;
	private String shape;
	private SimulationRestart simRestart;

    /**
     * Contructs device with buttons that affect the given simulation.
     */
    public DeviceTrioControllerButton(Simulation simulation) {
        this();
        setSimulation(simulation);
    }
    
    /**
     * No-argument contructor gives device that performs no action until
     * setSimulation is used to specify the target simulation.
     */
    public DeviceTrioControllerButton() {
        super();
        jp = new JPanel(new java.awt.GridLayout(1,0, 20, 20)); //default shape of panel
        jp.setBorder(new TitledBorder(null, "Control", TitledBorder.CENTER, TitledBorder.TOP));
        jp.setOpaque(false);

        startButton = new DeviceControllerButton(null);
        reinitButton = new DeviceButton(null);
        resetButton = new DeviceButton(null);
        reinitButton.setLabel("Reinitialize");
        resetButton.setLabel("Reset averages");
        
        jp.add(startButton.graphic()); 
        jp.add(reinitButton.graphic());  
        jp.add(resetButton.graphic());
                       
        setShape("VERTICAL");
    }
        
    /**
     * Sets the controller that is toggled by this device.
     */
    public void setSimulation(Simulation sim) {
        simulation = sim;
        simRestart = new SimulationRestart(sim);
        final Controller c = sim.getController();
        setController(c);
        startButton.setController(c);
        reinitButton.setPreAction(new Action() {
            public void actionPerformed() {
                if (c.isActive()) {
                    c.halt();
                    DeviceTrioControllerButton.this.reset();
                }
                c.reset();
            }
        });
        resetButton.setController(c);
        reinitButton.setAction(simRestart);
        resetButton.setAction(new SimulationDataAction(sim,new ResetAccumulators()));
    }
    
    /**
     * Returns the simulation affected by the buttons.
     */
    public Simulation getSimulation() {
        return simulation;
    }

    /**
     * Returns the JPanel that contains the buttons.
     */
    public java.awt.Component graphic(Object obj) {
        return jp;
    }
    
    public DeviceControllerButton getControllerButton() {return startButton;}
    public DeviceButton getReinitButton() {return reinitButton;}
    public DeviceButton getResetAveragesButton() {return resetButton;}
    
    /**
     * Sets controller toggle button to read "Start"
     */
    public void reset() {startButton.reset();}
    
    /**
     * Sets display shape of the device.  The argument must be a string having
     * one of the following values:<ul>
     * <li>"HORIZONTAL" causes buttons to be laid out in a row.
     * <li>"VERTICAL" causes buttons to be laid out in a column (default)
     * <li>"AUTOMATIC" causes buttons to adopt layout based on size of available space
     * </ul>
     * Any other value is ignored.
     */
    public void setShape(String s){
        shape = s;
        if(s=="HORIZONTAL"){jp.setLayout(new java.awt.GridLayout(1,0,4,4));jp.updateUI();}
        if(s=="VERTICAL"){jp.setLayout(new java.awt.GridLayout(0,1,4,4));jp.updateUI();}
        if(s=="AUTOMATIC"){jp.getParent().addComponentListener(new ComponentEventControllerButton());}
    }
    public String getShape() {return shape;}

    public SimulationRestart getSimRestart() {
    	return(simRestart);
    }

    /**
     * Inner class that catches action of simulation panel 
     */        
    protected class ComponentEventControllerButton implements ComponentListener {
  
        public void componentHidden(ComponentEvent e){}
{'fraction_non_alphanumeric': 0.09592961628153487, 'fraction_numerical': 0.002967988128047488, 'mean_word_length': 2.807506053268765, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6606557', 'n_tokens_mistral': 2624, 'n_tokens_neox': 2547, 'n_words': 687}