FileDocCategorySizeDatePackage
Colors.javaAPI DocAzureus 3.0.3.413147Mon Jul 23 11:03:54 BST 2007org.gudy.azureus2.ui.swt.mainwindow

Colors

public class Colors extends Object implements org.gudy.azureus2.core3.config.ParameterListener
author
Olivier Chalouhi
author
MjrTom 2005/Dec/08: green

Fields Summary
private static final LogIDs
LOGID
private static Colors
instance
public static final int
BLUES_LIGHTEST
public static final int
BLUES_DARKEST
public static final int
BLUES_MIDLIGHT
public static final int
BLUES_MIDDARK
public static final int
FADED_LIGHTEST
public static final int
FADED_DARKEST
public static org.eclipse.swt.graphics.Color[]
blues
public static org.eclipse.swt.graphics.Color[]
faded
public static org.eclipse.swt.graphics.Color
colorProgressBar
public static org.eclipse.swt.graphics.Color
colorInverse
public static org.eclipse.swt.graphics.Color
colorShiftLeft
public static org.eclipse.swt.graphics.Color
colorShiftRight
public static org.eclipse.swt.graphics.Color
colorError
public static org.eclipse.swt.graphics.Color
colorErrorBG
public static org.eclipse.swt.graphics.Color
colorAltRow
public static org.eclipse.swt.graphics.Color
colorWarning
public static org.eclipse.swt.graphics.Color
black
public static org.eclipse.swt.graphics.Color
light_grey
public static org.eclipse.swt.graphics.Color
blue
public static org.eclipse.swt.graphics.Color
green
public static org.eclipse.swt.graphics.Color
fadedGreen
public static org.eclipse.swt.graphics.Color
grey
public static org.eclipse.swt.graphics.Color
red
public static org.eclipse.swt.graphics.Color
fadedRed
public static org.eclipse.swt.graphics.Color
yellow
public static org.eclipse.swt.graphics.Color
white
public static org.eclipse.swt.graphics.Color
background
public static org.eclipse.swt.graphics.Color
red_ConsoleView
private static org.gudy.azureus2.core3.util.AEMonitor
class_mon
private org.eclipse.swt.widgets.Display
display
Constructors Summary
public Colors()

    instance = this;
    try {
    	display = SWTThread.getInstance().getDisplay();
    } catch (Exception e) {
    	display = Display.getDefault();
    }
    allocateDynamicColors();
    allocateNonDynamicColors();

    addColorsChangedListener(this);
  
Methods Summary
public voidaddColorsChangedListener(org.gudy.azureus2.core3.config.ParameterListener l)

    COConfigurationManager.addParameterListener("Color Scheme", l);
    COConfigurationManager.addParameterListener("Colors.progressBar.override", l);
    COConfigurationManager.addParameterListener("Colors.progressBar", l);
    COConfigurationManager.addParameterListener("Colors.error.override", l);
    COConfigurationManager.addParameterListener("Colors.error", l);
    COConfigurationManager.addParameterListener("Colors.warning.override", l);
    COConfigurationManager.addParameterListener("Colors.warning", l);
    COConfigurationManager.addParameterListener("Colors.altRow.override", l);
    COConfigurationManager.addParameterListener("Colors.altRow", l);
  
private voidallocateBlues()

  
         
    int r = 0;
    int g = 128;
    int b = 255;
    try {
      r = COConfigurationManager.getIntParameter("Color Scheme.red", r);
      g = COConfigurationManager.getIntParameter("Color Scheme.green", g);
      b = COConfigurationManager.getIntParameter("Color Scheme.blue", b);
      
      boolean bGrayScale = (r == b) && (b == g);

      HSLColor hslColor = new HSLColor();
      Color colorTables = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
      int tR = colorTables.getRed();
      int tG = colorTables.getGreen();
      int tB = colorTables.getBlue();
      
      // 0 == window background (white)
      // [blues.length-1] == rgb
      // in between == blend
      for (int i = 0; i < blues.length; i++) {
        hslColor.initHSLbyRGB(r, g, b);
        float blendBy = (i == 0) ? 1 : (float) 1.0
            - ((float) i / (float) (blues.length - 1));
        hslColor.blend(tR, tG, tB, blendBy);
        blues[i] = ColorCache.getColor(display, hslColor.getRed(),
						hslColor.getGreen(), hslColor.getBlue());
        int iSat = hslColor.getSaturation();
        if (iSat != 0)
          hslColor.setSaturation(iSat / 2);
        else if (bGrayScale) // gray
        	hslColor.brighten(0.8f);

        faded[i] = ColorCache.getColor(display, hslColor.getRed(),
						hslColor.getGreen(), hslColor.getBlue());
      }
      
      if (bGrayScale) {
      	if (b > 200)
      		b -= 20;
      	else
      		b += 20;
      }
      hslColor.initHSLbyRGB(r, g, b);
      hslColor.reverseColor();
      colorInverse = ColorCache.getColor(display, hslColor.getRed(),
					hslColor.getGreen(), hslColor.getBlue());

      hslColor.initHSLbyRGB(r, g, b);
      hslColor.setHue(hslColor.getHue() + 25);
      colorShiftRight = ColorCache.getColor(display, hslColor.getRed(),
					hslColor.getGreen(), hslColor.getBlue());

      hslColor.initHSLbyRGB(r, g, b);
      hslColor.setHue(hslColor.getHue() - 25);
      colorShiftLeft = ColorCache.getColor(display, hslColor.getRed(),
					hslColor.getGreen(), hslColor.getBlue());
    } catch (Exception e) {
    	Logger.log(new LogEvent(LOGID, "Error allocating colors", e));
    }
  
private voidallocateColorAltRow()

		if (display == null || display.isDisposed())
			return;

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				Color colorTables = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
				HSLColor hslColor = new HSLColor();
				hslColor.initHSLbyRGB(colorTables.getRed(), colorTables.getGreen(),
						colorTables.getBlue());

				int lum = hslColor.getLuminence();
				if (lum > 127)
					lum -= 10;
				else
					lum += 30; // it's usually harder to see difference in darkness
				hslColor.setLuminence(lum);
				colorAltRow = new AllocateColor("altRow", new RGB(hslColor.getRed(),
						hslColor.getGreen(), hslColor.getBlue()), colorAltRow).getColor();
			}
		}, false);
	
private voidallocateColorError()

		if (display == null || display.isDisposed())
			return;

		colorError = new AllocateColor("error", new RGB(255, 68, 68), colorError)
				.getColor();
	
private voidallocateColorErrorBG()

		if (display == null || display.isDisposed())
			return;

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				Color colorTables = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
				HSLColor hslColor = new HSLColor();
				hslColor.initHSLbyRGB(colorTables.getRed(), colorTables.getGreen(),
						colorTables.getBlue());
				int lum = hslColor.getLuminence();
				int sat = hslColor.getSaturation();

				lum = (int)((lum > 127) ? lum * 0.8 : lum * 1.3);
				
				if (sat == 0) {
					sat = 80;
				}
				
				hslColor.initRGBbyHSL(0, sat, lum);
				
				colorErrorBG = new AllocateColor("errorBG", new RGB(hslColor.getRed(),
						hslColor.getGreen(), hslColor.getBlue()), colorErrorBG).getColor();
			}
		}, false);
	
private voidallocateColorProgressBar()

		if (display == null || display.isDisposed())
			return;

		colorProgressBar = new AllocateColor("progressBar", colorShiftRight,
				colorProgressBar).getColor();
	
private voidallocateColorWarning()

		if (display == null || display.isDisposed())
			return;

		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				Color colorTables = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
				HSLColor hslBG = new HSLColor();
				hslBG.initHSLbyRGB(colorTables.getRed(), colorTables.getGreen(),
						colorTables.getBlue());
				int lum = hslBG.getLuminence();

				HSLColor hslColor = new HSLColor();
				hslColor.initRGBbyHSL(25, 200, 128 + (lum < 160 ? 10 : -10));
				colorWarning = new AllocateColor("warning", new RGB(hslColor.getRed(),
						hslColor.getGreen(), hslColor.getBlue()), colorWarning).getColor();
			}
		}, false);
	
private voidallocateDynamicColors()

    if(display == null || display.isDisposed())
      return;
    
    Utils.execSWTThread(new AERunnable(){
      public void runSupport() {
        allocateBlues();
        allocateColorProgressBar();
        allocateColorErrorBG();
      }
    }, false);
  
private voidallocateNonDynamicColors()

		allocateColorWarning();
		allocateColorError();
		allocateColorAltRow();

		black = ColorCache.getColor(display, 0, 0, 0);
		light_grey = ColorCache.getColor(display, 192, 192, 192);
		blue = ColorCache.getColor(display, 0, 0, 170);
		green = ColorCache.getColor(display, 0, 170, 0);
		fadedGreen = ColorCache.getColor(display, 96, 160, 96);
		grey = ColorCache.getColor(display, 170, 170, 170);
		red = ColorCache.getColor(display, 255, 0, 0);
		fadedRed = ColorCache.getColor(display, 160, 96, 96);
		yellow = ColorCache.getColor(display, 255, 255, 0);
		white = ColorCache.getColor(display, 255, 255, 255);
		background = ColorCache.getColor(display, 248, 248, 248);
		red_ConsoleView = ColorCache.getColor(display, 255, 192, 192);
	
public static org.gudy.azureus2.ui.swt.mainwindow.ColorsgetInstance()

  	try{
  		class_mon.enter();
	    if (instance == null)
	      instance = new Colors();
	
	    return instance;
  	}finally{
  		
  		class_mon.exit();
  	}
  
public voidparameterChanged(java.lang.String parameterName)

    if (parameterName.equals("Color Scheme")) {
      allocateDynamicColors();
    }

    if(parameterName.startsWith("Colors.progressBar")) {
      allocateColorProgressBar();      
    }
    if(parameterName.startsWith("Colors.error")) {
      allocateColorError();
    }
    if(parameterName.startsWith("Colors.warning")) {
      allocateColorWarning();
    }
    if(parameterName.startsWith("Colors.altRow")) {
      allocateColorAltRow();
    }
  
public voidremoveColorsChangedListener(org.gudy.azureus2.core3.config.ParameterListener l)

    COConfigurationManager.removeParameterListener("Color Scheme", l);
    COConfigurationManager.removeParameterListener("Colors.progressBar.override", l);
    COConfigurationManager.removeParameterListener("Colors.progressBar", l);
    COConfigurationManager.removeParameterListener("Colors.error.override", l);
    COConfigurationManager.removeParameterListener("Colors.error", l);
    COConfigurationManager.removeParameterListener("Colors.warning.override", l);
    COConfigurationManager.removeParameterListener("Colors.warning", l);
    COConfigurationManager.removeParameterListener("Colors.altRow.override", l);
    COConfigurationManager.removeParameterListener("Colors.altRow", l);