Coverage Report - org.jtheque.films.view.impl.toolbars.JPanelRealizerToolBar
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelRealizerToolBar
0 %
0/37
0 %
0/9
2.2
JPanelRealizerToolBar$1
0 %
0/1
N/A
2.2
 
 1  
 package org.jtheque.films.view.impl.toolbars;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.view.able.IViewManager;
 21  
 import org.jtheque.core.utils.ui.Borders;
 22  
 import org.jtheque.films.view.impl.actions.realizer.AcCancelRealizer;
 23  
 import org.jtheque.films.view.impl.actions.realizer.AcDeleteRealizer;
 24  
 import org.jtheque.films.view.impl.actions.realizer.AcEditRealizer;
 25  
 import org.jtheque.films.view.impl.actions.realizer.AcNewRealizer;
 26  
 import org.jtheque.films.view.impl.actions.realizer.AcSaveRealizer;
 27  
 import org.jtheque.primary.view.able.ToolbarView;
 28  
 import org.jtheque.primary.view.able.ViewMode;
 29  
 import org.jtheque.utils.ui.GridBagUtils;
 30  
 
 31  
 import javax.swing.Box;
 32  
 import javax.swing.JButton;
 33  
 import javax.swing.JPanel;
 34  
 import java.awt.Color;
 35  
 import java.awt.GridBagConstraints;
 36  
 
 37  
 /**
 38  
  * Tool bar for realizers.
 39  
  *
 40  
  * @author Baptiste Wicht
 41  
  */
 42  
 public final class JPanelRealizerToolBar extends JPanel implements ToolbarView {
 43  
     private static final long serialVersionUID = -688094676844153411L;
 44  
 
 45  
     private final JButton buttonAdd;
 46  
     private final JButton buttonEdit;
 47  
     private final JButton buttonSave;
 48  
     private final JButton buttonCancel;
 49  
     private final JButton buttonDelete;
 50  
 
 51  0
     private ViewMode mode = ViewMode.VIEW;
 52  
 
 53  0
     private final GridBagUtils gbc = new GridBagUtils();
 54  
 
 55  
     public JPanelRealizerToolBar() {
 56  0
         super();
 57  
         
 58  0
         setBackground(Color.white);
 59  0
         setBorder(Borders.DIALOG_BORDER);
 60  
         
 61  0
         buttonSave = new JButton(new AcSaveRealizer());
 62  0
         buttonCancel = new JButton(new AcCancelRealizer());
 63  0
         buttonDelete = new JButton(new AcDeleteRealizer());
 64  0
         buttonAdd = new JButton(new AcNewRealizer());
 65  0
         buttonEdit = new JButton(new AcEditRealizer());
 66  
 
 67  0
         add(Box.createHorizontalGlue(), gbc.gbcSet(0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.BASELINE_LEADING, 1.0, 1.0));
 68  
 
 69  0
         if (mode == ViewMode.VIEW) {
 70  0
             addViewModeButtons();
 71  
         } else {
 72  0
             addOtherModesButtons();
 73  
         }
 74  0
     }
 75  
 
 76  
     /**
 77  
      * Add the buttons for the view mode.
 78  
      */
 79  
     private void addViewModeButtons() {
 80  0
         add(buttonAdd, gbc.gbcSet(1, 0));
 81  0
         add(buttonEdit, gbc.gbcSet(2, 0));
 82  0
         add(buttonDelete, gbc.gbcSet(3, 0));
 83  0
     }
 84  
 
 85  
     /**
 86  
      * Add the buttons for all the others mode.
 87  
      */
 88  
     private void addOtherModesButtons() {
 89  0
         add(buttonSave, gbc.gbcSet(1, 0));
 90  0
         add(buttonCancel, gbc.gbcSet(2, 0));
 91  0
     }
 92  
 
 93  
     /**
 94  
      * Set the current mode of the view.
 95  
      *
 96  
      * @param mode The new current mode.
 97  
      */
 98  
     void setMode(ViewMode mode) {
 99  0
         if (this.mode != mode) {
 100  0
             this.mode = mode;
 101  
 
 102  0
             remove(buttonSave);
 103  0
             remove(buttonCancel);
 104  0
             remove(buttonAdd);
 105  0
             remove(buttonEdit);
 106  0
             remove(buttonDelete);
 107  
 
 108  0
             switch (mode) {
 109  
                 case VIEW:
 110  0
                     addViewModeButtons();
 111  
 
 112  0
                     break;
 113  
                 case NEW:
 114  
                 case EDIT:
 115  
                 case AUTO:
 116  0
                     addOtherModesButtons();
 117  
 
 118  
                     break;
 119  
             }
 120  
 
 121  0
             Managers.getManager(IViewManager.class).refresh(this);
 122  
         }
 123  0
     }
 124  
 
 125  
     @Override
 126  
     public void setDisplayMode(ViewMode mode) {
 127  0
         setMode(mode);
 128  0
     }
 129  
 }