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

The following examples show how to use org.eclipse.swt.graphics.RGB#equals() . 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: JavaUIPreferenceInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the default value and fires a property
 * change event if necessary.
 *
 * @param store	the preference store
 * @param key the preference key
 * @param newValue the new value
 * @param fireEvent <code>false</code> if no event should be fired
 * @since 3.4
 */
private static void setDefault(IPreferenceStore store, String key, RGB newValue, boolean fireEvent) {
	if (!fireEvent) {
		PreferenceConverter.setDefault(store, key, newValue);
		return;
	}

	RGB oldValue= null;
	if (store.isDefault(key))
		oldValue= PreferenceConverter.getDefaultColor(store, key);

	PreferenceConverter.setDefault(store, key, newValue);

	if (oldValue != null && !oldValue.equals(newValue))
		store.firePropertyChangeEvent(key, oldValue, newValue);
}
 
Example 2
Source File: EditorConfigUIPreferenceInitializer.java    From editorconfig-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the default value and fires a property change event if necessary.
 *
 * @param store
 *            the preference store
 * @param key
 *            the preference key
 * @param newValue
 *            the new value
 * @param fireEvent
 *            <code>false</code> if no event should be fired
 */
private static void setDefault(IPreferenceStore store, String key, RGB newValue, boolean fireEvent) {
	if (!fireEvent) {
		PreferenceConverter.setDefault(store, key, newValue);
		return;
	}

	RGB oldValue = null;
	if (store.isDefault(key)) {
		oldValue = PreferenceConverter.getDefaultColor(store, key);
	}
	PreferenceConverter.setDefault(store, key, newValue);

	if (oldValue != null && !oldValue.equals(newValue)) {
		store.firePropertyChangeEvent(key, oldValue, newValue);
	}
}
 
Example 3
Source File: SetColorEffect.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.nebula.animation.effects.AbstractEffect#applyEffect(long)
 */
public void applyEffect(final long currentTime) {

	Color currentColor = control.getColor();

	// Get the next color values
	int nextRed = (int) (src.getRed()
			+ diffR * easingFunction.getValue(currentTime));
	int nextGreen = (int) (src.getGreen()
			+ diffG * easingFunction.getValue(currentTime));
	int nextBlue = (int) (src.getBlue()
			+ diffB * easingFunction.getValue(currentTime));

	RGB nextRGB = new RGB(nextRed, nextGreen, nextBlue);

	if (currentColor == null || !nextRGB.equals(currentColor.getRGB())) {

		Color nextColor = new Color(Display.getCurrent(), nextRed,
				nextGreen, nextBlue);

		// If this is the destination color, dispose the newly created color
		// and use the destination one instead.
		if (dest.getRGB().equals(nextColor.getRGB())) {
			nextColor.dispose();
			nextColor = dest;
		}

		control.setColor(nextColor);

		// If the previous color is not the source or destination one,
		// dispose it.
		if (currentColor != null && !currentColor.isDisposed()) {
			if (dest != currentColor && src != currentColor) {
				currentColor.dispose();
			}
		}

	}

}
 
Example 4
Source File: FlatButton.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public FlatButton setColor(final GamaUIColor c) {
	final RGB oldColorCode = colorCode;
	final RGB newColorCode = c.getRGB();
	if (newColorCode.equals(oldColorCode)) { return this; }
	colorCode = c.getRGB();
	redraw();
	return this;
}
 
Example 5
Source File: YCbCrTest.java    From gradle-and-eclipse-rcp with Apache License 2.0 5 votes vote down vote up
private void roundTripTestCase(int r, int g, int b) {
	RGB expected = new RGB(r, g, b);
	RGB yCbCr = ColorPicker.toYCbCr(expected);
	RGB roundTrip = ColorPicker.fromYCbCr(yCbCr);
	if (!expected.equals(roundTrip)) {
		// if they don't match exactly, allow a maximum delta of 1 for rounding errors 
		int deltaR = Math.abs(roundTrip.red - expected.red);
		int deltaG = Math.abs(roundTrip.green - expected.green);
		int deltaB = Math.abs(roundTrip.blue - expected.blue);
		int maxDelta = Math.max(Math.max(deltaR, deltaG), deltaB);
		Assert.assertTrue(maxDelta <= 1);
	}
}
 
Example 6
Source File: SemanticHighlightings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the default value and fires a property
 * change event if necessary.
 *
 * @param store	the preference store
 * @param key the preference key
 * @param newValue the new value
 * @since 3.3
 */
private static void setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue) {
	RGB oldValue= null;
	if (store.isDefault(key))
		oldValue= PreferenceConverter.getDefaultColor(store, key);

	PreferenceConverter.setDefault(store, key, newValue);

	if (oldValue != null && !oldValue.equals(newValue))
		store.firePropertyChangeEvent(key, oldValue, newValue);
}
 
Example 7
Source File: ColorBuilder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Processes the save action.
 * 
 * @param rgb
 *            The new RGB value.
 */
protected void processAction( RGB rgb )
{
	String newComboText = predefinedColor;
	if ( newComboText == null )
	{
		newComboText = formatRGB( rgb );
	}

	if ( !combo.getText( ).equals( newComboText ) )
	{
		combo.setText( newComboText );
	}

	if ( oldRgb == null && rgb == null )
	{
		return;
	}

	if ( rgb != null && rgb.equals( oldRgb ) )
	{
		return;
	}

	oldRgb = rgb;
	if ( rgb == null || !rgb.equals( colorSelector.getColorValue( ) ) )
	{
		colorSelector.setColorValue( rgb );
	}
	notifyListeners( SWT.Modify, null );
}
 
Example 8
Source File: ColorBuilder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Processes the save action.
 * 
 * @param rgb
 *            The new RGB value.
 */
protected void processAction( RGB rgb )
{
	String newComboText = predefinedColor;
	if ( newComboText == null )
	{
		newComboText = formatRGB( rgb );
	}

	if ( !combo.getText( ).equals( newComboText ) )
	{
		combo.setText( newComboText );
	}

	if ( oldRgb == null && rgb == null )
	{
		notifyListeners( SWT.Modify, null );
		return;
	}

	if ( rgb != null && rgb.equals( oldRgb ) )
	{
		notifyListeners( SWT.Modify, null );
		return;
	}

	oldRgb = rgb;
	if ( rgb == null || !rgb.equals( colorSelector.getColorValue( ) ) )
	{
		colorSelector.setColorValue( rgb );
	}
	notifyListeners( SWT.Modify, null );
}
 
Example 9
Source File: PreferenceStoreAccessor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void populateTextStyle(String id, TextStyle style, TextStyle defaults) {
	IPreferenceStore editorsStore = EditorsUI.getPreferenceStore();
	RGB fontColorDefaultDefault = editorsStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) 
			? getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB()
			: PreferenceConverter.getColor(editorsStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND);
	RGB backgrounColorDefaultDefault = editorsStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) 
			? getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB() 
			: PreferenceConverter.getColor(editorsStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
	FontData[] fontDataDefaultDefault = JFaceResources.getTextFont().getFontData();

	IPreferenceStore preferenceStore = getPreferenceStore();
	String cssID = CSS_PREFIX + id;
	IPreferenceStore cssPrefStore = getPluginCssPreferenceStore();
	
	String colorKey = PREFERENCE_TAG + getTokenColorPreferenceKey(id);
	String cssFontColor = cssPrefStore.getString(getTokenColorPreferenceKey(cssID));
	if(!Strings.isEmpty(cssFontColor)) {
		preferenceStore.setDefault(colorKey, cssFontColor);
	} else if (defaults.getColor() != null) {
		PreferenceConverter.setDefault(preferenceStore, colorKey, defaults.getColor());
	} else {
		PreferenceConverter.setDefault(preferenceStore, colorKey, fontColorDefaultDefault);
	}
	
	String backgroundKey = PREFERENCE_TAG + getTokenBackgroundColorPreferenceKey(id);
	String cssBgColor = cssPrefStore.getString(getTokenBackgroundColorPreferenceKey(cssID));
	if(!Strings.isEmpty(cssBgColor)) {
		preferenceStore.setDefault(backgroundKey, cssBgColor);
	} else if (defaults.getBackgroundColor() != null) {
		PreferenceConverter.setDefault(preferenceStore, backgroundKey, defaults.getBackgroundColor());
	} else {
		PreferenceConverter.setDefault(preferenceStore, backgroundKey, backgrounColorDefaultDefault);
	}
	
	String fontKey = PREFERENCE_TAG + getTokenFontPreferenceKey(id);
	String cssFont = cssPrefStore.getString(getTokenFontPreferenceKey(cssID));
	if(!Strings.isEmpty(cssFont)) {
		preferenceStore.setDefault(fontKey, cssFont);
	} else if (defaults.getFontData() != null)
		PreferenceConverter.setDefault(preferenceStore, fontKey, defaults.getFontData());
	else {
		PreferenceConverter.setDefault(preferenceStore, fontKey, fontDataDefaultDefault);
	}
	
	String styleKey = PREFERENCE_TAG + getTokenStylePreferenceKey(id);
	int cssStyle = cssPrefStore.getInt(getTokenStylePreferenceKey(cssID));
	if(cssStyle != 0) {
		preferenceStore.setDefault(styleKey, cssStyle);
	} else {
		preferenceStore.setDefault(styleKey, defaults.getStyle());
	}
	
	// populate
	RGB color = PreferenceConverter.getColor(preferenceStore, colorKey);
	if (!color.equals(fontColorDefaultDefault))
		style.setColor(color);
	RGB background = PreferenceConverter.getColor(preferenceStore, backgroundKey);
	if (!background.equals(backgrounColorDefaultDefault))
		style.setBackgroundColor(background);
	FontData[] fontDataArray = PreferenceConverter.getFontDataArray(preferenceStore, fontKey);
	if (!Arrays.equals(fontDataArray, fontDataDefaultDefault)) {
		style.setFontData(fontDataArray);
	}
	style.setStyle(preferenceStore.getInt(styleKey));
}
 
Example 10
Source File: FilterColorEditorTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Test highlighting multiple elements in a message
 */
@Test
public void testMultiHighlightMessage() {
    final Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, MESSAGE_COLUMN);

    ImageHelper before = ImageHelper.grabImage(cellBounds);
    // enter regex in message column
    fTableBot.click(0, MESSAGE_COLUMN);
    fBot.text().typeText("e\n", 100);
    // make sure matching item is not selected
    fTableBot.select(ROW - 1);
    ImageHelper after = ImageHelper.waitForNewImage(cellBounds, before);

    Multiset<RGB> colorBefore = before.getHistogram();
    Multiset<RGB> colorAfter = after.getHistogram();

    assertTrue(colorBefore.contains(fBackground));
    assertTrue(colorBefore.contains(fForeground));
    assertFalse(colorBefore.contains(fHighlight));

    assertTrue(colorAfter.contains(fBackground));
    assertTrue(colorAfter.contains(fForeground));
    assertTrue(colorAfter.contains(fHighlight));

    int start = -1;
    int end;
    List<Point> intervals = new ArrayList<>();
    List<RGB> pixelRow = after.getPixelRow(2);
    for (int i = 1; i < pixelRow.size(); i++) {
        RGB prevPixel = pixelRow.get(i - 1);
        RGB pixel = pixelRow.get(i);
        if (prevPixel.equals(fBackground) && pixel.equals(fHighlight)) {
            start = i;
        }
        if (prevPixel.equals(fHighlight) && pixel.equals(fBackground)) {
            end = i;
            if (start == -1) {
                fail();
            }
            intervals.add(new Point(start, end));
        }
    }
    assertEquals(2, intervals.size());
}
 
Example 11
Source File: FilterColorEditorTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Switch to filter and back
 */
@Test
public void testSwitchToFilter() {
    Rectangle cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
    ImageHelper before = ImageHelper.grabImage(cellBounds);

    // enter regex in Timestamp column
    fTableBot.click(0, TIMESTAMP_COLUMN);
    fBot.text().typeText("00\n", 100);
    // make sure matching column is not selected
    fTableBot.select(ROW - 1);
    ImageHelper afterSearch = ImageHelper.waitForNewImage(cellBounds, before);

    // click Add as Filter
    fTableBot.click(0, 0);
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "<srch>", 0, TIMESTAMP_COLUMN));
    fBot.waitUntil(ConditionHelpers.isTableCellFilled(fTableBot, "22/22", 1, TIMESTAMP_COLUMN));
    // the bounds have changed after applying the filter
    cellBounds = SWTBotUtils.getCellBounds(fTableBot.widget, ROW, TIMESTAMP_COLUMN);
    ImageHelper afterFilter = ImageHelper.grabImage(cellBounds);

    // press DEL to clear highlighting
    fTableBot.pressShortcut(Keystrokes.DELETE);
    ImageHelper afterClear = ImageHelper.waitForNewImage(cellBounds, afterFilter);

    List<RGB> beforeLine = before.getPixelRow(2);
    List<RGB> afterSearchLine = afterSearch.getPixelRow(2);
    List<RGB> afterFilterLine = afterFilter.getPixelRow(2);
    List<RGB> afterClearLine = afterClear.getPixelRow(2);

    assertEquals(beforeLine.size(), afterSearchLine.size());
    assertEquals(beforeLine.size(), afterFilterLine.size());
    assertEquals(beforeLine.size(), afterClearLine.size());
    for (int i = 0; i < beforeLine.size(); i++) {
        RGB beforePixel = beforeLine.get(i);
        RGB afterSearchPixel = afterSearchLine.get(i);
        RGB afterFilterPixel = afterFilterLine.get(i);
        RGB afterClearPixel = afterClearLine.get(i);

        assertEquals(afterSearchPixel, afterFilterPixel);
        assertEquals(beforePixel, afterClearPixel);
        if (!afterSearchPixel.equals(fHighlight)) {
            assertEquals(beforePixel, afterSearchPixel);
        } else {
            assertNotEquals(fHighlight, beforePixel);
        }

    }
    assertEquals(afterSearchLine, afterFilterLine);
    assertEquals(beforeLine, afterClearLine);
    assertNotEquals(afterSearchLine, beforeLine);
}
 
Example 12
Source File: PreferenceConstants.java    From typescript.java with MIT License 3 votes vote down vote up
/**
 * Sets the default value and fires a property change event if necessary.
 * 
 * @param store
 *            the preference store
 * @param key
 *            the preference key
 * @param newValue
 *            the new value
 * 
 */
private static void setDefaultAndFireEvent(IPreferenceStore store, String key, RGB newValue) {
	RGB oldValue = null;
	if (store.isDefault(key))
		oldValue = PreferenceConverter.getDefaultColor(store, key);

	PreferenceConverter.setDefault(store, key, newValue);

	if (oldValue != null && !oldValue.equals(newValue))
		store.firePropertyChangeEvent(key, oldValue, newValue);
}