Coverage Report - org.jtheque.utils.ui.ButtonBarBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ButtonBarBuilder
0%
0/16
0%
0/2
1.2
 
 1  
 package org.jtheque.utils.ui;
 2  
 
 3  
 import javax.swing.Action;
 4  
 import javax.swing.Box;
 5  
 import javax.swing.JButton;
 6  
 import javax.swing.JPanel;
 7  
 import java.awt.Color;
 8  
 import java.awt.Component;
 9  
 import java.awt.GridBagConstraints;
 10  
 import java.awt.GridBagLayout;
 11  
 
 12  
 /*
 13  
  * This file is part of JTheque.
 14  
  *
 15  
  * JTheque is free software: you can redistribute it and/or modify
 16  
  * it under the terms of the GNU General Public License as published by
 17  
  * the Free Software Foundation, either version 3 of the License.
 18  
  *
 19  
  * JTheque is distributed in the hope that it will be useful,
 20  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 21  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 22  
  * GNU General Public License for more details.
 23  
  *
 24  
  * You should have received a copy of the GNU General Public License
 25  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 26  
  */
 27  
 
 28  
 /**
 29  
  * A builder for a button bar.
 30  
  *
 31  
  * @author Baptiste Wicht
 32  
  */
 33  
 public final class ButtonBarBuilder {
 34  
     private final JPanel panel;
 35  
     private final GridBagUtils gbc;
 36  
 
 37  
     private int column;
 38  
 
 39  
     /**
 40  
      * Construct a new ButtonBarBuilder.
 41  
      */
 42  
     public ButtonBarBuilder() {
 43  0
         super();
 44  
 
 45  0
         panel = new JPanel(new GridBagLayout());
 46  0
         panel.setBackground(Color.white);
 47  0
         gbc = new GridBagUtils();
 48  0
         gbc.setDefaultInsets(2, 2, 2, 2);
 49  0
     }
 50  
 
 51  
     /**
 52  
      * Add an action to the bar.
 53  
      *
 54  
      * @param action The action to add.
 55  
      */
 56  
     private void addAction(Action action) {
 57  0
         panel.add(new JButton(action), gbc.gbcSet(column, 0, GridBagConstraints.NONE, GridBagConstraints.BASELINE));
 58  0
         column++;
 59  0
     }
 60  
 
 61  
     /**
 62  
      * Add actions to the bar.
 63  
      *
 64  
      * @param actions The actions to add.
 65  
      */
 66  
     public void addActions(Action... actions) {
 67  0
         for (Action action : actions) {
 68  0
             addAction(action);
 69  
         }
 70  0
     }
 71  
 
 72  
     /**
 73  
      * A a glue to the bar.
 74  
      */
 75  
     public void addGlue() {
 76  0
         panel.add(Box.createHorizontalGlue(), gbc.gbcSet(column, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.BASELINE, 1.0, 1.0));
 77  0
         column++;
 78  0
     }
 79  
 
 80  
     /**
 81  
      * Return the panel.
 82  
      *
 83  
      * @return The panel.
 84  
      */
 85  
     public Component getPanel() {
 86  0
         return panel;
 87  
     }
 88  
 }