001: package com.sun.portal.proxylet.client.applet;
002:
003: /**
004: * Created by IntelliJ IDEA.
005: * User: Venugopala Rao M.
006: * Date: Mar 24, 2004
007: * Time: 4:21:59 PM
008: * To change this template use File | Settings | File Templates.
009: */
010:
011: import com.sun.portal.proxylet.client.common.Param;
012: import com.sun.portal.proxylet.client.common.Param;
013:
014: import javax.swing.*;
015: import java.awt.GridBagLayout;
016: import java.awt.Insets;
017: import java.awt.Toolkit;
018: import java.awt.Dimension;
019: import java.awt.Point;
020: import java.awt.GridBagConstraints;
021: import java.awt.Color;
022: import java.awt.event.ActionListener;
023: import java.awt.event.ItemListener;
024:
025: public class ProxyInfoDialog extends JDialog {
026:
027: private JPanel mainPanel;
028: private JPanel innerPanel;
029:
030: private ButtonGroup bg; // For direct, manual, and auto
031: public JRadioButton direct;
032: public JRadioButton manual;
033: public JRadioButton auto;
034:
035: private JLabel proxyHostLbl;
036: private JLabel proxyPortLbl;
037: private JLabel noProxyLbl;
038: private JLabel noProxySeparator;
039: private JLabel pageTitle;
040:
041: public JTextField proxyHost;
042: public JTextField proxyPort;
043: public JTextField noProxy;
044: public JTextField autoURL;
045:
046: public JButton ok;
047: public JButton cancel;
048: public JButton help;
049:
050: private GridBagConstraints gc;
051: private GridBagConstraints gcInner;
052:
053: /** Creates new form NewProxyInfoDialog */
054: public ProxyInfoDialog(JFrame parent, ActionListener a,
055: ItemListener i) {
056: /* Set the title */
057: super (parent, Param.getString("pui.13",
058: "Browser Proxy Information"));
059: setResizable(false);
060:
061: /* Initialize all components */
062: mainPanel = new JPanel();
063: gc = new GridBagConstraints();
064: gcInner = new GridBagConstraints();
065: bg = new ButtonGroup();
066: pageTitle = new JLabel(Param.getString("pui.14",
067: "Please configure your proxy settings"));
068: direct = new JRadioButton(Param.getString("pui.15",
069: "Direct connection to the Internet"));
070: manual = new JRadioButton(Param.getString("pui.16",
071: "Manual proxy configuration"));
072: auto = new JRadioButton(Param.getString("pui.17",
073: "Automatic proxy configuration URL:"));
074: proxyHostLbl = new JLabel(Param.getString("pui.18",
075: "Security proxy :"));
076: proxyHost = new JTextField(15);
077: proxyPortLbl = new JLabel(Param.getString("pui.19", "Port :"));
078: proxyPort = new JTextField(4);
079: noProxyLbl = new JLabel(Param.getString("pui.20",
080: "No proxy for:"));
081: noProxySeparator = new JLabel(Param.getString("pui.21",
082: "Use commas ( , ) to separate entries."));
083: noProxy = new JTextField(10);
084: autoURL = new JTextField(10);
085: ok = new JButton(Param.getString("pui.22", "OK"));
086: cancel = new JButton(Param.getString("pui.23", "Cancel"));
087: help = new JButton(Param.getString("pui.8", "Help"));
088:
089: /* Set default state and arrange the components */
090: getContentPane().setLayout(new java.awt.GridBagLayout());
091: mainPanel.setLayout(new java.awt.GridBagLayout());
092: manual.setForeground(Color.gray);
093: auto.setForeground(Color.gray);
094: proxyHostLbl.setForeground(Color.gray);
095: proxyPortLbl.setForeground(Color.gray);
096: noProxyLbl.setForeground(Color.gray);
097: noProxySeparator.setForeground(Color.gray);
098:
099: bg.add(direct);
100: bg.add(manual);
101: bg.add(auto);
102: direct.setSelected(true);
103: direct.addItemListener(i);
104: manual.addItemListener(i);
105: auto.addItemListener(i);
106: proxyHost.setEditable(false);
107: proxyPort.setEditable(false);
108: noProxy.setEditable(false);
109: autoURL.setEditable(false);
110: ok.setActionCommand("OK");
111: cancel.setActionCommand("Cancel");
112: help.setActionCommand("Help");
113:
114: gc.anchor = gc.CENTER;
115: gc.gridx = 0;
116: gc.gridy = 0;
117: mainPanel.add(pageTitle, gc);
118:
119: gc.anchor = gc.NORTHWEST;
120: gc.gridx = 0;
121: gc.gridy = 1;
122: mainPanel.add(direct, gc);
123: gc.gridy = 2;
124: mainPanel.add(manual, gc);
125:
126: innerPanel = new JPanel(new GridBagLayout());
127: gcInner.gridx = 0;
128: gcInner.gridy = 0;
129: gcInner.gridwidth = 1;
130: gcInner.gridheight = 1;
131: gcInner.insets = new Insets(0, 0, 5, 20);
132: innerPanel.add(proxyHostLbl, gcInner);
133:
134: gcInner.gridx = 1;
135: innerPanel.add(proxyHost, gcInner);
136: gcInner.anchor = gcInner.NORTHWEST;
137: gcInner.gridx = 2;
138: gcInner.insets = new Insets(0, 5, 5, 20);
139: innerPanel.add(proxyPortLbl, gcInner);
140:
141: gcInner.insets = new Insets(0, 0, 5, 0);
142: gcInner.gridx = 3;
143: gcInner.ipadx = 0;
144: innerPanel.add(proxyPort, gcInner);
145:
146: gcInner.gridx = 0;
147: gcInner.gridy = 1;
148: gcInner.gridwidth = 1;
149: gcInner.gridheight = 1;
150: gcInner.insets = new Insets(0, 0, 0, 20);
151: innerPanel.add(noProxyLbl, gcInner);
152:
153: gcInner.gridx = 1;
154: gcInner.weightx = 1;
155: gcInner.gridwidth = 3;
156: gcInner.insets = new Insets(0, 0, 0, 0);
157: gcInner.fill = gcInner.HORIZONTAL;
158: innerPanel.add(noProxy, gcInner);
159:
160: gcInner.gridx = 1;
161: gcInner.gridy = 2;
162: innerPanel.add(noProxySeparator, gcInner);
163:
164: gc.gridy = 3;
165: gc.weightx = 1;
166: gc.gridheight = 2;
167: gc.fill = gc.VERTICAL;
168: gc.insets = new Insets(0, 30, 0, 5);
169: mainPanel.add(innerPanel, gc);
170:
171: gc.gridheight = 1;
172: gc.weightx = 0;
173: gc.gridy = 6;
174: gc.gridx = 0;
175: //gc.fill = gc.NONE;
176: gc.insets = new Insets(0, 0, 0, 0);
177: mainPanel.add(auto, gc);
178:
179: innerPanel = new JPanel(new GridBagLayout());
180: gcInner.gridx = 0;
181: gcInner.gridy = 0;
182: gcInner.gridwidth = 1;
183: gcInner.gridheight = 1;
184: gcInner.fill = gcInner.HORIZONTAL;
185: innerPanel.add(autoURL, gcInner);
186:
187: gc.gridheight = 1;
188: gc.weightx = 0;
189: gc.gridy = 7;
190: gc.gridx = 0;
191: gc.insets = new Insets(0, 30, 0, 5);
192: // gc.anchor = gc.NORTHEAST;
193: gc.fill = gc.HORIZONTAL;
194: mainPanel.add(innerPanel, gc);
195:
196: /* Create a panel for buttons */
197: innerPanel = new JPanel(new GridBagLayout());
198: gcInner.gridx = 0;
199: gcInner.gridy = 0;
200: gcInner.gridwidth = 1;
201: gcInner.gridheight = 1;
202: gcInner.fill = gcInner.NONE;
203: gcInner.insets = new Insets(0, 0, 0, 10);
204: gcInner.ipadx = 30;
205: ok.addActionListener(a);
206: innerPanel.add(ok, gcInner);
207:
208: gcInner.gridx = 1;
209: gcInner.gridy = 0;
210: gcInner.gridwidth = 1;
211: gcInner.gridheight = 1;
212: gcInner.ipadx = 0;
213: cancel.addActionListener(a);
214: innerPanel.add(cancel, gcInner);
215:
216: gcInner.gridx = 2;
217: gcInner.gridy = 0;
218: gcInner.gridwidth = 1;
219: gcInner.gridheight = 1;
220: gcInner.ipadx = 26;
221: help.addActionListener(a);
222: innerPanel.add(help, gcInner);
223:
224: gc.gridheight = 1;
225: gc.weightx = 0;
226: gc.gridy = 8;
227: gc.gridx = 0;
228: gc.insets = new Insets(10, 0, 2, 0);
229: gc.anchor = gc.CENTER;
230: gc.fill = gc.NONE;
231: mainPanel.add(innerPanel, gc);
232:
233: gc.anchor = gc.NORTHWEST;
234: gc.gridx = 0;
235: gc.gridy = 0;
236: gc.weightx = 1;
237: gc.weighty = 1;
238: gc.gridheight = 5;
239: gc.gridwidth = 1;
240: gc.insets = new Insets(5, 5, 5, 5);
241: getContentPane().add(mainPanel, gc);
242:
243: pack();
244:
245: ok.requestFocus();
246:
247: Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
248: Point pt = new Point();
249: pt.x = (d.width / 6);
250: pt.y = (d.height / 6);
251: setLocation(pt);
252:
253: }
254:
255: public void showWarning() {
256: setVisible(true);
257: toFront();
258: }
259:
260: synchronized public void waitForAction() {
261: try {
262: wait();
263: } catch (InterruptedException e) {
264: }
265: }
266:
267: synchronized public void notifyAction() {
268: notify();
269: }
270:
271: public void setState(int proxyType) {
272: switch (proxyType) {
273: case PluginProxyInfo.DIRECT:
274: autoURL.setEditable(false);
275: proxyHost.setEditable(false);
276: proxyPort.setEditable(false);
277: noProxy.setEditable(false);
278: JComponent[] directcomps = { direct, manual, auto,
279: proxyHostLbl, proxyPortLbl, noProxyLbl,
280: noProxySeparator };
281: Color[] directcolors = { Color.black, Color.gray,
282: Color.gray, Color.gray, Color.gray, Color.gray,
283: Color.gray };
284: setLabelColors(directcomps, directcolors);
285: break;
286: case PluginProxyInfo.MANUAL:
287: autoURL.setEditable(false);
288: proxyHost.setEditable(true);
289: proxyPort.setEditable(true);
290: noProxy.setEditable(true);
291: JComponent[] manualcomps = { direct, manual, auto,
292: proxyHostLbl, proxyPortLbl, noProxyLbl,
293: noProxySeparator };
294: Color[] manualcolors = { Color.gray, Color.black,
295: Color.gray, Color.black, Color.black, Color.black,
296: Color.black };
297: setLabelColors(manualcomps, manualcolors);
298: break;
299: case PluginProxyInfo.AUTO:
300: proxyHost.setEditable(false);
301: proxyPort.setEditable(false);
302: noProxy.setEditable(false);
303: autoURL.setEditable(true);
304: JComponent[] autocomps = { direct, manual, auto,
305: proxyHostLbl, proxyPortLbl, noProxyLbl,
306: noProxySeparator };
307: Color[] autocolors = { Color.gray, Color.gray, Color.black,
308: Color.gray, Color.gray, Color.gray, Color.gray };
309: setLabelColors(autocomps, autocolors);
310: break;
311: }
312: }
313:
314: public void setLabelColors(JComponent[] comps, Color[] colors) {
315: for (int i = 0; i < comps.length; i++) {
316: comps[i].setForeground(colors[i]);
317: }
318: }
319:
320: }
|