Source code: com/yaftp/ftp/gui/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 package com.yaftp.ftp.gui ;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 import javax.swing.* ;
25 import javax.swing.tree.* ;
26 import javax.swing.border.* ;
27
28 import com.yaftp.utils.* ;
29 import com.yaftp.ftp.* ;
30
31
32 /**
33
34 Swing Basic connection panel for Ftp customizer
35
36 @Author Jean-Yves MENGANT
37 @version : 0.0.1
38
39
40 */
41
42 public class FtpSwingConnectPanel extends JPanel {
43
44 private final ImageIcon _EMPTY_ICON_ = new ImageIcon(
45 getClass().getResource( "images/blank.gif") ,
46 "blank"
47 ) ;
48 private final ImageIcon _TRACE_ICON_ = new ImageIcon(
49 getClass().getResource( "images/magnify.gif") ,
50 "trace"
51 ) ;
52 private final ImageIcon _CONNECT_ICON_ = new ImageIcon(
53 getClass().getResource( "images/ftp2.gif") ,
54 "connect"
55 ) ;
56
57 private final ImageIcon _FTP_ICON_ = new ImageIcon(
58 getClass().getResource( "images/ftp.gif") ,
59 "Ftp"
60 ) ;
61
62 private Ftp _curFtp ;
63
64 private SwingField _srvName = new SwingField("FTP server name :" , 20 ) ;
65 private SwingField _srvUsrId = new SwingField("User Id :" , 20 ) ;
66 private SwingField _srvPassWd = new SwingField("Password :" , 20 , true ) ;
67 private FtpServerTypeChoiceCombo _osTypeCombo = new FtpServerTypeChoiceCombo() ;
68 private SwingCheckBox _traces ;
69 private SwingEhnStatusBar _errors ;
70 private ActionListener _connectAction = new _CONNECT_FTP_() ;
71
72 class _CHECKBOX_PANEL_ extends JToolBar {
73
74 public _CHECKBOX_PANEL_() {
75
76 super() ;
77 setFloatable(false) ;
78 addSeparator() ;
79
80 _traces = new SwingCheckBox( "Enables Ftp traces" ,
81 _TRACE_ICON_ ,
82 _EMPTY_ICON_
83 ) ;
84
85
86 SwingButton connect = new SwingButton( null ,
87 " Pushing it starts connection process to FTP server " ,
88 new _CONNECT_FTP_() ,
89 _FTP_ICON_ ,
90 false
91 ) ;
92 add(_traces) ;
93 add(connect) ;
94
95 setBorder(SwingButton.createLoweredButtonBoxBorder()) ;
96 }
97 }
98
99 class _FIELDS_PANEL_ extends SwingBox {
100
101 public _FIELDS_PANEL_()
102 {
103 super( Swing.BOXSTANDARD ) ;
104
105 setBorder( BorderFactory.createRaisedBevelBorder() ) ;
106
107 addSwingField(2 , _srvName , 2 ) ;
108 addSwingField(2 , _srvUsrId , 2 ) ;
109 addSwingField(2 , _srvPassWd , 2 ) ;
110
111 _srvName.get_field().addActionListener(_connectAction) ;
112 _srvUsrId.get_field().addActionListener(_connectAction) ;
113 _srvPassWd.get_field().addActionListener(_connectAction) ;
114
115 installSwingFields() ;
116 }
117 }
118
119 class _CENTER_AREA_ extends JPanel {
120
121 public _CENTER_AREA_()
122 {
123 super() ;
124 setLayout( new BorderLayout() ) ;
125
126 add( BorderLayout.NORTH , new _CHECKBOX_PANEL_() ) ;
127 add( BorderLayout.CENTER , new _FIELDS_PANEL_() ) ;
128 }
129
130
131 }
132
133
134
135 class _CONNECT_FTP_ implements ActionListener {
136
137 public void actionPerformed ( ActionEvent e )
138 {
139 _errors.reset();
140 // Collect field values and go on with connection
141 _curFtp.set_ftpServerName( _srvName.getText() ) ;
142 _curFtp.set_userId( _srvUsrId.getText() ) ;
143 _curFtp.set_passWord( _srvPassWd.getText() ) ;
144 _curFtp.set_ftpOs( _osTypeCombo.get_selectedOs() ) ;
145 _curFtp.set_debug( _traces.isSelected() ) ;
146 _curFtp.set_graphicalDebug( _traces.isSelected() ) ; // As we're SWING
147
148
149 _curFtp.connect() ;
150 }
151 }
152
153 public FtpSwingConnectPanel( Ftp ftp ,
154 SwingEhnStatusBar errors
155 )
156 {
157 _curFtp = ftp ;
158 _errors = errors ;
159
160 setLayout( new BorderLayout() ) ;
161
162 add( BorderLayout.CENTER , new _CENTER_AREA_() ) ;
163
164 JPanel southPane = new SwingButtonsPanel( " Connect " ,
165 " Pushing it starts connection process to FTP server " ,
166 new _CONNECT_FTP_() ,
167 _CONNECT_ICON_
168 ) ;
169 southPane.add( _osTypeCombo ) ;
170
171 add( BorderLayout.SOUTH , southPane );
172 }
173
174 public static void main( String args[] )
175 {
176 // Test Exit
177 class WL extends WindowAdapter{
178 public void windowClosing( WindowEvent e )
179 {
180 System.exit(0) ;
181 }
182 }
183
184 JFrame f = new JFrame() ;
185 f.addWindowListener( new WL() ) ;
186
187 FtpSwingConnectPanel w = new FtpSwingConnectPanel( new Ftp() ,
188 new SwingEhnStatusBar()
189 ) ;
190 f.getContentPane().add(w,BorderLayout.CENTER) ;
191
192 f.pack() ;
193 f.show() ;
194 }
195
196
197
198 }