<commit_before>package j2s;

import java.awt.Font;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.texteditor.ITextEditor;

public class J2SView extends ViewPart {
	Label label;
	Button button;
	Composite parent;
	String selectedText = null;
	String selectedLink = "";

	public J2SView() {
	}

	public void createPartControl(Composite parent) {
		this.parent = parent;

		parent.setLayout(new RowLayout(SWT.VERTICAL));

		label = new Label(parent, SWT.WRAP);

		button = new Button(parent, SWT.PUSH);
		button.setText("Generate Query");

		button.addSelectionListener(buttonListener);

		getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);

	}

	private SelectionListener buttonListener = new SelectionListener() {

		@Override
		public void widgetSelected(SelectionEvent arg0) {
			label.setForeground(new Color(Display.getCurrent(), 255, 0, 0));

			String filename = System.getProperty("user.home") + "/Downloads/methodSelection.txt";
			File file = new File(filename);
			file.setReadable(true);
			file.setWritable(true);
			PrintWriter writer = null;
			try {
				writer = new PrintWriter(file);

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			writer.print(selectedText);
			writer.close();
			label.setText("Query generated, awaiting results...");
			parent.layout(true, true);
			GenerateSwiftQueryString tester = new GenerateSwiftQueryString();
			ArrayList<String> searchKeywords = tester.executeFrequencyAnalysis(filename);
			System.out.println("PRINTING KEYWORDS: " + searchKeywords.toString());
			SearchAndRank sar = null;
			try {
				sar = new SearchAndRank(searchKeywords);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			ArrayList<MetaData> rankedResults = sar.sortedFinalRanking;
			for (int i = 0; i < rankedResults.size(); i++) {
				System.out.println(rankedResults.get(i).getID());
				System.out.println(rankedResults.get(i).printFields());
				System.out.println(rankedResults.get(i).getCosValueFinal());
				System.out.println(rankedResults.get(i).getNormLinScore());
				System.out.println(rankedResults.get(i).getFinalRankingScore());
			}

			label.setText("Results: ");
			for (int i = 0; i < 2; i++) {
				MetaData result = rankedResults.get(i);
				if (result == null) {
					continue;
				} else {
					newActionLink(parent, result.getQuestionTitle()
							+ "\nhttp://www.stackoverflow.com/questions/" + result.getID());
				}
				
			}
			button.setVisible(false);
			parent.layout(true, true);
		}

		@Override
		public void widgetDefaultSelected(SelectionEvent arg0) {
			// TODO Auto-generated method stub

		}
	};

	/**
	 * Creates and returns a new Link, which when selected, will run the
	 * specified action.
	 * 
	 * @param parent
	 *            The parent composite in which to create the new link.
	 * @param text
	 *            The text to display in the link.
	 * @return The new link.
	 */
	public Button newActionLink(Composite parent, String text) {
		Button button1 = new Button(parent, SWT.RADIO);
		button1.setSelection(false);
		button1.setText(text);
		button1.setBackground(parent.getBackground());
		button1.addSelectionListener(linkListener);
		return button1;
	}

	private SelectionListener linkListener = new SelectionListener() {
		@Override
		public void widgetSelected(SelectionEvent arg0) {
			Button test = (Button) arg0.getSource();
			System.out.println(test.getText().split("\n")[1]);
			StringSelection selection = new StringSelection(test.getText().split("\n")[1]);
			Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
			clipboard.setContents(selection, selection);
			label.setText("URL copied to clipboard");
//			button.setVisible(true);
			parent.layout(true, true);<commit_msg>Add font change<commit_after>package j2s;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.texteditor.ITextEditor;

public class J2SView extends ViewPart {
	Label label;
	Button button;
	Composite parent;
	String selectedText = null;
	String selectedLink = "";

	public J2SView() {
	}

	public void createPartControl(Composite parent) {
		this.parent = parent;

		parent.setLayout(new RowLayout(SWT.VERTICAL));

		label = new Label(parent, SWT.WRAP);
		FontData[] fD = label.getFont().getFontData();
		fD[0].setHeight(16);
		label.setFont(new Font(null, fD));

		button = new Button(parent, SWT.PUSH);
		button.setText("Generate Query");

		button.addSelectionListener(buttonListener);

		getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(selectionListener);

	}

	private SelectionListener buttonListener = new SelectionListener() {

		@Override
		public void widgetSelected(SelectionEvent arg0) {
			label.setForeground(new Color(Display.getCurrent(), 255, 0, 0));

			String filename = System.getProperty("user.home") + "/Downloads/methodSelection.txt";
			File file = new File(filename);
			file.setReadable(true);
			file.setWritable(true);
			PrintWriter writer = null;
			try {
				writer = new PrintWriter(file);

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			writer.print(selectedText);
			writer.close();
			label.setText("Query generated, awaiting results...");
			parent.layout(true, true);
			GenerateSwiftQueryString tester = new GenerateSwiftQueryString();
			ArrayList<String> searchKeywords = tester.executeFrequencyAnalysis(filename);
			System.out.println("PRINTING KEYWORDS: " + searchKeywords.toString());
			SearchAndRank sar = null;
			try {
				sar = new SearchAndRank(searchKeywords);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			ArrayList<MetaData> rankedResults = sar.sortedFinalRanking;
			for (int i = 0; i < rankedResults.size(); i++) {
				System.out.println(rankedResults.get(i).getID());
				System.out.println(rankedResults.get(i).printFields());
				System.out.println(rankedResults.get(i).getCosValueFinal());
				System.out.println(rankedResults.get(i).getNormLinScore());
				System.out.println(rankedResults.get(i).getFinalRankingScore());
			}

			label.setText("Results: ");
			for (int i = 0; i < 2; i++) {
				MetaData result = rankedResults.get(i);
				if (result == null) {
					continue;
				} else {
					newActionLink(parent, result.getQuestionTitle()
							+ "\nhttp://www.stackoverflow.com/questions/" + result.getID());
				}
				
			}
			button.setVisible(false);
			parent.layout(true, true);
		}

		@Override
		public void widgetDefaultSelected(SelectionEvent arg0) {
			// TODO Auto-generated method stub

		}
	};

	/**
	 * Creates and returns a new Link, which when selected, will run the
	 * specified action.
	 * 
	 * @param parent
	 *            The parent composite in which to create the new link.
	 * @param text
	 *            The text to display in the link.
	 * @return The new link.
	 */
	public Button newActionLink(Composite parent, String text) {
		Button button1 = new Button(parent, SWT.RADIO);
		FontData[] fD = button1.getFont().getFontData();
		fD[0].setHeight(16);
		button1.setFont(new Font(null, fD));
		button1.setSelection(false);
		button1.setText(text);
		button1.setBackground(parent.getBackground());
		button1.addSelectionListener(linkListener);
		return button1;
	}

	private SelectionListener linkListener = new SelectionListener() {
		@Override
		public void widgetSelected(SelectionEvent arg0) {
			Button test = (Button) arg0.getSource();
			System.out.println(test.getText().split("\n")[1]);
			StringSelection selection = new StringSelection(test.getText().split("\n")[1]);
			Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
			clipboard.setContents(selection, selection);
			label.setText("URL copied to clipboard");
//			button.setVisible(true);
			parent.layout(true, true);
{'fraction_non_alphanumeric': 0.12464957949539447, 'fraction_numerical': 0.005406487785342411, 'mean_word_length': 4.373318988703604, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5246561', 'n_tokens_mistral': 3416, 'n_tokens_neox': 2991, 'n_words': 635}