/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * published by the Free Software Foundation; either version 2.1 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite
 * 330, Boston, MA  02111-1307, USA.
 * 
 */
 
package com.k_int.AdminApp.widgets;

import javax.swing.JComboBox;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComponent;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.logging.*;

/**
 * Title:       SelectionEnablingComboController
 * @version     $Id: SelectionEnablingComboController.java,v 1.1 2004/11/15 13:47:50 rob Exp $
 * Copyright:   Copyright (C) 1999 - 2004,Knowledge Integration Ltd.
 * @author      Rob Tice (rob.tice@k-int.com)
 * Company:     Knowledge Integration Ltd.
 * Description: 
 * 
 * Created 		Jul 26, 2004 7:09:57 PM
 * 
 * History:		
 * 				$Log: SelectionEnablingComboController.java,v $
 * 				Revision 1.1  2004/11/15 13:47:50  rob
 * 				*** empty log message ***
 * 				
 * 				Revision 1.1  2004/08/05 18:42:29  rob
 * 				*** empty log message ***
 * 				
 *
 */
public class SelectionEnablingComboController extends JComboBox
{
    private static Logger cat = Logger.getLogger("com.k_int.AdminApp.widgets.SelectionEnablingComboCOntroller");
    private ArrayList controlled_components = new ArrayList();
    boolean initialized;
    
    public SelectionEnablingComboController(Object[] objects)
    {
        super(objects);
    }
    
    public void addControlledComponent(JComponent component)
    {
        component.setEnabled(false);
        controlled_components.add(component);
    }
 
 
    public void setSelectedItem(Object item)
    {
        super.setSelectedItem(item);
        cat.fine("Set selected item"+item.toString());
        boolean enabled=false;
        if(item==null || item.toString().trim().equals(""))
        {;}
        else
            enabled=true;
       
       setComponentsEnabled(enabled);
    }
    
    
    protected void setComponentsEnabled(boolean enabled)
    {
        Iterator i = controlled_components.iterator();
        while(i.hasNext())
        {          
           JComponent component = (JComponent) i.next();          
           component.setEnabled(enabled);     
           cat.fine("Setting enabled" +enabled+" for "+component);      
       }         
    }
    
  /**  public void validate()
    {
        super.validate();
        setSelectedItem(getSelectedItem());
    }**/
    
    public void paint(Graphics g)
    {
        super.paint(g);
        if(initialized==false)
        {
            initialized=true;
            setSelectedItem(getSelectedItem());
            
        }
    }
     
}
