FileDocCategorySizeDatePackage
ColorUtils.javaAPI DocAzureus 3.0.3.43383Thu Feb 09 19:42:56 GMT 2006org.gudy.azureus2.ui.swt.components

ColorUtils

public final class ColorUtils extends Object
Facilitates utility methods for handling SWT Colors
author
James Yeh

Fields Summary
Constructors Summary
Methods Summary
public static final org.eclipse.swt.graphics.ColorgetBoundedShade(org.eclipse.swt.graphics.Color original, int delta)

Gets a new SWT color that has been uniformly added with delta

If the a RGB value goes out of bounds, the delta will be applied negatively

param
original Original color
param
delta Delta in 8bit RGB values
return
New color

        final RGB newRGB = new RGB(
                getBoundedShade(original.getRed(), delta),
                getBoundedShade(original.getGreen(), delta),
                getBoundedShade(original.getBlue(), delta)
        );

        return new Color(Display.getDefault(), newRGB);
    
private static intgetBoundedShade(int origValue, int delta)

Gets a 8bit RGB value that has been added with delta

If the RGB value goes out of bounds, the delta will be applied negatively

param
origValue Original RGB value
param
delta Delta
return
New RGB value

        int result = origValue + delta;
        if(result > 255)
        {
            result = origValue - delta;

            if(result < 0)
            {
                result = origValue;
            }
        }
        else if(result < 0)
        {
            result = origValue - delta;

            if(result > 255)
            {
                result = origValue;
            }
        }

        return result;
    
public static final org.eclipse.swt.graphics.ColorgetShade(org.eclipse.swt.graphics.Color original, int delta)

Gets a new SWT color that has been uniformly added with delta

There is range checking such that the new RGB values are 0 <= x <= 255

param
original Original color
param
delta Delta in 8bit RGB values
return
New color

        final RGB newRGB = new RGB(
                Math.min(255, Math.max(0, original.getRed() + delta)),
                Math.min(255, Math.max(0, original.getGreen() + delta)),
                Math.min(255, Math.max(0, original.getBlue() + delta))
        );
        return new Color(Display.getDefault(), newRGB);