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

📄 colors.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				}
				
				hslColor.initRGBbyHSL(0, sat, lum);
				
				colorErrorBG = new AllocateColor("errorBG", new RGB(hslColor.getRed(),
						hslColor.getGreen(), hslColor.getBlue()), colorErrorBG).getColor();
			}
		}, false);
	}

	private void allocateColorError() {
		if (display == null || display.isDisposed())
			return;

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

	private void allocateColorWarning() {
		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 void allocateColorAltRow() {
		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);
	}

  /** Allocates a color */
  private class AllocateColor extends AERunnable {
    private Color toBeDeleted = null;
    private String sName;
    private RGB rgbDefault;
    private Color newColor;
    
    public AllocateColor(String sName, RGB rgbDefault, Color colorOld) {
      toBeDeleted = colorOld;
      this.sName = sName;
      this.rgbDefault = rgbDefault;
    }
    
    public AllocateColor(String sName, final Color colorDefault, Color colorOld) {
			toBeDeleted = colorOld;
			this.sName = sName;
			Utils.execSWTThread(new AERunnable() {
				public void runSupport() {
					if (!colorDefault.isDisposed())
						AllocateColor.this.rgbDefault = colorDefault.getRGB();
					else
						AllocateColor.this.rgbDefault = new RGB(0, 0, 0);
				}
			}, false);
		}
    
    public Color getColor() {
    	Utils.execSWTThread(this, false);
      return newColor;
    }

    public void runSupport() {
      if (COConfigurationManager.getBooleanParameter("Colors." + sName + ".override")) {
        newColor = new Color(display,
           COConfigurationManager.getIntParameter("Colors." + sName + ".red", 
                                                  rgbDefault.red),
           COConfigurationManager.getIntParameter("Colors." + sName + ".green",
                                                  rgbDefault.green),
           COConfigurationManager.getIntParameter("Colors." + sName + ".blue",
                                                  rgbDefault.blue));
      } else {
        newColor = new Color(display, rgbDefault);
        // Since the color is not longer overriden, reset back to default
        // so that the user sees the correct color in Config.
        COConfigurationManager.setRGBParameter("Colors." + sName, rgbDefault.red, rgbDefault.green, rgbDefault.blue ); 
      }

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

  private void allocateNonDynamicColors() {
    allocateColorWarning();
    allocateColorError();
    allocateColorAltRow();
    
    black = new Color(display, new RGB(0, 0, 0));
    light_grey = new Color(display, new RGB(192, 192, 192));
    blue = new Color(display, new RGB(0, 0, 170));
    green = new Color(display, new RGB(0, 170, 0));
    fadedGreen = new Color(display, new RGB(96,160,96));
    grey = new Color(display, new RGB(170, 170, 170));
    red = new Color(display, new RGB(255, 0, 0));
    fadedRed = new Color(display, new RGB(160, 96, 96));
    yellow = new Color(display, new RGB(255, 255, 0));
    white = new Color(display, new RGB(255, 255, 255));
    background = new Color(display , new RGB(248,248,248));
    red_ConsoleView = new Color(display, new RGB(255, 192, 192));
  }   
  
  private Display display;
  
  public Colors() {
    instance = this;
    display = SWTThread.getInstance().getDisplay();
    allocateDynamicColors();
    allocateNonDynamicColors();

    addColorsChangedListener(this);
  }
  
  public static Colors getInstance() {
  	try{
  		class_mon.enter();
	    if (instance == null)
	      instance = new Colors();
	
	    return instance;
  	}finally{
  		
  		class_mon.exit();
  	}
  }
  
  public void addColorsChangedListener(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);
  }

  public void removeColorsChangedListener(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);
  }
  
  public void parameterChanged(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();
    }
  }
}

⌨️ 快捷键说明

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