1 /*
2 * $HeadURL: $
3 * $Date: $
4 * $Revision: $
5 * $Author: $
6 *
7 * Copyright (c) 2005 MindTree Consulting Ltd.
8 *
9 * This file is part of Insight.
10 *
11 * Insight is free software: you can redistribute it and/or modify it under the
12 * terms of the GNU General Public License as published by the Free Software
13 * Foundation, either version 3 of the License, or (at your option) any later
14 * version.
15 *
16 * Insight is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
19 * Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * Insight. If not, see <http://www.gnu.org/licenses/>.
23 */
24 package com.mindtree.techworks.insight.gui.preferences;
25
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28
29 import javax.swing.JCheckBox;
30 import javax.swing.JLabel;
31 import javax.swing.JPasswordField;
32 import javax.swing.JTextField;
33
34 import com.mindtree.techworks.insight.InsightConstants;
35
36
37 /**
38 *
39 * The <code>ProxyUIPanel</code> displays the UI for editing
40 * the proxy settings for remote file access.
41 *
42 * @see com.mindtree.techworks.insight.preferences.model.Preference
43 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel
44 *
45 * @author Regunath B
46 * @version 1.0, 05/03/22
47 */
48 public class ProxyUIPanel extends AbstractPreferencesUIPanel implements ActionListener {
49
50 /**
51 * Used for object serialization
52 */
53 private static final long serialVersionUID = -5481226146152529345L;
54
55 /**
56 * Constants for attribute Ids of the Proxy setting preference
57 */
58 private static final String HTTP_PROXY_HOST = "http.proxy.host";
59 private static final String HTTP_PROXY_PORT = "http.proxy.port";
60 // private static final String FTP_PROXY_HOST = "ftp.proxy.host";
61 // private static final String FTP_PROXY_PORT = "ftp.proxy.port";
62 // private static final String SOCKS_PROXY_HOST = "socks.proxy.host";
63 // private static final String SOCKS_PROXY_PORT = "socks.proxy.port";
64 private static final String AUTHENTICATION = "authentication";
65 private static final String USER = "user";
66 private static final String PASSWORD = "password";
67
68 /**
69 * Constant for 'true' and 'false' boolean value
70 */
71 private static final String TRUE = "true";
72 private static final String FALSE = "false";
73
74 /**
75 * UI widgets
76 */
77 private JTextField httpProxyHostField;
78 private JTextField httpProxyPortField;
79 // private JTextField ftpProxyHostField;
80 // private JTextField ftpProxyPortField;
81 // private JTextField socksProxyHostField;
82 // private JTextField socksProxyPortField;
83 private JCheckBox requiresAuthentication;
84 private JTextField userField;
85 private JPasswordField passwordField;
86
87 /**
88 * No args constructor
89 */
90 public ProxyUIPanel() {
91 }
92
93 /**
94 * ActionListener interface method implementation
95 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
96 */
97 public void actionPerformed(ActionEvent arg0) {
98 checkAuthenticationEnable();
99 }
100
101 /**
102 * Overriden super class method
103 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#initializeDisplay()
104 */
105 protected void initializeDisplay() {
106
107 addComponent(new JLabel(InsightConstants.getLiteral("HTTP_PROXY_HOST")),0,0,0,0,1,1);
108 this.httpProxyHostField = new JTextField();
109 addComponent(httpProxyHostField,1,0,1,0, 1, 1);
110 addComponent(new JLabel(InsightConstants.getLiteral("PROXY_PORT")),2,0,0,0,1,1);
111 this.httpProxyPortField = new JTextField();
112 addComponent(httpProxyPortField,3,0,1,0, 1, 1);
113
114 /* Commented out until FTP proxy is supported
115 addComponent(new JLabel(InsightConstants.getLiteral("FTP_PROXY_HOST")),0,1,0,0,1,1);
116 this.ftpProxyHostField = new JTextField();
117 addComponent(ftpProxyHostField,1,1,1,0, 1, 1);
118 addComponent(new JLabel(InsightConstants.getLiteral("PROXY_PORT")),2,1,0,0,1,1);
119 this.ftpProxyPortField = new JTextField();
120 addComponent(ftpProxyPortField,3,1,1,0, 1, 1);
121
122 addComponent(new JLabel(InsightConstants.getLiteral("SOCKS_PROXY_HOST")),0,2,0,0,1,1);
123 this.socksProxyHostField = new JTextField();
124 addComponent(socksProxyHostField,1,2,1,0, 1, 1);
125 addComponent(new JLabel(InsightConstants.getLiteral("PROXY_PORT")),2,2,0,0,1,1);
126 this.socksProxyPortField = new JTextField();
127 addComponent(socksProxyPortField,3,2,1,0, 1, 1);
128 */
129
130 this.requiresAuthentication = new JCheckBox(InsightConstants.getLiteral("REQUIRES_AUTHENTICATION"));
131 this.requiresAuthentication.addActionListener(this);
132 addComponent(requiresAuthentication,0,3,1,0, 4, 1);
133 addComponent(new JLabel(InsightConstants.getLiteral("USER")),0,4,0,0,1,1);
134 this.userField = new JTextField();
135 addComponent(userField,1,4,1,0, 1, 1);
136 addComponent(new JLabel(InsightConstants.getLiteral("PASSWORD")),2,4,0,0,1,1);
137 this.passwordField = new JPasswordField();
138 addComponent(passwordField,3,4,1,0, 1, 1);
139
140 // add the empty label to dock components to the top
141 addComponent(new JLabel(),0,5,1,1,4,1);
142 // initialize the widgets
143 this.requiresAuthentication.setSelected(this.preference.
144 getPreferenceAttributeById(AUTHENTICATION).getValue().equalsIgnoreCase(TRUE));
145 this.httpProxyHostField.setText(this.preference.getPreferenceAttributeById(HTTP_PROXY_HOST).getValue());
146 this.httpProxyPortField.setText(this.preference.getPreferenceAttributeById(HTTP_PROXY_PORT).getValue());
147 /* Commented out until FTP proxy is supported
148 this.ftpProxyHostField.setText(this.preference.getPreferenceAttributeById(FTP_PROXY_HOST).getValue());
149 this.ftpProxyPortField.setText(this.preference.getPreferenceAttributeById(FTP_PROXY_PORT).getValue());
150 this.socksProxyHostField.setText(this.preference.getPreferenceAttributeById(SOCKS_PROXY_HOST).getValue());
151 this.socksProxyPortField.setText(this.preference.getPreferenceAttributeById(SOCKS_PROXY_PORT).getValue());
152 */
153 checkAuthenticationEnable();
154 }
155
156 /**
157 * Overriden super class method
158 * @see com.mindtree.techworks.insight.gui.preferences.AbstractPreferencesUIPanel#setPreferenceValues()
159 */
160 protected void setPreferenceValues() {
161 this.preference.getPreferenceAttributeById(HTTP_PROXY_HOST).setValue(this.httpProxyHostField.getText());
162 this.preference.getPreferenceAttributeById(HTTP_PROXY_PORT).setValue(this.httpProxyPortField.getText());
163 /* Commented out until FTP proxy is supported
164 this.preference.getPreferenceAttributeById(FTP_PROXY_HOST).setValue(this.ftpProxyHostField.getText());
165 this.preference.getPreferenceAttributeById(FTP_PROXY_PORT).setValue(this.ftpProxyPortField.getText());
166 this.preference.getPreferenceAttributeById(SOCKS_PROXY_HOST).setValue(this.socksProxyHostField.getText());
167 this.preference.getPreferenceAttributeById(SOCKS_PROXY_PORT).setValue(this.socksProxyPortField.getText());
168 */
169 this.preference.getPreferenceAttributeById(AUTHENTICATION).setValue(this.requiresAuthentication.isSelected() ? TRUE: FALSE);
170 this.preference.getPreferenceAttributeById(USER).setValue(this.userField.getText());
171 this.preference.getPreferenceAttributeById(PASSWORD).setValue(new String(this.passwordField.getPassword()));
172 }
173
174 /**
175 * Helper method that checks enabling and disabling of the user credential widgets
176 */
177 private void checkAuthenticationEnable() {
178 boolean authenticationEnabled = this.requiresAuthentication.isSelected();
179 this.userField.setEditable(authenticationEnabled);
180 this.passwordField.setEditable(authenticationEnabled);
181 this.userField.setEnabled(authenticationEnabled);
182 this.passwordField.setEnabled(authenticationEnabled);
183 this.userField.setText(authenticationEnabled ? this.preference.getPreferenceAttributeById(USER).getValue() : "");
184 this.passwordField.setText(authenticationEnabled ? this.preference.getPreferenceAttributeById(PASSWORD).getValue() : "");
185 }
186
187 }