Coverage Report - org.jtheque.core.managers.view.impl.components.config.JPanelConfigOthers
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelConfigOthers
0 %
0/38
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.error.JThequeError;
 21  
 import org.jtheque.core.managers.language.ILanguageManager;
 22  
 import org.jtheque.core.managers.view.able.config.IOthersConfigView;
 23  
 import org.jtheque.core.managers.view.impl.components.JThequeCheckBox;
 24  
 import org.jtheque.core.utils.ui.Borders;
 25  
 import org.jtheque.core.utils.ui.PanelBuilder;
 26  
 import org.jtheque.utils.ui.GridBagUtils;
 27  
 
 28  
 import javax.swing.JCheckBox;
 29  
 import javax.swing.JComponent;
 30  
 import javax.swing.JPanel;
 31  
 import javax.swing.JTextField;
 32  
 import java.util.Collection;
 33  
 
 34  
 /**
 35  
  * Configuration panel for the others options.
 36  
  *
 37  
  * @author Baptiste Wicht
 38  
  */
 39  
 public final class JPanelConfigOthers extends JPanel implements IOthersConfigView, ConfigTabComponent {
 40  
     private JCheckBox boxDeleteLogs;
 41  
     private JCheckBox checkBoxStart;
 42  
     private JTextField fieldEmail;
 43  
     private JTextField fieldSmtpHost;
 44  
 
 45  
     /**
 46  
      * Construct a new JPanelConfigOthers.
 47  
      */
 48  
     public JPanelConfigOthers() {
 49  0
         super();
 50  
 
 51  0
         build();
 52  
 
 53  0
         fillAllFields();
 54  0
     }
 55  
 
 56  
     @Override
 57  
     public String getTitle() {
 58  0
         return Managers.getManager(ILanguageManager.class).getMessage("config.view.tab.others");
 59  
     }
 60  
 
 61  
     /**
 62  
      * Build the view.
 63  
      */
 64  
     private void build() {
 65  0
         PanelBuilder builder = new PanelBuilder(this);
 66  
 
 67  0
         addLogsPanel(builder);
 68  0
         addMailPanel(builder);
 69  
 
 70  0
         checkBoxStart = new JThequeCheckBox("update.view.verify");
 71  0
         add(checkBoxStart, builder.gbcSet(0, 2));
 72  0
     }
 73  
 
 74  
     /**
 75  
      * Add the "logs" panel.
 76  
      *
 77  
      * @param parent The parent builder.
 78  
      */
 79  
     private void addLogsPanel(PanelBuilder parent) {
 80  0
         PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START));
 81  0
         builder.getPanel().setBorder(Borders.createTitledBorder("config.others.logs.title"));
 82  
 
 83  0
         boxDeleteLogs = builder.addI18nCheckBox("config.others.logs.delete",
 84  
                 builder.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1));
 85  
 
 86  0
         builder.addI18nLabel("config.others.logs.days", builder.gbcSet(0, 1));
 87  0
     }
 88  
 
 89  
     /**
 90  
      * Add the "mail" panel.
 91  
      *
 92  
      * @param parent The parent builder.
 93  
      */
 94  
     private void addMailPanel(PanelBuilder parent) {
 95  0
         PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 1, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START));
 96  0
         builder.getPanel().setBorder(Borders.createTitledBorder("config.others.mail.title"));
 97  
 
 98  0
         builder.addI18nLabel("config.others.mail.userEmail", builder.gbcSet(0, 0, GridBagUtils.NONE, GridBagUtils.BASELINE_TRAILING));
 99  0
         builder.addI18nLabel("config.others.mail.smtpHost", builder.gbcSet(0, 1, GridBagUtils.NONE, GridBagUtils.BASELINE_TRAILING));
 100  
 
 101  0
         fieldEmail = builder.add(new JTextField(10), builder.gbcSet(1, 0, GridBagUtils.HORIZONTAL));
 102  0
         fieldSmtpHost = builder.add(new JTextField(10), builder.gbcSet(1, 1, GridBagUtils.HORIZONTAL));
 103  0
     }
 104  
 
 105  
     /**
 106  
      * Fill all the fields with the current informations.
 107  
      */
 108  
     private void fillAllFields() {
 109  0
         checkBoxStart.setSelected(Managers.getCore().getConfiguration().verifyUpdateOnStartup());
 110  0
         boxDeleteLogs.setSelected(Managers.getCore().getConfiguration().mustDeleteLogs());
 111  0
         fieldEmail.setText(Managers.getCore().getConfiguration().getUserEmail());
 112  0
         fieldSmtpHost.setText(Managers.getCore().getConfiguration().getSmtpHost());
 113  0
     }
 114  
 
 115  
     @Override
 116  
     public void apply() {
 117  0
         Managers.getCore().getConfiguration().setVerifyUpdateOnStartup(checkBoxStart.isSelected());
 118  0
         Managers.getCore().getConfiguration().setMustDeleteLogs(boxDeleteLogs.isSelected());
 119  0
         Managers.getCore().getConfiguration().setUserEmail(fieldEmail.getText());
 120  0
         Managers.getCore().getConfiguration().setSmtpHost(fieldSmtpHost.getText());
 121  0
     }
 122  
 
 123  
     @Override
 124  
     public void cancel() {
 125  0
         fillAllFields();
 126  0
     }
 127  
 
 128  
     @Override
 129  
     public JCheckBox getBoxDeleteLogs() {
 130  0
         return boxDeleteLogs;
 131  
     }
 132  
 
 133  
     @Override
 134  
     public void validate(Collection<JThequeError> errors) {
 135  
         //Nothing to validate in the view
 136  0
     }
 137  
 
 138  
     @Override
 139  
     public JComponent getComponent() {
 140  0
         return this;
 141  
     }
 142  
 }