Java Code Examples for org.eclipse.swt.graphics.RGB#getHSB()

The following examples show how to use org.eclipse.swt.graphics.RGB#getHSB() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: nebula   File: CSSShelfRenderer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static RGB saturate(RGB rgb, float saturation) {
	float[] hsb = rgb.getHSB();

	hsb[1] += saturation;
	if (hsb[1] > 1.0f) {
		hsb[1] = 1.0f;
	}
	if (hsb[1] < 0f) {
		hsb[1] = 0f;
	}

	// hue is 0.0..360.0, saturation and brightness 0.0..1.0
	hsb[0] += 360.0 * saturation;
	if (hsb[0] > 360.0f) {
		hsb[0] = 360.0f;
	}

	if (hsb[0] < 0f) {
		hsb[0] = 0f;
	}

	return new RGB(hsb[0], hsb[1], hsb[2]);
}
 
Example 2
private static RGB saturate(RGB rgb, float saturation) {
	float[] hsb = rgb.getHSB();

	hsb[1] += saturation;
	if (hsb[1] > 1.0f) {
		hsb[1] = 1.0f;
	}
	if (hsb[1] < 0f) {
		hsb[1] = 0f;
	}

	// hue is 0.0..360.0, saturation and brightness 0.0..1.0
	hsb[0] += 360.0 * saturation;
	if (hsb[0] > 360.0f) {
		hsb[0] = 360.0f;
	}

	if (hsb[0] < 0f) {
		hsb[0] = 0f;
	}

	return new RGB(hsb[0], hsb[1], hsb[2]);
}
 
Example 3
/**
 * Sets the viewer's background color to the given control's background color.
 * The background color is <em>only</em> set if it's visibly distinct from the
 * default Java source text color.
 * 
 * @param control the control with the default background color
 * @since 3.7
 */
public void adaptBackgroundColor(Control control) {
	// workaround for dark editor background color, see https://bugs.eclipse.org/330680
	
	Color defaultColor= control.getBackground();
	float[] defaultBgHSB= defaultColor.getRGB().getHSB();
	
	Color javaDefaultColor= JavaUI.getColorManager().getColor(IJavaColorConstants.JAVA_DEFAULT);
	RGB javaDefaultRGB= javaDefaultColor != null ? javaDefaultColor.getRGB() : new RGB(255, 255, 255);
	float[] javaDefaultHSB= javaDefaultRGB.getHSB();
	
	if (Math.abs(defaultBgHSB[2] - javaDefaultHSB[2]) >= 0.5f) {
		getTextWidget().setBackground(defaultColor);
		if (fBackgroundColor != null) {
			fBackgroundColor.dispose();
			fBackgroundColor= null;
		}
	}
}
 
Example 4
/**
 * Returns <code>null</code> if {@link SWT#COLOR_INFO_BACKGROUND} is visibly distinct from the
 * default Java source text color. Otherwise, returns the editor background color.
 * 
 * @param display the display
 * @return an RGB or <code>null</code>
 * @since 3.6.1
 */
public static RGB getVisibleBackgroundColor(Display display) {
	float[] infoBgHSB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB().getHSB();
	
	Color javaDefaultColor= JavaUI.getColorManager().getColor(IJavaColorConstants.JAVA_DEFAULT);
	RGB javaDefaultRGB= javaDefaultColor != null ? javaDefaultColor.getRGB() : new RGB(255, 255, 255);
	float[] javaDefaultHSB= javaDefaultRGB.getHSB();
	
	if (Math.abs(infoBgHSB[2] - javaDefaultHSB[2]) < 0.5f) {
		// workaround for dark tooltip background color, see https://bugs.eclipse.org/309334
		IPreferenceStore preferenceStore= JavaPlugin.getDefault().getCombinedPreferenceStore();
		boolean useDefault= preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
		if (useDefault)
			return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
		return PreferenceConverter.getColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
	}
	return null;
}
 
Example 5
/**
 * Returns <code>null</code> if {@link SWT#COLOR_INFO_BACKGROUND} is visibly distinct from the
 * default Java source text color. Otherwise, returns the editor background color.
 * 
 * @param display the display
 * @return an RGB or <code>null</code>
 * @since 3.6.1
 */
public static RGB getVisibleBackgroundColor(Display display) {
	float[] infoBgHSB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB().getHSB();
	
	RGB javaDefaultRGB = EditorSettings_Actual.CODE_DEFAULT_COLOR.getFieldValue().rgb;
	float[] javaDefaultHSB= javaDefaultRGB.getHSB();
	
	if (Math.abs(infoBgHSB[2] - javaDefaultHSB[2]) < 0.5f) {
		// workaround for dark tooltip background color, see https://bugs.eclipse.org/309334
		IPreferenceStore preferenceStore= LangUIPlugin.getInstance().getCombinedPreferenceStore();
		boolean useDefault= preferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
		if (useDefault)
			return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB();
		return PreferenceConverter.getColor(preferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
	}
	return null;
}
 
Example 6
Source Project: nebula   File: TimeSlot.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param color The RGB of the color
 * @param amount The amount to lighten as a percentage expresssed as a float between -1 and 1.
 * @return The new RGB that is lightened by the specified amount
 */
private RGB lighten(RGB color, float amount) {
	float[] hsb = color.getHSB();
	float b = hsb[2] + hsb[2] * amount;
	if (b < 0) b=0;
	if (b > 1) b=1;
	return new RGB(hsb[0], hsb[1], b);
}
 
Example 7
/**
 * @param color The RGB of the color
 * @param amount The amount to lighten as a percentage expresssed as a float between -1 and 1.
 * @return The new RGB that is lightened by the specified amount
 */
private RGB lighten(RGB color, float amount) {
	float[] hsb = color.getHSB();
	float b = hsb[2] + hsb[2] * amount;
	if (b < 0) b=0;
	if (b > 1) b=1;
	return new RGB(hsb[0], hsb[1], b);
}
 
Example 8
Source Project: nebula   File: Day.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param color The RGB of the color
 * @param amount The amount to lighten as a percentage expresssed as a float between -1 and 1.
 * @return The new RGB that is lightened by the specified amount
 */
private RGB lighten(RGB color, float amount) {
	float[] hsb = color.getHSB();
	float b = hsb[2] + hsb[2] * amount;
	if (b < 0)
		b = 0;
	if (b > 1)
		b = 1;
	return new RGB(hsb[0], hsb[1], b);
}
 
Example 9
Source Project: gama   File: GamaColors.java    License: GNU General Public License v3.0 5 votes vote down vote up
static Color computeInactive(final Color c) {
	final RGB data = c.getRGB();
	final float[] hsb = data.getHSB();
	final float[] newHsb = new float[3];
	newHsb[0] = hsb[0];
	newHsb[1] = hsb[1] / 2;
	newHsb[2] = Math.min(1.0f, hsb[2] + 0.2f);
	final RGB newData = new RGB(newHsb[0], newHsb[1], newHsb[2]);
	return getColor(newData.red, newData.green, newData.blue);
}
 
Example 10
Source Project: gama   File: GamaColors.java    License: GNU General Public License v3.0 5 votes vote down vote up
static Color computeDarker(final Color c) {
	final RGB data = c.getRGB();
	final float[] hsb = data.getHSB();
	final float[] newHsb = new float[3];
	newHsb[0] = hsb[0];
	newHsb[1] = hsb[1];
	newHsb[2] = Math.max(0.0f, hsb[2] - 0.1f);
	final RGB newData = new RGB(newHsb[0], newHsb[1], newHsb[2]);
	return getColor(newData.red, newData.green, newData.blue);
}
 
Example 11
Source Project: gama   File: GamaColors.java    License: GNU General Public License v3.0 5 votes vote down vote up
static Color computeLighter(final Color c) {
	final RGB data = c.getRGB();
	final float[] hsb = data.getHSB();
	final float[] newHsb = new float[3];
	newHsb[0] = hsb[0];
	newHsb[1] = hsb[1];
	newHsb[2] = Math.min(1f, hsb[2] + 0.2f);
	final RGB newData = new RGB(newHsb[0], newHsb[1], newHsb[2]);
	return getColor(newData.red, newData.green, newData.blue);
}
 
Example 12
Source Project: gama   File: GamaColors.java    License: GNU General Public License v3.0 5 votes vote down vote up
static Color computeGray(final Color c) {
	final RGB data = c.getRGB();
	final float[] hsb = data.getHSB();
	final float[] newHsb = new float[3];
	newHsb[0] = hsb[0];
	newHsb[1] = 0.0f;
	newHsb[2] = hsb[2];
	final RGB newData = new RGB(newHsb[0], newHsb[1], newHsb[2]);
	return getColor(newData.red, newData.green, newData.blue);
}
 
Example 13
Source Project: BiglyBT   File: ColorCache.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static Color getSchemedColor(Device device, int red, int green, int blue) {
	ensureMapColorsInitialized(device);

	Long key = new Long(((long) red << 16) + (green << 8) + blue + 0x1000000l);

	Color color = mapColors.get(key);
	if (color == null || color.isDisposed()) {
		try {
			if (red < 0) {
				red = 0;
			} else if (red > 255) {
				red = 255;
			}
			if (green < 0) {
				green = 0;
			} else if (green > 255) {
				green = 255;
			}
			if (blue < 0) {
				blue = 0;
			} else if (blue > 255) {
				blue = 255;
			}

      RGB rgb = new RGB(red, green, blue);
      float[] hsb = rgb.getHSB();
      hsb[0] += Colors.diffHue;
      if (hsb[0] > 360) {
      	hsb[0] -= 360;
      } else if (hsb[0] < 0) {
      	hsb[0] += 360;
      }
      hsb[1] *= Colors.diffSatPct;
      //hsb[2] *= Colors.diffLumPct;

      color = getColor(device, hsb);
      mapColors.put(key, color);
		} catch (IllegalArgumentException e) {
			Debug.out("One Invalid: " + red + ";" + green + ";" + blue, e);
		}
	}

	return color;
}
 
Example 14
RGB lighten(RGB color)
{
	float[] hsb = color.getHSB();
	return new RGB(hsb[0], hsb[1], Math.min(1, (float) (hsb[2] + 0.15)));
}
 
Example 15
RGB darken(RGB color)
{
	float[] hsb = color.getHSB();
	return new RGB(hsb[0], hsb[1], Math.max(0, (float) (hsb[2] - 0.15)));
}
 
Example 16
Source Project: erflute   File: InsertedImageEditPart.java    License: Apache License 2.0 4 votes vote down vote up
private void changeImage() {
    final InsertedImage model = (InsertedImage) getModel();

    final ImageData newImageData =
            new ImageData(imageData.width, imageData.height, imageData.depth, imageData.palette);

    for (int x = 0; x < imageData.width; x++) {
        for (int y = 0; y < imageData.height; y++) {
            final RGB rgb = imageData.palette.getRGB(imageData.getPixel(x, y));
            final float[] hsb = rgb.getHSB();

            if (model.getHue() != 0) {
                hsb[0] = model.getHue() & 360;
            }

            hsb[1] = hsb[1] + (model.getSaturation() / 100f);
            if (hsb[1] > 1.0f) {
                hsb[1] = 1.0f;
            } else if (hsb[1] < 0) {
                hsb[1] = 0f;
            }

            hsb[2] = hsb[2] + (model.getBrightness() / 100f);
            if (hsb[2] > 1.0f) {
                hsb[2] = 1.0f;

            } else if (hsb[2] < 0) {
                hsb[2] = 0f;
            }

            final RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

            final int pixel = imageData.palette.getPixel(newRGB);

            newImageData.setPixel(x, y, pixel);
        }
    }

    if (image != null && !image.isDisposed()) {
        image.dispose();
    }

    this.image = new Image(Display.getDefault(), newImageData);
}
 
Example 17
private void changeImage() {
	InsertedImage model = (InsertedImage) this.getModel();

	ImageData newImageData = new ImageData(this.imageData.width,
			this.imageData.height, this.imageData.depth,
			this.imageData.palette);

	for (int x = 0; x < this.imageData.width; x++) {
		for (int y = 0; y < this.imageData.height; y++) {
			RGB rgb = this.imageData.palette.getRGB(this.imageData
					.getPixel(x, y));
			float[] hsb = rgb.getHSB();

			if (model.getHue() != 0) {
				hsb[0] = model.getHue() & 360;
			}

			hsb[1] = hsb[1] + (model.getSaturation() / 100f);
			if (hsb[1] > 1.0f) {
				hsb[1] = 1.0f;
			} else if (hsb[1] < 0) {
				hsb[1] = 0f;
			}

			hsb[2] = hsb[2] + (model.getBrightness() / 100f);
			if (hsb[2] > 1.0f) {
				hsb[2] = 1.0f;

			} else if (hsb[2] < 0) {
				hsb[2] = 0f;
			}

			RGB newRGB = new RGB(hsb[0], hsb[1], hsb[2]);

			int pixel = imageData.palette.getPixel(newRGB);

			newImageData.setPixel(x, y, pixel);
		}
	}

	if (this.image != null && !this.image.isDisposed()) {
		this.image.dispose();
	}

	this.image = new Image(Display.getDefault(), newImageData);
}
 
Example 18
Source Project: nebula   File: TimeSlot.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the color's saturation to the specified value.
 * 
 * @param color The RGB of the color
 * @param saturation the new saturation (between 0 and 1)
 * @return a Color that is saturated by the specified amount
 */
private RGB saturate(RGB color, float saturation) {
	float[] hsb = color.getHSB();
	return new RGB(hsb[0], saturation, hsb[2]);
}
 
Example 19
/**
 * Sets the color's saturation to the specified value.
 * 
 * @param color The RGB of the color
 * @param saturation the new saturation (between 0 and 1)
 * @return a Color that is saturated by the specified amount
 */
private RGB saturate(RGB color, float saturation) {
	float[] hsb = color.getHSB();
	return new RGB(hsb[0], saturation, hsb[2]);
}
 
Example 20
Source Project: nebula   File: Day.java    License: Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Sets the color's saturation to the specified value.
 * 
 * @param color The RGB of the color
 * @param saturation the new saturation (between 0 and 1)
 * @return a Color that is saturated by the specified amount
 */
private RGB saturate(RGB color, float saturation) {
	float[] hsb = color.getHSB();
	return new RGB(hsb[0], saturation, hsb[2]);
}