package core.languageHandler.compiler;

import java.io.File;
import java.nio.file.Files;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import argo.jdom.JsonNode;
import argo.jdom.JsonNodeFactories;
import core.ipc.IPCServiceManager;
import core.ipc.IPCServiceName;
import core.ipc.repeatClient.PythonIPCClientService;
import core.languageHandler.Language;
import utilities.FileUtility;

public class PythonRemoteCompiler extends AbstractRemoteNativeCompiler {

	private File interpreter;

	{
		getLogger().setLevel(Level.ALL);
	}

	public PythonRemoteCompiler(File objectFileDirectory) {
		super(objectFileDirectory);
		interpreter = new File("python.exe");
	}

	@Override
	public boolean canSetPath() {
		return true;
	}

	@Override
	public boolean setPath(File file) {
		if (Files.isExecutable(file.toPath())) {
			interpreter = file;
			return true;
		}
		getLogger().warning("Python interpreter must be an executable.");
		return false;
	}

	@Override
	public File getPath() {
		return interpreter;
	}

	@Override
	public Language getName() {
		return Language.PYTHON;
	}

	@Override
	public String getExtension() {
		return ".py";
	}

	@Override
	public String getObjectExtension() {
		return ".py";
	}

	@Override
	public boolean parseCompilerSpecificArgs(JsonNode node) {
		return true;
	}

	@Override
	public JsonNode getCompilerSpecificArgs() {
		return JsonNodeFactories.object();
	}

	@Override
	protected String getDummyPrefix() {
		return "PY_";
	}

	@Override
	public Logger getLogger() {
		return Logger.getLogger(PythonRemoteCompiler.class.getName());
	}

	@Override
	protected boolean checkRemoteCompilerSettings() {
		if (!FileUtility.fileExists(interpreter) || !interpreter.canExecute()) {
			getLogger().severe("No interpreter found at " + interpreter.getAbsolutePath());
			return false;
		}

		return true;
	}

	/*******************************************************************/
	/************************Swing components***************************/
	/*******************************************************************/
	public void promptChangePath(JFrame parent) {
		JFileChooser chooser = new JFileChooser(getPath());
		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		if (chooser.showDialog(parent, "Set Python interpreter") == JFileChooser.APPROVE_OPTION) {
			File selectedFile = chooser.getSelectedFile();
			if (!selectedFile.canExecute()) {
				JOptionPane.showMessageDialog(parent,
						"Chosen file " + selectedFile.getName() + " is not executable", "Invalid choice", JOptionPane.WARNING_MESSAGE);
				return;
			}
			setPath(selectedFile);
			((PythonIPCClientService)IPCServiceManager.getIPCService(IPCServiceName.PYTHON)).setExecutingProgram(selectedFile);
		}
	}
}

@@ -159,275 +159,62 @@
 ort 
-javax.swing.JFileChooser;%0Aimport javax.swing.JFrame;%0Aimport javax.swing.JOptionPane;%0A%0Aimport argo.jdom.JsonNode;%0Aimport argo.jdom.JsonNodeFactories;%0Aimport core.ipc.IPCServiceManager;%0Aimport core.ipc.IPCServiceName;%0Aimport core.ipc.repeatClient.PythonIPCClientService
+argo.jdom.JsonNode;%0Aimport argo.jdom.JsonNodeFactories
 ;%0Aim
@@ -1728,888 +1728,7 @@
 ;%0A%09%7D
-%0A%0A%09/*******************************************************************/%0A%09/************************Swing components***************************/%0A%09/*******************************************************************/%0A%09public void promptChangePath(JFrame parent) %7B%0A%09%09JFileChooser chooser = new JFileChooser(getPath());%0A%09%09chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);%0A%09%09if (chooser.showDialog(parent, %22Set Python interpreter%22) == JFileChooser.APPROVE_OPTION) %7B%0A%09%09%09File selectedFile = chooser.getSelectedFile();%0A%09%09%09if (!selectedFile.canExecute()) %7B%0A%09%09%09%09JOptionPane.showMessageDialog(parent,%0A%09%09%09%09%09%09%22Chosen file %22 + selectedFile.getName() + %22 is not executable%22, %22Invalid choice%22, JOptionPane.WARNING_MESSAGE);%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%09setPath(selectedFile);%0A%09%09%09((PythonIPCClientService)IPCServiceManager.getIPCService(IPCServiceName.PYTHON)).setExecutingProgram(selectedFile);%0A%09%09%7D%0A%09%7D
 %0A%7D%0A

Remove unused Swing method.