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