001: // AuthPopup.java
002: // $Id: AuthPopup.java,v 1.4 2000/08/16 21:37:28 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadm.gui;
007:
008: import java.awt.Button;
009: import java.awt.Component;
010: import java.awt.Container;
011: import java.awt.GridBagConstraints;
012: import java.awt.GridBagLayout;
013: import java.awt.GridLayout;
014: import java.awt.Image;
015: import java.awt.Insets;
016: import java.awt.Label;
017: import java.awt.Panel;
018: import java.awt.TextComponent;
019: import java.awt.TextField;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import java.util.EventObject;
025:
026: import org.w3c.tools.codec.Base64Encoder;
027:
028: import org.w3c.www.http.HttpCredential;
029: import org.w3c.www.http.HttpFactory;
030:
031: class AuthPopup extends Panel implements ActionListener {
032:
033: protected ServerBrowser sb;
034: protected TextField user;
035: protected TextField passwd;
036: protected String orig;
037: protected Image img;
038: protected boolean ok;
039:
040: protected synchronized void done() {
041: ok = true;
042: notifyAll();
043: }
044:
045: public void actionPerformed(ActionEvent ae) {
046: if (ae.getActionCommand().equals("Ok")
047: || ae.getSource().equals(passwd)) {
048: if (!user.getText().equals("")) {
049: HttpCredential credential;
050: credential = HttpFactory.makeCredential("Basic");
051: Base64Encoder encoder = new Base64Encoder(user
052: .getText()
053: + ":" + passwd.getText());
054: credential.setAuthParameter("cookie", encoder
055: .processString());
056: sb.admin.setCredential(credential);
057: sb.dispose(true);
058: done();
059: } else {
060: // popup an Error? FIXME
061: user.requestFocus();
062: }
063: } else if (ae.getActionCommand().equals("Cancel")) {
064: sb.dispose(false);
065: } else if (ae.getSource().equals(user)) {
066: passwd.requestFocus();
067: }
068: }
069:
070: public synchronized boolean waitForCompletion() {
071: try {
072: wait();
073: } catch (InterruptedException ex) {
074: }
075: return ok;
076: }
077:
078: public AuthPopup(ServerBrowser sb, String name) {
079: GridBagLayout gbl = new GridBagLayout();
080: GridBagConstraints gbc = new GridBagConstraints();
081: GridBagLayout mgbl = new GridBagLayout();
082: GridBagConstraints mgbc = new GridBagConstraints();
083: Label l;
084: Button b;
085: Panel p = new Panel(gbl);
086:
087: ok = false;
088: this .sb = sb;
089: gbc.fill = GridBagConstraints.HORIZONTAL;
090: gbc.weightx = 0;
091: gbc.weighty = 0;
092: mgbc.fill = GridBagConstraints.NONE;
093: mgbc.weightx = 0;
094: mgbc.weighty = 0;
095: mgbc.insets = new Insets(16, 10, 16, 5);
096: setLayout(mgbl);
097: user = new TextField(10);
098: user.addActionListener(this );
099: passwd = new TextField(10);
100: passwd.setEchoChar('*');
101: passwd.addActionListener(this );
102:
103: // Construct the first block with the labels and textfields
104: if (name != null) {
105: l = new Label("Realm: ", Label.RIGHT);
106: gbc.gridwidth = 1;
107: gbl.setConstraints(l, gbc);
108: p.add(l);
109: l = new Label(name);
110: gbc.gridwidth = GridBagConstraints.REMAINDER;
111: gbl.setConstraints(l, gbc);
112: p.add(l);
113: }
114: l = new Label("User: ", Label.RIGHT);
115: gbc.gridwidth = 1;
116: gbl.setConstraints(l, gbc);
117: p.add(l);
118: gbc.gridwidth = GridBagConstraints.REMAINDER;
119: gbl.setConstraints(user, gbc);
120: p.add(user);
121:
122: l = new Label("Password: ", Label.RIGHT);
123: gbc.gridwidth = 1;
124: gbl.setConstraints(l, gbc);
125: p.add(l);
126: gbc.gridwidth = GridBagConstraints.REMAINDER;
127: gbl.setConstraints(passwd, gbc);
128: p.add(passwd);
129: mgbc.gridwidth = GridBagConstraints.REMAINDER;
130: mgbl.setConstraints(p, mgbc);
131: add(p);
132:
133: // and now the usual button bar
134: p = new Panel(new GridLayout(1, 2, 20, 20));
135: b = new Button("Ok");
136: b.addActionListener(this );
137: p.add(b);
138: b = new Button("Cancel");
139: b.addActionListener(this );
140: p.add(b);
141: mgbl.setConstraints(p, mgbc);
142: add(p);
143: }
144:
145: public AuthPopup(ServerBrowser sb) {
146: this(sb, null);
147: }
148: }
|