<commit_before>/*
 * Copyright 2015-2016 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tros.torgo.swing;

import org.tros.torgo.Controller;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import org.tros.torgo.ControllerListener;
import org.tros.torgo.TorgoToolkit;
import org.tros.torgo.interpreter.CodeBlock;
import org.tros.torgo.interpreter.InterpreterListener;
import org.tros.torgo.interpreter.Scope;
import org.tros.utils.logging.LogConsole;

/**
 * TODO: detect "pause" and "debug" across controllers...
 *
 * @author matta
 */
public class TorgoMenuBar extends JMenuBar implements ControllerListener {

    private final JMenu interpreterMenu;
    private final JMenuItem fileStart;
    private final JMenuItem fileStop;
    private final JMenuItem fileDebug;
    private final JMenuItem filePause;
    private final JMenuItem fileStep;

    private final JMenu languagesMenu;

    private final JMenu fileMenu;
    private final JMenuItem fileNew;
    private final JMenuItem fileOpen;
    private final JMenuItem fileClose;
    private final JMenuItem fileSave;
    private final JMenuItem fileSaveAs;
    private final JMenuItem fileQuit;
    private final JMenuItem logConsole;

    protected final Controller controller;
    protected final Component parent;

    private final AtomicBoolean paused;
    private final AtomicBoolean debugging;

    /**
     * Constructor.
     *
     * @param parent
     * @param controller
     */
    @SuppressWarnings("OverridableMethodCallInConstructor")
    public TorgoMenuBar(Component parent, final Controller controller) {
        this.controller = controller;
        this.parent = parent;
        this.controller.addControllerListener((ControllerListener) this);

        interpreterMenu = new JMenu("Interpreter");
        fileStart = new JMenuItem("Start");
        fileStop = new JMenuItem("Stop");
        fileDebug = new JMenuItem("Debug");
        filePause = new JMenuItem("Pause");
        fileStep = new JMenuItem("Step");

        languagesMenu = new JMenu("Switch Language");
        TorgoToolkit.getToolkits().stream().filter((lang) -> (!lang.equals(controller.getLang()))).forEachOrdered((lang) -> {
            JMenuItem langItem = new JMenuItem(lang);
            languagesMenu.add(langItem);
            langItem.addActionListener((ActionEvent ae) -> {
                final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(TorgoToolkit.class);
                prefs.put("lang", lang);
                controller.close();
                SwingUtilities.invokeLater(() -> {
                    Controller controller1 = TorgoToolkit.getController(lang);
                    if (controller1 != null) {
                        controller1.run();
                        controller.newFile();
                    }
                });
            });
        });

        fileMenu = new JMenu(Localization.getLocalizedString("FileMenu"));
        fileNew = new JMenuItem(Localization.getLocalizedString("FileNew"));
        fileClose = new JMenuItem(Localization.getLocalizedString("FileClose"));
        fileSave = new JMenuItem(Localization.getLocalizedString("FileSave"));
        fileSaveAs = new JMenuItem(Localization.getLocalizedString("FileSaveAs"));
        fileOpen = new JMenuItem(Localization.getLocalizedString("FileOpen"));
        fileQuit = new JMenuItem(Localization.getLocalizedString("FileQuit"));
        logConsole = new JMenuItem("View Log Console");

        debugging = new AtomicBoolean(false);<commit_msg>Fixed issue with switching languages not resetting the screen. This was a copy/paste bug.<commit_after>/*
 * Copyright 2015-2016 <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tros.torgo.swing;

import org.tros.torgo.Controller;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import org.tros.torgo.ControllerListener;
import org.tros.torgo.TorgoToolkit;
import org.tros.torgo.interpreter.CodeBlock;
import org.tros.torgo.interpreter.InterpreterListener;
import org.tros.torgo.interpreter.Scope;
import org.tros.utils.logging.LogConsole;

/**
 * TODO: detect "pause" and "debug" across controllers...
 *
 * @author matta
 */
public class TorgoMenuBar extends JMenuBar implements ControllerListener {

    private final JMenu interpreterMenu;
    private final JMenuItem fileStart;
    private final JMenuItem fileStop;
    private final JMenuItem fileDebug;
    private final JMenuItem filePause;
    private final JMenuItem fileStep;

    private final JMenu languagesMenu;

    private final JMenu fileMenu;
    private final JMenuItem fileNew;
    private final JMenuItem fileOpen;
    private final JMenuItem fileClose;
    private final JMenuItem fileSave;
    private final JMenuItem fileSaveAs;
    private final JMenuItem fileQuit;
    private final JMenuItem logConsole;

    protected final Controller controller;
    protected final Component parent;

    private final AtomicBoolean paused;
    private final AtomicBoolean debugging;

    /**
     * Constructor.
     *
     * @param parent
     * @param controller
     */
    @SuppressWarnings("OverridableMethodCallInConstructor")
    public TorgoMenuBar(Component parent, final Controller controller) {
        this.controller = controller;
        this.parent = parent;
        this.controller.addControllerListener((ControllerListener) this);

        interpreterMenu = new JMenu("Interpreter");
        fileStart = new JMenuItem("Start");
        fileStop = new JMenuItem("Stop");
        fileDebug = new JMenuItem("Debug");
        filePause = new JMenuItem("Pause");
        fileStep = new JMenuItem("Step");

        languagesMenu = new JMenu("Switch Language");
        TorgoToolkit.getToolkits().stream().filter((lang) -> (!lang.equals(controller.getLang()))).forEachOrdered((lang) -> {
            JMenuItem langItem = new JMenuItem(lang);
            languagesMenu.add(langItem);
            langItem.addActionListener((ActionEvent ae) -> {
                final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(TorgoToolkit.class);
                prefs.put("lang", lang);
                controller.close();
                SwingUtilities.invokeLater(() -> {
                    Controller controller1 = TorgoToolkit.getController(lang);
                    if (controller1 != null) {
                        controller1.run();
                        controller1.newFile();
                    }
                });
            });
        });

        fileMenu = new JMenu(Localization.getLocalizedString("FileMenu"));
        fileNew = new JMenuItem(Localization.getLocalizedString("FileNew"));
        fileClose = new JMenuItem(Localization.getLocalizedString("FileClose"));
        fileSave = new JMenuItem(Localization.getLocalizedString("FileSave"));
        fileSaveAs = new JMenuItem(Localization.getLocalizedString("FileSaveAs"));
        fileOpen = new JMenuItem(Localization.getLocalizedString("FileOpen"));
        fileQuit = new JMenuItem(Localization.getLocalizedString("FileQuit"));
        logConsole = new JMenuItem("View Log Console");

        debugging = new AtomicBoolean(false);
{'fraction_non_alphanumeric': 0.09359497299084996, 'fraction_numerical': 0.003417484290596406, 'mean_word_length': 3.273198304286387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5904472', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2378, 'n_words': 640}