Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sshtools/sshterm/ConnectionDialog.java


1   /**
2    *   Sshtools - SSHTerm
3    *
4    *   Copyright (C) 2002 Lee David Painter
5    *
6    *   Written by: 2002 Lee David Painter <lee@sshtools.com>
7    *
8    *   This program is free software; you can redistribute it and/or modify
9    *   it under the terms of the GNU General Public License as published by
10   *   the Free Software Foundation; either version 2 of the License, or
11   *   (at your option) any later version.
12   *
13   *   This program is distributed in the hope that it will be useful,
14   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   *   GNU General Public License for more details.
17   *
18   *   You should have received a copy of the GNU General Public License
19   *   along with this program; if not, write to the Free Software
20   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21   */
22  package com.sshtools.sshterm;
23  
24  import java.awt.*;
25  import com.sshtools.apps.*;
26  import java.net.*;
27  import javax.swing.*;
28  import java.security.*;
29  import java.awt.event.*;
30  import com.sshtools.j2ssh.authentication.*;
31  import java.util.*;
32  import com.sshtools.j2ssh.transport.cipher.*;
33  import com.sshtools.j2ssh.transport.hmac.*;
34  import com.sshtools.j2ssh.transport.compression.*;
35  import com.sshtools.j2ssh.transport.publickey.*;
36  import com.sshtools.j2ssh.transport.kex.*;
37  import com.sshtools.j2ssh.configuration.*;
38  import com.sshtools.sshterm.emulation.TerminalEmulation;
39  import com.sshtools.j2ssh.util.*;
40  import com.sshtools.sshterm.*;
41  import com.sshtools.j2ssh.ui.*;
42  import com.sshtools.j2ssh.transport.AlgorithmNotSupportedException;
43  
44  /**
45   *  <p>
46   *
47   *  The New Connection dialog for the SshTerminalFrame. This dialog allows the
48   *  user to select connection properties</p>
49   *
50   *@author     Lee David Painter (<A HREF="mailto:lee@sshtools.com">
51   *      lee@sshtools.com</A> )
52   *@created    31 August 2002
53   *@version    $Id: ConnectionDialog.java,v 1.9 2003/01/23 17:54:02 martianx Exp $
54   */
55  
56  class ConnectionDialog extends JDialog {
57  
58      //  Icon resources
59      final static String CONNECT_ICON = "/com/sshtools/sshterm/largeserveridentity.png";
60      final static String AUTH_ICON = "/com/sshtools/sshterm/largelock.png";
61      final static String TERM_ICON = "/com/sshtools/sshterm/largeterminal.png";
62      final static String KEYS_ICON = "/com/sshtools/sshterm/largessh.png";
63      final static String PREF_ICON = "/com/sshtools/sshterm/largenetwork.png";
64  
65      //  Strings
66      final String SHOW_AVAILABLE = "<Show available methods>";
67      final String DEFAULT = "<Default>";
68  
69      //
70      final int DEFAULT_PORT = 22;
71  
72      //  Dialog components
73  
74      XTextField jTextHostname = new XTextField();
75      NumericTextField jTextPort = new NumericTextField(
76              new Integer(0), new Integer(65535), new Integer(DEFAULT_PORT) );
77      XTextField jTextUsername = new XTextField();
78      JList jListAuths = new JList();
79      JComboBox jComboTerm = new JComboBox();
80      JComboBox jComboResizeStrategy = new JComboBox(
81                              new String[] { "None", "Font", "Screen" });
82      JComboBox jComboEOL = new JComboBox(
83                              new String[] { "Default", "CR+LF", "CR" });
84      JButton jButtonConnect = new JButton("Connect") {
85          public boolean isDefaultButton() {
86              return true;
87          }
88      };
89      JButton jButtonCancel = new JButton("Cancel");
90      JComboBox jComboCipherCS = new JComboBox();
91      JComboBox jComboCipherSC = new JComboBox();
92      JComboBox jComboMacCS = new JComboBox();
93      JComboBox jComboMacSC = new JComboBox();
94      JComboBox jComboCompCS = new JComboBox();
95      JComboBox jComboCompSC = new JComboBox();
96      JComboBox jComboKex = new JComboBox();
97      JComboBox jComboPK = new JComboBox();
98      java.util.List methods = new ArrayList();
99      boolean isCancelled = false;
100     JLabel jLabel1 = new JLabel();
101 
102     /**
103      *  Flag to determine if the user selected any authenticaiton methods
104      */
105     boolean hasChosenAuth = false;
106 
107     /**
108      *  Constructs the ConnectionDialog object
109      */
110     public ConnectionDialog() {
111         super((Frame)null, "New Connection", true);
112         init();
113     }
114 
115     /**
116      *  Constructs the ConnectionDialog object
117      *
118      *@param  frame  The parent frame
119      */
120     public ConnectionDialog(Frame parent) {
121         super(parent, "New Connection", true);
122         init();
123     }
124 
125     /**
126      *  Constructs the ConnectionDialog object
127      *
128      *@param  dialog  The parent dialog
129      */
130     public ConnectionDialog(Dialog parent) {
131         super(parent, "New Connection", true);
132         init();
133     }
134 
135     /**
136      * Initialise the dialog
137      */
138     void init() {
139 
140     //  Host tab
141 
142     //  Create the main connection details panel
143         JPanel mainConnectionDetailsPanel = new JPanel(new GridBagLayout());
144         GridBagConstraints gbc = new GridBagConstraints();
145         gbc.fill = GridBagConstraints.HORIZONTAL;
146         gbc.anchor = GridBagConstraints.NORTHWEST;
147         gbc.insets = new Insets(0, 2, 2, 2);
148         gbc.weightx = 1.0;
149 
150     //  Host name
151         UIUtil.jGridBagAdd(mainConnectionDetailsPanel,
152             new JLabel("Hostname"), gbc, GridBagConstraints.REMAINDER);
153         gbc.fill = GridBagConstraints.HORIZONTAL;
154         UIUtil.jGridBagAdd(mainConnectionDetailsPanel,
155             jTextHostname, gbc, GridBagConstraints.REMAINDER);
156         gbc.fill = GridBagConstraints.NONE;
157 
158     //  Port
159         UIUtil.jGridBagAdd(mainConnectionDetailsPanel,
160             new JLabel("Port"), gbc, GridBagConstraints.REMAINDER);
161         UIUtil.jGridBagAdd(mainConnectionDetailsPanel,
162             jTextPort, gbc, GridBagConstraints.REMAINDER);
163 
164     //  Username
165         UIUtil.jGridBagAdd(mainConnectionDetailsPanel,
166             new JLabel("Username"), gbc, GridBagConstraints.REMAINDER);
167         gbc.fill = GridBagConstraints.HORIZONTAL;
168         gbc.weighty = 1.0;
169         UIUtil.jGridBagAdd(mainConnectionDetailsPanel,
170             jTextUsername, gbc, GridBagConstraints.REMAINDER);
171         gbc.fill = GridBagConstraints.NONE;
172 
173     //
174         IconWrapperPanel iconMainConnectionDetailsPanel = new IconWrapperPanel(
175             new ResourceIcon(CONNECT_ICON), mainConnectionDetailsPanel);
176 
177 
178     //  Authentication methods panel
179         JPanel authMethodsPanel = new JPanel(new GridBagLayout());
180         authMethodsPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
181         gbc = new GridBagConstraints();
182         gbc.fill = GridBagConstraints.NONE;
183         gbc.anchor = GridBagConstraints.NORTHWEST;
184         gbc.insets = new Insets(2, 2, 2, 2);
185         gbc.weightx = 1.0;
186 
187     //  Authentication methods
188         UIUtil.jGridBagAdd(authMethodsPanel,
189             new JLabel("Authentication Methods"), gbc, GridBagConstraints.REMAINDER);
190         gbc.fill = GridBagConstraints.HORIZONTAL;
191         gbc.weighty = 1.0;
192         jListAuths.setVisibleRowCount(5);
193         UIUtil.jGridBagAdd(authMethodsPanel,
194             new JScrollPane(jListAuths), gbc, GridBagConstraints.REMAINDER);
195 
196     //
197         IconWrapperPanel iconAuthMethodsPanel = new IconWrapperPanel(
198             new ResourceIcon(AUTH_ICON), authMethodsPanel);
199 
200     //  Terminal tab
201         JPanel terminalPanel = new JPanel(new GridBagLayout());
202         gbc = new GridBagConstraints();
203         gbc.fill = GridBagConstraints.HORIZONTAL;
204         gbc.anchor = GridBagConstraints.NORTH;
205         gbc.insets = new Insets(2, 2, 2, 2);
206         gbc.weightx = 1.0;
207 
208     //  Authentication methods
209         UIUtil.jGridBagAdd(terminalPanel,
210             new JLabel("Terminal type"), gbc, GridBagConstraints.REMAINDER);
211         UIUtil.jGridBagAdd(terminalPanel, jComboTerm,
212                              gbc, GridBagConstraints.REMAINDER);
213         UIUtil.jGridBagAdd(terminalPanel,
214             new JLabel("Resize strategy"), gbc, GridBagConstraints.REMAINDER);
215         UIUtil.jGridBagAdd(terminalPanel, jComboResizeStrategy,
216                              gbc, GridBagConstraints.REMAINDER);
217         UIUtil.jGridBagAdd(terminalPanel,
218             new JLabel("EOL Type"), gbc, GridBagConstraints.REMAINDER);
219         gbc.weighty = 1.0;
220         UIUtil.jGridBagAdd(terminalPanel, jComboEOL,
221                              gbc, GridBagConstraints.REMAINDER);
222 
223     //
224         IconWrapperPanel iconTerminalPanel = new IconWrapperPanel(
225             new ResourceIcon(TERM_ICON), terminalPanel);
226 
227 
228     //  Preferences tab
229 
230     //  Keys
231         JPanel keysPanel = new JPanel(new GridBagLayout());
232         gbc = new GridBagConstraints();
233         gbc.fill = GridBagConstraints.NONE;
234         gbc.anchor = GridBagConstraints.WEST;
235         gbc.insets = new Insets(2, 2, 2, 2);
236         gbc.weightx = 1.0;
237 
238     //  Public key
239         UIUtil.jGridBagAdd(keysPanel,
240             new JLabel("Public key"), gbc, GridBagConstraints.REMAINDER);
241         gbc.fill = GridBagConstraints.HORIZONTAL;
242         UIUtil.jGridBagAdd(keysPanel, jComboPK, gbc, GridBagConstraints.REMAINDER);
243         gbc.fill = GridBagConstraints.NONE;
244 
245     //  Public key
246         UIUtil.jGridBagAdd(keysPanel,
247             new JLabel("Key exchange"), gbc, GridBagConstraints.REMAINDER);
248         gbc.fill = GridBagConstraints.HORIZONTAL;
249         UIUtil.jGridBagAdd(keysPanel, jComboKex, gbc, GridBagConstraints.REMAINDER);
250         gbc.fill = GridBagConstraints.NONE;
251 
252     //
253         IconWrapperPanel iconKeysPanel = new IconWrapperPanel(
254             new ResourceIcon(KEYS_ICON), keysPanel);
255 
256     //  Preferences
257         JPanel prefPanel = new JPanel(new GridBagLayout());
258         prefPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
259         gbc = new GridBagConstraints();
260         gbc.fill = GridBagConstraints.NONE;
261         gbc.anchor = GridBagConstraints.WEST;
262         gbc.insets = new Insets(2, 2, 2, 2);
263         gbc.weightx = 1.0;
264 
265     //  Public key
266         gbc.fill = GridBagConstraints.HORIZONTAL;
267         UIUtil.jGridBagAdd(prefPanel,
268             new JLabel("Client - > Server"), gbc, GridBagConstraints.RELATIVE);
269         UIUtil.jGridBagAdd(prefPanel,
270             new JLabel("Server - > Client"), gbc, GridBagConstraints.REMAINDER);
271 
272     //  Separator
273         gbc.weightx = 2.0;
274         UIUtil.jGridBagAdd(prefPanel, new JSeparator(JSeparator.HORIZONTAL),
275                 gbc, GridBagConstraints.REMAINDER);
276 
277     //  Cipher
278         UIUtil.jGridBagAdd(prefPanel,
279             new JLabel("Cipher"), gbc, GridBagConstraints.RELATIVE);
280         UIUtil.jGridBagAdd(prefPanel,
281             new JLabel("Cipher"), gbc, GridBagConstraints.REMAINDER);
282         UIUtil.jGridBagAdd(prefPanel,
283             jComboCipherCS, gbc, GridBagConstraints.RELATIVE);
284         UIUtil.jGridBagAdd(prefPanel,
285             jComboCipherSC, gbc, GridBagConstraints.REMAINDER);
286 
287     //  Mac
288         UIUtil.jGridBagAdd(prefPanel,
289             new JLabel("Mac"), gbc, GridBagConstraints.RELATIVE);
290         UIUtil.jGridBagAdd(prefPanel,
291             new JLabel("Mac"), gbc, GridBagConstraints.REMAINDER);
292         UIUtil.jGridBagAdd(prefPanel,
293             jComboMacCS, gbc, GridBagConstraints.RELATIVE);
294         UIUtil.jGridBagAdd(prefPanel,
295             jComboMacSC, gbc, GridBagConstraints.REMAINDER);
296 
297     //  Compression
298         UIUtil.jGridBagAdd(prefPanel,
299             new JLabel("Compression"), gbc, GridBagConstraints.RELATIVE);
300         UIUtil.jGridBagAdd(prefPanel,
301             new JLabel("Compression"), gbc, GridBagConstraints.REMAINDER);
302         UIUtil.jGridBagAdd(prefPanel,
303             jComboCompCS, gbc, GridBagConstraints.RELATIVE);
304         UIUtil.jGridBagAdd(prefPanel,
305             jComboCompSC, gbc, GridBagConstraints.REMAINDER);
306 
307     //
308         IconWrapperPanel iconPrefPanel = new IconWrapperPanel(
309             new ResourceIcon(PREF_ICON), prefPanel);
310 
311     //  Host tab
312         JPanel hostTabPanel = new JPanel(new GridBagLayout());
313         hostTabPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
314         gbc = new GridBagConstraints();
315         gbc.fill = GridBagConstraints.BOTH;
316         gbc.anchor = GridBagConstraints.WEST;
317         gbc.insets = new Insets(2, 2, 2, 2);
318         gbc.weightx = 1.0;
319         UIUtil.jGridBagAdd(hostTabPanel, iconMainConnectionDetailsPanel,
320                                             gbc, GridBagConstraints.REMAINDER);
321         gbc.weighty = 1.0;
322         UIUtil.jGridBagAdd(hostTabPanel, iconAuthMethodsPanel,
323                                         gbc, GridBagConstraints.REMAINDER);
324 
325     //  Terminal tab
326         JPanel terminalTabPanel = new JPanel(new GridBagLayout());
327         terminalTabPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
328         gbc = new GridBagConstraints();
329         gbc.fill = GridBagConstraints.BOTH;
330         gbc.anchor = GridBagConstraints.WEST;
331         gbc.insets = new Insets(2, 2, 2, 2);
332         gbc.weightx = 1.0;
333         gbc.weighty = 1.0;
334         UIUtil.jGridBagAdd(terminalTabPanel, iconTerminalPanel, gbc,
335                                             GridBagConstraints.REMAINDER);
336 
337     //  Preferences tab
338         JPanel prefTabPanel = new JPanel(new GridBagLayout());
339         prefTabPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
340         gbc = new GridBagConstraints();
341         gbc.fill = GridBagConstraints.NONE;
342         gbc.anchor = GridBagConstraints.WEST;
343         gbc.insets = new Insets(2, 2, 2, 2);
344         gbc.weightx = 1.0;
345         UIUtil.jGridBagAdd(prefTabPanel, iconKeysPanel,
346                                         gbc, GridBagConstraints.REMAINDER);
347         gbc.weighty = 1.0;
348         UIUtil.jGridBagAdd(prefTabPanel, iconPrefPanel,
349                                         gbc, GridBagConstraints.REMAINDER);
350 
351     //  All tabs
352         JTabbedPane tabs = new JTabbedPane();
353         tabs.addTab("Host", hostTabPanel);
354         tabs.addTab("Terminal", terminalTabPanel);
355         tabs.addTab("Preferences", prefTabPanel);
356 
357     //  Create the bottom button panel
358         jButtonCancel.setMnemonic('c');
359         jButtonCancel.addActionListener(new ActionListener() {
360             public void actionPerformed(ActionEvent evt) {
361                     jButtonCancel_actionPerformed(evt);
362             }
363         });
364         jButtonConnect.setMnemonic('t');
365         jButtonConnect.addActionListener(new ActionListener() {
366             public void actionPerformed(ActionEvent evt) {
367                     jButtonConnect_actionPerformed(evt);
368             }
369         });
370         getRootPane().setDefaultButton(jButtonConnect);
371         JPanel buttonPanel = new JPanel(new GridBagLayout());
372 //        buttonPanel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
373         gbc = new GridBagConstraints();
374         gbc.fill = GridBagConstraints.HORIZONTAL;
375         gbc.anchor = GridBagConstraints.CENTER;
376         gbc.insets = new Insets(6, 6, 0, 0);
377         gbc.weighty = 1.0;
378         UIUtil.jGridBagAdd(buttonPanel, jButtonCancel, gbc, GridBagConstraints.RELATIVE);
379         UIUtil.jGridBagAdd(buttonPanel, jButtonConnect, gbc, GridBagConstraints.REMAINDER);
380         JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
381         southPanel.add(buttonPanel);
382 
383     //
384         JPanel mainPanel = new JPanel(new BorderLayout());
385         mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
386         mainPanel.add(tabs, BorderLayout.CENTER);
387         mainPanel.add(southPanel, BorderLayout.SOUTH);
388 
389     //  Build this panel
390         getContentPane().setLayout(new GridLayout(1, 1));
391         getContentPane().add(mainPanel);
392 
393     //  Set up the values in the various components
394         addAuthenticationMethods();
395 
396         loadList(SshCipherFactory.getSupportedCiphers(), jComboCipherCS, true);
397         loadList(SshCipherFactory.getSupportedCiphers(), jComboCipherSC, true);
398         loadList(SshHmacFactory.getSupportedMacs(), jComboMacCS, true);
399         loadList(SshHmacFactory.getSupportedMacs(), jComboMacSC, true);
400         loadList(SshCompressionFactory.getSupportedCompression(), jComboCompCS, true);
401         loadList(SshCompressionFactory.getSupportedCompression(), jComboCompSC, true);
402         loadList(SshKeyExchangeFactory.getSupportedKeyExchanges(), jComboKex, true);
403         loadList(SshKeyPairFactory.getSupportedKeys(), jComboPK, true);
404 
405         loadList(TerminalEmulation.getSupportedEmulations(), jComboTerm, false);
406         jComboTerm.setSelectedItem(TerminalEmulation.VT100);
407 
408     //
409         setModal(true);
410         pack();
411         setResizable(false);
412     }
413 
414     /**
415      * Return what the current EOL setting is. This wont be necessary when
416      * the extended connection properties API is done.
417      *
418      * @return eol setting
419      */
420     protected int getEOL() {
421         return jComboEOL.getSelectedIndex();
422     }
423 
424     /**
425      * Return what the current terminal resize strategy  setting is.
426      * This wont be necessary when the extended connection properties API is done.
427      *
428      * @return resize stragety
429      */
430     protected int getResizeStrategy() {
431         return jComboResizeStrategy.getSelectedIndex();
432     }
433 
434     /**
435      *  Shows the connection dialog and returns the connection properties
436      *  selected.
437      *
438      *@return    The connection properties
439      */
440     public SshConnectionProperties showConnectionDialog() {
441         return showConnectionDialog(null, true, true, true);
442     }
443 
444     /**
445      *  Shows the connection dialog and returns the connection properties
446      *  selected. Using <code>false</code> for anyHost, anyUser or anyPort
447      *  only applies if a default properties object is supplied.
448      *
449      * @param     properties default properties
450      * @poaram    anyHost  user may connect to any host
451      * @poaram    anyUser  user may connect to any user
452      * @poaram    anyPort  user may connect to any port
453      * @return    The connection properties
454      */
455     public SshTermProfile showConnectionDialog(
456                             SshConnectionProperties properties,
457                             boolean anyHost, boolean anyUser, boolean anyPort) {
458 
459         //  If no properties are provided, then use the default
460         if(properties == null) {
461             jTextHostname.setText(PreferencesStore.get(SshTerminalPanel.PREF_CONNECTION_LAST_HOST, ""));
462             jTextPort.setValue(new Integer(PreferencesStore.getInt(
463                 SshTerminalPanel.PREF_CONNECTION_LAST_PORT ,DEFAULT_PORT)));
464             jTextUsername.setText(PreferencesStore.get(SshTerminalPanel.PREF_CONNECTION_LAST_USER, ""));
465         }
466         else {
467             jTextHostname.setText(properties.getHost());
468             jTextUsername.setText(properties.getUsername());
469             jTextPort.setValue(new Integer(properties.getPort()));
470         }
471         jComboResizeStrategy.setSelectedIndex(1);
472 
473         jTextHostname.setEnabled(properties == null || ( properties != null && anyHost) );
474         jTextUsername.setEnabled(properties == null || ( properties != null && anyUser) );
475         jTextPort.setEnabled(properties == null || ( properties != null && anyPort) );
476 
477         //
478         jTextHostname.requestFocus();
479 
480         // Show the dialog
481         UIUtil.positionComponent(SwingConstants.CENTER, this);
482         setVisible(true);
483 
484         if(isCancelled)
485           return null;
486 
487         // Create a new properties object
488         SshTermProfile ssh = new SshTermProfile();
489 
490         // Set the host details
491         ssh.setHost(jTextHostname.getText());
492         ssh.setPort(Integer.valueOf(jTextPort.getText()).intValue());
493         ssh.setUsername(jTextUsername.getText());
494         ssh.setTerminalProperty("TERM", (String)jComboTerm.getSelectedItem());
495         // Setup the authentications selected
496         if (hasChosenAuth) {
497 
498             Iterator it = methods.iterator();
499             while (it.hasNext()) {
500               String method = (String)it.next();
501               try {
502                 SshAuthentication auth = SshAuthenticationFactory.newInstance(method);
503                 auth.setUsername(jTextUsername.getText());
504                 ssh.addAuthenticationMethod(auth);
505               } catch(AlgorithmNotSupportedException anse) {
506                 JOptionPane.showMessageDialog(this, method + " is not supported!");
507               }
508 
509             }
510         }
511 
512         // Get the algorithm preferences
513         if (!jComboCipherCS.getSelectedItem().equals(DEFAULT)) {
514             ssh.setPrefCSEncryption((String) jComboCipherCS.getSelectedItem());
515         }
516         if (!jComboCipherSC.getSelectedItem().equals(DEFAULT)) {
517             ssh.setPrefSCEncryption((String) jComboCipherSC.getSelectedItem());
518         }
519         if (!jComboMacCS.getSelectedItem().equals(DEFAULT)) {
520             ssh.setPrefCSMac((String) jComboMacCS.getSelectedItem());
521         }
522         if (!jComboMacSC.getSelectedItem().equals(DEFAULT)) {
523             ssh.setPrefSCMac((String) jComboMacSC.getSelectedItem());
524         }
525         if (!jComboCompCS.getSelectedItem().equals(DEFAULT)) {
526             ssh.setPrefCSComp((String) jComboCompCS.getSelectedItem());
527         }
528         if (!jComboCompSC.getSelectedItem().equals(DEFAULT)) {
529             ssh.setPrefSCComp((String) jComboCompSC.getSelectedItem());
530         }
531         if (!jComboKex.getSelectedItem().equals(DEFAULT)) {
532             ssh.setPrefKex((String) jComboKex.getSelectedItem());
533         }
534         if (!jComboPK.getSelectedItem().equals(DEFAULT)) {
535             ssh.setPrefPublicKey((String) jComboPK.getSelectedItem());
536         }
537 
538         // Return the connection properties
539         return ssh;
540     }
541 
542 
543     /**
544      *  Sets up the authentication method list
545      */
546     private void addAuthenticationMethods() {
547 
548         java.util.List methods = new ArrayList();
549 
550         methods.add(SHOW_AVAILABLE);
551         methods.addAll(SshAuthenticationFactory.getSupportedMethods());
552         jListAuths.setListData(methods.toArray());
553         jListAuths.setSelectedIndex(0);
554 
555     }
556 
557 
558     /**
559      *  Loads a list into a combo box
560      *
561      *@param  list        The source list
562      *@param  combo       The destination combo box
563      *@param  addDefault  Whether to add the <Default> item
564      */
565     private void loadList(java.util.List list, JComboBox combo, boolean addDefault) {
566 
567         Iterator it = list.iterator();
568 
569         if (addDefault) {
570             combo.addItem(DEFAULT);
571         }
572 
573         while (it.hasNext()) {
574             combo.addItem(it.next());
575         }
576 
577     }
578 
579 
580     /**
581      *  Called when the button has been pressed
582      *
583      *@param  e  The action
584      */
585     void jButtonConnect_actionPerformed(ActionEvent e) {
586 
587         // Validate that we have enough information
588         if (jTextHostname.getText().equals("")
589                 || jTextPort.getText().equals("")
590                 || jTextUsername.getText().equals("")) {
591             JOptionPane.showMessageDialog(this, "Please enter all details!", "Connect", JOptionPane.OK_OPTION);
592             return;
593         }
594 
595         // Determine whether any authenticaiton methods we selected
596         Object[] auths = jListAuths.getSelectedValues();
597         String a;
598         if (auths != null) {
599 
600             for (int i = 0; i < auths.length; i++) {
601                 a = (String) auths[i];
602                 if (a.equals(SHOW_AVAILABLE)) {
603                     hasChosenAuth = false;
604                     break;
605                 } else {
606                     hasChosenAuth = true;
607                     methods.add(a);
608                 }
609 
610             }
611 
612         } else {
613             hasChosenAuth = false;
614         }
615 
616         // Hide the dialog
617         this.hide();
618     }
619 
620 
621     /**
622      *  Process a window event
623      *
624      *@param  e  The event
625      */
626     protected void processWindowEvent(WindowEvent e) {
627         super.processWindowEvent(e);
628         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
629             jTextPort.setValue(new Integer(DEFAULT_PORT));
630             jTextHostname.setText("");
631             jTextUsername.setText("");
632             hide();
633         }
634     }
635 
636   /**
637    * Handle the cancel event
638    * @param e
639    */
640   void jButtonCancel_actionPerformed(ActionEvent e) {
641       isCancelled = true;
642       hide();
643   }
644 }