content: package com.japisoft.editix.ui.panels.universalbrowser;
  
  import java.awt.event.ItemEvent;
  import java.awt.event.ItemListener;
  import java.util.List;
  
  /**
  This program is available under two licenses : 
  
  1. For non commercial usage : 
  
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
  2. For commercial usage :
  
  You need to get a commercial license for source usage at : 
  
  http://www.editix.com/buy.html
  
  Copyright (c) 2018 Alexandre Brillant - JAPISOFT SARL - http://www.japisoft.com
  
  @author Alexandre Brillant - abrillant@japisoft.com
  @author JAPISOFT SARL - http://www.japisoft.com
  
  */
  public class FTPChooserPanel 
  	extends javax.swing.JPanel implements ItemListener {
      
      /** Creates new form FTPChoooserPanel */
      public FTPChooserPanel() {
          initComponents();
      }
  
      public void restoreSaveHosts(List config ) {
      	cbHosts.removeAllItems();
      	for ( int i = 0; i < config.size(); i++ )
      		cbHosts.addItem( config.get( i ) );
      	if ( config.size() > 0 ) {
      		resetConfig( ( FTPConfig )config.get( 0 ) );
      	}
      }
  
      public void addNotify() {
      	super.addNotify();
      	cbHosts.addItemListener( this );
      }
  
      public void removeNotify() {
      	super.removeNotify();
      	cbHosts.removeItemListener( this );
      }
  
      public void itemStateChanged(ItemEvent e) {
      	FTPConfig config = ( FTPConfig )cbHosts.getSelectedItem();
      	if ( config != null ) {
      		resetConfig( config );
      	}
      }
  
      private void resetConfig( FTPConfig config ) {
      	txtHost.setText( config.host );
      	txtUser.setText( config.user );
      	txtPassword.setText( config.password );
      	txtDirectory.setText( config.directory );    	
      }
    
      public FTPConfig getFTPConfig() {
      	FTPConfig c = new FTPConfig();
      	c.host = txtHost.getText();
      	c.user = txtUser.getText();
      	c.directory = txtDirectory.getText();
      	c.password = txtPassword.getText();
      	c.save = cbSave.isSelected();
      	return c;
      }
  
      /** This method is called from within the constructor to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the Form Editor.
       */
      // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
      private void initComponents() {
          jLabel1 = new javax.swing.JLabel();
          cbHosts = new javax.swing.JComboBox();
          jSeparator1 = new javax.swing.JSeparator();
          jLabel2 = new javax.swing.JLabel();
          txtHost = new javax.swing.JTextField();
          jLabel3 = new javax.swing.JLabel();
          txtUser = new javax.swing.JTextField();
          jLabel4 = new javax.swing.JLabel();
          txtPassword = new javax.swing.JPasswordField();
          jLabel5 = new javax.swing.JLabel();
          txtDirectory = new javax.swing.JTextField();
          cbSave = new javax.swing.JCheckBox();
  
          jLabel1.setText("Host history");
  
          jLabel2.setText("Host");
  
          jLabel3.setText("User");
  
          jLabel4.setText("Password");
  
          jLabel5.setText("Default directory (optional)");
  
          cbSave.setText("Save");
          cbSave.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
          cbSave.setMargin(new java.awt.Insets(0, 0, 0, 0));
  
          org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
          this.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
              .add(layout.createSequentialGroup()
                  .addContainerGap()
                  .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                      .add(cbHosts, 0, 200, Short.MAX_VALUE)
                      .add(jLabel1)
                      .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                      .add(jLabel2)
                      .add(txtHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                      .add(jLabel3)
                      .add(txtUser, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                      .add(jLabel4)
                      .add(txtPassword, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                      .add(jLabel5)
                      .add(txtDirectory, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                      .add(cbSave))
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
              .add(layout.createSequentialGroup()
                  .addContainerGap()
                  .add(jLabel1)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(cbHosts, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(jLabel2)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(txtHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(jLabel3)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(txtUser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(jLabel4)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(txtPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(jLabel5)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(txtDirectory, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 21, Short.MAX_VALUE)
                  .add(cbSave)
                  .addContainerGap())
          );
      }// </editor-fold>
      
      
      // Variables declaration - do not modify
      private javax.swing.JComboBox cbHosts;
      private javax.swing.JCheckBox cbSave;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel2;
      private javax.swing.JLabel jLabel3;
      private javax.swing.JLabel jLabel4;
      private javax.swing.JLabel jLabel5;
      private javax.swing.JSeparator jSeparator1;
      private javax.swing.JTextField txtDirectory;
      private javax.swing.JTextField txtHost;
      private javax.swing.JPasswordField txtPassword;
      private javax.swing.JTextField txtUser;
      // End of variables declaration    
      
  }
  
  
  