content: package com.japisoft.editix.ui.panels.project2.synchro;
  
  import java.awt.Component;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.File;
  
  import javax.swing.JPanel;
  import javax.swing.text.JTextComponent;
  
  import com.japisoft.editix.ui.EditixFactory;
  import com.japisoft.framework.ui.toolkit.FileManager;
  
  /**
  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 SynchroConfigPanel extends JPanel implements ActionListener {
  
      private static final String FILE_TYPE = "LOCAL/NETWORK";
      
  	/** Creates new form SynchroConfigPanel */
  	public SynchroConfigPanel() {
  	    initComponents();
  	    String[] types = 
  	    	SynchronizerFactory.getInstance().getTypes();
  	    for ( String type : types ) {
  	    	cbType.addItem( 
  	    		type
  	    	);
  	    }
  	    txtFilePath.setName( "path" );
  	    txtHost.setName( "host" );
  	    txtPort.setName( "port" );
  	    txtUser.setName( "user" );
  	    txtPassword.setName( "password" );
  	    txtFTPPath.setName( "path" );
  	    txtFTPPath.setText( "/" );
  	    
          jLayeredPane1.add(FilePanel, 0);
          jLayeredPane1.add(FtpPanel, 1 );
          
          jLayeredPane1.moveToFront( FilePanel );
  	}
  
  	public Synchronizer getSynchronizer() {
      	Synchronizer s = SynchronizerFactory.getInstance().getSynchronizer( 
      		( String )cbType.getSelectedItem() );
      	JPanel panel = getCurrentPanel();
      	for ( int i = 0; i < panel.getComponentCount(); i++ ) {
      		Component c = panel.getComponent( i );
      		if ( c instanceof JTextComponent ) {
      			s.setProperty( 
      				c.getName(), 
      				( ( JTextComponent )c ).getText() 
      			);
      		}
      	}
      	return s;
  	}
  
      public JPanel getCurrentPanel() {
      	Component[] c = jLayeredPane1.getComponentsInLayer( 0 );
      	return (JPanel)c[ 0 ];
      }
  
  	@Override
  	public void addNotify() {
  		super.addNotify();
  		cbType.addActionListener( this );
  		btTestFTP.addActionListener( this );
  		btChooseFilePath.addActionListener( this );
  		
  		cbType.setSelectedIndex( 0 );
  	}
  
  	@Override
  	public void removeNotify() {
  		super.removeNotify();
  		cbType.removeActionListener( this );
  		btTestFTP.removeActionListener( this );
  		btChooseFilePath.removeActionListener( this );
  	}
  
  	public void actionPerformed(ActionEvent e) {
  		if ( e.getSource() == cbType ) {
      		String type = ( String )cbType.getSelectedItem();
      		if ( FILE_TYPE.equalsIgnoreCase( type ) ) {
          		jLayeredPane1.moveToFront( FilePanel );    			
      		} else
      			jLayeredPane1.moveToFront( FtpPanel );
      	} else
      	if ( e.getSource() == btTestFTP ) {
      		if ( getSynchronizer().test() ) {
      			EditixFactory.buildAndShowInformationDialog( "Success" );
      		} else {
      			EditixFactory.buildAndShowWarningDialog( "Can't connect" );
      		}
      	} else
      	if ( e.getSource() == btChooseFilePath ) {
      		File path = FileManager.getSelectedDirectory();
      		if ( path != null )
      			txtFilePath.setText( path.toString() );
      	}
  	}
  
      /** 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.
       */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">
      private void initComponents() {
  
          jLabel1 = new javax.swing.JLabel();
          cbType = new javax.swing.JComboBox();
          jSeparator1 = new javax.swing.JSeparator();
          jLayeredPane1 = new javax.swing.JLayeredPane();
          FtpPanel = new javax.swing.JPanel();
          jLabel3 = new javax.swing.JLabel();
          txtHost = new javax.swing.JTextField();
          jLabel4 = new javax.swing.JLabel();
          txtPort = new javax.swing.JTextField();
          jLabel5 = new javax.swing.JLabel();
          txtUser = new javax.swing.JTextField();
          jLabel6 = new javax.swing.JLabel();
          jLabel7 = new javax.swing.JLabel();
          txtFTPPath = new javax.swing.JTextField();
          btTestFTP = new javax.swing.JButton();
          txtPassword = new javax.swing.JPasswordField();
          FilePanel = new javax.swing.JPanel();
          jLabel2 = new javax.swing.JLabel();
          txtFilePath = new javax.swing.JTextField();
          btChooseFilePath = new javax.swing.JButton();
  
          jLabel1.setText("Type");
          jLabel1.setName("jLabel1"); // NOI18N
  
          cbType.setName("cbType"); // NOI18N
  
          jSeparator1.setName("jSeparator1"); // NOI18N
  
          jLayeredPane1.setName("jLayeredPane1"); // NOI18N
  
          FtpPanel.setName("FtpPanel"); // NOI18N
  
          jLabel3.setText("Host");
          jLabel3.setName("jLabel3"); // NOI18N
  
          txtHost.setName("txtHost"); // NOI18N
  
          jLabel4.setText("Port");
          jLabel4.setName("jLabel4"); // NOI18N
  
          txtPort.setText("21");
          txtPort.setName("txtPort"); // NOI18N
  
          jLabel5.setText("User");
          jLabel5.setName("jLabel5"); // NOI18N
  
          txtUser.setName("txtUser"); // NOI18N
  
          jLabel6.setText("Password");
          jLabel6.setName("jLabel6"); // NOI18N
  
          jLabel7.setText("Path");
          jLabel7.setName("jLabel7"); // NOI18N
  
          txtFTPPath.setName("txtFTPPath"); // NOI18N
  
          btTestFTP.setText("Test");
          btTestFTP.setName("btTestFTP"); // NOI18N
  
          txtPassword.setText("jPasswordField1");
          txtPassword.setName("txtPassword"); // NOI18N
  
          javax.swing.GroupLayout FtpPanelLayout = new javax.swing.GroupLayout(FtpPanel);
          FtpPanel.setLayout(FtpPanelLayout);
          FtpPanelLayout.setHorizontalGroup(
              FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(FtpPanelLayout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(FtpPanelLayout.createSequentialGroup()
                          .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                              .addComponent(jLabel7)
                              .addComponent(jLabel6)
                              .addComponent(jLabel5)
                              .addComponent(jLabel3))
                          .addGap(18, 18, 18)
                          .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                              .addComponent(txtPassword)
                              .addComponent(txtFTPPath)
                              .addComponent(txtHost, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                              .addComponent(txtUser, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE))
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(jLabel4)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addComponent(btTestFTP))
                  .addContainerGap(32, Short.MAX_VALUE))
          );
          FtpPanelLayout.setVerticalGroup(
              FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(FtpPanelLayout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel4)
                      .addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel3))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(txtUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel5))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel6)
                      .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGap(18, 18, 18)
                  .addGroup(FtpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(txtFTPPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel7))
                  .addGap(18, 18, 18)
                  .addComponent(btTestFTP)
                  .addContainerGap(18, Short.MAX_VALUE))
          );
  
          FtpPanel.setBounds(10, 10, 380, 190);
  
  
          FilePanel.setName("FilePanel"); // NOI18N
  
          jLabel2.setText("Path");
          jLabel2.setName("jLabel2"); // NOI18N
  
          txtFilePath.setName("txtFilePath"); // NOI18N
  
          btChooseFilePath.setText("Choose...");
          btChooseFilePath.setName("btChooseFilePath"); // NOI18N
  
          javax.swing.GroupLayout FilePanelLayout = new javax.swing.GroupLayout(FilePanel);
          FilePanel.setLayout(FilePanelLayout);
          FilePanelLayout.setHorizontalGroup(
              FilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(FilePanelLayout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(FilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(txtFilePath, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                      .addComponent(jLabel2)
                      .addComponent(btChooseFilePath))
                  .addContainerGap())
          );
          FilePanelLayout.setVerticalGroup(
              FilePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(FilePanelLayout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jLabel2)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(txtFilePath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(btChooseFilePath)
                  .addContainerGap(110, Short.MAX_VALUE))
          );
  
          FilePanel.setBounds(10, 10, 380, 190);
          
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
          this.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                      .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
                      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                          .addComponent(jLabel1)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(cbType, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                      .addComponent(jLayeredPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE))
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(jLabel1)
                      .addComponent(cbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                  .addContainerGap())
          );
      }// </editor-fold>
  
  
      // Variables declaration - do not modify
      private javax.swing.JPanel FilePanel;
      private javax.swing.JPanel FtpPanel;
      private javax.swing.JButton btChooseFilePath;
      private javax.swing.JButton btTestFTP;
      private javax.swing.JComboBox cbType;
      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.JLabel jLabel6;
      private javax.swing.JLabel jLabel7;
      private javax.swing.JLayeredPane jLayeredPane1;
      private javax.swing.JSeparator jSeparator1;
      private javax.swing.JTextField txtFTPPath;
      private javax.swing.JTextField txtFilePath;
      private javax.swing.JTextField txtHost;
      private javax.swing.JPasswordField txtPassword;
      private javax.swing.JTextField txtPort;
      private javax.swing.JTextField txtUser;
      // End of variables declaration
  
  }
  