package TestApp01_call;

import javax.swing.JOptionPane;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;

public class popUp03 extends Shell {
	private Text text;
	private String authCode = "";
	protected static Shell shell = null;
	protected static Composite composite;
	private static popUp03 popUp = null;

	public String getAuthCode() {
		return authCode;
	}
	
	public void setAuthCode(String authCode) {
		this.authCode = authCode;
		text.setText(this.authCode);
	}

	private static synchronized popUp03 getInstance() {
		try {
			if (popUp == null)
				popUp = (popUp03) Class.forName("popUp03").newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return popUp;
	}

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			shell = new popUp03(display);
			composite = new Composite(shell, SWT.NONE);
			shell.open();
			shell.setVisible(true);
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * 
	 * @param display
	 */
	public popUp03(Display display) {
		super(display, SWT.DIALOG_TRIM);

		text = new Text(this, SWT.BORDER | SWT.CENTER);
		text.setBounds(112, 36, 91, 26);
		text.setTextLimit(6);
		text.addVerifyListener(new VerifyListener() {

			@Override
			public void verifyText(VerifyEvent e) {
				String string = e.text;
				char[] chars = new char[string.length()];
				string.getChars(0, chars.length, chars, 0);
				for (int i = 0; i < chars.length; i++) {
					if (!('0' <= chars[i] && chars[i] <= '9')) {
						e.doit = false;
						return;
					}
				}
			}
		});
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("  ");
		setSize(322, 139);

		Label lblTableNumber = new Label(this, SWT.NONE);
		lblTableNumber.setAlignment(SWT.CENTER);
		lblTableNumber.setBounds(85, 10, 145, 20);
		lblTableNumber.setText("Authorization Code");

		Button btnOk = new Button(this, SWT.NONE);
		btnOk.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if (text.getText() != "") {
					authCode = text.getText();
					close();
				} else
					JOptionPane.showMessageDialog(null, "AUTH CODE CANNOT BE EMPTY");
			}
		});
		btnOk.setBounds(121, 68, 74, 30);
		btnOk.setText("OK");
	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
