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