1 package org.eparapher.rcp.dialog;
2
3
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.KeyEvent;
6 import org.eclipse.swt.events.KeyListener;
7 import org.eclipse.swt.layout.GridLayout;
8 import org.eclipse.swt.widgets.Button;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Dialog;
11 import org.eclipse.swt.widgets.Display;
12 import org.eclipse.swt.widgets.Label;
13 import org.eclipse.swt.widgets.Shell;
14 import org.eclipse.swt.widgets.Text;
15 import org.eparapher.rcp.tools.GUIIcons;
16
17 public class PINDialog extends Dialog {
18
19 private static final long serialVersionUID = 1L;
20
21 private String PINorPassword;
22
23 public boolean recieved;
24
25 private static final int panelheight = 100;
26 private static final int panelwidth = 350;
27
28
29 private Text txtPassword;
30 private Label txtLabel;
31 private Button butOK;
32 private Button butCancel;
33
34 private static PINDialog singleton = null;
35
36 public static PINDialog getInstance() {
37 if (singleton == null)
38 singleton = new PINDialog(Display.getDefault().getActiveShell());
39 return singleton;
40
41 }
42
43 public PINDialog(Shell activeShell) {
44
45 super(activeShell);
46 String title = "Secret Protecting your Keystore";
47 String message = "Enter you passphrase : ";
48
49
50
51
52 activeShell.setLocation(0,0);
53 activeShell.setText(title);
54 activeShell.setLayout(new GridLayout());
55
56 final Composite composite = new Composite(activeShell, SWT.BORDER );
57 final GridLayout gridLayout = new GridLayout();
58
59 gridLayout.verticalSpacing = 15;
60 gridLayout.numColumns = 2;
61 composite.setLayout(gridLayout);
62
63
64 txtPassword = new Text(composite,SWT.PASSWORD | SWT.BORDER |SWT.SINGLE);
65 txtLabel = new Label(composite,SWT.NONE);
66 txtLabel.setText("Code PIN :");
67
68 butOK = new Button(composite,SWT.NONE);
69 butOK.setText("OK");
70 butOK.setImage(GUIIcons.OK_ICON_IMAGE);
71 butCancel = new Button(composite,SWT.NONE);
72 butCancel.setText("Cancel");
73 butCancel.setImage(GUIIcons.KO_ICON_IMAGE);
74
75
76
77
78
79
80
81 PINDialogKeyAdapter keyadapter = new PINDialogKeyAdapter();
82 txtPassword.addKeyListener(keyadapter);
83
84
85
86
87
88
89
90
91
92
93 }
94
95 public void prompt() {
96
97
98
99 }
100
101 public String getPINorPassword() {
102 String myPIN = this.PINorPassword;
103 this.PINorPassword = null;
104 this.txtPassword.setText("");
105 return myPIN;
106 }
107 class PINDialogKeyAdapter implements KeyListener {
108
109 public void keyPressed(KeyEvent keyevent) {
110
111 if(keyevent.keyCode == 10) {
112 PINorPassword = new String ( txtPassword.getText() );
113
114 recieved = true;
115 }
116 }
117
118 public void keyReleased(KeyEvent e) {
119
120 }
121
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 }
164