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

Quick Search    Search Deep

Source code: com/yaftp/ftp/gui/MvsRecordFormatDialog.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.gui ;
21  
22  import java.awt.* ;
23  import java.awt.event.* ;
24  import javax.swing.* ;
25  import javax.swing.border.* ;
26  import java.util.* ;
27  import com.yaftp.utils.* ;
28  
29  
30  /**
31     Provides an automatic way to set RECORD fields before a file transfert
32  
33     @author  JYMEN
34     @version
35   */
36  public class MvsRecordFormatDialog
37  extends JDialog  {
38  
39    private final static String _SITE_HEADER_ = "site recfm=" ;
40    private final static String _LRECL_ = " lrecl=" ;
41    private final static String _BLKSIZE_ = " blksize=" ;
42  
43  
44    /** gif groups image resource */
45    private final static String _RECORD_TITLE_ = "** MVS FTP record **" ;
46    private final  ImageIcon _RECORD_BIGICON_  =  new ImageIcon(
47                                   getClass().getResource( "images/records.gif") ,
48                                                           "records"
49                                                                )   ;
50  
51    private String            _title     ;
52    private _RECORD_PANE_     _dialog    ;
53    private String            _curSite = null ;
54  
55    class _RECORD_PANE_
56    extends SwingBox
57    {
58      private SwingField _recfm   = new SwingField( "Record Format : " ,30 ) ;
59      private SwingField _lrecl   = new SwingField( "Record Length  : " ,30 ) ;
60      private SwingField _blkSize = new SwingField( "Block Size  : " ,30 ) ;
61  
62      public _RECORD_PANE_()
63      {
64        super( Swing.BOXSTANDARD ) ;
65        addSwingField(0 , _recfm   , 5  ) ;
66        addSwingField(0 , _lrecl , 5  ) ;
67        addSwingField(0 , _blkSize , 5  ) ;
68        installSwingFields()  ;
69      }
70  
71      public final  String get_recfm()
72      { return _recfm.getText() ; }
73  
74      public final String get_lrecl()
75      { return _lrecl.getText() ; }
76  
77      public final String get_blksize()
78      { return _blkSize.getText() ; }
79  
80      /**
81        build the ftp site command
82      */
83      public String buildSite()
84      {
85      StringBuffer returned = new StringBuffer(_SITE_HEADER_) ;
86        returned.append(get_recfm()) ;
87        returned.append(_LRECL_) ;
88        returned.append(get_lrecl()) ;
89        returned.append(_BLKSIZE_) ;
90        returned.append(get_blksize()) ;
91        return returned.toString() ;
92      }
93    }
94  
95  
96    class _OK_PRESSED_
97    implements ActionListener {
98  
99      public void actionPerformed( ActionEvent e )
100     {
101       _curSite = _dialog.buildSite() ;
102       MvsRecordFormatDialog.this.setVisible(false) ;
103     }
104   }
105   class _CANCEL_PRESSED_
106   implements ActionListener {
107 
108     public void actionPerformed( ActionEvent e )
109     {
110       // since we're modal , the following line will close dialog
111       // calling dispose here won't work
112       MvsRecordFormatDialog.this.setVisible(false) ;
113      _curSite = null ;
114     }
115   }
116 
117   class _OK_CANCEL_
118   extends SwingButtonsPanel  {
119 
120     private SwingButton _button ;
121 
122     public _OK_CANCEL_ ()
123     {
124     super( FlowLayout.CENTER ) ;
125       addButton( " Ok " , null , new _OK_PRESSED_()  , null  ) ;
126       addButton( " Cancel " , null , new _CANCEL_PRESSED_() , null  ) ;
127       _button = get_button() ;
128     }
129   }
130 
131   class _NORTH_AREA_
132   extends JPanel
133   {
134     public _NORTH_AREA_()
135     {
136       setLayout( new BorderLayout() ) ;
137       add( BorderLayout.WEST , new JLabel( _RECORD_BIGICON_ ) ) ;
138     }
139   }
140 
141   class _SOUTH_AREA_
142   extends JPanel
143   {
144     public _SOUTH_AREA_()
145     {
146       setLayout( new BorderLayout() ) ;
147       add( BorderLayout.NORTH ,  new _OK_CANCEL_() ) ;
148     }
149   }
150 
151   class _DIALOG_PANE_
152   extends JPanel {
153 
154     private String _error = null ;
155 
156     public _DIALOG_PANE_( JPanel    center )
157     {
158       setLayout( new BorderLayout() ) ;
159       add ( BorderLayout.CENTER , center ) ;
160     }
161 
162     public String get_error()
163     { return _error ; }
164 
165     public void set_error( String error )
166     { _error = error ; }
167   }
168 
169   class _DIALOG_AREA_
170   extends JPanel
171   {
172     public _DIALOG_AREA_()
173     {
174       setLayout( new BorderLayout() ) ;
175       add( BorderLayout.NORTH , new _NORTH_AREA_() )  ;
176       _dialog = new  _RECORD_PANE_() ;
177       add( BorderLayout.CENTER , _dialog ) ;
178 
179       this.setBorder( Swing.buildBorder( "Mvs Ftp Records structure option " ,
180                                           TitledBorder.LEFT   ,
181                                           TitledBorder.TOP ,
182                                           Swing.BOXLIGHTTITLE12 ,
183                                           Swing.BEVELRAISED
184                                         )
185                     ) ;
186     }
187   }
188 
189   private void initDialog()
190   {
191     super.setTitle(_title);
192     super.setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE );
193 
194     getContentPane().setLayout( new BorderLayout() ) ;
195     getContentPane().add( BorderLayout.CENTER , new _DIALOG_AREA_() ) ;
196     getContentPane().add( BorderLayout.SOUTH , new _SOUTH_AREA_() ) ;
197     pack() ;
198   }
199 
200   /**
201     launch the User / group panel info
202     and activate the loggin session call
203 
204     @exception throws UserServiceUIException whenever Cancel is entered or login failed
205 
206   */
207   public void display()
208   {
209     // Just block here waiting for user action
210     show() ;
211   }
212 
213   public void close()
214   { dispose() ; }
215 
216   public String getSiteCommand()
217   { return _curSite ; }
218 
219   public MvsRecordFormatDialog(Component c)
220   {
221     super.setModal(true) ;
222     super.setLocationRelativeTo(c);
223     initDialog() ;
224   }
225 
226   public static void main ( String args[] )
227   {
228     MvsRecordFormatDialog dialog = new MvsRecordFormatDialog(null) ;
229 
230     dialog.display() ;
231     System.out.println("after display : " + dialog.getSiteCommand() ) ;
232     dialog.close()   ;
233     System.out.println("I am closed : "  ) ;
234   }
235 }