View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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  			{
42  				if( getComponentCount() == 0 )
43  					builder.addGlue();
44  				else
45  					builder.addUnrelatedGap();
46  			}
47  
48  			if( action == ActionSupport.SEPARATOR_ACTION )
49  			{
50  				builder.addUnrelatedGap();
51  			}
52  			else
53  			{
54  				if( c > 0 )
55  					builder.addRelatedGap();
56  
57  				JButton button = new JButton( action );
58  				if( c == 0 || actions.getDefaultAction() == action )
59  					defaultButton = button;
60  
61  				if( action.getValue( Action.SMALL_ICON ) != null )
62  					button.setText( null );
63  
64  				builder.addFixed( button );
65  			}
66  
67  			if( action instanceof HelpActionMarker && c == 0 )
68  				builder.addGlue();
69  		}
70  	}
71  
72  	public JButton getDefaultButton()
73  	{
74  		return defaultButton;
75  	}
76  }