Coverage Report - org.xmlhammer.gui.preferences.ProxyPreferencesPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
ProxyPreferencesPanel
95% 
100% 
1
 
 1  
 /*
 2  
  * $Id$
 3  
  *
 4  
  * The contents of this file are subject to the Mozilla Public License 
 5  
  * Version 1.1 (the "License"); you may not use this file except in 
 6  
  * compliance with the License. You may obtain a copy of the License at 
 7  
  * http://www.mozilla.org/MPL/ 
 8  
  *
 9  
  * Software distributed under the License is distributed on an "AS IS" basis, 
 10  
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 11  
  * for the specific language governing rights and limitations under the License.
 12  
  *
 13  
  * The Original Code is XML Hammer code. (org.xmlhammer.*)
 14  
  *
 15  
  * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
 16  
  * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
 17  
  * All Rights Reserved.
 18  
  *
 19  
  * Contributor(s): Edwin Dankert <edankert@gmail.com>
 20  
  */
 21  
 
 22  
 
 23  
 package org.xmlhammer.gui.preferences;
 24  
 
 25  
 import java.awt.event.ItemEvent;
 26  
 import java.awt.event.ItemListener;
 27  
 
 28  
 import javax.swing.Box;
 29  
 import javax.swing.JCheckBox;
 30  
 import javax.swing.JLabel;
 31  
 import javax.swing.JPanel;
 32  
 import javax.swing.JTextField;
 33  
 
 34  
 import org.bounce.FormLayout;
 35  
 import org.xmlhammer.model.preferences.Proxy;
 36  
 
 37  
 /**
 38  
  * Put comment...
 39  
  * 
 40  
  * @version $Revision$, $Date$
 41  
  * @author Edwin Dankert <edankert@gmail.com>
 42  
  */
 43  
 
 44  
 public class ProxyPreferencesPanel extends PreferencesPanel {
 45  
     private static final long serialVersionUID = -4140066420809363167L;
 46  
 
 47  22
     private JLabel proxyAddressLabel = null;
 48  22
     private JLabel proxyPortLabel = null;
 49  22
     private JTextField proxyAddressField = null;
 50  22
     private JTextField proxyPortField = null;
 51  22
     private JCheckBox proxyEnabled = null;
 52  
         
 53  
         /**
 54  
          * @param name
 55  
          */
 56  
         public ProxyPreferencesPanel() {
 57  22
                 super("HTTP Proxy", "preferences.proxy");
 58  22
         JPanel preferences = new JPanel( new FormLayout( 5, 2));
 59  
         
 60  22
         proxyEnabled = new JCheckBox("Enable HTTP Proxy Settings");
 61  22
         proxyEnabled.addItemListener(new ItemListener() {
 62  22
            public void itemStateChanged(ItemEvent event) {
 63  0
                update();
 64  0
            }
 65  
         });
 66  
         
 67  22
         preferences.add(proxyEnabled, FormLayout.FULL);
 68  
         
 69  22
         preferences.add(Box.createVerticalStrut(10), FormLayout.FULL);
 70  
 
 71  22
         proxyAddressField = new JTextField();
 72  
         
 73  22
         proxyAddressLabel = new JLabel("Proxy Address:");
 74  22
         preferences.add(proxyAddressLabel, FormLayout.LEFT);
 75  22
         preferences.add(proxyAddressField, FormLayout.RIGHT_FILL);
 76  
 
 77  22
         proxyPortField = new JTextField();
 78  
 
 79  22
         proxyPortLabel = new JLabel( "Proxy Port:");
 80  22
         preferences.add(proxyPortLabel, FormLayout.LEFT);
 81  22
         preferences.add(proxyPortField, FormLayout.RIGHT_FILL);
 82  
         
 83  22
         setCenterPane(preferences);
 84  22
     }
 85  
 
 86  
         public void setProxy(Proxy proxy) {
 87  22
                 proxyAddressField.setText(proxy.getAddress() == null ? "" : proxy.getAddress());
 88  22
         proxyPortField.setText(proxy.getPort() == null ? "" : proxy.getPort());
 89  22
         proxyEnabled.setSelected(proxy.isEnabled());
 90  22
         update();
 91  22
         }
 92  
         
 93  
         public Proxy getProxy() {
 94  22
         Proxy proxy = new Proxy();
 95  22
         proxy.setAddress(proxyAddressField.getText());
 96  22
         proxy.setPort(proxyPortField.getText());
 97  22
         proxy.setEnabled(proxyEnabled.isSelected());
 98  
                 
 99  22
                 return proxy;
 100  
         }
 101  
         
 102  
         public void update() {
 103  22
         proxyPortLabel.setEnabled(proxyEnabled.isSelected());
 104  22
         proxyPortField.setEnabled(proxyEnabled.isSelected());
 105  22
         proxyAddressField.setEnabled(proxyEnabled.isSelected());
 106  22
         proxyAddressLabel.setEnabled(proxyEnabled.isSelected());
 107  22
         }
 108  
 }