⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colors.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Created on 2 mai 2004 Created by Olivier Chalouhi
 * 
 * Copyright (C) 2004, 2005, 2006 Aelitis SAS, All rights Reserved
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details (
 * see the LICENSE file ).
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * AELITIS, SAS au capital de 46,603.30 euros, 8 Alle Lenotre, La Grille Royale,
 * 78600 Le Mesnil le Roi, France.
 */
package org.gudy.azureus2.ui.swt.mainwindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.AEMonitor;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.ui.swt.Utils;
/**
 * @author Olivier Chalouhi
 * @author MjrTom
 *			2005/Dec/08: green
 *  
 */
public class Colors implements ParameterListener {
	private static final LogIDs LOGID = LogIDs.GUI;
  private static Colors instance = null;
  public static final int BLUES_LIGHTEST = 0;
  public static final int BLUES_DARKEST = 9;
  public static final int BLUES_MIDLIGHT = (BLUES_DARKEST + 1) / 4;
  public static final int BLUES_MIDDARK = ((BLUES_DARKEST + 1) / 2)
      + BLUES_MIDLIGHT;
  public static final int FADED_LIGHTEST = 0;
  public static final int FADED_DARKEST = 9;
  
  public static Color[] blues = new Color[BLUES_DARKEST + 1];
  public static Color[] faded = new Color[FADED_DARKEST + 1];
  public static Color colorProgressBar;
  public static Color colorInverse;
  public static Color colorShiftLeft;
  public static Color colorShiftRight;
  public static Color colorError;
  public static Color colorErrorBG;
  public static Color colorAltRow;
  public static Color colorWarning;
  public static Color black;
  public static Color light_grey;
  public static Color blue;
  public static Color green;
  public static Color fadedGreen;
  public static Color grey;
  public static Color red;
  public static Color fadedRed;
  public static Color yellow;
  public static Color white;
  public static Color background;
  public static Color red_ConsoleView;
  
  private static AEMonitor	class_mon	= new AEMonitor( "Colors" );
  
  private void allocateBlues() {    
    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++) {
        Color toBeDisposed = blues[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] = new Color(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] = new Color(display, hslColor.getRed(), hslColor.getGreen(),
            hslColor.getBlue());
        if (toBeDisposed != null && !toBeDisposed.isDisposed()) {
          toBeDisposed.dispose();
        }
      }
      
      if (bGrayScale) {
      	if (b > 200)
      		b -= 20;
      	else
      		b += 20;
      }
      Color toBeDisposed = colorInverse;
      hslColor.initHSLbyRGB(r, g, b);
      hslColor.reverseColor();
      colorInverse = new Color(display, hslColor.getRed(), hslColor.getGreen(),
          hslColor.getBlue());
      if (toBeDisposed != null && !toBeDisposed.isDisposed()) {
        toBeDisposed.dispose();
      }
      toBeDisposed = colorShiftRight;
      hslColor.initHSLbyRGB(r, g, b);
      hslColor.setHue(hslColor.getHue() + 25);
      colorShiftRight = new Color(display, hslColor.getRed(), hslColor
          .getGreen(), hslColor.getBlue());
      if (toBeDisposed != null && !toBeDisposed.isDisposed()) {
        toBeDisposed.dispose();
      }
      toBeDisposed = colorShiftLeft;
      hslColor.initHSLbyRGB(r, g, b);
      hslColor.setHue(hslColor.getHue() - 25);
      colorShiftLeft = new Color(display, hslColor.getRed(), hslColor
          .getGreen(), hslColor.getBlue());
      if (toBeDisposed != null && !toBeDisposed.isDisposed()) {
        toBeDisposed.dispose();
      }
    } catch (Exception e) {
    	Logger.log(new LogEvent(LOGID, "Error allocating colors", e));
    }
  }
  
  public void disposeColors() {
    if(display == null || display.isDisposed())
      return;
    
    Utils.execSWTThread(new AERunnable() {
      public void runSupport() {
        if (Colors.colorProgressBar != null
            && !Colors.colorProgressBar.isDisposed())
          Colors.colorProgressBar.dispose();
        for (int i = 0; i < Colors.blues.length; i++) {
          if (Colors.blues[i] != null && !Colors.blues[i].isDisposed())
            Colors.blues[i].dispose();
        }
        Color[] colorsToDispose = {colorInverse, colorShiftLeft, colorShiftRight,
        		colorError, grey, black, light_grey, blue, green, red, white,
        		red_ConsoleView, colorAltRow, colorWarning};
        for (int i = 0; i < colorsToDispose.length; i++) {
          if (colorsToDispose[i] != null && !colorsToDispose[i].isDisposed()) {
            colorsToDispose[i].dispose();
          }
        }
      }
    }, false);
  }
  
  /**
   * @param background The background to set.
   */
  public void setBackground(Color background) {
    if(Colors.background != null && !Colors.background.isDisposed()) {
      Color old = Colors.background;
      Colors.background = background;
      old.dispose();
    }    
  }
  
  private void allocateColorProgressBar() {
		if (display == null || display.isDisposed())
			return;

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

  private void allocateColorErrorBG() {
		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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -