<commit_before>package edu.rpi.phil.legup.newgui;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import edu.rpi.phil.legup.BoardState;
import edu.rpi.phil.legup.Legup;
import edu.rpi.phil.legup.PuzzleModule;
import edu.rpi.phil.legup.Selection;

// callback used for the right-click functionality of NormalBoard
public class ChangeBoardCell implements ActionListener
{
	JPopupMenu storedMenu;
	Point toChange;
	PuzzleModule pm = Legup.getInstance().getPuzzleModule();

	public ChangeBoardCell(Point p)
	{
		toChange = p;
		storedMenu = new JPopupMenu();
		List<String> menuoptions = pm.getSelectableCellsList();
		for(String option : menuoptions)
		{
			if(option == null)continue;
			JMenuItem item = new JMenuItem(option);

			item.addActionListener(this);
			storedMenu.add(item);
		}
		//storedMenu.show(this,temp.x, temp.y);
	}

	public JPopupMenu getPopupMenu() { return storedMenu; }

	public void actionPerformed(ActionEvent e)
	{
		List<String> menuoptions = pm.getSelectableCellsList();
		// linearly search through the states to find which popup item was clicked (TODO: find better way or confirm none exists)
		for(int a=0; a < menuoptions.size(); a++)
		{
			if(e.getSource() == storedMenu.getComponent(a))
			{
				Selection selection = Legup.getInstance().getSelections().getFirstSelection();
				BoardState state = selection.getState();

				int optionchosen = a;

				BoardState next = state.conditionalAddTransition();
				if(next != null)
				{
					next.setCellContents(toChange.x, toChange.y,
						pm.getStateNumber(menuoptions.get(optionchosen)));

					//make sure annotations don't cover the final result
					pm.disableAnnotationsForCell(toChange.x,toChange.y); 
				}
			}
		}
	}
}<commit_msg>Simplified the lookup of right-click menu items.<commit_after>package edu.rpi.phil.legup.newgui;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import edu.rpi.phil.legup.BoardState;
import edu.rpi.phil.legup.Legup;
import edu.rpi.phil.legup.PuzzleModule;
import edu.rpi.phil.legup.Selection;

// callback used for the right-click functionality of NormalBoard
public class ChangeBoardCell implements ActionListener
{
	JPopupMenu storedMenu;
	Point toChange;
	PuzzleModule pm = Legup.getInstance().getPuzzleModule();

	public ChangeBoardCell(Point p)
	{
		toChange = p;
		storedMenu = new JPopupMenu();
		List<String> menuoptions = pm.getSelectableCellsList();
		for(String option : menuoptions)
		{
			if(option == null)continue;
			JMenuItem item = new JMenuItem(option);

			item.addActionListener(this);
			storedMenu.add(item);
		}
		//storedMenu.show(this,temp.x, temp.y);
	}

	public JPopupMenu getPopupMenu() { return storedMenu; }

	public void actionPerformed(ActionEvent e)
	{
		List<String> menuoptions = pm.getSelectableCellsList();
		int optionchosen = storedMenu.getComponentIndex((Component)e.getSource());
		if(optionchosen == -1) { throw new Error("A menu option was selected that doesn't exist."); }

		Selection selection = Legup.getInstance().getSelections().getFirstSelection();
		BoardState state = selection.getState();

		BoardState next = state.conditionalAddTransition();
		if(next != null)
		{
			next.setCellContents(toChange.x, toChange.y,
				pm.getStateNumber(menuoptions.get(optionchosen)));

			//make sure annotations don't cover the final result
			pm.disableAnnotationsForCell(toChange.x,toChange.y); 
		}
	}
}
{'fraction_non_alphanumeric': 0.11448087431693989, 'fraction_numerical': 0.000546448087431694, 'mean_word_length': 4.6671826625387, 'pattern_counts': {'":': 0, '<': 8, '<?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': '7552613', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1178, 'n_words': 255}