ColorParameterpublic class ColorParameter extends Parameter implements org.gudy.azureus2.core3.config.ParameterListener
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.Control | getControl()
return colorChooser;
| public void | newColorChosen()
// subclasses can write their own code
| public void | parameterChanged(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 void | setLayoutData(java.lang.Object layoutData)
colorChooser.setLayoutData(layoutData);
| public void | setValue(java.lang.Object value)
// not needed, we already trap external changes
| private void | updateButtonColor(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();
|
|