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