View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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 com.eviware.soapui.support.HelpActionMarker;
16  import com.eviware.soapui.support.action.swing.ActionList;
17  import com.eviware.soapui.support.action.swing.ActionSupport;
18  import com.eviware.soapui.support.swing.JXButtonPanel;
19  import com.jgoodies.forms.builder.ButtonBarBuilder;
20  
21  import javax.swing.*;
22  
23  public class JButtonBar extends JXButtonPanel
24  {
25     private ButtonBarBuilder builder;
26     private JButton defaultButton;
27  
28     public JButtonBar()
29     {
30        builder = new ButtonBarBuilder( this );
31     }
32  
33     public void addActions( ActionList actions )
34     {
35        for( int c = 0; c < actions.getActionCount(); c++ )
36        {
37           Action action = actions.getActionAt( c );
38  
39           if( !( action instanceof HelpActionMarker ) && c == 0 )
40           {
41              if( getComponentCount() == 0 )
42                 builder.addGlue();
43              else
44                 builder.addUnrelatedGap();
45           }
46  
47           if( action == ActionSupport.SEPARATOR_ACTION )
48           {
49              builder.addUnrelatedGap();
50           }
51           else
52           {
53              if( c > 0 )
54                 builder.addRelatedGap();
55  
56              JButton button = new JButton( action );
57              if( c == 0 || actions.getDefaultAction() == action )
58                 defaultButton = button;
59  
60              if( action.getValue( Action.SMALL_ICON ) != null )
61                 button.setText( null );
62  
63              builder.addFixed( button );
64           }
65  
66           if( action instanceof HelpActionMarker && c == 0 )
67              builder.addGlue();
68        }
69     }
70  
71     public JButton getDefaultButton()
72     {
73        return defaultButton;
74     }
75  }