content: package com.japisoft.editix.ui.panels.project2.synchro;
  
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JPanel;
  
  import com.japisoft.framework.ApplicationModel;
  import com.japisoft.framework.dialog.DialogManager;
  
  /**
  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 SynchroChoosePanel extends JPanel implements ActionListener {
  
  	private int initSelection;
  	
      /** Creates new form SynchroPanel */
      public SynchroChoosePanel( Synchronizer[] synchronizers, int selection ) {
          initComponents();
          if ( synchronizers != null ) {
          	for ( Synchronizer s : synchronizers ) {
          		cbConfig.addItem( s );
          	}
          }
          initSelection = selection;
      }
  
      @Override
      public void addNotify() {
      	super.addNotify();
      	btDelete.addActionListener( this );
      	btNewConfig.addActionListener( this );
      	if ( initSelection > -1 && cbConfig.getItemCount() > 0 ) {
      		cbConfig.setSelectedIndex( initSelection );
      	}
      }
  
      @Override
      public void removeNotify() {
      	super.removeNotify();
      	btDelete.removeActionListener( this );
      	btNewConfig.removeActionListener( this );    	
      }
      
      public Synchronizer[] getSynchronizers() {
      	Synchronizer[] t = new Synchronizer[ cbConfig.getItemCount() ];
      	for ( int i = 0; i< cbConfig.getItemCount(); i++ ) {
      		t[ i ] = ( Synchronizer )cbConfig.getItemAt( i );
      	}
      	return t;
      }
      
      public Synchronizer getSelectedSynchronizer() {
      	return ( Synchronizer )cbConfig.getSelectedItem();
      }
      
      public void actionPerformed(ActionEvent e) {
      	if ( e.getSource() == btDelete ) {
      		if ( cbConfig.getSelectedItem() != null )
      			cbConfig.removeItem( 
      				cbConfig.getSelectedItem() 
      			);
      	} else 
      	if ( e.getSource() == btNewConfig ) {
      		SynchroConfigPanel scp = new SynchroConfigPanel();
      		if ( DialogManager.showDialog( 
      			ApplicationModel.MAIN_FRAME, 
      			"Configuration", 
      			"Configuration", 
      			"Configuration a server", 
      			null, 
      			scp ) == DialogManager.OK_ID ) {
      			Synchronizer s = scp.getSynchronizer();
      			if ( s != null ) {
      				cbConfig.addItem( s );
      				cbConfig.setSelectedItem( s );
      			}
      		}
      	}
      }
  
      /** 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();
          cbConfig = new javax.swing.JComboBox();
          btNewConfig = new javax.swing.JButton();
          btDelete = new javax.swing.JButton();
  
          jLabel1.setText("Source");
          jLabel1.setName("jLabel1"); // NOI18N
  
          cbConfig.setName("cbConfig"); // NOI18N
  
          btNewConfig.setText("New source...");
          btNewConfig.setName("btNewConfig"); // NOI18N
  
          btDelete.setText("Delete");
          btDelete.setName("btDelete"); // NOI18N
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
          this.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jLabel1)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(layout.createSequentialGroup()
                          .addComponent(btNewConfig)
                          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                          .addComponent(btDelete))
                      .addComponent(cbConfig, 0, 383, 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(cbConfig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(btNewConfig)
                      .addComponent(btDelete))
                  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          );
      }// </editor-fold>
  
  
      // Variables declaration - do not modify
      private javax.swing.JButton btDelete;
      private javax.swing.JButton btNewConfig;
      private javax.swing.JComboBox cbConfig;
      private javax.swing.JLabel jLabel1;
      // End of variables declaration
  
  }
  