<commit_before>package authoring_environment;

import java.util.ArrayList;
import java.util.List;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.SingleSelectionModel;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;

/**
 * Workspace TabPane for having multiple
 * workspaces in the authoring environment
 * 
 * @author <NAME>
 *
 */
public class WorkspaceView extends TabPane {
	
	private List<ShapeGrid> myGrids;
	private int myCurrentTabIdx;
	
	public WorkspaceView() {
		myGrids = new ArrayList<>();
	}
	
	/**
	 * Adds a new tab to the workspace
	 * and gives it a new name based on the
	 * number of tabs that have been made
	 * @param tab
	 */
	
	/*
	 * TODO: This only works when you close the most recent workspace (rightmost one). 
	 * Closing any other workspace does not automatically select the next one (the 
	 * workspaces ahead of the closed one shift left one - for some goddamn reason
	 * JavaFX does not detect this as a change in index. Actually what the hell.
	 * 
	 * Also when you close the last tab, then make a new one. Creating that new tab is
	 * not recognized as a selection switch. 
	 * 
	 * @Mi<NAME>
	 */
	
	public void addNextTab(Tab tab, String name) {
		
		tab.setText(name);	
		
		super.getTabs().add(tab);
		getSelectionModel().select(tab);
		
		tab.setOnClosed(new EventHandler<Event>() {
        	@Override
			public void handle(Event closed) {
<<<<<<< HEAD
          		int idx = getSelectionModel().getSelectedIndex();
=======
        		//System.out.println("second?");
        		int idx = getSelectionModel().getSelectedIndex();
>>>>>>> 213773f8df2968a8b02494670ae4c30dd7e19e2a

            	if(idx>=0){
        			myGrids.remove(idx);
        		}
            	if(idx==-1){
            		myGrids.remove(0);
            	}
			}
        });
	}
	
	public ShapeGrid getActiveGrid(){
		SingleSelectionModel<Tab> selectionModel = getSelectionModel();
		int idx = selectionModel.getSelectedIndex();

		
		if(idx==-1 || idx>=myGrids.size()){
			return myGrids.get(0);
		}
		return myGrids.get(idx);
	}
	
	public void addGrid(ShapeGrid grid){
		myGrids.add(grid);<commit_msg>Actually fixed errors<commit_after>package authoring_environment;

import java.util.ArrayList;
import java.util.List;

import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.control.SingleSelectionModel;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;

/**
 * Workspace TabPane for having multiple
 * workspaces in the authoring environment
 * 
 * @author <NAME>
 *
 */
public class WorkspaceView extends TabPane {
	
	private List<ShapeGrid> myGrids;
	private int myCurrentTabIdx;
	
	public WorkspaceView() {
		myGrids = new ArrayList<>();
	}
	
	/**
	 * Adds a new tab to the workspace
	 * and gives it a new name based on the
	 * number of tabs that have been made
	 * @param tab
	 */
	
	/*
	 * TODO: This only works when you close the most recent workspace (rightmost one). 
	 * Closing any other workspace does not automatically select the next one (the 
	 * workspaces ahead of the closed one shift left one - for some goddamn reason
	 * JavaFX does not detect this as a change in index. Actually what the hell.
	 * 
	 * Also when you close the last tab, then make a new one. Creating that new tab is
	 * not recognized as a selection switch. 
	 * 
	 * @Mi<NAME>
	 */
	
	public void addNextTab(Tab tab, String name) {
		
		tab.setText(name);	
		
		super.getTabs().add(tab);
		getSelectionModel().select(tab);
		
		tab.setOnClosed(new EventHandler<Event>() {
        	@Override
			public void handle(Event closed) {
          		int idx = getSelectionModel().getSelectedIndex();


            	if(idx>=0){
        			myGrids.remove(idx);
        		}
            	if(idx==-1){
            		myGrids.remove(0);
            	}
			}
        });
	}
	
	public ShapeGrid getActiveGrid(){
		SingleSelectionModel<Tab> selectionModel = getSelectionModel();
		int idx = selectionModel.getSelectedIndex();

		
		if(idx==-1 || idx>=myGrids.size()){
			return myGrids.get(0);
		}
		return myGrids.get(idx);
	}
	
	public void addGrid(ShapeGrid grid){
		myGrids.add(grid);
{'fraction_non_alphanumeric': 0.10584291187739464, 'fraction_numerical': 0.008860153256704981, 'mean_word_length': 3.0751219512195123, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 26, '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': '7310941', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1237, 'n_words': 383}