/*
 * Fichero:     NombrePar.java
 * Fecha:       20/10/06
 * Autor:       Alvaro Sarmiento Losada
 * Asignatura:  Proyecto Fin de Carrera
 * Descripción: Clase que representa una interfaz de diálogo con el usuario
 * 				a través de la cual se indica el nombre que queremos que tenga 
 * 				nuestro par y su password correspondiente.
 *
 * Este fichero pertenece al proyecto fin de carrera del autor,
 * consistente en el estudio de JXTA y su aplicación al comercio 
 * electrónico b2b.
 */


package com.pfc.ventanas;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Slider;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class nombrePar extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Text text2;
	private Label label2;
	private Button button1;
	private Label label3;
	private Label label1;
	private Label label4;
	private Slider slider1;
	private CLabel cLabel1;
	private StyledText styledText1;
	private Combo combo1;
	private Text text1;
	String[] resultado=new String [2];

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			nombrePar inst = new nombrePar(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public nombrePar(Shell parent, int style) {
		super(parent, style);
	}

	public String[] open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			FormLayout dialogShellLayout = new FormLayout();
			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();
			dialogShell.setSize(414, 321);
			dialogShell.setText("Catalogo v1.0");
			{
				label4 = new Label(dialogShell, SWT.NONE);
				label4.setText("Bienvenido a Catalogo v1.0");
				FormData label4LData = new FormData();
				label4LData.width = 133;
				label4LData.height = 14;
				label4LData.left =  new FormAttachment(0, 1000, 133);
				label4LData.top =  new FormAttachment(0, 1000, 28);
				label4.setLayoutData(label4LData);
			}

			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				FormData button1LData = new FormData();
				button1LData.width = 49;
				button1LData.height = 21;
				button1LData.left =  new FormAttachment(0, 1000, 329);
				button1LData.top =  new FormAttachment(0, 1000, 252);
				button1.setLayoutData(button1LData);
				button1.setText("Aceptar");
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label3 = new Label(dialogShell, SWT.NONE);
				FormData label3LData = new FormData();
				label3LData.width = 280;
				label3LData.height = 14;
				label3LData.left =  new FormAttachment(0, 1000, 63);
				label3LData.top =  new FormAttachment(0, 1000, 77);
				label3.setLayoutData(label3LData);
				label3.setText("Introduzca el nombre de su peer y el password que desea:");
				label3.setToolTipText("Catalogo v1.0");
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				FormData label2LData = new FormData();
				label2LData.width = 49;
				label2LData.height = 14;
				label2LData.left =  new FormAttachment(0, 1000, 42);
				label2LData.top =  new FormAttachment(0, 1000, 203);
				label2.setLayoutData(label2LData);
				label2.setText("Password:");
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				FormData label1LData = new FormData();
				label1LData.width = 63;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 42);
				label1LData.top =  new FormAttachment(0, 1000, 140);
				label1.setLayoutData(label1LData);
				label1.setText("Nombre:");
			}
			{
				FormData text2LData = new FormData();
				text2LData.width = 212;
				text2LData.height = 22;
				text2LData.left =  new FormAttachment(0, 1000, 133);
				text2LData.top =  new FormAttachment(0, 1000, 189);
				text2 = new Text(dialogShell, SWT.SINGLE |SWT.PASSWORD | SWT.BORDER);
				text2.setLayoutData(text2LData);
			}
			{
				FormData text1LData = new FormData();
				text1LData.width = 212;
				text1LData.height = 22;
				text1LData.left =  new FormAttachment(0, 1000, 133);
				text1LData.top =  new FormAttachment(0, 1000, 126);
				text1 = new Text(dialogShell, SWT.SINGLE | SWT.BORDER);
				text1.setLayoutData(text1LData);
			}
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return resultado;
	}
	
	private void button1MouseDoubleClick(MouseEvent evt) {
		if (text1.getText()!="" && text2.getText()!=""){
			
			
			//elementos_busqueda=open();
			String nombre=text1.getText();
			String password=text2.getText();
			
			resultado[0]=nombre;
			resultado[1]=password;
			
			
			nombre="";
			password="";
			
			
			dialogShell.close();
			System.gc();
		
		
		
		}
	}

}
