<commit_before>package live_py;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.compare.Splitter;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.IViewportListener;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.VerticalRuler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.osgi.framework.Bundle;
import org.python.pydev.core.IPythonNature;
import org.python.pydev.core.MisconfigurationException;
import org.python.pydev.core.bundle.BundleUtils;
import org.python.pydev.core.log.Log;
import org.python.pydev.editor.PyEdit;
import org.python.pydev.editor.codefolding.PySourceViewer;
import org.python.pydev.runners.UniversalRunner;
import org.python.pydev.runners.UniversalRunner.AbstractRunner;

import com.aptana.shared_core.io.FileUtils;
import com.aptana.shared_core.structure.Tuple;

/**
 * This actually runs the Python code and displays the analysis.
 * @author <NAME>
 *
 */
public class LiveCodingAnalyst {
	/**
	 * Making it true will print some debug info to stdout.
	 */
	private final static boolean DEBUG = false;
	
	private static LinkedBlockingQueue<AnalysisTask> toAnalyse =
			new LinkedBlockingQueue<AnalysisTask>();
	private static Thread analysisThread = new Thread() {
		public void run() {
			try {
				while (true) {
					AnalysisTask last = toAnalyse.take();
					AnalysisTask next;
					do {
						next = toAnalyse.poll(0, TimeUnit.SECONDS);
						if (next != null)
						{
							last = next;
						}
					} while (next != null);
					last.analyst.analyseDocument(last.sourceCode, last.bounds);
				}
			} catch (InterruptedException e) {
				// Just exit the thread if it was interrupted.
			}
		};
	};
	
	static {
		analysisThread.setDaemon(true);
		analysisThread.start();
	}
	
	private class AnalysisTask {
		public String sourceCode;
		public LiveCodingAnalyst analyst;
		public Rectangle bounds;
	}

	private ISourceViewer mainViewer;
	private IDocument mainDocument;
	private Document displayDocument;
	private SourceViewer displayViewer;
	private LiveCanvasView canvasView;
	private File scriptPath;
	private ArrayList<CanvasCommand> canvasCommands = 
			new ArrayList<CanvasCommand>();
	private Composite liveDisplay;
	private Splitter splitter;
	private boolean isVisible;

	/**
	 * This callback inserts a new composite inside the standard window
	 * and then returns the left pane of the splitter as the new parent
	 * for the main editor controls.
	 * @param parent The standard window that usually holds the editor.
	 * @return The new control that the editor can be created in.
	 */
	public Object createPartControl(Composite parent) {
		splitter = new Splitter(parent, SWT.HORIZONTAL);
		
		Composite editorContent = new Composite(splitter, SWT.NONE);
		editorContent.setLayout(new FillLayout());
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		editorContent.setLayoutData(gridData);
		
		liveDisplay = new Composite(splitter, SWT.NONE);
		liveDisplay.setLayout(new FillLayout());
		GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
		liveDisplay.setLayoutData(gridData2);
		
		VerticalRuler ruler = new VerticalRuler(12);
		int styles = 
				SWT.V_SCROLL | 
				SWT.H_SCROLL | 
				SWT.MULTI | 
				SWT.BORDER | <commit_msg>Fixes #24 by setting layouts.<commit_after>package live_py;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.compare.Splitter;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.IViewportListener;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.VerticalRuler;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.osgi.framework.Bundle;
import org.python.pydev.core.IPythonNature;
import org.python.pydev.core.MisconfigurationException;
import org.python.pydev.core.bundle.BundleUtils;
import org.python.pydev.core.log.Log;
import org.python.pydev.editor.PyEdit;
import org.python.pydev.editor.codefolding.PySourceViewer;
import org.python.pydev.runners.UniversalRunner;
import org.python.pydev.runners.UniversalRunner.AbstractRunner;

import com.aptana.shared_core.io.FileUtils;
import com.aptana.shared_core.structure.Tuple;

/**
 * This actually runs the Python code and displays the analysis.
 * @author <NAME>
 *
 */
public class LiveCodingAnalyst {
	/**
	 * Making it true will print some debug info to stdout.
	 */
	private final static boolean DEBUG = false;
	
	private static LinkedBlockingQueue<AnalysisTask> toAnalyse =
			new LinkedBlockingQueue<AnalysisTask>();
	private static Thread analysisThread = new Thread() {
		public void run() {
			try {
				while (true) {
					AnalysisTask last = toAnalyse.take();
					AnalysisTask next;
					do {
						next = toAnalyse.poll(0, TimeUnit.SECONDS);
						if (next != null)
						{
							last = next;
						}
					} while (next != null);
					last.analyst.analyseDocument(last.sourceCode, last.bounds);
				}
			} catch (InterruptedException e) {
				// Just exit the thread if it was interrupted.
			}
		};
	};
	
	static {
		analysisThread.setDaemon(true);
		analysisThread.start();
	}
	
	private class AnalysisTask {
		public String sourceCode;
		public LiveCodingAnalyst analyst;
		public Rectangle bounds;
	}

	private ISourceViewer mainViewer;
	private IDocument mainDocument;
	private Document displayDocument;
	private SourceViewer displayViewer;
	private LiveCanvasView canvasView;
	private File scriptPath;
	private ArrayList<CanvasCommand> canvasCommands = 
			new ArrayList<CanvasCommand>();
	private Composite liveDisplay;
	private Splitter splitter;
	private boolean isVisible;

	/**
	 * This callback inserts a new composite inside the standard window
	 * and then returns the left pane of the splitter as the new parent
	 * for the main editor controls.
	 * @param parent The standard window that usually holds the editor.
	 * @return The new control that the editor can be created in.
	 */
	public Object createPartControl(Composite parent) {
		parent.setLayout(new GridLayout());
		parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));             

		splitter = new Splitter(parent, SWT.HORIZONTAL);
		splitter.setLayout(new FillLayout());
		splitter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));           
		
		Composite editorContent = new Composite(splitter, SWT.NONE);
		editorContent.setLayout(new FillLayout());
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		editorContent.setLayoutData(gridData);
		
		liveDisplay = new Composite(splitter, SWT.NONE);
		liveDisplay.setLayout(new FillLayout());
		GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
		liveDisplay.setLayoutData(gridData2);
		
		VerticalRuler ruler = new VerticalRuler(12);
		int styles = 
				SWT.V_SCROLL | 
				SWT.H_SCROLL | 
				SWT.MULTI | 
				SWT.BORDER | 
{'fraction_non_alphanumeric': 0.09832516805286544, 'fraction_numerical': 0.001367209752762903, 'mean_word_length': 4.524229074889868, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4614391', 'n_tokens_mistral': 2957, 'n_tokens_neox': 2689, 'n_words': 640}