FileDocCategorySizeDatePackage
PasswordParameter.javaAPI DocAzureus 3.0.3.44028Mon Jan 15 22:37:24 GMT 2007org.gudy.azureus2.ui.swt.config

PasswordParameter

public class PasswordParameter extends Parameter
author
Olivier

Fields Summary
String
name
org.eclipse.swt.widgets.Text
inputField
Constructors Summary
public PasswordParameter(org.eclipse.swt.widgets.Composite composite, String name)

  	this( composite, name, org.gudy.azureus2.plugins.ui.config.PasswordParameter.ET_SHA1 );
  
public PasswordParameter(org.eclipse.swt.widgets.Composite composite, String name, int encoding)

  	super(name);
    this.name = name;
    inputField = new Text(composite, SWT.BORDER);
    inputField.setEchoChar('*");
    byte[] value = COConfigurationManager.getByteParameter(name, "".getBytes());
    if(value.length > 0)
      inputField.setText("***");
    inputField.addListener(SWT.Modify, new Listener() {
      public void handleEvent(Event event) {
        try{
          String	password_string = inputField.getText();
        	
          byte[] password = password_string.getBytes();
          byte[] encoded;
          if(password.length > 0 ){
        	  if ( encoding == org.gudy.azureus2.plugins.ui.config.PasswordParameter.ET_PLAIN ){
        		  
        		 encoded = password;
        		  
        	  }else if ( encoding == org.gudy.azureus2.plugins.ui.config.PasswordParameter.ET_SHA1 ){
        		  
       	         SHA1Hasher hasher = new SHA1Hasher();

       	         encoded = hasher.calculateHash(password);
       	         
        	  }else{
        		 
        		  	// newly added, might as well go for UTF-8
        		  
        		 encoded = MessageDigest.getInstance( "md5").digest( password_string.getBytes( "UTF-8" ));		  
        	  }
          }else{
            encoded = password;
          }
          
          COConfigurationManager.setParameter(name, encoded);
        } catch(Exception e) {
        	Debug.printStackTrace( e );
        }
      }
    });
  
Methods Summary
public org.eclipse.swt.widgets.ControlgetControl()

	 return inputField;
   
public java.lang.StringgetValue()

    return inputField.getText();
  
public voidsetLayoutData(java.lang.Object layoutData)

    inputField.setLayoutData(layoutData);
  
public voidsetValue(java.lang.String value)

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (inputField == null || inputField.isDisposed()
						|| inputField.getText().equals(value)) {
					return;
				}
				inputField.setText(value);
			}
		});

    if (!COConfigurationManager.getParameter(name).equals(value)) {
    	COConfigurationManager.setParameter(name, value);
    }
  
public voidsetValue(java.lang.Object value)

  	if (value instanceof String) {
  		setValue((String)value);
  	}