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

Quick Search    Search Deep

Source code: com/yaftp/ftp/FtpSwingConnectPanel.java


1    /**
2    *
3    * CopyRights Jean-Yves MENGANT 1999,2000,2001,2002
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  
20  package com.yaftp.ftp;
21  
22  import java.awt.*;
23  import java.awt.event.*;
24  
25  import javax.swing.* ;
26  import javax.swing.tree.* ;
27  import javax.swing.border.* ;
28  
29  import com.yaftp.utils.* ;
30  
31  /**
32  
33    Swing Basic connection panel for Ftp customizer
34  
35  */
36  
37  public class FtpSwingConnectPanel extends JPanel  {
38  
39    private final ImageIcon _EMPTY_ICON_  =  new ImageIcon(
40                                           getClass().getResource( "images/blank.gif") ,
41                                                                   "blank"
42                                                         )    ;
43    private final ImageIcon _TRACE_ICON_  =  new ImageIcon(
44                                           getClass().getResource( "images/magnify.gif") ,
45                                                                   "trace"
46                                                         )    ;
47    private final ImageIcon _CONNECT_ICON_  =  new ImageIcon(
48                                           getClass().getResource( "images/network.gif") ,
49                                                                   "connect"
50                                                         )    ;
51  
52    private final ImageIcon _FTP_ICON_  =  new ImageIcon(
53                                           getClass().getResource( "images/ftp.gif") ,
54                                                                   "Ftp"
55                                                         )    ;
56  
57    private Ftp _curFtp ;
58  
59    private SwingField _srvName     = new SwingField("FTP server name :" , 20  ) ;
60    private SwingField _srvUsrId    = new SwingField("User Id :" , 20  ) ;
61    private SwingField _srvPassWd   = new SwingField("Password :" , 20 , true ) ;
62    private SwingCheckBox  _traces    ;
63    private SwingEhnStatusBar _errors ;
64  
65    class _CHECKBOX_PANEL_ extends JToolBar {
66  
67      public _CHECKBOX_PANEL_() {
68  
69        super() ;
70        setFloatable(false) ;
71        addSeparator()     ;
72  
73        _traces = new SwingCheckBox( "Enables Ftp traces" ,
74                                     _TRACE_ICON_ ,
75                                     _EMPTY_ICON_
76                                   ) ;
77  
78  
79        SwingButton connect = new SwingButton( null ,
80                    " Pushing it starts connection process to FTP server " ,
81                                         new _CONNECT_FTP_() ,
82                                         _FTP_ICON_  ,
83                                         false
84                                       ) ;
85        add(_traces) ;
86        add(connect) ;
87        setBorder(SwingButton.createLoweredButtonBoxBorder()) ;
88      }
89    }
90  
91    class _FIELDS_PANEL_ extends SwingBox {
92  
93      public _FIELDS_PANEL_()
94      {
95        super( Swing.BOXSTANDARD ) ;
96  
97        setBorder( BorderFactory.createRaisedBevelBorder() ) ;
98  
99        addSwingField(2 ,  _srvName  , 2  ) ;
100       addSwingField(2 , _srvUsrId  , 2  ) ;
101       addSwingField(2 , _srvPassWd , 2  ) ;
102       installSwingFields()  ;
103 
104     }
105   }
106 
107   class _CENTER_AREA_ extends JPanel {
108 
109     public _CENTER_AREA_()
110     {
111       super() ;
112       setLayout( new BorderLayout() ) ;
113 
114       add( BorderLayout.NORTH  , new _CHECKBOX_PANEL_() ) ;
115       add( BorderLayout.CENTER , new _FIELDS_PANEL_() )   ;
116     }
117 
118 
119   }
120 
121 
122 
123   class _CONNECT_FTP_ implements ActionListener {
124 
125     public void actionPerformed ( ActionEvent e )
126     {
127        // Collect field values and go on with connection
128        _curFtp.set_ftpServerName( _srvName.getText() ) ;
129        _curFtp.set_userId( _srvUsrId.getText() ) ;
130        _curFtp.set_passWord( _srvPassWd.getText() ) ;
131        _curFtp.set_debug( _traces.isSelected() )  ;
132        _curFtp.set_graphicalDebug( _traces.isSelected() )  ; // As we're SWING
133 
134 
135        _curFtp.connect() ;
136     }
137   }
138 
139   public FtpSwingConnectPanel( Ftp ftp ,
140                                SwingEhnStatusBar errors
141                              )
142   {
143     _curFtp = ftp ;
144     _errors = errors  ;
145 
146     setLayout( new BorderLayout() ) ;
147 
148     add( BorderLayout.CENTER , new _CENTER_AREA_() ) ;
149 
150     add( BorderLayout.SOUTH ,
151          new SwingButtonsPanel( " Connect FTP " ,
152                                 " Pushing it starts connection process to FTP server " ,
153                                 new _CONNECT_FTP_()   ,
154                                 _CONNECT_ICON_
155                                )
156         ) ;
157 
158   }
159 
160   public static void main( String args[] )
161   {
162     // Test Exit
163     class WL extends WindowAdapter{
164       public void windowClosing( WindowEvent e )
165       {
166         System.exit(0) ;
167       }
168     }
169 
170     JFrame f = new JFrame() ;
171     f.addWindowListener( new WL() ) ;
172 
173     FtpSwingConnectPanel  w = new FtpSwingConnectPanel( new Ftp() ,
174                                                         new SwingEhnStatusBar()
175                                                       )   ;
176     f.getContentPane().add(w,BorderLayout.CENTER) ;
177 
178     f.pack() ;
179     f.show() ;
180   }
181 
182 
183 
184 }