View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    10   *  See the GNU Lesser General Public License for more details at gnu.org.
    11   */
    12
    13   package> com.eviware.soapui.support.components;
    14
    15  import javax.swing.Action;
    16  import javax.swing.JButton;
    17
    18  import com.eviware.soapui.support.HelpActionMarker;
    19  import com.eviware.soapui.support.action.swing.ActionList;
    20  import com.eviware.soapui.support.action.swing.ActionSupport;
    21  import com.eviware.soapui.support.swing.JXButtonPanel;
    22  import com.jgoodies.forms.builder.ButtonBarBuilder;
    23
    24  public class JButtonBar extends JXButtonPanel
    25  {
    26  	private ButtonBarBuilder builder;
    27  	private JButton defaultButton;
    28
    29  	public JButtonBar()
    30  	{
    31  		builder = new ButtonBarBuilder( this );
    32  	}
    33
    34  	public void addActions(ActionList actions)
    35  	{
    36  		for( int c = 0; c < actions.getActionCount(); c++ )
    37  		{
    38  			Action action = actions.getActionAt( c );
    39
    40  			if( !(action instanceof HelpActionMarker) && c == 0 )
    41  				builder.addGlue();
    42
    43  			if( action == ActionSupport.SEPARATOR_ACTION )
    44  			{
    45  	   		builder.addUnrelatedGap();
    46  			}
    47  	   	else
    48  	   	{
    49  	   		if( c > 0 )
    50  	   			builder.addRelatedGap();
    51
    52  	   		JButton button = new JButton( action);
    53  	   		if( c == 0 || actions.getDefaultAction() == action)
    54  	   			defaultButton = button;
    55
    56  	   		if( action.getValue( Action.SMALL_ICON ) != null )
    57  	   			button.setText( null );
    58
    59  				builder.addFixed( button);
    60  	   	}
    61
    62  			if( action instanceof HelpActionMarker && c == 0 )
    63  				builder.addGlue();
    64  	   }
    65  	}
    66
    67  	public JButton getDefaultButton()
    68  	{
    69  		return defaultButton;
    70  	}
    71  }