Coverage Report - org.jtheque.core.managers.view.impl.components.config.JPanelConfigNetwork
 
Classes in this File Line Coverage Branch Coverage Complexity
JPanelConfigNetwork
0 %
0/33
0 %
0/2
1.091
 
 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.INetworkConfigView;
 23  
 import org.jtheque.core.managers.view.impl.actions.config.CheckProxyAction;
 24  
 import org.jtheque.core.utils.ui.Borders;
 25  
 import org.jtheque.core.utils.ui.PanelBuilder;
 26  
 import org.jtheque.core.utils.ui.ValidationUtils;
 27  
 import org.jtheque.utils.ui.GridBagUtils;
 28  
 
 29  
 import javax.swing.JCheckBox;
 30  
 import javax.swing.JComponent;
 31  
 import javax.swing.JPanel;
 32  
 import javax.swing.JTextField;
 33  
 import java.util.Collection;
 34  
 
 35  
 /**
 36  
  * A configuration panel for the network.
 37  
  *
 38  
  * @author Baptiste Wicht
 39  
  */
 40  
 public final class JPanelConfigNetwork extends JPanel implements INetworkConfigView, ConfigTabComponent {
 41  
     private JCheckBox boxProxy;
 42  
     private JTextField fieldAddress;
 43  
     private JTextField fieldPort;
 44  
 
 45  
     /**
 46  
      * Construct a new JPanelConfigNetwork. 
 47  
      */
 48  
     public JPanelConfigNetwork(){
 49  0
         super();
 50  
 
 51  0
         addProxyPanel();
 52  
 
 53  0
         fillAllFields();
 54  0
     }
 55  
 
 56  
     /**
 57  
      * Add the proxy panel.
 58  
      */
 59  
     private void addProxyPanel() {
 60  0
         PanelBuilder parent = new PanelBuilder(this);
 61  
 
 62  0
         PanelBuilder builder = parent.addPanel(parent.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.FIRST_LINE_START));
 63  0
         builder.getPanel().setBorder(Borders.createTitledBorder("config.network.proxy.title"));
 64  
 
 65  0
         boxProxy = builder.addI18nCheckBox("config.network.proxy.check",
 66  
                 parent.gbcSet(0, 0, GridBagUtils.HORIZONTAL, GridBagUtils.BASELINE_LEADING, 2, 1));
 67  0
         boxProxy.addActionListener(new CheckProxyAction());
 68  
 
 69  0
         builder.addI18nLabel("config.network.proxy.address", parent.gbcSet(0, 1));
 70  0
         fieldAddress = builder.add(new JTextField(10), parent.gbcSet(1, 1, GridBagUtils.HORIZONTAL));
 71  
 
 72  0
         builder.addI18nLabel("config.network.proxy.port", parent.gbcSet(0, 2));
 73  0
         fieldPort = builder.add(new JTextField(10), parent.gbcSet(1, 2, GridBagUtils.HORIZONTAL));
 74  0
     }
 75  
 
 76  
     /**
 77  
      * Fill all the fields with the current informations.
 78  
      */
 79  
     private void fillAllFields() {
 80  0
         boxProxy.setSelected(Managers.getCore().getConfiguration().hasAProxy());
 81  0
         fieldPort.setText(Managers.getCore().getConfiguration().getProxyPort());
 82  0
         fieldAddress.setText(Managers.getCore().getConfiguration().getProxyAddress());
 83  0
     }
 84  
 
 85  
     @Override
 86  
     public String getTitle() {
 87  0
         return Managers.getManager(ILanguageManager.class).getMessage("config.view.tab.network");
 88  
     }
 89  
 
 90  
     @Override
 91  
     public void apply() {
 92  0
         Managers.getCore().getConfiguration().setHasAProxy(boxProxy.isSelected());
 93  0
         Managers.getCore().getConfiguration().setProxyPort(fieldPort.getText());
 94  0
         Managers.getCore().getConfiguration().setProxyAddress(fieldAddress.getText());
 95  0
     }
 96  
 
 97  
     @Override
 98  
     public void cancel() {
 99  0
         fillAllFields();
 100  0
     }
 101  
 
 102  
     @Override
 103  
     public JTextField getFieldPort() {
 104  0
         return fieldPort;
 105  
     }
 106  
 
 107  
     @Override
 108  
     public JTextField getFieldAddress() {
 109  0
         return fieldAddress;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public JCheckBox getBoxProxy() {
 114  0
         return boxProxy;
 115  
     }
 116  
 
 117  
     @Override
 118  
     public void validate(Collection<JThequeError> errors) {
 119  0
         if (boxProxy.isSelected()) {
 120  0
             ValidationUtils.rejectIfEmpty(fieldAddress.getText(), "config.network.proxy.address", errors);
 121  0
             ValidationUtils.rejectIfEmpty(fieldPort.getText(), "config.network.proxy.port", errors);
 122  
         }
 123  0
     }
 124  
 
 125  
     @Override
 126  
     public JComponent getComponent() {
 127  0
         return this;
 128  
     }
 129  
 }