FileDocCategorySizeDatePackage
FloatParameter.javaAPI DocAzureus 3.0.3.44158Thu Feb 09 19:42:44 GMT 2006org.gudy.azureus2.ui.swt.config

FloatParameter

public class FloatParameter extends Object

Fields Summary
org.eclipse.swt.widgets.Text
inputField
float
fMinValue
float
fMaxValue
float
fDefaultValue
int
iDigitsAfterDecimal
String
sParamName
boolean
allowZero
Constructors Summary
public FloatParameter(org.eclipse.swt.widgets.Composite composite, String name)


        
    fDefaultValue = COConfigurationManager.getFloatParameter(name);
    initialize(composite,name);
  
public FloatParameter(org.eclipse.swt.widgets.Composite composite, String name, float minValue, float maxValue, boolean allowZero, int digitsAfterDecimal)

    fDefaultValue = COConfigurationManager.getFloatParameter(name);
    initialize(composite,name);
    fMinValue = minValue;
    fMaxValue = maxValue;
    this.allowZero = allowZero;
    iDigitsAfterDecimal = digitsAfterDecimal;
  
Methods Summary
public org.eclipse.swt.widgets.ControlgetControl()

  	return( inputField );
  
public voidinitialize(org.eclipse.swt.widgets.Composite composite, java.lang.String name)

    sParamName = name;

    inputField = new Text(composite, SWT.BORDER);
    float value = COConfigurationManager.getFloatParameter(name);
    inputField.setText(String.valueOf(value));
    inputField.addListener(SWT.Verify, new Listener() {
      public void handleEvent(Event e) {
        String text = e.text;
        char[] chars = new char[text.length()];
        text.getChars(0, chars.length, chars, 0);
        for (int i = 0; i < chars.length; i++) {
          if ( !((chars[i] >= '0" && chars[i] <= '9") || chars[i] == '.") ) {
            e.doit = false;
            return;
          }
        }
      }
    });

    inputField.addListener(SWT.Modify, new Listener() {
      public void handleEvent(Event event) {
        try {
          float val = Float.parseFloat(inputField.getText());
          if (val < fMinValue) {
            if (!(allowZero && val == 0)) {
            	val = fMinValue;
            }
          }
          if (val > fMaxValue) {
            if (fMaxValue > -1) {
              val = fMaxValue;
            }
          }
          COConfigurationManager.setParameter(name, val);
        }
        catch (Exception e) {}
      }
    });

    inputField.addListener(SWT.FocusOut, new Listener() {
      public void handleEvent(Event event) {
        try {
          float val = Float.parseFloat(inputField.getText());
          if (val < fMinValue) {
            if (!(allowZero && val == 0)) {
              inputField.setText(String.valueOf(fMinValue));
              COConfigurationManager.setParameter(name, fMinValue);
            }
          }
          if (val > fMaxValue) {
            if (fMaxValue > -1) {
            	inputField.setText(String.valueOf(fMaxValue));
            	COConfigurationManager.setParameter(name, fMaxValue);
            }
          }
        }
        catch (Exception e) {}
      }
    });
  
public voidsetLayoutData(java.lang.Object layoutData)

    inputField.setLayoutData(layoutData);