<commit_before>import java.awt.Canvas;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.JOptionPane;

public class GUIframe{
	
	private JFrame window;
	
	private JPanel mainPanel;	//the main Panel will have sub panels
	private JPanel canvasPanel;
	private JPanel buttonsPanel;
	BufferedImage image;
	private MyCanvas canvas;
	String suffices[];
	private Engine engine;
	private JButton startFilter;
	private Timer timer;
	private long startTime;
	private long timeToRun;

	public GUIframe(int width, int height) throws FileNotFoundException, IOException {
	
		window = new JFrame("Dot Vinci");
		window.setSize(width, height);
		
		//add canvasPanel objects
        canvas = new MyCanvas();
        //image = ImageIO.read(new FileInputStream("C:/Users/Pranav/Pictures/doge.jpeg"));
		canvas.setSize(width, height);
		canvas.setBounds(0, 0, 300, 300);
		canvas.setBackground(Color.WHITE);
		
		//intialize engine
		engine = new Engine();

		//add buttonsPanel objects
		
		// - add buttons
		JButton openImage = new JButton("Open Image");
		openImage.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
				if(startTime != -1) {
					JOptionPane.showMessageDialog(window, "Cannot open new image while timer is running");
					return;
				}
				//open a JFilesChooser when the open button is clicked
		        JFileChooser chooser = new JFileChooser();
		        
		        // Get array of available formats (only once)
		        if(suffices == null){	
		        	suffices = ImageIO.getReaderFileSuffixes();

		        	// Add a file filter for each one
		        	for (int i = 0; i < suffices.length; i++) {
		        		FileNameExtensionFilter filter = new FileNameExtensionFilter(suffices[i] + " files", suffices[i]);
		        		System.out.println(suffices[i]+"\n");
		        		chooser.addChoosableFileFilter(filter);
		        	}
		        }
		        chooser.setFileFilter(new ImageFilter());
		        chooser.setAcceptAllFileFilterUsed(false);
		        
		        int ret = chooser.showDialog(null, "Open file");

		        if (ret == JFileChooser.APPROVE_OPTION) {
		        	
		          //add the selected file to the canvas
		          File file = chooser.getSelectedFile(); 
		          try {
					image = ImageIO.read(new FileInputStream(file.toString()));
		          	engine.loadImageFromFile(file);
					canvas.repaint();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		          System.out.println(file);
		        }

			}
		});
		
		JButton saveImage = new JButton("Save Image");
		
		// - add filters
		JLabel filterText = new JLabel("Filters:");
		JRadioButton noFilter = new JRadioButton("None");
		noFilter.setSelected(true);
		JRadioButton sepiaFilter = new JRadioButton("Sepia");
		JRadioButton grayscaleFilter = new JRadioButton("Gray Scale");
		JRadioButton negativeFilter = new JRadioButton("Negative");
		
		// - add slider
		JLabel renderSpeedText = new JLabel("Render Speed:");
		final JSlider renderSpeed_slider = new JSlider(1, 100);
		final JTextField renderSpeed_value = new JTextField(3);
		Dimension dim = new Dimension(40, 30);
		renderSpeed_value.setSize(20, 20);
		renderSpeed_value.setMaximumSize(dim);
		renderSpeed_value.setText("50%");
		renderSpeed_slider.addChangeListener(new ChangeListener(){
            @Override
            public void stateChanged(ChangeEvent e) {
            	renderSpeed_value.setText(String.valueOf(renderSpeed_slider.getValue() + "%"));
            }
        });
		
		
		//setup the panels
		mainPanel = new JPanel();<commit_msg>Fixed radio buttons<commit_after>import java.awt.Canvas;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.JOptionPane;

public class GUIframe{
	
	private JFrame window;
	
	private JPanel mainPanel;	//the main Panel will have sub panels
	private JPanel canvasPanel;
	private JPanel buttonsPanel;
	BufferedImage image;
	private MyCanvas canvas;
	String suffices[];
	private Engine engine;
	private JButton startFilter;
	private Timer timer;
	private long startTime;
	private long timeToRun;

	public GUIframe(int width, int height) throws FileNotFoundException, IOException {
	
		window = new JFrame("Dot Vinci");
		window.setSize(width, height);
		
		//add canvasPanel objects
        canvas = new MyCanvas();
        //image = ImageIO.read(new FileInputStream("C:/Users/Pranav/Pictures/doge.jpeg"));
		canvas.setSize(width, height);
		canvas.setBounds(0, 0, 300, 300);
		canvas.setBackground(Color.WHITE);
		
		//intialize engine
		engine = new Engine();

		//add buttonsPanel objects
		
		// - add buttons
		JButton openImage = new JButton("Open Image");
		openImage.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				
				if(startTime != -1) {
					JOptionPane.showMessageDialog(window, "Cannot open new image while timer is running");
					return;
				}
				//open a JFilesChooser when the open button is clicked
		        JFileChooser chooser = new JFileChooser();
		        
		        // Get array of available formats (only once)
		        if(suffices == null){	
		        	suffices = ImageIO.getReaderFileSuffixes();

		        	// Add a file filter for each one
		        	for (int i = 0; i < suffices.length; i++) {
		        		FileNameExtensionFilter filter = new FileNameExtensionFilter(suffices[i] + " files", suffices[i]);
		        		System.out.println(suffices[i]+"\n");
		        		chooser.addChoosableFileFilter(filter);
		        	}
		        }
		        chooser.setFileFilter(new ImageFilter());
		        chooser.setAcceptAllFileFilterUsed(false);
		        
		        int ret = chooser.showDialog(null, "Open file");

		        if (ret == JFileChooser.APPROVE_OPTION) {
		        	
		          //add the selected file to the canvas
		          File file = chooser.getSelectedFile(); 
		          try {
					image = ImageIO.read(new FileInputStream(file.toString()));
		          	engine.loadImageFromFile(file);
					canvas.repaint();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		          System.out.println(file);
		        }

			}
		});
		
		JButton saveImage = new JButton("Save Image");
		
		// - add filters
		JLabel filterText = new JLabel("Filters:");
		final JRadioButton noFilter = new JRadioButton("None");
		noFilter.setSelected(true);
		final JRadioButton sepiaFilter = new JRadioButton("Sepia");
		final JRadioButton grayscaleFilter = new JRadioButton("Gray Scale");
		final JRadioButton negativeFilter = new JRadioButton("Negative");
		
		//prevent user from unchecking a radio button
		noFilter.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(noFilter.isSelected() == false)
					noFilter.setSelected(true);
			}
		});
		sepiaFilter.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(sepiaFilter.isSelected() == false)
					sepiaFilter.setSelected(true);
			}
		});
		negativeFilter.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(negativeFilter.isSelected() == false)
					negativeFilter.setSelected(true);
			}
		});
		grayscaleFilter.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if(grayscaleFilter.isSelected() == false)
					grayscaleFilter.setSelected(true);
			}
		});
		
		//uncheck all other radio buttons when the user checks a radio button
		noFilter.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				if(noFilter.isSelected() == true){
					sepiaFilter.setSelected(false);
					grayscaleFilter.setSelected(false);
					negativeFilter.setSelected(false);
				}
			}
		});
		sepiaFilter.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				if(sepiaFilter.isSelected() == true){
					noFilter.setSelected(false);
					grayscaleFilter.setSelected(false);
					negativeFilter.setSelected(false);
				}
			}
		});
		negativeFilter.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				if(negativeFilter.isSelected() == true){
					sepiaFilter.setSelected(false);
					grayscaleFilter.setSelected(false);
					noFilter.setSelected(false);
				}
			}
		});
		grayscaleFilter.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				if(grayscaleFilter.isSelected() == true){
					sepiaFilter.setSelected(false);
					noFilter.setSelected(false);
					negativeFilter.setSelected(false);
				}
			}
		});
		
		// - add slider
		JLabel renderSpeedText = new JLabel("Render Speed:");
		final JSlider renderSpeed_slider = new JSlider(1, 100);
		final JTextField renderSpeed_value = new JTextField(3);
		Dimension dim = new Dimension(40, 30);
		renderSpeed_value.setSize(20, 20);
		renderSpeed_value.setMaximumSize(dim);
		renderSpeed_value.setText("50%");
		renderSpeed_slider.addChangeListener(new ChangeListener(){
            @Override
            public void stateChanged(ChangeEvent e) {
            	renderSpeed_value.setText(String.valueOf(renderSpeed_slider.getValue() + "%"));
            }
        });
		
		
		//setup the panels
		mainPanel = new JPanel();
{'fraction_non_alphanumeric': 0.10403726708074534, 'fraction_numerical': 0.005003450655624569, 'mean_word_length': 3.469159599074788, 'pattern_counts': {'":': 0, '<': 5, '<?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': '450209', 'n_tokens_mistral': 3931, 'n_tokens_neox': 3341, 'n_words': 782}