FileDocCategorySizeDatePackage
ColorParameter.javaAPI DocAzureus 3.0.3.44161Thu May 10 14:02:40 BST 2007org.gudy.azureus2.ui.swt.config

ColorParameter

public class ColorParameter extends Parameter implements org.gudy.azureus2.core3.config.ParameterListener
author
Olivier

Fields Summary
private org.eclipse.swt.widgets.Button
colorChooser
protected String
sParamName
private org.eclipse.swt.graphics.Image
img
Constructors Summary
public ColorParameter(org.eclipse.swt.widgets.Composite composite, String name, int r, int g, int b)

  	super(name);
    sParamName = name;
    colorChooser = new Button(composite,SWT.PUSH);
    final int rV = COConfigurationManager.getIntParameter(name+".red",r);
    final int gV = COConfigurationManager.getIntParameter(name+".green",g);
    final int bV = COConfigurationManager.getIntParameter(name+".blue",b);
    updateButtonColor(composite.getDisplay(), rV, gV, bV);

    COConfigurationManager.addParameterListener(sParamName, this);
    
    colorChooser.addListener(SWT.Dispose, new Listener() {
      public void handleEvent(Event e) {
        COConfigurationManager.removeParameterListener(sParamName, ColorParameter.this);
        if(img != null && ! img.isDisposed()) {
          img.dispose();          
        }
      }
    });

    colorChooser.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        ColorDialog cd = new ColorDialog(composite.getShell());
        cd.setRGB(new RGB(rV,gV,bV));
        RGB newColor = cd.open();
        if (newColor == null)
          return;
        newColorChosen();
        COConfigurationManager.setRGBParameter(name, newColor.red, newColor.green, newColor.blue);
      }
    });
    
  
Methods Summary
public org.eclipse.swt.widgets.ControlgetControl()

    return colorChooser;
  
public voidnewColorChosen()

    // subclasses can write their own code
  
public voidparameterChanged(java.lang.String parameterName)

    final int rV = COConfigurationManager.getIntParameter(sParamName+".red");
    final int gV = COConfigurationManager.getIntParameter(sParamName+".green");
    final int bV = COConfigurationManager.getIntParameter(sParamName+".blue");
    updateButtonColor(colorChooser.getDisplay(), rV, gV, bV);
  
public voidsetLayoutData(java.lang.Object layoutData)

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

  	// not needed, we already trap external changes
  
private voidupdateButtonColor(org.eclipse.swt.widgets.Display display, int rV, int gV, int bV)

    Image oldImg = img;
    Color color = ColorCache.getColor(display, rV, gV, bV);
    img = new Image(display,25,10);
    GC gc = new GC(img);
    gc.setBackground(color);
    gc.fillRectangle(0,0,25,10);
    gc.dispose();
    colorChooser.setImage(img);
    if(oldImg != null && ! oldImg.isDisposed())
      oldImg.dispose();