
import java.io.*;
import javax.swing.*;

public class NewSession extends Command
{
	protected QueueDialog queueDialog;

	void cancelCommand()
	{
		try {
			writeCommand("noop");
		}
		catch (java.io.IOException e)
		{
			System.out.println("cancelCommand: IOException");
		}
	}

	protected void parseRankHint(String lineStr) throws IOException
	{
		StreamTokenizer tokenizer
			= new StreamTokenizer(
				new StringReader(lineStr));

		tokenizer.nextToken();
		if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER)
			return;
		queueDialog.setRank((int)tokenizer.nval);
	}

	void processHint(String str)
	{
		try
		{
			if (str.startsWith("rank"))
				parseRankHint(str);
		}
		catch (IOException e)
		{
		}
/*		int n = 0;
		if (parse(str, "rank", n))
			queueDialog.setRank(n);
*/	}

	public void run()
	{
		if (!(this instanceof OpenSession))
			run("newSession",
				"titleCreateSession", "createSession");
		super.run();
	}

	protected void run(String cmd, String title, String msg)
	{
		queueDialog = new QueueDialog(
			CDcreator.mainWin, i18n(title), i18n(msg));
		showDialog(queueDialog);

		execCommand(cmd + " " + sessionID);

		try {
			if (cancel)
				readResult();
		}
		catch (java.io.IOException e)
		{
			System.out.println(cmd + ": IOException");
		}

		hideDialog();
		if (!lastResultOK())
			showDialog(new JOptionPane(
				lastResult,
				JOptionPane.INFORMATION_MESSAGE,
				JOptionPane.DEFAULT_OPTION,
				null, okButton).createDialog(
				CDcreator.mainWin, i18n("error")));
	}
}

