KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > NewAccountWindow


1 import whisper.*;
2 import java.awt.*;
3 import java.awt.event.*;
4 import java.io.File JavaDoc;
5 import java.io.FileOutputStream JavaDoc;
6 import java.security.SecureRandom JavaDoc;
7 import javax.swing.*;
8 import javax.swing.border.*;
9 import org.jivesoftware.smack.*;
10
11 /** Window for creating a new account.*/
12 public class NewAccountWindow{
13
14     private String JavaDoc helpTopic=new String JavaDoc("new.html"); //current help-topic, dependant on which frame isvisible
15
private static final int GAP=10; //gap in pixels between components
16
private static final int NO_OF_PANELS=4;
17     
18     private final SecureRandom JavaDoc sr=new SecureRandom JavaDoc();
19
20     final JFrame frame=new JFrame(Lang.gs("new account title"));
21     final JPanel btnPanel=new JPanel(new FlowLayout(FlowLayout.TRAILING,GAP,GAP));
22     final JPanel titlePanel=new JPanel();
23     final CardLayout cardLayout=new CardLayout(GAP,GAP);
24     final JPanel layersPanel=new JPanel(cardLayout); // card layout panel
25
final JPanel panels[]=new JPanel[NO_OF_PANELS]; //the individual set panels
26

27     int current=0;
28     Cursor normal;
29     
30     // 0 First panel components - Account info
31
final JLabel accountNameLbl=new JLabel(System.getProperties().getProperty("user.name")); //normal
32
final JTextField accountNameField=new JTextField(8); // for shared machines
33
final JLabel accountLbl=new JLabel(Lang.gs("account"));
34         // jabber settings panel
35
final JPanel jabberPanel=new JPanel(new GridLayout(7,2,GAP,GAP));
36         final JLabel jabberUsernameLbl=new JLabel(Lang.gs("jabber_username"));
37         final JTextField jabberUsername=new JTextField(15);
38         final JLabel jabberServerLbl=new JLabel(Lang.gs("jabber_server"));
39         final JTextField jabberServer=new JTextField(15);
40         final JLabel jabberPasswordLbl=new JLabel(Lang.gs("jabber_password"));
41         final JPasswordField jabberPassword=new JPasswordField(15);
42         final JLabel jabberRememberPassLbl=new JLabel(Lang.gs("remember password"));
43         final JCheckBox jabberRememberPass=new JCheckBox("",true);
44         final JLabel jabberResourceLbl=new JLabel(Lang.gs("jabber_resource"));
45         final JTextField jabberResource=new JTextField("here");
46         final JLabel jabberSSLLbl=new JLabel(Lang.gs("jabber_ssl"));
47         final JCheckBox jabberSSL=new JCheckBox("",true);
48         final JLabel blank=new JLabel();
49         final JButton jabberNewBtn=new JButton(Lang.gs("jabber_new"));
50     //1 second panel - Key generation
51
final JLabel generationInfoLbl=new JLabel("<html><p>"+Lang.gs("generation info")+"</p></html>");
52     final JPanel passphrasePanel=new JPanel(new SpringLayout());
53         final JPasswordField passphrase1=new JPasswordField(30);
54         final JLabel passphraseLbl1=new JLabel(Lang.gs("passphrase"));
55         final JPasswordField passphrase2=new JPasswordField(30);
56         final JLabel passphraseLbl2=new JLabel(Lang.gs("reenter passphrase"));
57     final JProgressBar keyProgress=new JProgressBar(0,1);
58     // 2 Third Panel
59
final JLabel readyLbl=new JLabel("<html><p>"+Lang.gs("ready")+"</p><p><ul><li>"+Lang.gs("account"));
60     // 3 Fourth Panel - the last one
61
final JLabel lastLbl=new JLabel("<html><p>"+Lang.gs("done")+"</p></html>");
62     
63     // Buttons
64
final JButton backBtn=new JButton(Lang.gs("back"),Icons.BACK);
65     final JButton nextBtn=new JButton(Lang.gs("next"),Icons.NEXT);
66     final JButton cancelBtn=new JButton(Lang.gs("cancel"),Icons.CANCEL);
67     final JButton helpBtn=new JButton(Lang.gs("help"),Icons.HELP);
68     
69     final JLabel title=new JLabel(Lang.gs("title0"));
70     final BtnClick click=new BtnClick();
71     NewKeyPairThread newKeyPairThread=new NewKeyPairThread();
72     final JWaitDialog wait=new JWaitDialog(frame,"talk with server");
73     
74     /** Creates a new NewAccountWindow.
75     * @param parent The frame of the window creating this NewAccountWindow.
76     * Usually the JFrame of a LogInFrame instance.*/

77     public NewAccountWindow(){
78         frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
79         frame.setIconImage(Icons.NEW_ACCOUNT.getImage());
80         normal=frame.getCursor();
81         Container cp=frame.getContentPane();
82         cp.setLayout(new BorderLayout());
83         // Button pannel
84
nextBtn.setMnemonic(Lang.s2k("next_mn"));
85         backBtn.setMnemonic(Lang.s2k("back_mn"));
86         backBtn.setEnabled(false); //disabled for first panel
87
cancelBtn.setMnemonic(Lang.s2k("cancel_mn"));
88         helpBtn.setMnemonic(Lang.s2k("help_mn"));
89         btnPanel.add(helpBtn);
90         btnPanel.add(backBtn);
91         btnPanel.add(nextBtn);
92         btnPanel.add(cancelBtn);
93         nextBtn.setDefaultCapable(true);
94         frame.getRootPane().setDefaultButton(nextBtn);
95         helpBtn.addActionListener(click);
96         backBtn.addActionListener(click);
97         nextBtn.addActionListener(click);
98         cancelBtn.addActionListener(click);
99         btnPanel.setPreferredSize(btnPanel.getMinimumSize());
100         // Title panel
101
title.setHorizontalAlignment(SwingConstants.CENTER);
102         titlePanel.add(title);
103         titlePanel.setPreferredSize(titlePanel.getMinimumSize());
104         // First panel
105
panels[0]=new JPanel(new SpringLayout());
106         accountLbl.setToolTipText(Lang.gs("account_tt"));
107         GUI.connect(accountLbl,accountNameField,"account_mn","account_tt");
108         if(WhisperIM.sharedMachine){
109             accountNameField.setMaximumSize(accountNameField.getPreferredSize());
110             accountLbl.setLabelFor(accountNameField);
111             panels[0].add(GUI.panel(accountLbl,accountNameField,GAP));
112         }
113         else{
114             accountNameLbl.setToolTipText(Lang.gs("account_tt"));
115             accountNameLbl.setMaximumSize(accountNameLbl.getPreferredSize());
116             panels[0].add(GUI.panel(accountLbl,accountNameLbl,GAP));
117         }
118         // jabber panel
119
jabberPanel.setBorder(new TitledBorder(new LineBorder(Color.BLACK),Lang.gs("jabber_settings")));
120         GUI.connect(jabberUsernameLbl,jabberUsername,"jabber_username_mn","jabber_username_tt");
121         GUI.connect(jabberServerLbl,jabberServer,"jabber_server_mn","jabber_server_tt");
122         GUI.connect(jabberPasswordLbl,jabberPassword,"jabber_password_mn","jabber_password_tt");
123         GUI.connect(jabberRememberPassLbl,jabberRememberPass,null,"remember password_tt");
124         GUI.connect(jabberResourceLbl,jabberResource,"jabber_resource_mn","jabber_resource_tt");
125         GUI.connect(jabberSSLLbl,jabberSSL,null,"jabber_ssl_tt");
126         jabberNewBtn.setMnemonic(Lang.s2k("jabber_new_mn"));
127         jabberNewBtn.setToolTipText(Lang.gs("jabber_new_tt"));
128         jabberSSLLbl.setIcon(Icons.PADLOCK);
129         jabberPanel.add(jabberUsernameLbl);
130         jabberPanel.add(jabberUsername);
131         jabberPanel.add(jabberServerLbl);
132         jabberPanel.add(jabberServer);
133         jabberPanel.add(jabberPasswordLbl);
134         jabberPanel.add(jabberPassword);
135         jabberPanel.add(jabberRememberPassLbl);
136         jabberPanel.add(jabberRememberPass);
137         jabberPanel.add(jabberResourceLbl);
138         jabberPanel.add(jabberResource);
139         jabberPanel.add(jabberSSLLbl);
140         jabberPanel.add(jabberSSL);
141         jabberPanel.add(blank);
142         jabberPanel.add(jabberNewBtn);
143         jabberNewBtn.addActionListener(click);
144         // set default values
145
jabberUsername.setText(System.getProperties().getProperty("user.name"));
146         jabberServer.setText(WhisperIM.Config.getProperty("jabberDefaultServer"));
147         jabberResource.setText(WhisperIM.Config.getProperty("jabberDefaultResource"));
148         // jabber panel control based on config
149
if(WhisperIM.Config.getProperty("jabberLockToUserName").equals("true")){
150             jabberUsername.setEnabled(false);
151         }
152         if(WhisperIM.Config.getProperty("jabberLockToDefaultServer").equals("true")){
153             jabberServer.setEnabled(false);
154         }
155         if(WhisperIM.Config.getProperty("jabberLockToDefaultResource").equals("true")){
156             jabberResource.setEnabled(false);
157         }
158         if(WhisperIM.Config.getProperty("jabberAllowNewAccounts").equals("false")){
159             jabberNewBtn.setVisible(false);
160         }
161         if(WhisperIM.Config.getProperty("jabberAllowNonSSL").equals("false")){
162             jabberSSL.setEnabled(false);
163         }
164         
165         panels[0].add(jabberPanel);
166         SpringUtilities.makeCompactGrid(panels[0],
167                          2, 1, //rows, cols
168
GAP, GAP, //initialX, initialY
169
GAP,GAP);//xPad, yPad
170
// second panel
171
panels[1]=new JPanel(new BorderLayout(GAP,GAP));
172         panels[1].add(generationInfoLbl,BorderLayout.NORTH);
173         Box passphraseBox=new Box(BoxLayout.Y_AXIS);
174         GUI.connect(passphraseLbl1,passphrase1,"passphrase_mn",null);
175         GUI.connect(passphraseLbl2,passphrase2,"reenter passphrase_mn",null);
176         passphrasePanel.add(passphraseLbl1);
177         passphrasePanel.add(passphrase1);
178         passphrasePanel.add(passphraseLbl2);
179         passphrasePanel.add(passphrase2);
180         SpringUtilities.makeCompactGrid(passphrasePanel,2,2,GAP,GAP,GAP,GAP);
181         passphrasePanel.setMaximumSize(passphrasePanel.getPreferredSize());
182         passphraseBox.add(passphrasePanel);
183         passphraseBox.add(Box.createGlue());
184         panels[1].add(passphraseBox,BorderLayout.CENTER);
185         keyProgress.setStringPainted(true);
186         keyProgress.setString(Lang.gs("generating key"));
187         keyProgress.setIndeterminate(true);
188         panels[1].add(keyProgress,BorderLayout.SOUTH);
189         // third panel
190
panels[2]=new JPanel(new BorderLayout(GAP,GAP));
191         panels[2].add(readyLbl,BorderLayout.NORTH);
192         // Last panel
193
panels[3]=new JPanel(new BorderLayout(GAP,GAP));
194         panels[3].add(lastLbl,BorderLayout.NORTH);
195         // add individual step panels to layers panel
196
for(int i=0;i<NO_OF_PANELS;i++){
197             layersPanel.add(panels[i],i+"");
198         }
199         layersPanel.setSize(layersPanel.getMinimumSize());
200         // add layers and button panel to content frame
201
cp.add(titlePanel, BorderLayout.NORTH);
202         cp.add(layersPanel, BorderLayout.CENTER);
203         cp.add(btnPanel,BorderLayout.SOUTH);
204         frame.pack();
205         frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(WhisperIM.HELP_KEY,0),"help"); //put in help key for action help
206
frame.getRootPane().getActionMap().put("help",new HelpAction(frame,helpTopic));
207         frame.setSize(frame.getMinimumSize());
208         frame.setLocationRelativeTo(null);
209     }
210     
211     /** Shows the frame.*/
212     public void show(){
213         WhisperIM.KEYPAIR=null;
214         cardLayout.first(layersPanel);
215         title.setText(Lang.gs("title0"));
216         current=0;
217         backBtn.setEnabled(false);
218         cancelBtn.setEnabled(true);
219         nextBtn.setText(Lang.gs("next"));
220         nextBtn.setMnemonic(Lang.s2k("next_mn"));
221         nextBtn.setEnabled(true);
222         nextBtn.setIcon(Icons.NEXT);
223         frame.setCursor(normal);
224         frame.show();
225     }
226     
227     /** Disposes the dialog.*/
228     public void dispose(){
229         // set the progress bars to end or we wont dispose properly
230
// dispose of the top frame
231
keyProgress.setIndeterminate(false);
232         if(newKeyPairThread.isAlive()){
233             newKeyPairThread.interrupt();
234         }
235         frame.dispose();
236     }
237     
238     /** Method called when the panel is shown,
239     * from back or next.*/

240     private void doEnter(){
241         if(current==0){ //first panel
242
backBtn.setEnabled(false);
243             nextBtn.setEnabled(true);
244             frame.setCursor(GUI.NORMAL);
245             return;
246         }
247         if(current==1){ //second panel
248
keyProgress.setVisible(false);
249             passphrase1.setEnabled(true);
250             passphrase2.setEnabled(true);
251             passphrase1.setText("");
252             passphrase2.setText("");
253             passphrase1.requestFocus();
254             nextBtn.setEnabled(true);
255             return;
256         }
257         if(current==2){
258             if(WhisperIM.sharedMachine){
259                 readyLbl.setText(readyLbl.getText()+" "+accountNameField.getText()+"</li><li>"+Lang.gs("jabber_username")+" "+jabberUsername.getText()+"@"+jabberServer.getText()+"</li></ul></p></html>");
260             }
261             else{
262                 readyLbl.setText(readyLbl.getText()+" "+accountNameLbl.getText()+"</li><li>"+Lang.gs("jabber_username")+" "+jabberUsername.getText()+"@"+jabberServer.getText()+"</li></ul></p></html>");
263             }
264         }
265         if(current==NO_OF_PANELS-1){ //last panel
266
backBtn.setEnabled(false);
267             cancelBtn.setEnabled(false);
268             nextBtn.setText(Lang.gs("finish"));
269             nextBtn.setMnemonic(Lang.s2k("finish_mn"));
270             nextBtn.setIcon(Icons.FINISHED);
271         }
272     }
273     
274     /** Method called when next button is clicked.*/
275     private void doNext(){
276         //panel specific code
277
if(current==0){//first panel
278
// validate data
279
if(WhisperIM.sharedMachine){
280                 if(accountNameField.getText().compareTo("")==0){
281                     showInfo("you must enter a account name");
282                     accountNameField.requestFocus();
283                     return;
284                 }
285                 // trim and set account name to max of 8 characters
286
String JavaDoc accountName=accountNameField.getText().trim();
287                 if(accountName.length()==0){
288                     showInfo("you must enter a account name");
289                     accountNameField.setText("");
290                     accountNameField.requestFocus();
291                     return;
292                 }
293                 accountNameField.setText(accountName);
294                 if(accountName.length()>8){
295                     accountName=accountName.substring(0,8).trim();
296                     accountNameField.setText(accountName);
297                     if(accountName.length()==0){
298                         showInfo("you must enter a account name");
299                         accountNameField.setText("");
300                         accountNameField.requestFocus();
301                         return;
302                     }
303                 }
304                 File JavaDoc tmp=new File JavaDoc(WhisperIM.accountDir,accountName);
305                 if(tmp.exists() && tmp.isDirectory()){
306                     showInfo("account name already exists");
307                     accountNameField.requestFocus();
308                     return;
309                 }
310                 
311             }
312             if(!jabberOk()){
313                 return;
314             }
315             
316             backBtn.setEnabled(true);
317         }
318
319         // 2nd panel key generation
320
if(current==1){
321             // validate passphrase
322
String JavaDoc p1=new String JavaDoc(passphrase1.getPassword());
323             String JavaDoc p2=new String JavaDoc(passphrase2.getPassword());
324             if(p1.length()<20){
325                 showInfo("passphrase too short");
326                 passphrase1.requestFocus();
327                 return;
328             }
329             if(!p1.equals(p2)){
330                 showInfo("passphrase mismatch");
331                 passphrase2.requestFocus();
332                 return;
333             }
334             p1=null;
335             p2=null;
336             nextBtn.setEnabled(false);
337             keyProgress.setIndeterminate(true);
338             keyProgress.setVisible(true);
339             frame.setCursor(GUI.WAIT);
340             passphrase1.setEnabled(false);
341             passphrase2.setEnabled(false);
342             newKeyPairThread=new NewKeyPairThread();
343             newKeyPairThread.start();
344             return;
345         }
346         if(current==2){
347             frame.setCursor(GUI.WAIT);
348             if(WhisperIM.sharedMachine){
349                 WhisperIM.userDir=new File JavaDoc(WhisperIM.accountDir,accountNameField.getText());
350             }
351             // create directory
352
if(!WhisperIM.userDir.exists()){// check not already created
353
if(WhisperIM.userDir.mkdir()==false){
354                     frame.setCursor(GUI.NORMAL);
355                     try{
356                         GUI.showError(frame,"new account title","cannot create userdir",WhisperIM.userDir.getCanonicalPath());
357                     }
358                     catch(Exception JavaDoc e){
359                         GUI.showError(frame,"new account title","cannot create userdir");
360                     }
361                     return;
362                 }
363             }
364             
365             // save preference file
366
try{
367                 if(WhisperIM.isMac){
368                     WhisperIM.UserPref.setProperty("laf","native");
369                 }
370                 WhisperIM.UserPref.store(new FileOutputStream JavaDoc(new File JavaDoc(WhisperIM.userDir,WhisperIM.USER_PREF_FILE_NAME),false),"Whisper preferences");
371             }
372             catch(Exception JavaDoc e2){
373                 frame.setCursor(GUI.NORMAL);
374                 GUI.showError(frame,"new account title","cannot save",e2.getMessage());
375                 return;
376             }
377             // key pair
378
try{
379                 byte salt[]=new byte[64];
380                 WhisperIM.SR.nextBytes(salt);
381                 WhisperOutputStream wos=new WhisperOutputStream(new File JavaDoc(WhisperIM.userDir,WhisperIM.KEYPAIR_FILENAME), Util.passphrase2Key(passphrase1.getPassword(),salt), WhisperIM.SR, salt);
382                 wos.write(WhisperIM.KEYPAIR.publicKey());
383                 wos.write(WhisperIM.KEYPAIR.privateKey());
384                 wos.close();
385             }
386             catch(Exception JavaDoc e3){
387                 frame.setCursor(GUI.NORMAL);
388                 GUI.showError(frame,"new account title","cannot save keypair",e3.getMessage());
389                 return;
390             }
391             // key cache key
392
// create the key cache key
393
WhisperIM.SR.nextBytes(WhisperIM.MainWindow.keycachekey);
394             // encrypt using RSA
395
byte[] encryptedkck=RSA.encryptSessionKey(WhisperIM.MainWindow.keycachekey,WhisperIM.KEYPAIR.publicKey().getN(),RSAKeyPair.E17 ,WhisperIM.SR);
396             //Write out
397
try{
398                 FileOutputStream JavaDoc kckos=new FileOutputStream JavaDoc(new File JavaDoc(WhisperIM.userDir,WhisperIM.KCK_FILE_NAME),false);
399                 kckos.write(Util.arrayLength(encryptedkck)); //prepend with length of ekck as 2 bytes
400
kckos.write(encryptedkck);
401                 kckos.flush();
402                 kckos.close();
403                 Util.wipe(encryptedkck);
404             }
405             catch(Exception JavaDoc e4){
406                 frame.setCursor(GUI.NORMAL);
407                 GUI.showError(frame,"new account title","cannot save keypair",e4.getMessage());
408                 return;
409             }
410             // account settings
411
WhisperIM.accountSettings.JabberUserName=jabberUsername.getText();
412             WhisperIM.accountSettings.JabberServer=jabberServer.getText();
413             WhisperIM.accountSettings.JabberPassword=new String JavaDoc(jabberPassword.getPassword());
414             WhisperIM.accountSettings.JabberResource=jabberResource.getText();
415             WhisperIM.accountSettings.JabberRememberPassword=jabberRememberPass.isSelected();
416             try{
417                 WhisperIM.accountSettings.Save();
418             }
419             catch (Exception JavaDoc e){
420                 frame.setCursor(GUI.NORMAL);
421                 GUI.showError(frame,"new account title","cannot save",e.getMessage());
422                 return;
423             }
424             //backup
425
try{
426                 BackUp.backUp(new File JavaDoc(WhisperIM.userDir,AccountSettings.FILENAME));
427                 BackUp.backUp(new File JavaDoc(WhisperIM.userDir,WhisperIM.KEYPAIR_FILENAME));
428                 BackUp.backUp(new File JavaDoc(WhisperIM.userDir,WhisperIM.KCK_FILE_NAME));
429             }
430             catch(Exception JavaDoc bue){
431                 bue.printStackTrace();
432             }
433             frame.setCursor(GUI.NORMAL);
434             passphrase1.setText("");
435             passphrase2.setText("");
436         }
437         // Last panel - finished
438
if(current==NO_OF_PANELS-1){
439             // get rid of other windows
440
frame.hide();
441             WhisperIM.Login_Window.dispose();
442             WhisperIM.Login_Window=null;
443             if(WhisperIM.Config_Window!=null){
444                 WhisperIM.Config_Window.dispose();
445                 WhisperIM.Config_Window=null;
446             }
447             //show main window
448
if(WhisperIM.sharedMachine){
449                 WhisperIM.MainWindow.show_new(accountNameField.getText());
450             }
451             else{
452                 WhisperIM.MainWindow.show_new(accountNameLbl.getText());
453             }
454             // dispose of this
455
frame.dispose();
456             WhisperIM.New_Account_Window=null;
457             return;
458         }
459         showNext();
460         doEnter();
461     }
462     
463     /** Shows the next panel.*/
464     private void showNext(){
465         current++;
466         title.setText(Lang.gs("title"+current));
467         cardLayout.next(layersPanel);
468     }
469     
470     /** Displays an info dialog with a title of new account title.*/
471     private void showInfo(String JavaDoc message){
472         GUI.showInfo(frame,"new account title",message);
473     }
474     
475     /** Checks the jabber fields.
476     * Returns false if there is a problem.*/

477     private boolean jabberOk(){
478         if(jabberUsername.getText().equals("")){
479             showInfo("enter a user name");
480             jabberUsername.requestFocus();
481             return false;
482         }
483         if(jabberServer.getText().equals("")){
484             showInfo("you must enter servername");
485             jabberServer.requestFocus();
486             return false;
487         }
488         if(jabberPassword.getPassword().length==0){
489             showInfo("you must enter password");
490             jabberPassword.requestFocus();
491             return false;
492         }
493         return true;
494     }
495     
496     /** Methhod called in EDT when NewKeyPairThread has finsihed.*/
497     public void doKeyGenerated(){
498         if(current!=1){return;}
499         frame.show();
500         frame.toFront();
501         Toolkit.getDefaultToolkit().beep();
502         frame.setCursor(GUI.NORMAL);
503         nextBtn.setEnabled(true);
504         showNext();
505         doEnter();
506     }
507     
508     
509     final class BtnClick implements ActionListener{
510         public void actionPerformed(ActionEvent ae){
511             //get button
512
String JavaDoc b=ae.getActionCommand();
513             // call method depending on button clicked
514
if(b.equals(cancelBtn.getText())){
515                 frame.hide();
516                 return;
517             }
518             if(b.equals(helpBtn.getText())){
519                 WhisperIM.Help_Window.show(frame,helpTopic);
520                 return;
521             }
522             if(b.equals(jabberNewBtn.getText())){
523                 if(jabberServer.getText().equals("")){
524                     showInfo("you must enter servername");
525                     jabberServer.requestFocus();
526                     return;
527                 }
528                 wait.show();
529                 final SwingWorker worker = new SwingWorker() {
530                     JNewJabberDialog newjabberdialog;
531                     
532                     public Object JavaDoc construct(){
533                         newjabberdialog=new JNewJabberDialog(frame,jabberServer.getText(),jabberUsername.getText(),(new String JavaDoc(jabberPassword.getPassword())),jabberSSL.isSelected());
534                         return null;
535                     }
536                     
537                     //Runs on the event-dispatching thread.
538
public void finished() {
539                         wait.dispose();
540                         newjabberdialog.show();
541                         if(newjabberdialog.created()){
542                             jabberUsername.setText(newjabberdialog.getUsername());
543                             jabberPassword.setText(newjabberdialog.getPassword());
544                         }
545                     }
546                 };
547                 
548                 worker.start();
549                 return;
550             }
551             if(b.equals(nextBtn.getText())){
552                 doNext();
553             }
554             if(b.equals(backBtn.getText())){
555                 current--;
556                 title.setText(Lang.gs("title"+current));
557                 cardLayout.previous(layersPanel);
558                 doEnter();
559             }
560         }
561     }
562     
563     /** Thread class that creates a new keypair.*/
564     final class NewKeyPairThread extends Thread JavaDoc{
565         public NewKeyPairThread(){
566             super();
567             setDaemon(true); // so it doesn't keep the VM running
568
setPriority(Thread.MIN_PRIORITY);// means it takes longer but wont hog the system
569
}
570         
571         public void run(){
572             WhisperIM.KEYPAIR=new KeyPair("<jabber>"+jabberUsername.getText()+"@"+jabberServer.getText()+"</jabber>",WhisperIM.SR);
573             javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc(){
574                 public void run(){
575                     doKeyGenerated(); //alters GUI so needs to be in EDT
576
}
577             });
578         }
579     }
580             
581     
582 }
Popular Tags