<commit_before>package com.jensen.game.view;

import com.jensen.game.controller.GameOption;
import com.jensen.game.exception.NoSuchViewFoundException;
import com.jensen.game.inteface.GameView;
import com.jensen.game.inteface.SingleView;
import com.jensen.game.model.Difficulty;
import com.jensen.game.model.GridPosition;
import com.jensen.game.othello.view.OthelloGameView;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.util.HashMap;
import java.util.Map;

public class SwingView implements SingleView {

    private Window window;
    private GameView game;
    private GameSetupView setupView;
    private ActionListener menuListener;
    private ActionListener setupListener;
    private MouseListener gridListener;
    private Map<String, GameOption> settings;

    public SwingView() {
        window = new Window();
        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    @Override
    public void changeViewTo(String viewName) throws NoSuchViewFoundException {
        // TODO switch case with all available views
        switch (viewName.toLowerCase()) {
            case "menu":
                displayMenu();
                break;
            case "othello_setup":
                displayOthelloSetup();
                break;
            case "othello":
                displayOthelloGame();
                break;
            case "ongoing_game":
                continuGame();
                break;

            default:
                throw new NoSuchViewFoundException("Missing case for: " + viewName);
        }
    }

    @Override
    public void displayErrorMessage(String msg) {
        window.displayErrorMessage(msg);
    }

    @Override
    public void updateCell(int x, int y, String status) {
        if (isPlaying()) {
            game.updateCell(x, y, status);
        }
    }

    @Override
    public void mouseEnteredCell(int x, int y, String status) {
        if (isPlaying()) {
            game.mouseEnteredCell(x, y, status);
        }
    }

    @Override
    public GridPosition getPositionOf(Object o) {
        if (isPlaying()) {
           return game.getPositionOf(o);
        }
        // TODO change exception
        throw new NullPointerException("Not Playing");
    }

    @Override
    public void updateMessage(String msg) {
        if (isPlaying()) {
            game.updateMessage(msg);
        }
    }

    @Override
    public void setSetupListener(ActionListener l) {
        setupListener = l;
    }

    @Override
    public void setMenuListener(ActionListener l) {
        menuListener = l;
    }

    @Override
    public void setGridListener(MouseListener l) {
        gridListener = l;
    }

    @Override
    public Map<String, GameOption> getOptions() {
        // TODO switch case with game name as key to create a map with nec. info.
        //  or pass along to the view if it's a setup view
        Map<String, GameOption> map = new HashMap<String, GameOption>();
        map.put("name", new GameOption<>("gameName", "Othello"));
        map.put("size", new GameOption<>("size", setupView.getBoardSize()));
        map.put("difficulty", new GameOption<>("difficulty", setupView.getDifficulty()));
        map.put("opponent", new GameOption<>("opponent", setupView.getOpponentType()));
        //map.put("playercount", new GameOption<>("playercount", setupView.getPlayerCount()));
        settings = map;
        return settings;
    }

    private void displayMenu() {
        String[] games = { "Othello" };
        MenuView menu = new MenuView(games);
        menu.addListener(menuListener);

        if (game != null) {
            menu.showContinue();
        }

        window.setView(menu);
    }

    private void displayOthelloSetup() {
        setupView = new GameSetupView();
        setupView.showOpponentType(new String[] { "Human", "Computer" });

        Difficulty[] difficulties = Difficulty.values();
        String[] strings = new String[difficulties.length];

        for (int i = 0; i < difficulties.length; i++) {
            Difficulty difficulty = difficulties[i];
            strings[i] = difficulty.toString();
        }

        setupView.showDifficulties(strings);
        setupView.showBoardSize(8, 14, 2);
        setupView.addListeners(setupListener);
        window.setView(setupView);
    }

    private void displayOthelloGame() {
        // TODO make generic game view creation
        // switch case on setup name defualt creates a DefualtGameView
        int size = (int) settings.get("size").getValue();
        game = new OthelloGameView(size, size);
        game.addGridListener(gridListener);
        game.addMenuButtonListener(menuListener);
        window.setView((JPanel) game);
    }

    private void continuGame() {
        window.setView((JPanel) game);
    }

    private boolean isPlaying() {
        return window.getCurrentView().equals(game);
    }
}
<commit_msg>made SwingView more adaptive and cleaner with SingleView's new methods<commit_after>package com.jensen.game.view;

import com.jensen.game.controller.GameOption;
import com.jensen.game.inteface.GameView;
import com.jensen.game.inteface.SingleView;
import com.jensen.game.model.GridPosition;
import com.jensen.game.othello.view.OthelloGameView;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.util.HashMap;
import java.util.Map;

/**
 * TODO
 */
public class SwingView implements SingleView {

    private Window window;
    private GameView game;
    private GameSetupView setupView;
    private ActionListener menuListener;
    private ActionListener setupListener;
    private MouseListener gridListener;
    private Map<String, GameOption> settings;

    /**
     * TODO
     */
    public SwingView() {
        window = new Window();
        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }

    @Override
    public void displayMenu(String[] games) {
        MenuView menu = new MenuView(games);
        menu.addListener(menuListener);

        if (game != null) {
            menu.showContinue();
        }

        window.setView(menu);
    }

    @Override
    public void displaySetup(String name, int[] size, String[] opponentTypes, String[] difficulties, int[] playerCount) {
        setupView = new GameSetupView(name);

        if (opponentTypes != null) {
            setupView.showOpponentType(opponentTypes);
        }

        if (difficulties != null) {
            setupView.showDifficulties(difficulties);
        }

        if (size != null) {
            setupView.showBoardSize(size[0], size[1], size[2]);
        }

        if (playerCount != null) {
            setupView.showPlayerCount(playerCount[0], playerCount[1]);
        }

        setupView.addListeners(setupListener);
        window.setView(setupView);
    }

    @Override
    public void playGame(String name, int width, int height) {
        // TODO make generic game view creation
        // switch case on setup name defualt creates a DefualtGameView
        switch (name.toLowerCase()) {
            case "othello":
                game = new OthelloGameView(width, height);
                break;
            default:
                game = new DefualtGameView(name, width, height);
                break;
        }
        game.addGridListener(gridListener);
        game.addMenuButtonListener(menuListener);
        window.setView((JPanel) game);
    }

    @Override
    public void continuGame() {
        window.setView((JPanel) game);
    }

    @Override
    public void quit() {
        window.dispose();
    }

    @Override
    public void displayErrorMessage(String msg) {
        window.displayErrorMessage(msg);
    }

    @Override
    public void updateCell(int x, int y, String status) {
        if (isPlaying()) {
            game.updateCell(x, y, status);
        }
    }

    @Override
    public void mouseEnteredCell(int x, int y, String status) {
        if (isPlaying()) {
            game.mouseEnteredCell(x, y, status);
        }
    }

    @Override
    public GridPosition getPositionOf(Object o) {
        if (isPlaying()) {
            return game.getPositionOf(o);
        }
        // TODO change exception
        throw new NullPointerException("Not Playing");
    }

    @Override
    public void updateMessage(String msg) {
        if (isPlaying()) {
            game.updateMessage(msg);
        }
    }

    @Override
    public void setSetupListener(ActionListener l) {
        setupListener = l;
    }

    @Override
    public void setMenuListener(ActionListener l) {
        menuListener = l;
    }

    @Override
    public void setGridListener(MouseListener l) {
        gridListener = l;
    }

    @Override
    public Map<String, GameOption> getOptions() {
        // TODO switch case with game name as key to create a map with nec. info.
        //  or pass along to the view if it's a setup view
        Map<String, GameOption> map = new HashMap<String, GameOption>();

        if (window.getCurrentView().equals(setupView)) {
            map.put("name", new GameOption<>("gamename", setupView.getName()));
            map.put("size", new GameOption<>("size", setupView.getBoardSize()));
            map.put("difficulty", new GameOption<>("difficulty", setupView.getDifficulty()));
            map.put("opponent", new GameOption<>("opponent", setupView.getOpponentType()));
            map.put("playercount", new GameOption<>("playercount", setupView.getPlayerCount()));
            settings = map;
        }

        return settings;
    }

    private boolean isPlaying() {
        return window.getCurrentView().equals(game);
    }
}

{'fraction_non_alphanumeric': 0.10617283950617284, 'fraction_numerical': 0.00102880658436214, 'mean_word_length': 2.414471373375483, 'pattern_counts': {'":': 5, '<': 22, '<?xml version=': 0, '>': 21, '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': '2352150', 'n_tokens_mistral': 2738, 'n_tokens_neox': 2637, 'n_words': 649}