001         package com.croftsoft.core.gui;
002    
003         import java.awt.*;
004    
005         import com.croftsoft.core.lang.NullArgumentException;
006    
007         /*********************************************************************
008         * A Panel of Buttons evenly distributed in a single horizontal row.
009         *
010         * <p>
011         * Uses GridBagLayout instead of GridLayout to ensure even distribution
012         * during layout of the Buttons when the Panel is odd-sized.
013         * </p>
014         *
015         * <p>
016         * Example:
017         * <code>
018         * <pre>
019         * buttonPanel = new ButtonPanel1 (
020         *   new Button [ ] {
021         *     playButton  = new Button ( "Play"  ),
022         *     stopButton  = new Button ( "Stop"  ),
023         *     pauseButton = new Button ( "Pause" ) } );
024         * </pre>
025         * </code>
026         * </p>
027         *
028         * <p>
029         * Java 1.1 compatible.
030         * </p>
031         *
032         * @version
033         *   2001-08-08
034         * @since
035         *   2001-04-16
036         * @author
037         *   <a href="http://www.CroftSoft.com/">David W. Croft</a>
038         *********************************************************************/
039    
040         public final class  ButtonPanel1
041           extends Panel
042         //////////////////////////////////////////////////////////////////////
043         //////////////////////////////////////////////////////////////////////
044         {
045    
046         /*********************************************************************
047         * @param  panelBackgroundColor
048         *
049         *   If null, the default will be used.
050         *
051         * @throws NullArgumentException
052         *
053         *   If buttons is null or buttons[i] is null.
054         *********************************************************************/
055         public  ButtonPanel1 (
056           Button [ ]  buttons,
057           Color       panelBackgroundColor )
058         //////////////////////////////////////////////////////////////////////
059         {
060           super ( new GridBagLayout ( ) );
061    
062           NullArgumentException.check ( buttons );
063    
064           GridBagConstraints  gridBagConstraints = new GridBagConstraints ( );
065    
066           gridBagConstraints.weightx = 1.0;
067    
068           gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
069    
070           for ( int  i = 0; i < buttons.length; i++ )
071           {
072             Button  button = buttons [ i ];
073    
074             NullArgumentException.check (
075               button, "buttons[" + i + "] is null" );
076    
077             gridBagConstraints.gridx = i;
078    
079             add ( button, gridBagConstraints );
080           }
081    
082           if ( panelBackgroundColor != null )
083           {
084             setBackground ( panelBackgroundColor );
085           }
086         }
087    
088         /*********************************************************************
089         * this ( buttons, null );
090         *********************************************************************/
091         public  ButtonPanel1 ( Button [ ]  buttons )
092         //////////////////////////////////////////////////////////////////////
093         {
094           this ( buttons, null );
095         }
096    
097         //////////////////////////////////////////////////////////////////////
098         //////////////////////////////////////////////////////////////////////
099         }