package org.eparapher.rcp.dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Dialog; 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.eparapher.rcp.tools.GUIIcons; public class PINDialog extends Dialog { private static final long serialVersionUID = 1L; private String PINorPassword; public boolean recieved; //GUI Settings private static final int panelheight = 100; private static final int panelwidth = 350; //GUI Objects private Text txtPassword; private Label txtLabel; private Button butOK; private Button butCancel; private static PINDialog singleton = null; public static PINDialog getInstance() { if (singleton == null) singleton = new PINDialog(Display.getDefault().getActiveShell()); return singleton; } public PINDialog(Shell activeShell) { super(activeShell); String title = "Secret Protecting your Keystore"; String message = "Enter you passphrase : "; /* Display display = Display.getDefault(); Shell shell = new Shell(SWT.NONE); shell.setSize(panelwidth, panelheight);*/ activeShell.setLocation(0,0); activeShell.setText(title); activeShell.setLayout(new GridLayout()); final Composite composite = new Composite(activeShell, SWT.BORDER ); final GridLayout gridLayout = new GridLayout(); //gridLayout.makeColumnsEqualWidth = true; gridLayout.verticalSpacing = 15; gridLayout.numColumns = 2; composite.setLayout(gridLayout); //GUI Elements txtPassword = new Text(composite,SWT.PASSWORD | SWT.BORDER |SWT.SINGLE); txtLabel = new Label(composite,SWT.NONE); txtLabel.setText("Code PIN :"); butOK = new Button(composite,SWT.NONE); butOK.setText("OK"); butOK.setImage(GUIIcons.OK_ICON_IMAGE); butCancel = new Button(composite,SWT.NONE); butCancel.setText("Cancel"); butCancel.setImage(GUIIcons.KO_ICON_IMAGE); //GUI Settings //PINDialogActionListener actionlistener = new PINDialogActionListener(); //butOK.addActionListener(actionlistener); //butCancel.addActionListener(actionlistener); //gestion du bouton entree PINDialogKeyAdapter keyadapter = new PINDialogKeyAdapter(); txtPassword.addKeyListener(keyadapter); // Gestion du bouton "fermer la fenetre" //PINDialogWindowAdapter windowadapter = new PINDialogWindowAdapter(); //addWindowListener(windowadapter); //setResizable(false); //Dimension dimension = getToolkit().getScreenSize(); //Rectangle rectangle = getBounds(); //setLocation((dimension.width - rectangle.width) / 2, (dimension.height - rectangle.height) / 2); //setVisible(false); } public void prompt() { //setVisible(true); //toFront(); //requestFocusInWindow(); } public String getPINorPassword() { String myPIN = this.PINorPassword; this.PINorPassword = null; this.txtPassword.setText(""); return myPIN; } class PINDialogKeyAdapter implements KeyListener { public void keyPressed(KeyEvent keyevent) { //Catch a key : validate if enter is pressed if(keyevent.keyCode == 10) { PINorPassword = new String ( txtPassword.getText() ); //setVisible(false); recieved = true; } } public void keyReleased(KeyEvent e) { } } /* //GUI Events class PINDialogActionListener implements ActionListener { public void actionPerformed(ActionEvent actionevent) { Object obj = actionevent.getSource(); if(obj == butOK) { try { PINorPassword = new String ( txtPassword.getPassword() ); } catch(Exception _ex) { PINorPassword = null; } } if(obj == butCancel) { PINorPassword = null; } setVisible(false); recieved = true; } }*/ /* //GUI Events class PINDialogWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent windowevent) { PINorPassword = null; recieved = true; setVisible(false); dispose(); } }*/ }