/*
 * Fichero:     elementoAtributos.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 qué valores toman los distintos
 * 				atributos que caracterizan el producto que estamos registrando.
 * 
 * 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.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
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 elementosAtributos extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Text valor=null;
	private Text atributo=null;
	static String value=new String();
	//static String anterior_valor=new String();
	private Button button1;
	private Label label3;
	private Label label2;
	private Label label1;
	static String atributos=new String();
	//static String anterior_atributos=new String();
	String []resultado=new String[4];

	/**
	* 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);
			elementosAtributos inst = new elementosAtributos(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public elementosAtributos(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(407, 202);
			dialogShell.setText("Catalogo v1.0");
			{
				button1 = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				button1.setText("Aceptar");
				FormData button1LData = new FormData();
				button1LData.width = 49;
				button1LData.height = 21;
				button1LData.left = new FormAttachment(0, 1000, 322);
				button1LData.top = new FormAttachment(0, 1000, 133);
				button1.setLayoutData(button1LData);
				button1.addMouseListener(new MouseAdapter() {
					public void mouseDoubleClick(MouseEvent evt) {
						button1MouseDoubleClick(evt);
					}
				});
			}
			{
				label3 = new Label(dialogShell, SWT.NONE);
				label3.setText("Valor:");
				FormData label3LData = new FormData();
				label3LData.width = 28;
				label3LData.height = 14;
				label3LData.left =  new FormAttachment(0, 1000, 49);
				label3LData.top =  new FormAttachment(0, 1000, 119);
				label3.setLayoutData(label3LData);
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				label2.setText("Atributo:");
				FormData label2LData = new FormData();
				label2LData.width = 42;
				label2LData.height = 14;
				label2LData.left =  new FormAttachment(0, 1000, 49);
				label2LData.top =  new FormAttachment(0, 1000, 77);
				label2.setLayoutData(label2LData);
			}
			{
				label1 = new Label(dialogShell, SWT.NONE);
				label1.setText("Rellene los campos de Atributo y Valor:");
				FormData label1LData = new FormData();
				label1LData.width = 189;
				label1LData.height = 14;
				label1LData.left =  new FormAttachment(0, 1000, 105);
				label1LData.top =  new FormAttachment(0, 1000, 21);
				label1.setLayoutData(label1LData);
			}
			{
				valor = new Text(dialogShell, SWT.MULTI | SWT.BORDER);
				FormData valorLData = new FormData();
				valorLData.width = 163;
				valorLData.height = 15;
				valorLData.left =  new FormAttachment(0, 1000, 112);
				valorLData.top =  new FormAttachment(0, 1000, 112);
				valor.setLayoutData(valorLData);
				/*valor.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent ev){
					 	int r=ev.keyCode;
					    char a=(char)r;	
					    if(r==8){  
					    	anterior_valor=value.substring(0,(value.length()-1));
					    	value=anterior_valor;
					    }
					    else		
					    	value=value+a;
					

					
					    
					 }
			
				});*/
			}
			{
				FormData atributoLData = new FormData();
				atributoLData.width = 163;
				atributoLData.height = 15;
				atributoLData.left =  new FormAttachment(281, 1000, 0);
				atributoLData.right =  new FormAttachment(720, 1000, 0);
				atributoLData.top =  new FormAttachment(419, 1000, 0);
				atributoLData.bottom =  new FormAttachment(544, 1000, 0);
				atributo = new Text(dialogShell, SWT.H_SCROLL | SWT.BORDER);
				atributo.setLayoutData(atributoLData);
				/*atributo.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent ev){
					 	int r=ev.keyCode;
					    char a=(char)r;	
					    if(r==8){  
					    	anterior_atributos=atributos.substring(0,(atributos.length()-1));
					    	atributos=anterior_atributos;
					    }
					    else		
					    	atributos=atributos+a;
						    
					 }
				
				});*/
			}
			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 (atributo.getText()!="" && valor.getText()!="" ){
			
				atributos=atributo.getText();
				value=valor.getText();
				resultado[0]="atributo";
				resultado[1]=atributos;
				resultado[2]="valor";
				resultado[3]=value;
				value="";
				atributos="";
				dialogShell.close();
				System.gc();
		}
			
			
		
		
		
	
	}

}
