<commit_before>/**
 * 
 */
package ca.eandb.jmist.framework.display.visualizer;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.filechooser.FileNameExtensionFilter;

import ca.eandb.jmist.framework.Display;
import ca.eandb.jmist.framework.Raster;
import ca.eandb.jmist.framework.color.Color;
import ca.eandb.jmist.framework.color.ColorModel;
import ca.eandb.util.io.FileUtil;

/**
 * @author brad
 *
 */
public final class JVisualizerFrame extends JFrame implements Display {
	
	/** Serialization version ID. */
	private static final long serialVersionUID = 6053456293463524773L;
	
	private static final String DEFAULT_TITLE = "jMIST Visualizer";
	
	private final JVisualizerDisplay display;
	
	public JVisualizerFrame(JColorVisualizerPanel visualizerPanel) {		
		display = new JVisualizerDisplay(visualizerPanel);
		
		JScrollPane displayScrollPane = new JScrollPane(display);
		
		setLayout(new BorderLayout());
		add(displayScrollPane, BorderLayout.CENTER);
		add(visualizerPanel, BorderLayout.SOUTH);
		
		JMenuBar menuBar = new JMenuBar();
		JMenu menu;
		JMenuItem menuItem;
		
		menu = new JMenu("File");
		menu.setMnemonic(KeyEvent.VK_F);
		
		menuItem = new JMenuItem("Save", KeyEvent.VK_S);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
		menuItem.getAccessibleContext().setAccessibleDescription("Save the image to a file.");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				save_OnActionPerformed(e);
			}
		});
		menu.add(menuItem);
		
		menuBar.add(menu);
		setJMenuBar(menuBar);
		setTitle(DEFAULT_TITLE);

		pack();
	}

	private void save_OnActionPerformed(ActionEvent event) {
		JFileChooser chooser = new JFileChooser();
	    FileNameExtensionFilter filter = new FileNameExtensionFilter(
	        "Image Files", ImageIO.getWriterFileSuffixes());
	    chooser.setFileFilter(filter);
		chooser.setAcceptAllFileFilterUsed(false);
	    int returnVal = chooser.showSaveDialog(this);
	    if (returnVal == JFileChooser.APPROVE_OPTION) {
	    	File file = chooser.getSelectedFile();
	    	String suffix = FileUtil.getExtension(file.getName());
	    	try {
				boolean foundWriter = ImageIO.write(display.getRenderedImage(), suffix, file);
				if (!foundWriter) {
					String message = String.format("Invalid image file format (%s)", suffix);
					JOptionPane.showMessageDialog(this, message, "Error saving image", JOptionPane.WARNING_MESSAGE);
				}
			} catch (IOException e) {
				JOptionPane.showMessageDialog(this, e.getMessage(),
						"Error saving image", JOptionPane.WARNING_MESSAGE);
			}<commit_msg>Set a minimum size for JVisualizerFrame.<commit_after>/**
 * 
 */
package ca.eandb.jmist.framework.display.visualizer;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.filechooser.FileNameExtensionFilter;

import ca.eandb.jmist.framework.Display;
import ca.eandb.jmist.framework.Raster;
import ca.eandb.jmist.framework.color.Color;
import ca.eandb.jmist.framework.color.ColorModel;
import ca.eandb.util.io.FileUtil;

/**
 * @author brad
 *
 */
public final class JVisualizerFrame extends JFrame implements Display {
	
	/** Serialization version ID. */
	private static final long serialVersionUID = 6053456293463524773L;
	
	private static final String DEFAULT_TITLE = "jMIST Visualizer";
	
	private static final Dimension MINIMUM_SIZE = new Dimension(640, 480);
	
	private final JVisualizerDisplay display;
	
	public JVisualizerFrame(JColorVisualizerPanel visualizerPanel) {		
		display = new JVisualizerDisplay(visualizerPanel);
		
		JScrollPane displayScrollPane = new JScrollPane(display);
		
		setLayout(new BorderLayout());
		add(displayScrollPane, BorderLayout.CENTER);
		add(visualizerPanel, BorderLayout.SOUTH);
		
		JMenuBar menuBar = new JMenuBar();
		JMenu menu;
		JMenuItem menuItem;
		
		menu = new JMenu("File");
		menu.setMnemonic(KeyEvent.VK_F);
		
		menuItem = new JMenuItem("Save", KeyEvent.VK_S);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
		menuItem.getAccessibleContext().setAccessibleDescription("Save the image to a file.");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				save_OnActionPerformed(e);
			}
		});
		menu.add(menuItem);
		
		menuBar.add(menu);
		setJMenuBar(menuBar);
		setTitle(DEFAULT_TITLE);
		setMinimumSize(MINIMUM_SIZE);

		pack();
	}

	private void save_OnActionPerformed(ActionEvent event) {
		JFileChooser chooser = new JFileChooser();
	    FileNameExtensionFilter filter = new FileNameExtensionFilter(
	        "Image Files", ImageIO.getWriterFileSuffixes());
	    chooser.setFileFilter(filter);
		chooser.setAcceptAllFileFilterUsed(false);
	    int returnVal = chooser.showSaveDialog(this);
	    if (returnVal == JFileChooser.APPROVE_OPTION) {
	    	File file = chooser.getSelectedFile();
	    	String suffix = FileUtil.getExtension(file.getName());
	    	try {
				boolean foundWriter = ImageIO.write(display.getRenderedImage(), suffix, file);
				if (!foundWriter) {
					String message = String.format("Invalid image file format (%s)", suffix);
					JOptionPane.showMessageDialog(this, message, "Error saving image", JOptionPane.WARNING_MESSAGE);
				}
			} catch (IOException e) {
				JOptionPane.showMessageDialog(this, e.getMessage(),
						"Error saving image", JOptionPane.WARNING_MESSAGE);
			}
{'fraction_non_alphanumeric': 0.10566762728146013, 'fraction_numerical': 0.007044508485430675, 'mean_word_length': 4.96087786259542, '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': '2654413', 'n_tokens_mistral': 2185, 'n_tokens_neox': 1927, 'n_words': 390}