<commit_before>package nl.mpi.kinnate.ui.menu;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import nl.mpi.kinnate.ui.window.DiagramWindowManager;

/**
 *  Document   : WindowMenu
 *  Created on : Dec 6, 2011, 12:58:54 PM
 *  Author     : <NAME>
 */
public class WindowMenu extends JMenu implements ActionListener {

    DiagramWindowManager diagramWindowManager;
    ArrayList<Component> diagramArray = new ArrayList<Component>();

    public WindowMenu(DiagramWindowManager diagramWindowManager) {
        this.setText("Window");
        this.diagramWindowManager = diagramWindowManager;
        this.addMenuListener(new MenuListener() {

            public void menuCanceled(MenuEvent evt) {
            }

            public void menuDeselected(MenuEvent evt) {
            }

            public void menuSelected(MenuEvent evt) {
                initMenu();
            }
        });
    }

    private void initMenu() {
        for (Component currentDiagram : diagramWindowManager.getAllDiagrams()) {
            diagramArray.add(currentDiagram);
            JMenuItem currentMenuItem = new JMenuItem(currentDiagram.getName());
            currentMenuItem.setActionCommand(Integer.toString(diagramArray.size() - 1));
            currentMenuItem.addActionListener(this);
            this.add(currentMenuItem);
        }
    }

    public void actionPerformed(ActionEvent e) {
        int diagramIndex = Integer.getInteger(e.getActionCommand());
        Component diagramComponent = diagramArray.get(diagramIndex);
        diagramWindowManager.setSelectedDiagram(diagramComponent);<commit_msg>Separated the file menu from the MainFrame class. Created a diagram window manager class and moved relevant code out of the MainFrame into the new class. Added a check for unsaved diagrams on application close. Separated out the edit menu into a different class. Updated the import data menu. Updated the edit menu to use the SavePanel and better handle hot keys. Completed the code to expand the diagram selection to include immediate relations and enabled its menu item in the edit menu. Refactored the menu classes. Created an abstract diagram manager class so that the tabbed pane can be optionally replaced by separate windows or a jdesktop pane. Added a window select menu for when the tab pane is not used.<commit_after>package nl.mpi.kinnate.ui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import nl.mpi.kinnate.ui.window.DiagramWindowManager;

/**
 *  Document   : WindowMenu
 *  Created on : Dec 6, 2011, 12:58:54 PM
 *  Author     : <NAME>
 */
public class WindowMenu extends JMenu implements ActionListener {

    DiagramWindowManager diagramWindowManager;

    public WindowMenu(DiagramWindowManager diagramWindowManager) {
        this.setText("Window");
        this.diagramWindowManager = diagramWindowManager;
        this.addMenuListener(new MenuListener() {

            public void menuCanceled(MenuEvent evt) {
            }

            public void menuDeselected(MenuEvent evt) {
            }

            public void menuSelected(MenuEvent evt) {
                initMenu();
            }
        });
    }

    private void initMenu() {
        this.removeAll();
        int diagramCount = diagramWindowManager.getAllDiagrams().length;
        int selectedDiagramIndex = diagramWindowManager.getSavePanelIndex();
        for (int diagramCounter = 0; diagramCounter < diagramCount; diagramCounter++) {
            JCheckBoxMenuItem currentMenuItem = new JCheckBoxMenuItem(diagramWindowManager.getSavePanelTitle(diagramCounter));
            currentMenuItem.setActionCommand(Integer.toString(diagramCounter));
            currentMenuItem.addActionListener(this);
            currentMenuItem.setSelected(diagramCounter == selectedDiagramIndex);
            this.add(currentMenuItem);
        }
    }

    public void actionPerformed(ActionEvent e) {
        int diagramIndex = Integer.valueOf(e.getActionCommand());
        diagramWindowManager.setSelectedDiagram(diagramIndex);
{'fraction_non_alphanumeric': 0.07751937984496124, 'fraction_numerical': 0.005471956224350205, 'mean_word_length': 3.3094302554027504, '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': '4821823', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1100, 'n_words': 303}