/*
 * Copyright (C) 2001-2006 University Bayreuth, BayCEER, Dept. of Mycology 
 * 
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package net.metadiversity.diversity.navikey.ui;

import java.awt.BorderLayout;
import java.util.Vector;

import javax.swing.JList;
import javax.swing.JLabel;
import net.metadiversity.diversity.navikey.bo.BasicItemCharacter;

/**
 * ItemCharacterPanel.java
 *
 * @author Michael Bartley
 * 3/25/98
 * @author Dieter Neubacher
 */

class ItemCharacterPanel extends javax.swing.JPanel
{
    
    /**
     * Comment for <code>serialVersionUID</code>
     */
    private static final long serialVersionUID = 3257007657100653361L;
    Vector basicItemCharacters;
    javax.swing.JList theList;
    javax.swing.JScrollPane jScrollPane;
    
    Vector listData;
    
    private final static int VISIBLE_ROWS = 15;
    private boolean enableColorSelection = false;
    
    public ItemCharacterPanel()
    {
        super();
        setLayout( new BorderLayout() );

        JLabel title = new JLabel( "Characters available" );
        add( java.awt.BorderLayout.NORTH, title );
        
        basicItemCharacters = null;
        
        listData = new java.util.Vector();
        
        theList = new JList( listData );
        theList.setVisibleRowCount( VISIBLE_ROWS );
        theList.setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION );
        
        jScrollPane = new javax.swing.JScrollPane();
        jScrollPane.setViewportView( theList );
        
        add( java.awt.BorderLayout.CENTER, jScrollPane );
        
        if( enableColorSelection )
        {
            theList.setBackground( NaviKey.naviKeyBackgroundColor );
            theList.setForeground( NaviKey.itemCharacterColor );            
        }
        
        setVisible( true );        
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    public void addListSelectionListener( javax.swing.event.ListSelectionListener l )
    {
        theList.addListSelectionListener( l );
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    public JList getTheList()
    {
        return theList;
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    public BasicItemCharacter getItemCharacter()
    {
        return ( BasicItemCharacter ) basicItemCharacters.elementAt( theList.getSelectedIndex() );
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    public BasicItemCharacter getItemCharacter( int index )
    {
        return ( BasicItemCharacter ) basicItemCharacters.elementAt( index );
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    public void setItemCharacters( Vector basicItemCharacters )
    {
        this.basicItemCharacters = basicItemCharacters;
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
    public void updateList()
    {
        theList.removeAll();
        listData.removeAllElements();
        
        if( basicItemCharacters == null )
        {
            System.out.println( "NULL, idiot" );
        }
        else
        {
            for( int i = 0; i < basicItemCharacters.size(); i++ )
            {
                BasicItemCharacter ic = ( BasicItemCharacter )basicItemCharacters.elementAt( i );
                
                // dependencies
                // only add the character if not depended
                
                listData.add( ic.getFeature() );
            }
            // Don't sort ItemCharacters
            // java.util.Collections.sort( listData );
            theList.setListData( listData );
        }
    }
    //--------------------------------------------------------------------------
    //--------------------------------------------------------------------------
}
