Coverage Report - org.jtheque.films.view.impl.toolbars.JPanelActorToolBar
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelActorToolBar
0 %
0/40
0 %
0/9
2.2
JPanelActorToolBar$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.actor.AcCancelActor;
 23  
 import org.jtheque.films.view.impl.actions.actor.AcDeleteActor;
 24  
 import org.jtheque.films.view.impl.actions.actor.AcDisplayFilmography;
 25  
 import org.jtheque.films.view.impl.actions.actor.AcEditActor;
 26  
 import org.jtheque.films.view.impl.actions.actor.AcNewActor;
 27  
 import org.jtheque.films.view.impl.actions.actor.AcSaveActor;
 28  
 import org.jtheque.primary.view.able.ToolbarView;
 29  
 import org.jtheque.primary.view.able.ViewMode;
 30  
 import org.jtheque.utils.ui.GridBagUtils;
 31  
 
 32  
 import javax.swing.Box;
 33  
 import javax.swing.JButton;
 34  
 import javax.swing.JPanel;
 35  
 import java.awt.Color;
 36  
 import java.awt.GridBagConstraints;
 37  
 
 38  
 /**
 39  
  * A tool bar for the actor view.
 40  
  *
 41  
  * @author Baptiste Wicht
 42  
  */
 43  
 public final class JPanelActorToolBar extends JPanel implements ToolbarView {
 44  
     private static final long serialVersionUID = -688094676844153411L;
 45  
 
 46  
     private final JButton buttonAdd;
 47  
     private final JButton buttonEdit;
 48  
     private final JButton buttonSave;
 49  
     private final JButton buttonCancel;
 50  
     private final JButton buttonDelete;
 51  
     private final JButton buttonFilmo;
 52  
 
 53  0
     private ViewMode mode = ViewMode.VIEW;
 54  
 
 55  0
     private final GridBagUtils gbc = new GridBagUtils();
 56  
 
 57  
     public JPanelActorToolBar() {
 58  0
         super();
 59  
         
 60  0
         setBackground(Color.white);
 61  0
         setBorder(Borders.DIALOG_BORDER);
 62  
 
 63  0
         buttonSave = new JButton(new AcSaveActor());
 64  0
         buttonCancel = new JButton(new AcCancelActor());
 65  0
         buttonDelete = new JButton(new AcDeleteActor());
 66  0
         buttonAdd = new JButton(new AcNewActor());
 67  0
         buttonEdit = new JButton(new AcEditActor());
 68  0
         buttonFilmo = new JButton(new AcDisplayFilmography());
 69  
 
 70  0
         add(Box.createHorizontalGlue(), gbc.gbcSet(0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.BASELINE_LEADING, 1.0, 1.0));
 71  
 
 72  0
         if (mode == ViewMode.VIEW) {
 73  0
             addViewModeButtons();
 74  
         } else {
 75  0
             addOtherModesButtons();
 76  
         }
 77  0
     }
 78  
 
 79  
     /**
 80  
      * Add the buttons of the view mode.
 81  
      */
 82  
     private void addViewModeButtons() {
 83  0
         add(buttonAdd, gbc.gbcSet(1, 0));
 84  0
         add(buttonEdit, gbc.gbcSet(2, 0));
 85  0
         add(buttonDelete, gbc.gbcSet(3, 0));
 86  0
         add(buttonFilmo, gbc.gbcSet(4, 0));
 87  0
     }
 88  
 
 89  
     /**
 90  
      * Add the button of the other modes.
 91  
      */
 92  
     private void addOtherModesButtons() {
 93  0
         add(buttonSave, gbc.gbcSet(1, 0));
 94  0
         add(buttonCancel, gbc.gbcSet(2, 0));
 95  0
     }
 96  
 
 97  
     /**
 98  
      * Set the display mode of the view.
 99  
      *
 100  
      * @param mode The display mode.
 101  
      */
 102  
     void setMode(ViewMode mode) {
 103  0
         if (this.mode != mode) {
 104  0
             this.mode = mode;
 105  
 
 106  0
             remove(buttonSave);
 107  0
             remove(buttonCancel);
 108  0
             remove(buttonAdd);
 109  0
             remove(buttonEdit);
 110  0
             remove(buttonFilmo);
 111  0
             remove(buttonDelete);
 112  
 
 113  0
             switch (mode) {
 114  
                 case VIEW:
 115  0
                     addViewModeButtons();
 116  
 
 117  0
                     break;
 118  
                 case NEW:
 119  
                 case EDIT:
 120  
                 case AUTO:
 121  0
                     addOtherModesButtons();
 122  
 
 123  
                     break;
 124  
             }
 125  
 
 126  0
             Managers.getManager(IViewManager.class).refresh(this);
 127  
         }
 128  0
     }
 129  
 
 130  
     @Override
 131  
     public void setDisplayMode(ViewMode mode) {
 132  0
         setMode(mode);
 133  0
     }
 134  
 }