1 18 19 package org.objectweb.jac.aspects.gui.swing; 20 21 import java.awt.Dimension ; 22 import javax.swing.JLabel ; 23 import javax.swing.JPasswordField ; 24 import javax.swing.JTextField ; 25 import org.objectweb.jac.aspects.gui.FieldEditor; 26 import org.objectweb.jac.aspects.gui.GuiAC; 27 import org.objectweb.jac.aspects.gui.Length; 28 import org.objectweb.jac.core.rtti.FieldItem; 29 import org.objectweb.jac.core.rtti.NamingConventions; 30 31 34 35 public class PasswordFieldEditor extends AbstractFieldEditor 36 implements FieldEditor 37 { 38 JTextField textField; 39 JTextField confirmField; 40 41 43 44 public PasswordFieldEditor(Object substance, FieldItem field) 45 { 46 super(substance,field); 47 textField = new JPasswordField (); 48 confirmField = new JPasswordField (); 49 Dimension minSize = textField.getPreferredSize(); 52 Dimension maxSize = textField.getMaximumSize(); 53 textField.setMaximumSize(new Dimension (maxSize.width,minSize.height)); 54 55 add(textField); 57 58 confirmField.setMaximumSize(new Dimension (maxSize.width,minSize.height)); 59 confirmField.addFocusListener(this); 60 add(new JLabel ("Retype "+NamingConventions.textForName(field.getName()))); 61 add(confirmField); 62 63 } 64 65 67 public Object getValue() { 68 if (!(confirmField.getText().equals(textField.getText()))) 69 throw new RuntimeException (NamingConventions.textForName(field.getName())+" and its confirmation are different"); 70 return( textField.getText() ); 71 } 72 73 public void setValue(Object value) { 74 super.setValue(value); 75 if( value == null ) value=""; 76 textField.setText(GuiAC.toString(value)); 77 Dimension minSize = textField.getPreferredSize(); 78 minSize.width = 100; 79 textField.setMinimumSize(minSize); 80 } 81 82 public void setSize(Length width, Length height) { 83 super.setSize(width,height); 84 SwingUtils.setColumns(textField,width); 85 SwingUtils.setColumns(confirmField,width); 86 } 87 88 91 public void requestFocus() { 92 textField.requestFocus(); 93 } 94 95 } 96 | Popular Tags |