001: // PasswordAttributeEditor.java
002: // $Id: PasswordAttributeEditor.java,v 1.14 2000/08/16 21:37:27 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.editors;
007:
008: import java.awt.BorderLayout;
009: import java.awt.Button;
010: import java.awt.Color;
011: import java.awt.Component;
012: import java.awt.Container;
013: import java.awt.Dimension;
014: import java.awt.Frame;
015: import java.awt.GridBagConstraints;
016: import java.awt.GridBagLayout;
017: import java.awt.GridLayout;
018: import java.awt.Image;
019: import java.awt.Insets;
020: import java.awt.Label;
021: import java.awt.Panel;
022: import java.awt.TextComponent;
023: import java.awt.TextField;
024: import java.awt.Window;
025:
026: import java.awt.event.ActionEvent;
027: import java.awt.event.ActionListener;
028:
029: import java.util.EventObject;
030: import java.util.Properties;
031:
032: import org.w3c.tools.resources.Attribute;
033:
034: import org.w3c.jigsaw.admin.RemoteAccessException;
035: import org.w3c.jigsaw.admin.RemoteResource;
036:
037: import org.w3c.jigadm.RemoteResourceWrapper;
038:
039: class PasswordEditor extends Panel implements ActionListener {
040:
041: protected PasswordAttributeEditor pae;
042: protected TextField passwd;
043: protected TextField verify;
044: protected String orig;
045: protected Image img;
046:
047: public void actionPerformed(ActionEvent ae) {
048: if (ae.getActionCommand().equals("Ok")
049: || ae.getSource().equals(verify)) {
050: if (passwd.getText().equals(verify.getText())
051: && !passwd.getText().equals("")) {
052: pae.setValue(passwd.getText());
053: pae.dispose();
054: } else {
055: // popup an Error? FIXME
056: passwd.requestFocus();
057: }
058: } else if (ae.getActionCommand().equals("Cancel")) {
059: pae.dispose();
060: } else if (ae.getSource().equals(passwd)) {
061: verify.requestFocus();
062: }
063: }
064:
065: public PasswordEditor(PasswordAttributeEditor pae, String name) {
066: GridBagLayout gbl = new GridBagLayout();
067: GridBagConstraints gbc = new GridBagConstraints();
068: GridBagLayout mgbl = new GridBagLayout();
069: GridBagConstraints mgbc = new GridBagConstraints();
070: Label l;
071: Button b;
072: Panel p = new Panel(gbl);
073:
074: this .pae = pae;
075: gbc.fill = GridBagConstraints.HORIZONTAL;
076: gbc.weightx = 0;
077: gbc.weighty = 0;
078: mgbc.fill = GridBagConstraints.NONE;
079: mgbc.weightx = 0;
080: mgbc.weighty = 0;
081: mgbc.insets = new Insets(16, 10, 16, 5);
082: setLayout(mgbl);
083: passwd = new TextField(10);
084: passwd.setEchoChar('*');
085: passwd.addActionListener(this );
086: verify = new TextField(10);
087: verify.setEchoChar('*');
088: verify.addActionListener(this );
089:
090: // Construct the first block with the labels and textfields
091: if (name != null) {
092: l = new Label("User: ", Label.RIGHT);
093: gbc.gridwidth = 1;
094: gbl.setConstraints(l, gbc);
095: p.add(l);
096: l = new Label(name);
097: gbc.gridwidth = GridBagConstraints.REMAINDER;
098: gbl.setConstraints(l, gbc);
099: p.add(l);
100: }
101: l = new Label("Password: ", Label.RIGHT);
102: gbc.gridwidth = 1;
103: gbl.setConstraints(l, gbc);
104: p.add(l);
105: gbc.gridwidth = GridBagConstraints.REMAINDER;
106: gbl.setConstraints(passwd, gbc);
107: p.add(passwd);
108:
109: l = new Label("Verify: ", Label.RIGHT);
110: gbc.gridwidth = 1;
111: gbl.setConstraints(l, gbc);
112: p.add(l);
113: gbc.gridwidth = GridBagConstraints.REMAINDER;
114: gbl.setConstraints(verify, gbc);
115: p.add(verify);
116: mgbc.gridwidth = GridBagConstraints.REMAINDER;
117: mgbl.setConstraints(p, mgbc);
118: add(p);
119:
120: // and now the usual button bar
121: p = new Panel(new GridLayout(1, 2, 20, 20));
122: b = new Button("Ok");
123: b.addActionListener(this );
124: p.add(b);
125: b = new Button("Cancel");
126: b.addActionListener(this );
127: p.add(b);
128: mgbl.setConstraints(p, mgbc);
129: add(p);
130: }
131:
132: public PasswordEditor(PasswordAttributeEditor pae) {
133: this (pae, null);
134: }
135: }
136:
137: public class PasswordAttributeEditor extends AttributeEditor {
138:
139: class PasswordEditorListener implements ActionListener {
140:
141: public void actionPerformed(ActionEvent ae) {
142: popupDialog();
143: }
144:
145: }
146:
147: protected String name = null;
148: private String origs;
149: private String current;
150: Button widget;
151: private Frame popup = null;
152:
153: // get rid of the password editor
154:
155: protected void dispose() {
156: if (popup != null) {
157: popup.dispose();
158: popup = null;
159: }
160: }
161:
162: // pops up a new editor
163:
164: protected void popupDialog() {
165: if (popup == null) {
166: PasswordEditor pe = new PasswordEditor(this , name);
167: popup = new Frame("Jigsaw Password Editor");
168: popup.setBackground(Color.lightGray);
169: popup.setSize(new Dimension(300, 200));
170: popup.setLayout(new BorderLayout());
171: popup.add("Center", pe);
172: popup.show();
173: pe.passwd.requestFocus();
174: }
175: }
176:
177: protected void setLabel(String s) {
178: if (s.equals("")) {
179: widget.setLabel("WARNING: No password, click to edit");
180: } else {
181: char c[] = new char[s.length()];
182: for (int i = 0; i < s.length(); i++)
183: c[i] = '*';
184: widget.setLabel(new String(c));
185: }
186: }
187:
188: /**
189: * @see org.w3c.jigadm.editors.AttributeEditorInterface
190: */
191:
192: public boolean hasChanged() {
193: return !origs.equals(current);
194: }
195:
196: /**
197: * @see org.w3c.jigadm.editors.AttributeEditorInterface
198: */
199:
200: public void clearChanged() {
201: origs = new String(current);
202: setLabel(current);
203: }
204:
205: /**
206: * @see org.w3c.jigadm.editors.AttributeEditorInterface
207: */
208:
209: public void resetChanges() {
210: current = new String(origs);
211: setLabel(current);
212: }
213:
214: /**
215: * @see org.w3c.jigadm.editors.AttributeEditorInterface
216: */
217:
218: public Object getValue() {
219: return current;
220: }
221:
222: /**
223: * @see org.w3c.jigadm.editors.AttributeEditorInterface
224: */
225:
226: public void setValue(Object o) {
227: current = o.toString();
228: setLabel(current);
229: }
230:
231: /*
232: * @see org.w3c.jigadm.editors.AttributeEditor
233: */
234:
235: public Component getComponent() {
236: return widget;
237: }
238:
239: public PasswordAttributeEditor() {
240: widget = new Button();
241: origs = "";
242: }
243:
244: /**
245: * Initialize the editor
246: * @param w the ResourceWrapper father of the attribute
247: * @param a the Attribute we are editing
248: * @param o the value of the above attribute
249: * @param p some Properties, used to fine-tune the editor
250: * @exception RemoteAccessException if a remote access error occurs.
251: */
252: public void initialize(RemoteResourceWrapper w, Attribute a,
253: Object o, Properties p) throws RemoteAccessException {
254: RemoteResource r = w.getResource();
255: name = (String) r.getValue("identifier");
256: if (o == null) {
257: String v = null;
258: v = (String) r.getValue(a.getName());
259: if (v == null)
260: if (a.getDefault() != null)
261: v = a.getDefault().toString();
262: if (v != null) {
263: origs = v;
264: }
265: } else {
266: origs = o.toString();
267: }
268: current = origs;
269: setLabel(origs);
270: widget.addActionListener(new PasswordEditorListener());
271: }
272: }
|