567ef2e992814c84ebdfc38cf4d1ed8bf93fc80a
[FinalKeyGui.git] / src / fkgui / NewAccountDialog.java
1 package fkgui;
2
3 import org.eclipse.swt.widgets.Dialog;
4 import org.eclipse.swt.widgets.Display;
5 import org.eclipse.swt.widgets.Shell;
6 import org.eclipse.swt.layout.FormLayout;
7 import org.eclipse.swt.layout.FillLayout;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.widgets.TabFolder;
10 import org.eclipse.swt.widgets.TabItem;
11 import org.eclipse.swt.layout.FormData;
12 import org.eclipse.swt.layout.FormAttachment;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Label;
16 import org.eclipse.swt.widgets.MessageBox;
17 import org.eclipse.swt.widgets.Text;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.events.ModifyEvent;
20 import org.eclipse.swt.events.ModifyListener;
21 import org.eclipse.swt.events.SelectionAdapter;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.events.SelectionListener;
24 import org.eclipse.swt.widgets.Spinner;
25 import org.eclipse.wb.swt.SWTResourceManager;
26
27 public class NewAccountDialog extends Dialog implements FkActionEventListener {
28
29         protected Object result;
30         protected Shell shlNewAccount;
31         private Text txtAccountName;
32         private Text txtUserName;
33         private Text txtManPSW;
34         private Text txtSpecials;
35         
36         private enum FkNewAccStep { NAMES, PASSTYPE, PASS_MAN, PASS_AUT, SEPERATOR, REVIEW, CLICKBTN, SAVING };
37         
38         private String strAccountName = "";
39         private String strUserName = "";
40         private String strPassword = "";
41         private String autoPassSpecials = "!@#,.-_()";
42         private Boolean autoPassword = true;
43         private Boolean autoPassAllSpecials = true;
44         private int autoPassLen = 16;
45         private Boolean seperatorTab=true;
46
47         //NamePage
48         Button btnNext0;
49
50         
51         //PassType
52         Button radAutPSW;
53         Button radManPSW;
54         
55         //ManPass
56         Label lblTypeThePassword;
57         FormData fd_lblTypeThePassword; 
58         Label lblPassword;
59         FormData fd_lblPassword;
60         Button chkShowPsw;
61         Button btnManPassPageNext;
62         
63         //Autopass
64         Button radAllSymbols;
65         Spinner spnLen;
66         
67         //Seperator
68         Button radTabSep;
69         
70         //Saving
71         Label txtBUSYMSG;
72         Animation animation;
73         
74         NewAccountDialog mySelf;
75
76         
77         
78         Composite composite;
79         /**
80          * Create the dialog.
81          * @param parent
82          * @param style
83          */
84         public NewAccountDialog(Shell parent, int style) {
85                 super(parent, style);
86                 
87         }
88
89         /**
90          * Open the dialog.
91          * @return the result
92          */
93         public Object open() {
94                 createContents();
95                 shlNewAccount.open();
96                 shlNewAccount.layout();
97                 Display display = getParent().getDisplay();
98                 mySelf = this;
99                 while (!shlNewAccount.isDisposed()) {
100                         if (!display.readAndDispatch()) {
101                                 display.sleep();
102                         }
103                 }
104                 return result;
105         }
106         
107         private void checkNamePage()
108         {
109                 if( txtAccountName.getText().length() > 0 && txtUserName.getText().length() > 0 )
110                 {
111                         btnNext0.setVisible(true);
112                 } else {
113                         btnNext0.setVisible(false);
114                 }
115         }
116
117         private void createNamePage()
118         {
119                 composite = new Composite(shlNewAccount, SWT.NONE);
120         //      tbtmStepUsername.setControl(composite);
121                 composite.setLayout(new FormLayout());
122                 
123                 
124                 
125                 Label lblEnterNewName = new Label(composite, SWT.NONE);
126                 FormData fd_lblEnterNewName = new FormData();
127                 fd_lblEnterNewName.bottom = new FormAttachment(0, 112);
128                 fd_lblEnterNewName.right = new FormAttachment(0, 603);
129                 fd_lblEnterNewName.top = new FormAttachment(0, 10);
130                 fd_lblEnterNewName.left = new FormAttachment(0, 10);
131                 lblEnterNewName.setLayoutData(fd_lblEnterNewName);
132                 lblEnterNewName.setText("This creates a new account on your FinalKey.\nTo begin, choose a name for your account, for example the\nname of the website or service you want to login to.\nThis is the name that will be visible in the list of accounts.");
133                 Label lblUsername = new Label(composite, SWT.NONE);
134                 FormData fd_lblUsername = new FormData();
135                 lblUsername.setLayoutData(fd_lblUsername);
136                 lblUsername.setText("Account Name:");
137                 
138                 txtAccountName = new Text(composite, SWT.BORDER);
139                 fd_lblUsername.bottom = new FormAttachment(txtAccountName, 0, SWT.BOTTOM);
140                 fd_lblUsername.right = new FormAttachment(txtAccountName, -6);
141                 FormData fd_txtAccountName = new FormData();
142                 fd_txtAccountName.top = new FormAttachment(lblEnterNewName, 6);
143                 fd_txtAccountName.right = new FormAttachment(100, -274);
144                 fd_txtAccountName.left = new FormAttachment(0, 180);
145                 txtAccountName.setLayoutData(fd_txtAccountName);
146                 txtAccountName.addModifyListener( new ModifyListener() {
147                         @Override
148                         public void modifyText(ModifyEvent arg0) {
149                                 checkNamePage();
150
151                         }
152                 });
153                 
154                 Label lblNewLabel = new Label(composite, SWT.NONE);
155                 FormData fd_lblNewLabel = new FormData();
156                 fd_lblNewLabel.left = new FormAttachment(0, 10);
157                 fd_lblNewLabel.right = new FormAttachment(100);
158                 fd_lblNewLabel.top = new FormAttachment(lblUsername, 20);
159                 lblNewLabel.setLayoutData(fd_lblNewLabel);
160                 lblNewLabel.setText("The username is the name that The Final Key will\ntype into the service when logging in, it is typically an E-Mail address.");
161                 
162                 Label lblUsername_1 = new Label(composite, SWT.NONE);
163                 FormData fd_lblUsername_1 = new FormData();
164                 fd_lblUsername_1.top = new FormAttachment(lblNewLabel, 6);
165                 fd_lblUsername_1.right = new FormAttachment(lblUsername, 0, SWT.RIGHT);
166                 lblUsername_1.setLayoutData(fd_lblUsername_1);
167                 lblUsername_1.setText("Username:");
168                 
169                 txtUserName = new Text(composite, SWT.BORDER);
170                 FormData fd_txtUserName = new FormData();
171                 fd_txtUserName.left = new FormAttachment(txtAccountName, 0, SWT.LEFT);
172                 fd_txtUserName.right = new FormAttachment(txtAccountName, 0, SWT.RIGHT);
173                 fd_txtUserName.top = new FormAttachment(lblNewLabel, 6);
174                 txtUserName.setLayoutData(fd_txtUserName);
175                 txtUserName.addModifyListener( new ModifyListener() {
176                         @Override
177                         public void modifyText(ModifyEvent arg0) {
178                                 checkNamePage();
179                         }
180                 });
181                 
182                 Button btnCancel = new Button(composite, SWT.NONE);
183                 btnCancel.addSelectionListener(new SelectionAdapter() {
184                         @Override
185                         public void widgetSelected(SelectionEvent e) {
186                                 shlNewAccount.close();
187                         }
188                 });
189                 FormData fd_btnCancel = new FormData();
190                 fd_btnCancel.bottom = new FormAttachment(100, -10);
191                 fd_btnCancel.left = new FormAttachment(0, 10);
192                 btnCancel.setLayoutData(fd_btnCancel);
193                 btnCancel.setText("Cancel");
194                 
195                 btnNext0 = new Button(composite, SWT.NONE);
196                 btnNext0.addSelectionListener(new SelectionAdapter() {
197                         @Override
198                         public void widgetSelected(SelectionEvent e) {
199                                 strAccountName = txtAccountName.getText();
200                                 strUserName = txtUserName.getText();
201                                 updatePage(FkNewAccStep.PASSTYPE);
202                         }
203                 });
204                 btnNext0.setText("Next");
205                 FormData fd_btnNext0 = new FormData();
206                 fd_btnNext0.bottom = new FormAttachment(btnCancel, 0, SWT.BOTTOM);
207                 fd_btnNext0.right = new FormAttachment(lblEnterNewName, 0, SWT.RIGHT);
208                 btnNext0.setLayoutData(fd_btnNext0);
209                 btnNext0.setVisible(false);
210                 
211                 txtUserName.setText( strUserName );
212                 txtAccountName.setText( strAccountName );
213
214         Control[] controls = new Control[] { txtAccountName, txtUserName, btnNext0, btnCancel };
215         composite.setTabList(controls);         
216                 
217         }
218         
219         
220         private void createPassTypePage()
221         {
222                 composite = new Composite(shlNewAccount, SWT.NONE);
223                 composite.setLayout(new FormLayout());
224                 
225                 Label lblNextUpSetting = new Label(composite, SWT.NONE);
226                 FormData fd_lblNextUpSetting = new FormData();
227                 fd_lblNextUpSetting.right = new FormAttachment(0, 603);
228                 fd_lblNextUpSetting.top = new FormAttachment(0, 10);
229                 fd_lblNextUpSetting.left = new FormAttachment(0, 10);
230                 lblNextUpSetting.setLayoutData(fd_lblNextUpSetting);
231                 lblNextUpSetting.setText("Next up: Setting a safe password!\nYou have two options: Manually enter a password or to\nhave The Final Key generate a strong and random password,\nit is strongly recommended to let The Final Key generate a\nrandom password, select the longest that is allowed by the service.");
232                 
233                 radAutPSW = new Button(composite, SWT.RADIO);
234                 if( autoPassword )
235                 {
236                         radAutPSW.setSelection(true);
237                 }
238                 FormData fd_radAutPSW = new FormData();
239                 fd_radAutPSW.top = new FormAttachment(lblNextUpSetting, 37);
240                 fd_radAutPSW.left = new FormAttachment(0, 213);
241                 radAutPSW.setLayoutData(fd_radAutPSW);
242                 radAutPSW.setText("Automatic");
243                 
244                 radManPSW = new Button(composite, SWT.RADIO);
245                 if( !autoPassword )
246                 {
247                         radManPSW.setSelection(true);
248                 }               
249                 FormData fd_radManPSW = new FormData();
250                 fd_radManPSW.top = new FormAttachment(radAutPSW, 6);
251                 fd_radManPSW.left = new FormAttachment(radAutPSW, 0, SWT.LEFT);
252                 radManPSW.setLayoutData(fd_radManPSW);
253                 radManPSW.setText("Manual Entry");
254                 
255                 Button btnNext1 = new Button(composite, SWT.NONE);
256                 btnNext1.setText("Next");
257                 FormData fd_btnNext1 = new FormData();
258                 fd_btnNext1.bottom = new FormAttachment(100, -10);
259                 fd_btnNext1.right = new FormAttachment(100, -10);
260                 btnNext1.setLayoutData(fd_btnNext1);
261                 btnNext1.addSelectionListener(new SelectionListener() {
262                         
263                         @Override
264                         public void widgetSelected(SelectionEvent arg0) {
265                                 if( radAutPSW.getSelection() )
266                                 {
267                                         updatePage(FkNewAccStep.PASS_AUT);
268                                         autoPassword = true;
269                                 } else {
270                                         updatePage(FkNewAccStep.PASS_MAN);
271                                         autoPassword = false;
272                                 }
273                         }
274                         
275                         @Override
276                         public void widgetDefaultSelected(SelectionEvent arg0) {
277                                 // TODO Auto-generated method stub
278                                 
279                         }
280                 });
281                 
282                 Button btnBack0 = new Button(composite, SWT.NONE);
283                 btnBack0.setText("Back");
284                 FormData fd_btnBack0 = new FormData();
285                 fd_btnBack0.bottom = new FormAttachment(btnNext1, 0, SWT.BOTTOM);
286                 fd_btnBack0.left = new FormAttachment(lblNextUpSetting, 0, SWT.LEFT);
287                 btnBack0.setLayoutData(fd_btnBack0);
288                 btnBack0.addSelectionListener( new SelectionListener() {
289                         
290                         @Override
291                         public void widgetSelected(SelectionEvent arg0) {
292                                 updatePage( FkNewAccStep.NAMES );
293                                 
294                         }
295                         
296                         @Override
297                         public void widgetDefaultSelected(SelectionEvent arg0) {
298                                 // TODO Auto-generated method stub
299                                 
300                         }
301                 });
302                 
303         Control[] controls = new Control[] { radAutPSW, radManPSW, btnNext1, btnBack0 };
304         composite.setTabList(controls);
305         radAutPSW.setFocus();
306 }
307         
308         void autoPassPageSaveValues()
309         {
310                 autoPassAllSpecials = radAllSymbols.getSelection();
311                 autoPassSpecials = txtSpecials.getText();
312                 autoPassLen = spnLen.getSelection();            
313         }
314         void createPassAutPage()
315         {
316                 composite = new Composite(shlNewAccount, SWT.NONE);
317                 
318                 Label lblBeforeCreatingA = new Label(composite, SWT.NONE);
319                 lblBeforeCreatingA.setBounds(10, 10, 593, 104);
320                 lblBeforeCreatingA.setText("Before creating a password, please select how long it should be.\nA longer password is safer, but the maximum allowed length varies,\ndepending on where you're using it. For example many websites do not\nallow passwords longer than 16 characters.");
321                 
322                 Label lblPasswordLength = new Label(composite, SWT.NONE);
323                 lblPasswordLength.setBounds(32, 132, 127, 23);
324                 lblPasswordLength.setText("Password length:");
325                 
326                 spnLen = new Spinner(composite, SWT.BORDER);
327                 spnLen.setMaximum(128);
328                 spnLen.setSelection(autoPassLen);
329                 spnLen.setBounds(165, 120, 62, 35);
330                 
331                 Label lblASafePassword = new Label(composite, SWT.NONE);
332                 lblASafePassword.setBounds(10, 161, 593, 76);
333                 lblASafePassword.setText("A strong password contains not only uppercase and lowercase\nletters and numbers, but also other symbols.\nIt differs which symbols are allowed, some allow all ASCII symbols.");
334                 
335                 radAllSymbols = new Button(composite, SWT.RADIO);
336                 if( autoPassAllSpecials )
337                 {
338                         radAllSymbols.setSelection(true);
339                 }
340                 radAllSymbols.setBounds(10, 251, 120, 27);
341                 radAllSymbols.setText("All symbols");
342                 
343                 Button radOnlySelected = new Button(composite, SWT.RADIO);
344                 if( !autoPassAllSpecials )
345                 {
346                         radOnlySelected.setSelection(true);
347                 }
348                 radOnlySelected.setBounds(165, 251, 120, 27);
349                 radOnlySelected.setText("Only these:");
350                 
351                 txtSpecials = new Text(composite, SWT.BORDER);
352                 txtSpecials.setText(autoPassSpecials);
353                 txtSpecials.setBounds(291, 243, 312, 35);
354                 
355                 Button button_5 = new Button(composite, SWT.NONE);
356                 button_5.setText("Back");
357                 button_5.setBounds(10, 288, 48, 35);
358                 button_5.addSelectionListener(new SelectionListener() {
359                         
360                         @Override
361                         public void widgetSelected(SelectionEvent arg0) {
362                                 autoPassPageSaveValues();
363                                 updatePage( FkNewAccStep.PASSTYPE );
364                         }
365                         
366                         @Override
367                         public void widgetDefaultSelected(SelectionEvent arg0) {                                
368                         }
369                 });
370                 
371                 Button button_6 = new Button(composite, SWT.NONE);
372                 button_6.setText("Next");
373                 button_6.setBounds(555, 288, 48, 35);
374                 button_6.addSelectionListener(new SelectionListener() {
375                         
376                         @Override
377                         public void widgetSelected(SelectionEvent arg0) {
378                                 autoPassPageSaveValues();
379                                 updatePage( FkNewAccStep.SEPERATOR );
380                         }
381                         
382                         @Override
383                         public void widgetDefaultSelected(SelectionEvent arg0) {                                
384                         }
385                 });
386                 
387         Control[] controls = new Control[] { spnLen, radAllSymbols, radOnlySelected, button_6, button_5 };
388         composite.setTabList(controls);                 
389                 spnLen.setFocus();
390
391         }
392         
393         
394         void makePswField(Boolean showPsw)
395         {
396                 txtManPSW = new Text(composite, SWT.BORDER | ((showPsw)?0:SWT.PASSWORD) );
397                 fd_lblPassword.bottom = new FormAttachment(txtManPSW, 0, SWT.BOTTOM);
398                 FormData fd_txtManPSW = new FormData();
399                 fd_txtManPSW.right = new FormAttachment(100, -10);
400                 fd_txtManPSW.left = new FormAttachment(lblPassword, 6);
401                 fd_txtManPSW.top = new FormAttachment(lblTypeThePassword, 6);
402                 txtManPSW.setLayoutData(fd_txtManPSW);
403                 txtManPSW.setText(strPassword);
404                 txtManPSW.addModifyListener( new ModifyListener() {
405                         
406                         @Override
407                         public void modifyText(ModifyEvent arg0) {
408                                 strPassword = txtManPSW.getText();
409                                 if( txtManPSW.getText().length() > 0 )
410                                 {
411                                         btnManPassPageNext.setVisible(true);
412                                 } else {
413                                         btnManPassPageNext.setVisible(false);
414                                 }
415                                 
416                         }
417                 });
418                 
419                 chkShowPsw = new Button(composite, SWT.CHECK);
420                 FormData fd_chkShowPsw = new FormData();
421                 fd_chkShowPsw.top = new FormAttachment(txtManPSW, 6);
422                 fd_chkShowPsw.left = new FormAttachment(txtManPSW, 0, SWT.LEFT);
423                 chkShowPsw.setLayoutData(fd_chkShowPsw);
424                 chkShowPsw.setText("Show Password");
425                 chkShowPsw.setSelection(showPsw);
426                 
427                 chkShowPsw.addSelectionListener( new SelectionListener() {
428
429                         @Override
430                         public void widgetSelected(SelectionEvent arg0) {
431                                 Button btnChk = (Button)arg0.getSource();
432
433                                 txtManPSW.dispose();
434                                 
435                                 
436                                 if( btnChk.getSelection() )
437                                 {
438                                         chkShowPsw.dispose();
439                                         makePswField(true);
440                                 } else {
441                                         chkShowPsw.dispose();
442                                         makePswField(false);
443                                 }
444                                 
445                                 
446                         }
447                         
448                         @Override
449                         public void widgetDefaultSelected(SelectionEvent arg0) {
450                         }
451                 });             
452                 composite.layout();
453         }
454         
455
456         
457         void createPassManPage()
458         {
459                 composite = new Composite(shlNewAccount, SWT.NONE);
460                 composite.setLayout(new FormLayout());
461                 
462                 Button BtnBack1 = new Button(composite, SWT.NONE);
463                 FormData fd_BtnBack1 = new FormData();
464                 fd_BtnBack1.top = new FormAttachment(0, 288);
465                 fd_BtnBack1.left = new FormAttachment(0, 10);
466                 BtnBack1.setLayoutData(fd_BtnBack1);
467                 BtnBack1.setText("Back");
468                 BtnBack1.addSelectionListener( new SelectionListener() {
469                         
470                         @Override
471                         public void widgetSelected(SelectionEvent arg0) {
472                                 updatePage(FkNewAccStep.PASSTYPE);
473                         }
474                         
475                         @Override
476                         public void widgetDefaultSelected(SelectionEvent arg0) {
477                                 
478                         }
479                 });
480                 
481                 btnManPassPageNext = new Button(composite, SWT.NONE);
482                 FormData fd_button_4 = new FormData();
483                 fd_button_4.top = new FormAttachment(0, 288);
484                 fd_button_4.left = new FormAttachment(0, 555);
485                 btnManPassPageNext.setLayoutData(fd_button_4);
486                 btnManPassPageNext.setText("Next");
487                 btnManPassPageNext.setVisible(false);
488                 btnManPassPageNext.addSelectionListener( new SelectionListener() {
489                         
490                         @Override
491                         public void widgetSelected(SelectionEvent arg0) {
492                                 updatePage(FkNewAccStep.SEPERATOR);
493                         }
494                         
495                         @Override
496                         public void widgetDefaultSelected(SelectionEvent arg0) {                                
497                         }
498                 });
499                 
500                 lblTypeThePassword = new Label(composite, SWT.NONE);
501                 fd_lblTypeThePassword = new FormData();
502                 fd_lblTypeThePassword.top = new FormAttachment(0, 10);
503                 fd_lblTypeThePassword.left = new FormAttachment(0, 10);
504                 lblTypeThePassword.setLayoutData(fd_lblTypeThePassword);
505                 lblTypeThePassword.setText("Type the password your wish to use for ACCOUNT\nIn the box below.");
506                 
507                 lblPassword = new Label(composite, SWT.NONE);
508                 fd_lblPassword = new FormData();
509                 fd_lblPassword.left = new FormAttachment(BtnBack1, 0, SWT.LEFT);
510                 lblPassword.setLayoutData(fd_lblPassword);
511                 lblPassword.setText("Password:");
512                 
513                 makePswField(false);
514                 
515                 
516         Control[] controls = new Control[] { txtManPSW, btnManPassPageNext, BtnBack1 };
517         composite.setTabList(controls); 
518         txtManPSW.setFocus();
519                 
520         }
521         
522
523         void createSeperatorPage()
524         {
525                 composite = new Composite(shlNewAccount, SWT.NONE);
526                 composite.setLayout(new FormLayout());
527                 
528                 Label lblToMakeFinalkey = new Label(composite, SWT.NONE);
529                 FormData fd_lblToMakeFinalkey = new FormData();
530                 fd_lblToMakeFinalkey.top = new FormAttachment(0, 10);
531                 fd_lblToMakeFinalkey.left = new FormAttachment(0, 10);
532                 lblToMakeFinalkey.setLayoutData(fd_lblToMakeFinalkey);
533                 lblToMakeFinalkey.setText("When you trigger the Final Key to type an account (Username + Password), it\nwill also type a \"seperation\" key, to jump from the Username input to the\nPassword input. On most websites, the \"tab\" key is used for this.\nHowever, in some applications, the \"enter\" key is used.\nHere you can select which key can be used between the username and password\nfor this account.");
534                 
535                 radTabSep = new Button(composite, SWT.RADIO);
536                 if( seperatorTab )
537                 {
538                         radTabSep.setSelection(true);
539                 }
540                 FormData fd_radTabSep = new FormData();
541                 fd_radTabSep.top = new FormAttachment(lblToMakeFinalkey, 24);
542                 fd_radTabSep.left = new FormAttachment(0, 231);
543                 radTabSep.setLayoutData(fd_radTabSep);
544                 radTabSep.setText("Tab");
545                 
546                 Button radEnterSep = new Button(composite, SWT.RADIO);
547                 if( !seperatorTab )
548                 {
549                         radEnterSep.setSelection(true);
550                 }
551                 FormData fd_radEnterSep = new FormData();
552                 fd_radEnterSep.top = new FormAttachment(radTabSep, 6);
553                 fd_radEnterSep.left = new FormAttachment(radTabSep, 0, SWT.LEFT);
554                 radEnterSep.setLayoutData(fd_radEnterSep);
555                 radEnterSep.setText("Enter");
556                 
557                 Button button_7 = new Button(composite, SWT.NONE);
558                 button_7.setText("Back");
559                 FormData fd_button_7 = new FormData();
560                 fd_button_7.bottom = new FormAttachment(100, -10);
561                 fd_button_7.left = new FormAttachment(0, 10);
562                 button_7.setLayoutData(fd_button_7);
563                 button_7.addSelectionListener(new SelectionListener() {
564                         
565                         @Override
566                         public void widgetSelected(SelectionEvent arg0) {
567                                 seperatorTab = radTabSep.getSelection();
568                                 if( autoPassword )
569                                 {
570                                         updatePage(FkNewAccStep.PASS_AUT);
571                                 } else {
572                                         updatePage(FkNewAccStep.PASS_MAN);
573                                 }
574                         }
575                         
576                         @Override
577                         public void widgetDefaultSelected(SelectionEvent arg0) {
578                         }
579                 });
580                 
581                 Button button_8 = new Button(composite, SWT.NONE);
582                 button_8.setText("Next");
583                 FormData fd_button_8 = new FormData();
584                 fd_button_8.bottom = new FormAttachment(button_7, 0, SWT.BOTTOM);
585                 fd_button_8.right = new FormAttachment(lblToMakeFinalkey, 0, SWT.RIGHT);
586                 button_8.setLayoutData(fd_button_8);
587                 button_8.addSelectionListener(new SelectionListener() {
588                         
589                         @Override
590                         public void widgetSelected(SelectionEvent arg0) {
591                                 seperatorTab = radTabSep.getSelection();
592                                 updatePage(FkNewAccStep.REVIEW);
593                         }
594                         
595                         @Override
596                         public void widgetDefaultSelected(SelectionEvent arg0) {
597                         }
598                 });
599                 
600
601         Control[] controls = new Control[] { radTabSep, radEnterSep, button_8, button_7 };
602         composite.setTabList(controls);         
603         radTabSep.setFocus();
604                 
605         }
606         
607
608         void createReviewPage()
609         {
610                 composite = new Composite(shlNewAccount, SWT.NONE);
611                 composite.setLayout(new FormLayout());
612                 
613                 Label lblHeresAnOverview = new Label(composite, SWT.NONE);
614                 FormData fd_lblHeresAnOverview = new FormData();
615                 fd_lblHeresAnOverview.right = new FormAttachment(0, 603);
616                 fd_lblHeresAnOverview.top = new FormAttachment(0, 10);
617                 fd_lblHeresAnOverview.left = new FormAttachment(0, 10);
618                 lblHeresAnOverview.setLayoutData(fd_lblHeresAnOverview);
619                 lblHeresAnOverview.setText("Here's an overview of the account information");
620                 
621                 Label lblAccountName = new Label(composite, SWT.NONE);
622                 FormData fd_lblAccountName = new FormData();
623                 fd_lblAccountName.left = new FormAttachment(0, 120);
624                 fd_lblAccountName.top = new FormAttachment(lblHeresAnOverview, 18);
625                 lblAccountName.setLayoutData(fd_lblAccountName);
626                 lblAccountName.setText("Account Name:");
627                 
628                 Label lblPasswordType = new Label(composite, SWT.NONE);
629                 FormData fd_lblPasswordType = new FormData();
630                 fd_lblPasswordType.right = new FormAttachment(lblAccountName, 0, SWT.RIGHT);
631                 lblPasswordType.setLayoutData(fd_lblPasswordType);
632                 lblPasswordType.setText("Password:");
633                 
634                 Label lblUserName = new Label(composite, SWT.NONE);
635                 fd_lblPasswordType.top = new FormAttachment(lblUserName, 6);
636                 FormData fd_lblUserName = new FormData();
637                 fd_lblUserName.top = new FormAttachment(lblAccountName, 6);
638                 fd_lblUserName.right = new FormAttachment(lblAccountName, 0, SWT.RIGHT);
639                 lblUserName.setLayoutData(fd_lblUserName);
640                 lblUserName.setText("User Name:");
641                 
642                 Label lblIfEverythingLooks = new Label(composite, SWT.NONE);
643                 FormData fd_lblIfEverythingLooks = new FormData();
644                 fd_lblIfEverythingLooks.top = new FormAttachment(lblPasswordType, 49);
645                 fd_lblIfEverythingLooks.left = new FormAttachment(lblHeresAnOverview, 0, SWT.LEFT);
646                 lblIfEverythingLooks.setLayoutData(fd_lblIfEverythingLooks);
647                 lblIfEverythingLooks.setText("If everything looks okay, press save and wait until the Final Key blinks,\nwhen it blinks, press the button to allow the account to be saved.");
648                 
649                 Label lblSeperator = new Label(composite, SWT.NONE);
650                 FormData fd_lblSeperator = new FormData();
651                 fd_lblSeperator.top = new FormAttachment(lblPasswordType, 6);
652                 fd_lblSeperator.right = new FormAttachment(lblAccountName, 0, SWT.RIGHT);
653                 lblSeperator.setLayoutData(fd_lblSeperator);
654                 lblSeperator.setText("Seperator:");
655                 
656                 Button button_9 = new Button(composite, SWT.NONE);
657                 button_9.setText("Back");
658                 FormData fd_button_9 = new FormData();
659                 fd_button_9.bottom = new FormAttachment(100, -10);
660                 fd_button_9.left = new FormAttachment(lblHeresAnOverview, 0, SWT.LEFT);
661                 button_9.setLayoutData(fd_button_9);
662                 button_9.addSelectionListener( new SelectionListener() {
663                         
664                         @Override
665                         public void widgetSelected(SelectionEvent arg0) {
666                                 updatePage(FkNewAccStep.SEPERATOR);
667                         }
668                         
669                         @Override
670                         public void widgetDefaultSelected(SelectionEvent arg0) {                
671                         }
672                 });
673                 
674                 Button btnSave = new Button(composite, SWT.NONE);
675                 FormData fd_btnSave = new FormData();
676                 fd_btnSave.bottom = new FormAttachment(button_9, 0, SWT.BOTTOM);
677                 fd_btnSave.right = new FormAttachment(lblHeresAnOverview, 0, SWT.RIGHT);
678                 btnSave.setLayoutData(fd_btnSave);
679                 btnSave.setText("Save");
680                 btnSave.setFocus();
681                 
682                 btnSave.addSelectionListener( new SelectionListener() {
683                         
684                         @Override
685                         public void widgetSelected(SelectionEvent arg0) {
686                                 MessageBox dialog = new MessageBox(shlNewAccount, SWT.ICON_INFORMATION | SWT.OK );
687                                 dialog.setText("Get ready");
688                                 dialog.setMessage("When you press OK, The Final Key will start blinking, you then have 5 seconds to press the button to save the account.");
689                                 dialog.open();
690                                 FkManager.getInstance().createAccount( strAccountName, strUserName, autoPassword, autoPassLen, autoPassAllSpecials, autoPassSpecials, strPassword, seperatorTab, mySelf );
691                                 updatePage(FkNewAccStep.SAVING);
692                         }
693                         
694                         @Override
695                         public void widgetDefaultSelected(SelectionEvent arg0) {
696                                 
697                         }
698                 });
699                 
700                 Label lblAccName = new Label(composite, SWT.NONE);
701                 FormData fd_lblAccName = new FormData();
702                 fd_lblAccName.right = new FormAttachment(lblHeresAnOverview, 0, SWT.RIGHT);
703                 fd_lblAccName.top = new FormAttachment(lblHeresAnOverview, 18);
704                 fd_lblAccName.left = new FormAttachment(lblAccountName, 6);
705                 lblAccName.setLayoutData(fd_lblAccName);
706                 lblAccName.setText(strAccountName);
707                 
708                 Label lblUsrName = new Label(composite, SWT.NONE);
709                 FormData fd_lblUsrName = new FormData();
710                 fd_lblUsrName.top = new FormAttachment(lblAccName, 6);
711                 fd_lblUsrName.left = new FormAttachment(lblUserName, 6);
712                 fd_lblUsrName.right = new FormAttachment(100, -10);
713                 lblUsrName.setLayoutData(fd_lblUsrName);
714                 lblUsrName.setText(strUserName);
715                 
716                 Label lblPasswordInfo = new Label(composite, SWT.NONE);
717                 
718                 String passInfo;
719                 if( autoPassword )
720                 {
721                         passInfo = "Automatic, " + autoPassLen + " long, ";
722                         if( autoPassAllSpecials )
723                         {
724                                 passInfo += "all specials";
725                         } else {
726                                 passInfo += "{"+autoPassSpecials+ "}";
727                         }
728                         
729                 } else {
730                         passInfo ="Manual, " + strPassword.length() +" long";
731                 }
732                 
733                 lblPasswordInfo.setText(passInfo);
734                 FormData fd_lblPasswordInfo = new FormData();
735                 fd_lblPasswordInfo.right = new FormAttachment(lblPasswordType, 373, SWT.RIGHT);
736                 fd_lblPasswordInfo.top = new FormAttachment(lblUsrName, 6);
737                 fd_lblPasswordInfo.left = new FormAttachment(lblPasswordType, 6);
738                 lblPasswordInfo.setLayoutData(fd_lblPasswordInfo);
739                 
740                 Label lblSeperatorInfo = new Label(composite, SWT.NONE);
741                 
742                 String sepInfo;
743                 if( seperatorTab )
744                 {
745                         sepInfo = "Tab Key";
746                 } else {
747                         sepInfo = "Enter Key";
748                 }
749                 
750                 lblSeperatorInfo.setText(sepInfo);
751                 FormData fd_lblSeperatorInfo = new FormData();
752                 fd_lblSeperatorInfo.right = new FormAttachment(lblSeperator, 373, SWT.RIGHT);
753                 fd_lblSeperatorInfo.top = new FormAttachment(lblPasswordInfo, 6);
754                 fd_lblSeperatorInfo.left = new FormAttachment(lblSeperator, 6);
755                 lblSeperatorInfo.setLayoutData(fd_lblSeperatorInfo);
756                 
757         Control[] controls = new Control[] { btnSave, button_9 };
758         composite.setTabList(controls);                         
759
760         }
761         
762         void createSavingPage()
763         {
764                 composite = new Composite(shlNewAccount, SWT.NONE);
765                 composite.setLayout(new FormLayout());
766                 
767                 txtBUSYMSG = new Label(composite, SWT.NONE);
768                 FormData fd_lblSaving = new FormData();
769                 fd_lblSaving.right = new FormAttachment(0, 603);
770                 fd_lblSaving.top = new FormAttachment(0, 10);
771                 fd_lblSaving.left = new FormAttachment(0, 10);
772                 txtBUSYMSG.setLayoutData(fd_lblSaving);
773                 txtBUSYMSG.setText("Working...");
774                 
775                 animation = new Animation(shlNewAccount, SWT.NONE, 4);
776                 animation.setBounds(10, 32, 32, 32);
777                 animation.setVisible(true);
778                 animation.addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey1.png") );
779                 animation.addFrame( SWTResourceManager.getImage(MainWin.class, "/fkgui/gfx/finalkey2.png") );
780                 animation.setPlaying(true);
781                 FormData fdAni = new FormData();
782                 fdAni.top = new FormAttachment(txtBUSYMSG);
783                 
784
785                 
786         }
787         
788         
789         private void updatePage(FkNewAccStep curPage)
790         {
791                 if(composite != null && !composite.isDisposed() )
792                 {
793                         composite.dispose();
794                 }
795                 System.out.println(curPage);
796                 
797                 switch(curPage)
798                 {
799                 case CLICKBTN:
800                         break;
801                 case NAMES:
802                         createNamePage();
803                         break;
804                 case PASSTYPE:
805                         createPassTypePage();
806                         break;
807                 case PASS_AUT:
808                         createPassAutPage();
809                         break;
810                 case PASS_MAN:
811                         createPassManPage();
812                         break;
813                 case REVIEW:
814                         createReviewPage();
815                         break;
816                 case SEPERATOR:
817                         createSeperatorPage();
818                         break;
819                 case SAVING:
820                         createSavingPage();
821                         break;
822
823                         
824                 }
825                 
826                 shlNewAccount.layout();
827         }
828         /**
829          * Create contents of the dialog.
830          */
831         private void createContents() {
832                 shlNewAccount = new Shell(getParent(), getStyle());
833                 shlNewAccount.setSize(625, 394);
834                 shlNewAccount.setText("Create New Account");
835                 shlNewAccount.setLayout(new FillLayout(SWT.HORIZONTAL));
836                 
837         //      TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
838                 
839                 //TabItem tbtmStepUsername = new TabItem(tabFolder, SWT.NONE);
840                 //tbtmStepUsername.setText("Name");
841                 
842                 updatePage(FkNewAccStep.NAMES);
843
844         }
845
846         @Override
847         public void fkActionEvent(FkActionEvent event) {
848                 //System.out.println( "Event data:"+ event.data );
849                 MessageBox dialog;
850                 Boolean closeSelf=false;
851                 
852                 switch(event.type)
853                 {
854                 case ACTION_ABORTED:
855                         txtBUSYMSG.setText("Error.");
856                         dialog = new MessageBox(shlNewAccount, SWT.ICON_WARNING);
857                         dialog.setText("Account not created");
858                         dialog.setMessage("The account was not created.\nMaybe you were not quick enough to press FinalKey button?\nPlease try again.");
859                         dialog.open();
860                         updatePage(FkNewAccStep.REVIEW);                        
861                         break;
862                 case ACTION_ERROR:
863                         txtBUSYMSG.setText("Error.");
864
865                         dialog = new MessageBox(shlNewAccount, SWT.ICON_ERROR);
866                         dialog.setText("Error");
867                         dialog.setMessage("There was an error creating the acccount, please reconnect to FinalKey and try again.");
868                         dialog.open();
869                         closeSelf=true;
870                         break;
871                 case ACTION_OKAY:
872                         txtBUSYMSG.setText("Account saved.");
873                         dialog = new MessageBox(shlNewAccount, SWT.ICON_INFORMATION);
874                         dialog.setText("Account created");
875                         dialog.setMessage("The account was created.");
876                         dialog.open();
877                         closeSelf=true;
878                         break;
879                 case ACTION_WAITING:
880                         txtBUSYMSG.setText("Waiting for buttonpress...");
881                         break;
882                 case ACTION_WORKING:
883                         txtBUSYMSG.setText("Saving...");
884                         animation.setVisible(false);
885                         break;
886                 }
887                 
888                 if( !shlNewAccount.isDisposed() && closeSelf )
889                 {
890                         shlNewAccount.close();
891                 }
892         }
893 }