View Javadoc

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      private JLabel proxyAddressLabel = null;
48      private JLabel proxyPortLabel = null;
49      private JTextField proxyAddressField = null;
50      private JTextField proxyPortField = null;
51      private JCheckBox proxyEnabled = null;
52  	
53  	/***
54  	 * @param name
55  	 */
56  	public ProxyPreferencesPanel() {
57  		super("HTTP Proxy", "preferences.proxy");
58          JPanel preferences = new JPanel( new FormLayout( 5, 2));
59          
60          proxyEnabled = new JCheckBox("Enable HTTP Proxy Settings");
61          proxyEnabled.addItemListener(new ItemListener() {
62             public void itemStateChanged(ItemEvent event) {
63                 update();
64             }
65          });
66          
67          preferences.add(proxyEnabled, FormLayout.FULL);
68          
69          preferences.add(Box.createVerticalStrut(10), FormLayout.FULL);
70  
71          proxyAddressField = new JTextField();
72          
73          proxyAddressLabel = new JLabel("Proxy Address:");
74          preferences.add(proxyAddressLabel, FormLayout.LEFT);
75          preferences.add(proxyAddressField, FormLayout.RIGHT_FILL);
76  
77          proxyPortField = new JTextField();
78  
79          proxyPortLabel = new JLabel( "Proxy Port:");
80          preferences.add(proxyPortLabel, FormLayout.LEFT);
81          preferences.add(proxyPortField, FormLayout.RIGHT_FILL);
82          
83          setCenterPane(preferences);
84      }
85  
86  	public void setProxy(Proxy proxy) {
87  		proxyAddressField.setText(proxy.getAddress() == null ? "" : proxy.getAddress());
88          proxyPortField.setText(proxy.getPort() == null ? "" : proxy.getPort());
89          proxyEnabled.setSelected(proxy.isEnabled());
90          update();
91  	}
92  	
93  	public Proxy getProxy() {
94          Proxy proxy = new Proxy();
95          proxy.setAddress(proxyAddressField.getText());
96          proxy.setPort(proxyPortField.getText());
97          proxy.setEnabled(proxyEnabled.isSelected());
98  		
99  		return proxy;
100 	}
101 	
102 	public void update() {
103         proxyPortLabel.setEnabled(proxyEnabled.isSelected());
104         proxyPortField.setEnabled(proxyEnabled.isSelected());
105         proxyAddressField.setEnabled(proxyEnabled.isSelected());
106         proxyAddressLabel.setEnabled(proxyEnabled.isSelected());
107 	}
108 }