<commit_before>package stackprogramvisualiser.gui;

import javax.swing.*;
import java.awt.*;
import java.util.Stack;

public class StackGui extends JPanel {

	private JPanel mainPanel;
	private Stack<Integer> data = null;

	// empty label
	private static JLabel emptyLabel = new JLabel("Empty Stack", SwingConstants.CENTER);
	private static GridBagConstraints emptyLabelGBC = new GridBagConstraints();

	static {
		emptyLabel.setFont(emptyLabel.getFont().deriveFont(emptyLabel.getFont().getStyle() & ~Font.BOLD));
		GridBagConstraints emptyLabelGBC = new GridBagConstraints();
		emptyLabelGBC.anchor = GridBagConstraints.PAGE_START;
		emptyLabelGBC.gridx = 0;
		emptyLabelGBC.gridy = 0;
		emptyLabelGBC.fill = GridBagConstraints.HORIZONTAL;
		emptyLabelGBC.insets = new Insets(2, 2, 2, 2);
	}

	public StackGui() {
		// set layout
		setLayout(new GridLayout(1, 1));

		// set main panel
		mainPanel = new JPanel(new GridBagLayout());
		mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
		add(new JScrollPane(mainPanel));

		// set default data
		mainPanel.add(emptyLabel, emptyLabelGBC);
		mainPanel.revalidate();
	}

	public void setDataSource(Stack<Integer> data) {
		this.data = data;
	}

	public void redraw() {
		// clear it out, then start again
		mainPanel.removeAll();
		mainPanel.revalidate();

		// empty?
		if (data == null || data.isEmpty()) {
			mainPanel.add(emptyLabel, emptyLabelGBC);
			return;
		}

		// make GBC for each cell
		GridBagConstraints cellGCB = new GridBagConstraints();
		cellGCB.anchor = GridBagConstraints.PAGE_START;
		cellGCB.gridx = 0;
		cellGCB.gridy = 0;
		cellGCB.weightx = 1;
		cellGCB.fill = GridBagConstraints.HORIZONTAL;
		cellGCB.insets = new Insets(2, 2, 2, 2);

		// fill stack, top to bottom
		for (int i = 0; i < data.size(); ++i) {
			cellGCB.gridy = i;
			mainPanel.add(new StackCell(data.get(data.size() - (i + 1))), cellGCB);
		}

		// fill remaining space
		GridBagConstraints glueGCB = new GridBagConstraints();
		glueGCB.anchor = GridBagConstraints.PAGE_START;
		glueGCB.gridx = 0;
		glueGCB.gridy = data.size();
		glueGCB.weightx = 1;
		glueGCB.weighty = 1;
		glueGCB.fill = GridBagConstraints.HORIZONTAL;
		glueGCB.insets = new Insets(2, 2, 2, 2);
		mainPanel.add(Box.createGlue(), glueGCB);

		mainPanel.revalidate();
	}

}<commit_msg>Fix bug with "empty stack" message staying on screen<commit_after>package stackprogramvisualiser.gui;

import javax.swing.*;
import java.awt.*;
import java.util.Stack;

public class StackGui extends JPanel {

	private JPanel mainPanel;
	private Stack<Integer> data = null;

	// empty label
	private static JLabel emptyLabel = new JLabel("Empty Stack", SwingConstants.CENTER);
	private static GridBagConstraints emptyLabelGBC = new GridBagConstraints();

	static {
		emptyLabel.setFont(emptyLabel.getFont().deriveFont(emptyLabel.getFont().getStyle() & ~Font.BOLD));
		GridBagConstraints emptyLabelGBC = new GridBagConstraints();
		emptyLabelGBC.anchor = GridBagConstraints.PAGE_START;
		emptyLabelGBC.gridx = 0;
		emptyLabelGBC.gridy = 0;
		emptyLabelGBC.weightx = 1;
		emptyLabelGBC.weighty = 1;
		emptyLabelGBC.fill = GridBagConstraints.HORIZONTAL;
		emptyLabelGBC.insets = new Insets(2, 2, 2, 2);
	}

	public StackGui() {
		// set layout
		setLayout(new GridLayout(1, 1));

		// set main panel
		mainPanel = new JPanel(new GridBagLayout());
		mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
		add(new JScrollPane(mainPanel));

		// set default data
		mainPanel.add(emptyLabel, emptyLabelGBC);
		mainPanel.revalidate();
	}

	public void setDataSource(Stack<Integer> data) {
		this.data = data;
	}

	public void redraw() {
		// clear it out, then start again
		mainPanel.removeAll();
		mainPanel.revalidate();
		mainPanel.repaint();

		// empty?
		if (data == null || data.isEmpty()) {
			mainPanel.add(emptyLabel, emptyLabelGBC);
			return;
		}

		// make GBC for each cell
		GridBagConstraints cellGCB = new GridBagConstraints();
		cellGCB.anchor = GridBagConstraints.PAGE_START;
		cellGCB.gridx = 0;
		cellGCB.gridy = 0;
		cellGCB.weightx = 1;
		cellGCB.fill = GridBagConstraints.HORIZONTAL;
		cellGCB.insets = new Insets(2, 2, 2, 2);

		// fill stack, top to bottom
		for (int i = 0; i < data.size(); ++i) {
			cellGCB.gridy = i;
			mainPanel.add(new StackCell(data.get(data.size() - (i + 1))), cellGCB);
		}

		// fill remaining space
		GridBagConstraints glueGCB = new GridBagConstraints();
		glueGCB.anchor = GridBagConstraints.PAGE_START;
		glueGCB.gridx = 0;
		glueGCB.gridy = data.size();
		glueGCB.weightx = 1;
		glueGCB.weighty = 1;
		glueGCB.fill = GridBagConstraints.HORIZONTAL;
		glueGCB.insets = new Insets(2, 2, 2, 2);
		mainPanel.add(Box.createGlue(), glueGCB);

		mainPanel.revalidate();
		mainPanel.repaint();
	}

}
{'fraction_non_alphanumeric': 0.12513121981944153, 'fraction_numerical': 0.01217719924417384, 'mean_word_length': 4.217962760131435, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '3738979', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1653, 'n_words': 374}