<commit_before>package org.opensim.console;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.Reader;
import java.io.Writer;

import javax.swing.JTextArea;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;

import org.python.core.Py;
import org.python.core.PyException;
import org.python.core.PySystemState;
import org.python.util.InteractiveInterpreter;
import org.python.util.JLineConsole;

/**
 * Copyright (c)  2005-2012, Stanford University and <NAME>
 * Use of the OpenSim software in source form is permitted provided that the following
 * conditions are met:
 * 	1. The software is used only for non-commercial research and education. It may not
 *     be used in relation to any commercial activity.
 * 	2. The software is not distributed or redistributed.  Software distribution is allowed 
 *     only through https://simtk.org/home/opensim.
 * 	3. Use of the OpenSim software or derivatives must be acknowledged in all publications,
 *      presentations, or documents describing work in which OpenSim or derivatives are used.
 * 	4. Credits to developers may not be removed from executables
 *     created from modifications of the source.
 * 	5. Modifications of source code must retain the above copyright notice, this list of
 *     conditions and the following disclaimer. 
 * 
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 *  SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 *  OR BUSINESS INTERRUPTION) OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 *  WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author Ayman based on JavaForum code
 */
public class JConsole extends JTextArea implements KeyListener {

    /**
     * The input stream that will pass data to the script engine
     */
    public final Reader in;
    /**
     * The output stream from the script engine
     */
    public final Writer out;
    /**
     * The error stream from the script engine
     */
    public final Writer err;
    private CommandHistory history;
    /**
     * index of where we can start editing text
     */
    int editStart;
    /**
     * True when a script is running
     */
    boolean running;
    /**
     * The script engine and scope we're using
     */
    InteractiveInterpreter interp;
    /**
     * The allowed variables and stuff to use
     */
    // private Bindings bindings;
    // ScriptContext context;
    private ConsoleFilter filter;
    private Thread pythonThread;

    /**
     * 
     */
    public JConsole() {
        
        // create streams that will link with this
        in = new ConsoleInputStream(this);
        // System.setIn(in);
        out = new ConsoleOutputStream(this);
        //System.setOut(new PrintStream(out));
        err = new ConsoleOutputStream(this);
        // setup the command history
        history = new CommandHistory();
        // setup the script engine
        interp = new InteractiveInterpreter();

        // no postProps, registry values used 
        //JLineConsole.initialize(System.getProperties(), null, new String[0]);

        //interp = new JLineConsole();
        /*
        // important line, set JLineConsole to internal python variable to be able to 
        // acces console from python interface
        interp.getSystemState().__setattr__("_jy_interpreter", Py.java2py(interp));

        // this instance - in order to call interrupt on correct thread
        //interp.getSystemState().__setattr__("_jy_main", Py.java2py(this));
		
        // JLINE console initialization
        JLineConsole.initialize(System.getProperties(), null, new String[0]);       // setup the script interp
        
        // enable autocomplete by default:)
        interp.exec("import rlcompleter, readline");
        interp.exec("readline.parse_and_bind('tab: complete')");
        */
        Py.getSystemState().setClassLoader(
                this.getClass().getClassLoader());
        interp.exec("import sys");
        interp.exec("import javax.swing as swing");
        interp.exec("import java.lang as lang");
        interp.exec("import org.opensim.modeling as modeling");
        interp.exec("modeling.OpenSimObject.setDebugLevel(3)");
        interp.exec("from org.opensim.console.gui import *");
        interp.exec("from org.opensim.console.OpenSimPlotter import *");
        <commit_msg>Remove call to setDebugLevel in JConsole constructor to avoid verbose messages in the GUI.<commit_after>package org.opensim.console;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.Reader;
import java.io.Writer;

import javax.swing.JTextArea;
import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.DocumentFilter;

import org.python.core.Py;
import org.python.core.PyException;
import org.python.core.PySystemState;
import org.python.util.InteractiveInterpreter;
import org.python.util.JLineConsole;

/**
 * Copyright (c)  2005-2012, Stanford University and <NAME>
 * Use of the OpenSim software in source form is permitted provided that the following
 * conditions are met:
 * 	1. The software is used only for non-commercial research and education. It may not
 *     be used in relation to any commercial activity.
 * 	2. The software is not distributed or redistributed.  Software distribution is allowed 
 *     only through https://simtk.org/home/opensim.
 * 	3. Use of the OpenSim software or derivatives must be acknowledged in all publications,
 *      presentations, or documents describing work in which OpenSim or derivatives are used.
 * 	4. Credits to developers may not be removed from executables
 *     created from modifications of the source.
 * 	5. Modifications of source code must retain the above copyright notice, this list of
 *     conditions and the following disclaimer. 
 * 
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 *  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 *  SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 *  OR BUSINESS INTERRUPTION) OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 *  WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * @author Ayman based on JavaForum code
 */
public class JConsole extends JTextArea implements KeyListener {

    /**
     * The input stream that will pass data to the script engine
     */
    public final Reader in;
    /**
     * The output stream from the script engine
     */
    public final Writer out;
    /**
     * The error stream from the script engine
     */
    public final Writer err;
    private CommandHistory history;
    /**
     * index of where we can start editing text
     */
    int editStart;
    /**
     * True when a script is running
     */
    boolean running;
    /**
     * The script engine and scope we're using
     */
    InteractiveInterpreter interp;
    /**
     * The allowed variables and stuff to use
     */
    // private Bindings bindings;
    // ScriptContext context;
    private ConsoleFilter filter;
    private Thread pythonThread;

    /**
     * 
     */
    public JConsole() {
        
        // create streams that will link with this
        in = new ConsoleInputStream(this);
        // System.setIn(in);
        out = new ConsoleOutputStream(this);
        //System.setOut(new PrintStream(out));
        err = new ConsoleOutputStream(this);
        // setup the command history
        history = new CommandHistory();
        // setup the script engine
        interp = new InteractiveInterpreter();

        // no postProps, registry values used 
        //JLineConsole.initialize(System.getProperties(), null, new String[0]);

        //interp = new JLineConsole();
        /*
        // important line, set JLineConsole to internal python variable to be able to 
        // acces console from python interface
        interp.getSystemState().__setattr__("_jy_interpreter", Py.java2py(interp));

        // this instance - in order to call interrupt on correct thread
        //interp.getSystemState().__setattr__("_jy_main", Py.java2py(this));
		
        // JLINE console initialization
        JLineConsole.initialize(System.getProperties(), null, new String[0]);       // setup the script interp
        
        // enable autocomplete by default:)
        interp.exec("import rlcompleter, readline");
        interp.exec("readline.parse_and_bind('tab: complete')");
        */
        Py.getSystemState().setClassLoader(
                this.getClass().getClassLoader());
        interp.exec("import sys");
        interp.exec("import javax.swing as swing");
        interp.exec("import java.lang as lang");
        interp.exec("import org.opensim.modeling as modeling");
        interp.exec("from org.opensim.console.gui import *");
        interp.exec("from org.opensim.console.OpenSimPlotter import *");
        
{'fraction_non_alphanumeric': 0.08375761205949885, 'fraction_numerical': 0.0034940600978336828, 'mean_word_length': 2.9301686936053355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5759900', 'n_tokens_mistral': 2707, 'n_tokens_neox': 2567, 'n_words': 986}