Coverage Report - org.jtheque.core.managers.view.impl.components.config.JPanelConfigAppearance
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelConfigAppearance
0 %
0/29
N/A
1
 
 1  
 package org.jtheque.core.managers.view.impl.components.config;
 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.core.CoreConfiguration;
 21  
 import org.jtheque.core.managers.error.JThequeError;
 22  
 import org.jtheque.core.managers.language.ILanguageManager;
 23  
 import org.jtheque.core.managers.view.able.config.IAppearanceConfigView;
 24  
 import org.jtheque.core.managers.view.impl.components.model.AvailableLanguagesComboBoxModel;
 25  
 import org.jtheque.core.utils.ui.Borders;
 26  
 import org.jtheque.core.utils.ui.PanelBuilder;
 27  
 import org.jtheque.core.utils.ui.ValidationUtils;
 28  
 import org.jtheque.utils.ui.GridBagUtils;
 29  
 
 30  
 import javax.swing.JCheckBox;
 31  
 import javax.swing.JComponent;
 32  
 import javax.swing.JPanel;
 33  
 import java.util.Collection;
 34  
 
 35  
 /**
 36  
  * A config panel for the appearance.
 37  
  *
 38  
  * @author Baptiste Wicht
 39  
  */
 40  
 public final class JPanelConfigAppearance extends JPanel implements ConfigTabComponent, IAppearanceConfigView {
 41  
     private AvailableLanguagesComboBoxModel modelLanguages;
 42  
     private JCheckBox boxRetainSizeAndPosition;
 43  
 
 44  
     /**
 45  
      * Construct a new JPanelConfigAppearance.
 46  
      */
 47  
     public JPanelConfigAppearance() {
 48  0
         super();
 49  
 
 50  0
         PanelBuilder builder = new PanelBuilder(this);
 51  
 
 52  0
         addPanelGeneral(builder);
 53  0
         addPanelLookAndFeel(builder);
 54  
 
 55  0
         fillAllFields();
 56  0
     }
 57  
 
 58  
     @Override
 59  
     public String getTitle() {
 60  0
         return Managers.getManager(ILanguageManager.class).getMessage("config.view.tab.appearance");
 61  
     }
 62  
 
 63  
     /**
 64  
      * Add the panel "generals options".
 65  
      *
 66  
      * @param parent The parent builder.
 67  
      */
 68  
     private void addPanelGeneral(PanelBuilder parent) {
 69  0
         PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START));
 70  0
         builder.getPanel().setBorder(Borders.createTitledBorder("config.appearance.general.title"));
 71  
 
 72  0
         builder.addI18nLabel("config.appearance.language", parent.gbcSet(0, 0));
 73  
 
 74  0
         modelLanguages = new AvailableLanguagesComboBoxModel();
 75  
 
 76  0
         builder.addComboBox(modelLanguages, parent.gbcSet(1, 0, GridBagUtils.HORIZONTAL));
 77  
 
 78  0
         boxRetainSizeAndPosition = builder.addI18nCheckBox("config.appearance.size",
 79  
                 parent.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1));
 80  0
     }
 81  
 
 82  
     /**
 83  
      * Add the "look and feel" panel.
 84  
      *
 85  
      * @param parent The parent builder.
 86  
      */
 87  
     private static void addPanelLookAndFeel(PanelBuilder parent) {
 88  0
         PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START));
 89  0
         builder.getPanel().setBorder(Borders.createTitledBorder("config.appearance.lookandfeel"));
 90  0
     }
 91  
 
 92  
     /**
 93  
      * Fill the all fields with the current configurations.
 94  
      */
 95  
     private void fillAllFields() {
 96  0
         modelLanguages.setSelectedItem(Managers.getManager(ILanguageManager.class).getCurrentLanguage());
 97  0
         boxRetainSizeAndPosition.setSelected(Managers.getCore().getConfiguration().retainSizeAndPositionOfWindow());
 98  0
     }
 99  
 
 100  
     @Override
 101  
     public void apply() {
 102  0
         CoreConfiguration configuration = Managers.getCore().getConfiguration();
 103  
 
 104  0
         Managers.getManager(ILanguageManager.class).setCurrentLanguage(modelLanguages.getSelectedLanguage());
 105  0
         configuration.setRetainSizeAndPositionOfWindow(boxRetainSizeAndPosition.isSelected());
 106  0
     }
 107  
 
 108  
     @Override
 109  
     public void cancel() {
 110  0
         fillAllFields();
 111  0
     }
 112  
 
 113  
     @Override
 114  
     public void validate(Collection<JThequeError> errors) {
 115  0
         ValidationUtils.rejectIfNothingSelected(modelLanguages, "config.appearance.language", errors);
 116  0
     }
 117  
 
 118  
     @Override
 119  
     public JComponent getComponent() {
 120  0
         return this;
 121  
     }
 122  
 }