Java Code Examples for org.eclipse.swt.graphics.Color#getRGB()

The following examples show how to use org.eclipse.swt.graphics.Color#getRGB() . 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 File: ViewportAnnotation.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public ViewportAnnotation(User source) {
  super(
      ViewportAnnotation.TYPE,
      true,
      CoreUtils.format(Messages.ViewportAnnotation_visible_scope_of, source),
      source);

  Display display = Display.getDefault();

  Color currentColor = getColor(TYPE, source.getColorID());

  RGB rgb = currentColor.getRGB();

  currentColor.dispose();

  strokeColor = new Color(display, ColorUtils.scaleColorBy(rgb, STROKE_SCALE));
  // FIXME: dispose strokeColor somewhere
  fillColor = new Color(display, ColorUtils.scaleColorBy(rgb, FILL_SCALE));
  // FIXME: dispose fillColor somewhere
}
 
Example 2
Source File: Colors.java    From BiglyBT with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isColorContrastOk(Color color1, Color color2) {
	// https://www.w3.org/TR/AERT/#color-contrast
	// Two colors provide good color visibility if the brightness difference and the color difference between the two colors are greater than a set range.
	// Color brightness is determined by the following formula:
	//((Red value X 299) + (Green value X 587) + (Blue value X 114)) / 1000
	//Note: This algorithm is taken from a formula for converting RGB values to YIQ values. This brightness value gives a perceived brightness for a color.
	//
	//Color difference is determined by the following formula:
	//(maximum (Red value 1, Red value 2) - minimum (Red value 1, Red value 2)) + (maximum (Green value 1, Green value 2) - minimum (Green value 1, Green value 2)) + (maximum (Blue value 1, Blue value 2) - minimum (Blue value 1, Blue value 2))
	//
	//The rage for color brightness difference is 125. The range for color difference is 500.
	RGB rgb1 = color1.getRGB();
	RGB rgb2 = color2.getRGB();

	int b1 = ((rgb1.red * 299) + (rgb1.green * 587) + (rgb1.blue * 114)) / 1000;
	int b2 = ((rgb2.red * 299) + (rgb2.green * 587) + (rgb2.blue * 114)) / 1000;
	if (Math.abs(b1 - b2) >= 125) {
		return true;
	}
	int hueDiff = (Math.max(rgb2.red, rgb1.red) - Math.min(rgb2.red, rgb1.red))
			+ (Math.max(rgb2.green, rgb1.green) - Math.min(rgb2.green, rgb1.green))
			+ (Math.max(rgb2.blue, rgb1.blue) - Math.min(rgb2.blue, rgb1.blue));
	return hueDiff >= 500;
}
 
Example 3
Source File: SourceViewerInformationControl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 4
Source File: Axis.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setBackgroundColor(Color bg) {
	RGB backRGB = bg.getRGB();
	revertBackColor = XYGraphMediaFactory.getInstance().getColor(255 - backRGB.red, 255 - backRGB.green,
			255 - backRGB.blue);
	super.setBackgroundColor(bg);
}
 
Example 5
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the RGB value for the foreground of a specific token.
 * 
 * @param string
 * @return
 */
public RGB getForegroundAsRGB(String scope)
{
	Color fg = getForeground(scope);
	if (fg == null)
	{
		return null;
	}
	return fg.getRGB();
}
 
Example 6
Source File: GamaColors.java    From gama with 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 7
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the RGB value for the background of a specific token.
 * 
 * @param string
 * @return
 */
public RGB getBackgroundAsRGB(String scope)
{
	Color bg = getBackground(scope);
	if (bg == null)
	{
		return null;
	}
	return bg.getRGB();
}
 
Example 8
Source File: BoxDecoratorImpl.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void decorate(final boolean mouseDbClickColorChange) {
	decorated = false;
	if (boxText == null || settings == null) { return; }

	boxPaint = new BoxPaintListener();
	boxMouseMove = new BoxMouseMoveListener();
	boxMouseTrack = new BoxMouseTrackListener();
	boxTextChange = new BoxTextChangeListener();
	fillMouseClick = new FillBoxMouseClick();
	boxKey = new BoxKeyListener();
	boxModify = new BoxModifyListener();

	if (mouseDbClickColorChange) {
		boxMouseClick = new BoxMouseClickListener();
	}

	final Color c = boxText.getBackground();
	if (c != null) {
		oldBackground = c.getRGB();
	}
	oldIndent = boxText.getIndent();
	if (oldIndent < 3) {
		boxText.setIndent(3);
	}
	boxText.addPaintListener(boxPaint);
	boxText.addMouseMoveListener(boxMouseMove);
	boxText.addMouseTrackListener(boxMouseTrack);
	boxText.getContent().addTextChangeListener(boxTextChange);
	boxText.addMouseListener(fillMouseClick);
	boxText.addModifyListener(boxModify);
	boxText.addKeyListener(boxKey);

	if (mouseDbClickColorChange) {
		boxText.addMouseListener(boxMouseClick);
	}

	decorated = true;
}
 
Example 9
Source File: XYChartLegendImageProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Deprecated
@Override
public Image getLegendImage(int imageHeight, int imageWidth, @NonNull String name) {
    /*
     * If series exists in chart, then image legend match that series. Image will
     * make sense if series exists in chart. If it does not exists, an image will
     * still be created.
     */
    IYAppearance appearance = fChartViewer.getSeriesAppearance(name);
    RGBAColor rgb = appearance.getColor();
    Color lineColor = new Color(Display.getDefault(), rgb.getRed(), rgb.getGreen(), rgb.getBlue());
    Color background = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);

    PaletteData palette = new PaletteData(background.getRGB(), lineColor.getRGB());
    ImageData imageData = new ImageData(imageWidth, imageHeight, 8, palette);
    imageData.transparentPixel = 0;
    Image image = new Image(Display.getDefault(), imageData);
    GC gc = new GC(image);

    gc.setBackground(background);
    gc.fillRectangle(0, 0, imageWidth, imageHeight);
    drawStyleLine(gc, lineColor, imageWidth, imageHeight, appearance.toOutputElementStyle());

    drawStyledDot(gc, lineColor, imageWidth, imageHeight, appearance.toOutputElementStyle());

    gc.dispose();
    lineColor.dispose();
    return image;
}
 
Example 10
Source File: Annotation.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param annotationColor
 *            the annotationColor to set
 */
public void setAnnotationColor(Color annotationColor) {
	this.annotationColor = annotationColor;

	if (annotationColor != null)
		this.annotationColorRGB = annotationColor.getRGB();

	infoLabel.setForegroundColor(annotationColor);
	pointer.setForegroundColor(annotationColor);
}
 
Example 11
Source File: Axis.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param majorGridColor
 *            the majorGridColor to set
 */
public void setMajorGridColor(final Color majorGridColor) {
	this.majorGridColor = majorGridColor;
	this.majorGridColorRGB = majorGridColor.getRGB();
	if (xyGraph != null)
		xyGraph.repaint();
}
 
Example 12
Source File: Axis.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setForegroundColor(final Color color) {
	Color oldColor = getForegroundColor();
	super.setForegroundColor(color);
	colorRGB = color.getRGB();
	if (xyGraph != null)
		xyGraph.repaint();
	fireAxisForegroundColorChanged(oldColor, color);
}
 
Example 13
Source File: AbstractDocumentationHover.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Computes the hover info and returns a {@link DocumentationBrowserInformationControlInput} for it.
 * 
 * @param element
 *            the resolved element
 * @param useHTMLTags
 * @param previousInput
 *            the previous input, or <code>null</code>
 * @param editorPart
 *            (can be <code>null</code>)
 * @param hoverRegion
 * @return the HTML hover info for the given element(s) or <code>null</code> if no information is available
 */
@SuppressWarnings("unused")
protected DocumentationBrowserInformationControlInput getHoverInfo(Object element, boolean useHTMLTags,
		DocumentationBrowserInformationControlInput previousInput, IEditorPart editorPart, IRegion hoverRegion)
{
	if (element == null)
	{
		return null;
	}
	StringBuffer buffer = new StringBuffer();
	String base = null;

	int leadingImageWidth = 0;
	setHeader(getHeader(element, editorPart, hoverRegion), buffer, useHTMLTags);
	setDocumentation(getDocumentation(element, editorPart, hoverRegion), buffer, useHTMLTags);
	if (buffer.length() > 0)
	{
		if (useHTMLTags)
		{
			Color borderColor = getBorderColor();
			Color bgColor = getBackgroundColor();
			Color fgColor = getForegroundColor();

			String borderColorHex = (borderColor != null) ? getHexColor(borderColor.getRGB())
					: DEFAULT_BORDER_COLOR;
			RGB bgRGB = (bgColor != null) ? bgColor.getRGB() : null;
			RGB fgRGB = (fgColor != null) ? fgColor.getRGB() : null;

			// We need to set the border color before we call insertPageProlog on the style-sheet
			String styleSheet = getStyleSheet();
			styleSheet = styleSheet.replaceAll(BORDER_COLOR_CSS_TEXT, borderColorHex);
			HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, styleSheet);
			if (base != null)
			{
				int endHeadIdx = buffer.indexOf("</head>"); //$NON-NLS-1$
				buffer.insert(endHeadIdx, "\n<base href='" + base + "'>\n"); //$NON-NLS-1$ //$NON-NLS-2$
			}
			HTMLPrinter.addPageEpilog(buffer);
		}
		return new DocumentationBrowserInformationControlInput(previousInput, element, buffer.toString(),
				leadingImageWidth, hoverRegion);
	}
	return null;
}
 
Example 14
Source File: Flasher.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
static Color invertColor(Color c) {
	RGB rgb = c.getRGB();
	return new Color(c.getDevice(), 255 - rgb.red, 255 - rgb.green, 255 - rgb.blue);
}
 
Example 15
Source File: JavadocView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected void setBackground(Color color) {
	getControl().setBackground(color);
	fBackgroundColorRGB= color.getRGB();
	refresh();
}
 
Example 16
Source File: BoxSettingsImpl.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
protected Color setColorCopy(final Color old, final Color newColor) {
	if (old != null) {
		old.dispose();
	}
	return newColor == null ? null : new Color(null, newColor.getRGB());
}
 
Example 17
Source File: XYGraph.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param titleColor
 *            the titleColor to set
 */
public void setTitleColor(Color titleColor) {
	this.titleColor = titleColor;
	titleLabel.setForegroundColor(titleColor);
	this.titleColorRgb = titleColor.getRGB();
}
 
Example 18
Source File: GamaColors.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
static Color computeReverse(final Color c) {
	final RGB data = c.getRGB();
	return getColor(255 - data.red, 255 - data.green, 255 - data.blue);
}
 
Example 19
Source File: Utils.java    From tracecompass with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Get the system color with the given ID.
 *
 * @param id
 *            The color ID
 * @return The resulting color
 */
public static Color getSysColor(int id) {
    Color col = Display.getCurrent().getSystemColor(id);
    return new Color(col.getDevice(), col.getRGB());
}
 
Example 20
Source File: TimelineViewer.java    From nebula with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Convert a color into its color code.
 *
 * @param color
 *            color to convert
 * @return HTML color code, eg '#12557F'
 */
private static String toColorCode(Color color) {
	final RGB rgb = color.getRGB();

	return "#" + toHexValue(rgb.red) + toHexValue(rgb.green) + toHexValue(rgb.blue);
}