import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import threadsv.* ;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Form1' is
 * created in the main() method.
 */
public class Form1 extends Form
{
	IGetCurrentThreadID m_Obj ;

	
	public Form1()
	{
		// Required for Visual J++ Form Designer support
		initForm();		

		// TODO: Add any constructor code after initForm call
		
		txt_ClientThread.setText(""+GetCurrentThreadId()) ;
	}

	/**
	 * Form1 overrides dispose so it can clean up the
	 * component list.
	 */
	public void dispose()
	{
		super.dispose();
		components.dispose();
	}

	private void btn_Create_click(Object source, Event e)
	{
		if (rb_Single.getChecked() == true)
		{
			m_Obj = new MsjJavademoSingle ( ) ;
		}
		else if (rb_Apartment.getChecked() == true)
		{
			m_Obj = new MsjJavademoApartment ( ) ;
		}
		else if (rb_Free.getChecked() == true)
		{
			m_Obj = new MsjJavademoFree ( ) ;
		}
		else if (rb_Both.getChecked() == true)
		{
			m_Obj = new MsjJavademoBoth ( ) ; 
		}

		btn_Create.setEnabled (false) ;
		btn_Release.setEnabled(true) ;
		btn_Call.setEnabled (true) ;

	}

	private void btn_Release_click(Object source, Event e)
	{
		m_Obj = null ;
		
		btn_Create.setEnabled (true) ;
		btn_Release.setEnabled(false) ;
		btn_Call.setEnabled (false) ;
		txt_ThreadReceived.setText ("") ;
	}

	private void btn_Call_click(Object source, Event e)
	{
		txt_ThreadReceived.setText(""+m_Obj.getCurrentThreadId ( )) ;	
	}

	/**
	 * NOTE: The following code is required by the Visual J++ form
	 * designer.  It can be modified using the form editor.  Do not
	 * modify it using the code editor.
	 */
	Container components = new Container();
	RadioButton rb_Single = new RadioButton();
	RadioButton rb_Apartment = new RadioButton();
	RadioButton rb_Free = new RadioButton();
	RadioButton rb_Both = new RadioButton();
	Button btn_Create = new Button();
	Button btn_Release = new Button();
	Edit txt_ClientThread = new Edit();
	Label label1 = new Label();
	Edit txt_ThreadReceived = new Edit();
	Label label2 = new Label();
	Button btn_Call = new Button();

	private void initForm()
	{
		this.setText("Essence of COM Java Thread Client");
		this.setAutoScaleBaseSize(new Point(5, 13));
		this.setClientSize(new Point(314, 320));

		rb_Single.setLocation(new Point(16, 32));
		rb_Single.setSize(new Point(80, 24));
		rb_Single.setTabIndex(0);
		rb_Single.setText("Single");

		rb_Apartment.setLocation(new Point(16, 80));
		rb_Apartment.setSize(new Point(80, 24));
		rb_Apartment.setTabIndex(1);
		rb_Apartment.setTabStop(true);
		rb_Apartment.setText("Apartment");
		rb_Apartment.setChecked(true);

		rb_Free.setLocation(new Point(16, 128));
		rb_Free.setSize(new Point(80, 24));
		rb_Free.setTabIndex(2);
		rb_Free.setText("Free");

		rb_Both.setLocation(new Point(16, 176));
		rb_Both.setSize(new Point(72, 32));
		rb_Both.setTabIndex(3);
		rb_Both.setText("Both");

		btn_Create.setLocation(new Point(16, 224));
		btn_Create.setSize(new Point(72, 32));
		btn_Create.setTabIndex(4);
		btn_Create.setText("Create");
		btn_Create.addOnClick(new EventHandler(this.btn_Create_click));

		btn_Release.setEnabled(false);
		btn_Release.setLocation(new Point(16, 272));
		btn_Release.setSize(new Point(72, 32));
		btn_Release.setTabIndex(5);
		btn_Release.setText("Release");
		btn_Release.addOnClick(new EventHandler(this.btn_Release_click));

		txt_ClientThread.setBackColor(Color.INACTIVEBORDER);
		txt_ClientThread.setLocation(new Point(200, 56));
		txt_ClientThread.setSize(new Point(48, 20));
		txt_ClientThread.setTabIndex(6);
		txt_ClientThread.setText("");
		txt_ClientThread.setReadOnly(true);

		label1.setLocation(new Point(200, 24));
		label1.setSize(new Point(80, 32));
		label1.setTabIndex(7);
		label1.setTabStop(false);
		label1.setText("Client app on thread:");

		txt_ThreadReceived.setBackColor(Color.INACTIVEBORDER);
		txt_ThreadReceived.setLocation(new Point(200, 128));
		txt_ThreadReceived.setSize(new Point(48, 20));
		txt_ThreadReceived.setTabIndex(8);
		txt_ThreadReceived.setText("");
		txt_ThreadReceived.setReadOnly(true);

		label2.setLocation(new Point(200, 96));
		label2.setSize(new Point(96, 32));
		label2.setTabIndex(9);
		label2.setTabStop(false);
		label2.setText("Object received call on thread:");

		btn_Call.setLocation(new Point(200, 168));
		btn_Call.setSize(new Point(80, 32));
		btn_Call.setTabIndex(10);
		btn_Call.setText("Call");
		btn_Call.addOnClick(new EventHandler(this.btn_Call_click));

		this.setNewControls(new Control[] {
							btn_Call, 
							label2, 
							txt_ThreadReceived, 
							label1, 
							txt_ClientThread, 
							btn_Release, 
							btn_Create, 
							rb_Both, 
							rb_Free, 
							rb_Apartment, 
							rb_Single});
	}

	/**
	 * The main entry point for the application. 
	 *
	 * @param args Array of parameters passed to the application
	 * via the command line.
	 */
	public static void main(String args[])
	{
		Application.run(new Form1());
	}
	
	/**
	 * @dll.import("KERNEL32",auto) 
	 */
	public static native int GetCurrentThreadId();

}
