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

IntListParameter

public class IntListParameter extends Parameter
author
Olivier

Fields Summary
org.eclipse.swt.widgets.Combo
list
private final int[]
values
private final String
name
Constructors Summary
public IntListParameter(org.eclipse.swt.widgets.Composite composite, String name, String[] labels, int[] values)

    this(composite, name, COConfigurationManager.getIntParameter(name), labels, values);
  
public IntListParameter(org.eclipse.swt.widgets.Composite composite, String name, int defaultValue, String[] labels, int[] values)

		super(name);
		this.name = name;
		this.values = values;

      if(labels.length != values.length)
        return;
      int value = COConfigurationManager.getIntParameter(name,defaultValue);
      int index = findIndex(value,values);
      list = new Combo(composite,SWT.SINGLE | SWT.READ_ONLY);
      for(int i = 0 ; i < labels.length  ;i++) {
        list.add(labels[i]);
      }
      
      setIndex(index);
      
      list.addListener(SWT.Selection, new Listener() {
           public void handleEvent(Event e) {
          	 setIndex(list.getSelectionIndex());
           }
         });
      
    
Methods Summary
private intfindIndex(int value, int[] values)

    for(int i = 0 ; i < values.length ;i++) {
      if(values[i] == value)
        return i;
    }
    return 0;
  
public org.eclipse.swt.widgets.ControlgetControl()

    return list;
  
public java.lang.ObjectgetValueObject()

  	return new Integer(COConfigurationManager.getIntParameter(name));
  
protected voidsetIndex(int index)

param
index

  	int	selected_value = values[index];
  	
  	Utils.execSWTThread(new AERunnable() {
  		public void runSupport() {
  			if (list == null || list.isDisposed()) {
  				return;
  			}

  	  	if (list.getSelectionIndex() != index) {
  	  		list.select(index);
  	  	}
  		}
  	});
  	
  	if (COConfigurationManager.getIntParameter(name) != selected_value) {
  		COConfigurationManager.setParameter(name, selected_value);
  	}
	
public voidsetLayoutData(java.lang.Object layoutData)

    list.setLayoutData(layoutData);
   
public voidsetValue(java.lang.Object value)

  	if (value instanceof Number) {
  		int i = ((Number)value).intValue();
      setIndex(findIndex(i, values));
  	}