Java Code Examples for org.eclipse.swt.graphics.RGB

The following examples show how to use org.eclipse.swt.graphics.RGB. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void initializeDefaultPreferences()
{
	IEclipsePreferences node = DefaultScope.INSTANCE.getNode(FrameworkUtil.getBundle(getClass()).getSymbolicName());

	if (node != null)
	{
		node.put("rootPageValue", "DEFAULT ROOT PAGE VALUE");
		node.put("page1", "DEFAULT PAGE 1 VALUE");
		node.put("page2", "DEFAULT PAGE 2 VALUE");
	
		node.put("prefCombo", "value2");
		node.put("prefColor", StringConverter.asString(new RGB(0,255,0)));
		node.putBoolean("prefBoolean",true);
		node.put("prefString","Default string value");
		
		try { node.flush();  }  catch (BackingStoreException e) { }
	}		
	
	
	
}
 
Example 2
Source Project: birt   Source File: UIUtil.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static Color createColor( IPreferenceStore store, String key,
		Display display )
{
	RGB rgb = null;
	if ( store.contains( key ) )
	{
		if ( store.isDefault( key ) )
		{
			rgb = PreferenceConverter.getDefaultColor( store, key );
		}
		else
		{
			rgb = PreferenceConverter.getColor( store, key );
		}
		if ( rgb != null )
		{
			return new Color( display, rgb );
		}
	}
	return null;
}
 
Example 3
Source Project: gama   Source File: AutoStartup.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void earlyStartup() {
	GamaPreferences.Modeling.EDITOR_BASE_FONT.init(() -> getDefaultFontData()).onChange(font -> {
		try {
			final FontData newValue = new FontData(font.getName(), font.getSize(), font.getStyle());
			setValue(EditorsPlugin.getDefault().getPreferenceStore(), TEXT_FONT, newValue);
		} catch (final Exception e) {}
	});
	GamaPreferences.Modeling.EDITOR_BACKGROUND_COLOR.init(() -> getDefaultBackground()).onChange(c -> {
		final RGB rgb = new RGB(c.getRed(), c.getGreen(), c.getBlue());
		PreferenceConverter.setValue(EditorsPlugin.getDefault().getPreferenceStore(),
				AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, rgb);
		GamaPreferences.Modeling.OPERATORS_MENU_SORT
				.onChange(newValue -> OperatorsReferenceMenu.byName = newValue.equals("Name"));
	});
	GamlRuntimeModule.staticInitialize();
	GamlEditorBindings.install();
	GamlReferenceSearch.install();
}
 
Example 4
Source Project: saros   Source File: ColorUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Scales a color's lightness; the higher the ratio the lighter the color
 *
 * @param rgb that defines the color
 * @param scale non-negative whereas 0 results in zero lightness = black color
 * @return the scaled RGB
 * @see <a href="http://en.wikipedia.org/wiki/HSL_and_HSV">HSL and HSV</a>
 */
public static RGB scaleColorBy(RGB rgb, float scale) {
  if (scale < 0) throw new IllegalArgumentException();

  /*
   * Convert to HLS; HLS and HSL are synonym
   */
  float[] hls =
      ColorSpaceConversion.RGBtoHLS(
          (float) rgb.red / 255, (float) rgb.green / 255, (float) rgb.blue / 255);

  /*
   * Scale the lightness
   */
  hls[1] *= scale;

  /*
   * Convert back from HLS to RGB
   */
  float[] scaledRGB = ColorSpaceConversion.HLStoRGB(hls[0], hls[1], hls[2]);

  return new RGB(
      Math.round(scaledRGB[0] * 255),
      Math.round(scaledRGB[1] * 255),
      Math.round(scaledRGB[2] * 255));
}
 
Example 5
/**
 * Get the color for a series
 *
 * @param name
 *            the series name
 * @return The color in RGB
 * @since 4.1
 */
public RGB getColorForItem(String name) {
    if (fSegmentStoreProviders.size() == 1) {
        return BAR_COLOR;
    }
    Set<String> keys = fSegmentStoreProviders.keySet();
    int i = 0;
    for (String key : keys) {
        if (key.equals(name)) {
            break;
        }
        i++;
    }
    float pos = (float) i / keys.size();
    int index = Math.max((int) (PALETTE.getNbColors() * pos), 0) % PALETTE.getNbColors();
    return Objects.requireNonNull(RGBAUtil.fromRGBAColor(PALETTE.get().get(index)).rgb);
}
 
Example 6
@Override
public Object getPreferredValue(EStructuralFeature feature) {
       Object preferenceStore = getDiagramPreferencesHint().getPreferenceStore();
       if (preferenceStore instanceof IPreferenceStore) {
           if (feature == NotationPackage.eINSTANCE.getLineStyle_LineColor()) {
               
               return FigureUtilities.RGBToInteger(new RGB(44,109,163));
               
           } else if (feature == NotationPackage.eINSTANCE
               .getFontStyle_FontColor()) {
               
               return FigureUtilities.RGBToInteger(PreferenceConverter
                   .getColor((IPreferenceStore) preferenceStore,
                       IPreferenceConstants.PREF_FONT_COLOR));
               
           } else if (feature == NotationPackage.eINSTANCE
               .getFillStyle_FillColor()) {
               
               return FigureUtilities.RGBToInteger(new RGB(184,185,218));
               
           }
       }

       return getStructuralFeatureValue(feature);
   }
 
Example 7
private RGBa merge(RGBa top, RGBa bottom, RGB defaultParent)
{
	if (top == null && bottom == null)
	{
		return new RGBa(defaultParent);
	}
	if (top == null) // for some reason there is no top.
	{
		return bottom;
	}
	if (top.isFullyOpaque()) // top has no transparency, just return it
	{
		return top;
	}
	if (bottom == null) // there is no parent, merge onto default FG/BG for theme
	{
		return new RGBa(Theme.alphaBlend(defaultParent, top.toRGB(), top.getAlpha()));
	}
	return new RGBa(Theme.alphaBlend(bottom.toRGB(), top.toRGB(), top.getAlpha()));
}
 
Example 8
Source Project: nebula   Source File: ResourceHelper.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public static Color getColor(String rgbString) {
	if (!JFaceResources.getColorRegistry().hasValueFor(rgbString)) {
		if (rgbString.startsWith("#")) {
			// decode hex to rgb
			Integer intval = Integer.decode(rgbString);
	        int i = intval.intValue();
	        RGB rgb = new RGB((i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF);
	        JFaceResources.getColorRegistry().put(rgbString, rgb);
		} else {
			// rgb string in format rgb(r, g, b)
			String rgbValues = rgbString.substring(rgbString.indexOf('(') + 1, rgbString.lastIndexOf(')'));
			String[] values = rgbValues.split(",");
			try {
				int red = Integer.valueOf(values[0].trim());
				int green = Integer.valueOf(values[1].trim());
				int blue = Integer.valueOf(values[2].trim());
				
				JFaceResources.getColorRegistry().put(rgbString, new RGB(red, green, blue));
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		}
	}
	return JFaceResources.getColorRegistry().get(rgbString);
}
 
Example 9
Source Project: nebula   Source File: DefaultGridLookPainter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private void paintCell(GC gc, RGB background, Rectangle bounds,
		boolean topOpen, boolean bottomOpen) {
	// Compute effective cell rectangle
	int x = bounds.x - border.getLeft() - cellPadding.x;
	int y = bounds.y - border.getTop(topOpen)
			- (topOpen ? 0 : cellPadding.y);
	int width = bounds.width + border.getWidth() + cellPadding.x
			+ cellPadding.width;
	int height = bounds.height + border.getHeight(topOpen, bottomOpen)
			+ (bottomOpen ? 0 : cellPadding.y + cellPadding.height);

	// Paint background
	Color backgroundColor = resources.getColor(background);
	if (backgroundColor != null) {
		Color oldBackground = gc.getBackground();
		gc.setBackground(backgroundColor);
		gc.fillRectangle(x, y, width, height);
		gc.setBackground(oldBackground);
	}

	// Paint border
	border.paint(gc, x, y, width, height, topOpen, bottomOpen);
}
 
Example 10
Source Project: AndroidRobot   Source File: SetCheckPoint2.java    License: Apache License 2.0 6 votes vote down vote up
public ImageData getImageData(BufferedImage bufferedImage) {
    DirectColorModel colorModel = (DirectColorModel) bufferedImage.getColorModel();
    PaletteData palette = new PaletteData(colorModel.getRedMask(), colorModel.getGreenMask(),
        colorModel.getBlueMask());
    ImageData data = new ImageData(bufferedImage.getWidth(), bufferedImage.getHeight(),
        colorModel.getPixelSize(), palette);
    WritableRaster raster = bufferedImage.getRaster();
    int[] pixelArray = new int[3];
    for (int y = 0; y < data.height; y++) {
        for (int x = 0; x < data.width; x++) {
            raster.getPixel(x, y, pixelArray);
            int pixel = palette.getPixel(new RGB(pixelArray[0], pixelArray[1], pixelArray[2]));
            data.setPixel(x, y, pixel);
        }
    }
    return data;
}
 
Example 11
Source Project: hop   Source File: SwtGc.java    License: Apache License 2.0 5 votes vote down vote up
private Color getColor( int r, int g, int b ) {
  Color color = new Color( PropsUi.getDisplay(), new RGB( r, g, b ) );
  int index = colors.indexOf( color );
  if ( index < 0 ) {
    colors.add( color );
  } else {
    color.dispose();
    color = colors.get( index );
  }
  return color;
}
 
Example 12
Source Project: BiglyBT   Source File: Colors.java    License: GNU General Public License v2.0 5 votes vote down vote up
public AllocateColor(String sName, final Color colorDefault, Color colorOld) {
	this.sName = sName;
	Utils.execSWTThread(() -> {
		if (!colorDefault.isDisposed()) {
			AllocateColor.this.rgbDefault = colorDefault.getRGB();
			COConfigurationManager.setRGBDefault("Colors." + sName,
					rgbDefault.red, rgbDefault.green, rgbDefault.blue);
		} else {
			AllocateColor.this.rgbDefault = new RGB(0, 0, 0);
		}
	}, false);
}
 
Example 13
@Override
public void setInput(Object input)
{
	if (input instanceof RGB)
	{
		setBackgroundColor(getColorManager().getColor((RGB) input));
	}
	else if (input instanceof String)
	{
		setInformation((String) input);
	}
}
 
Example 14
@Override
public void initializeDefaultPreferences() {
	// 设置 colors 首选项页的初始值
	IPreferenceStore store = Activator.getDefault().getPreferenceStore();
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TAG_FG_COLOR, new RGB(234, 234, 234));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TAG_BG_COLOR, new RGB(223, 112, 0));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.WRONG_TAG_COLOR, new RGB(255, 0, 0));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.DIFFERENCE_FG_COLOR, new RGB(255, 0, 0));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.DIFFERENCE_BG_COLOR, new RGB(244, 244, 159));

	PreferenceConverter.setDefault(store, IColorPreferenceConstant.PT_COLOR, new RGB(255, 0, 0));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.QT_COLOR, new RGB(255, 204, 204));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.MT_COLOR, new RGB(171, 217, 198));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TM_MATCH101_COLOR, new RGB(255, 255, 204));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TM_MATCH100_COLOR, new RGB(37, 168, 204));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TM_MATCH90_COLOR, new RGB(79, 185, 214));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TM_MATCH80_COLOR, new RGB(114, 199, 222));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TM_MATCH70_COLOR, new RGB(155, 215, 231));
	PreferenceConverter.setDefault(store, IColorPreferenceConstant.TM_MATCH0_COLOR, new RGB(198, 240, 251));

	PreferenceConverter.setDefault(store, IColorPreferenceConstant.HIGHLIGHTED_TERM_COLOR, new RGB(170, 255, 85));

	// 设置 net.heartsome.cat.common.core 插件中的语言代码初始值
	IPreferenceStore corePreferenceStore = new ScopedPreferenceStore(ConfigurationScope.INSTANCE, CoreActivator
			.getDefault().getBundle().getSymbolicName());
	corePreferenceStore.setDefault(IPreferenceConstants.LANGUAGECODE, LocaleService.getLanguageConfigAsString());

	// 设置选择路径对话框的初始值
	PlatformUI.getPreferenceStore()
			.setDefault(IPreferenceConstants.LAST_DIRECTORY, System.getProperty("user.home"));
	
	ColorConfigLoader.init();
}
 
Example 15
Source Project: hop   Source File: PropsUi.java    License: Apache License 2.0 5 votes vote down vote up
public RGB getGraphColorRGB() {
  int r = Const.toInt( getProperty( STRING_GRAPH_COLOR_R ), ConstUi.COLOR_GRAPH_RED ); // default White
  int g = Const.toInt( getProperty( STRING_GRAPH_COLOR_G ), ConstUi.COLOR_GRAPH_GREEN );
  int b = Const.toInt( getProperty( STRING_GRAPH_COLOR_B ), ConstUi.COLOR_GRAPH_BLUE );

  return new RGB( r, g, b );
}
 
Example 16
Source Project: ermaster-b   Source File: ChangeBackgroundColorAction.java    License: Apache License 2.0 5 votes vote down vote up
public ChangeBackgroundColorAction(IWorkbenchPart part, ERDiagram diagram) {
	super(part, Action.AS_DROP_DOWN_MENU);

	this.setId(ID);

	this.setText(ResourceString
			.getResourceString("action.title.change.background.color"));
	this.setToolTipText(ResourceString
			.getResourceString("action.title.change.background.color"));

	int[] defaultColor = diagram.getDefaultColor();

	this.rgb = new RGB(defaultColor[0], defaultColor[1], defaultColor[2]);
	this.setColorToImage();
}
 
Example 17
Source Project: gradle-and-eclipse-rcp   Source File: XkcdColorPicker.java    License: Apache License 2.0 5 votes vote down vote up
public XkcdColorPicker(Composite parent, RGB initRGB) {
	super(new Composite(parent, SWT.NONE));
	RGB initYCbCr = ColorPicker.toYCbCr(initRGB);

	// create a scale and bind it to an RxBox<Integer>
	RxBox<Integer> luminance = RxBox.of(initYCbCr.red);

	// colorpanel in the center
	ColorPicker cbcrPanel = new ColorPicker(wrapped);
	Rx.subscribe(luminance, cbcrPanel::setY);

	// controls at the right
	Composite rightCmp = new Composite(wrapped, SWT.NONE);

	// scale below
	Scale scale = new Scale(wrapped, SWT.HORIZONTAL);
	scale.setMinimum(0);
	scale.setMaximum(255);
	Rx.subscribe(luminance, scale::setSelection);
	scale.addListener(SWT.Selection, e -> {
		luminance.set(scale.getSelection());
	});

	Layouts.setGrid(wrapped).numColumns(2);
	Layouts.setGridData(cbcrPanel).grabAll();
	Layouts.setGridData(rightCmp).grabVertical().verticalSpan(2);
	Layouts.setGridData(scale).grabHorizontal();

	// populate the bottom
	Layouts.setGrid(rightCmp).margin(0);
	XkcdColors.Lookup xkcdLookup = new XkcdColors.Lookup(rightCmp);

	Group hoverGrp = new Group(rightCmp, SWT.SHADOW_ETCHED_IN);
	hoverGrp.setText("Hover");
	createGroup(hoverGrp, cbcrPanel.rxMouseMove(), xkcdLookup);

	Group clickGrp = new Group(rightCmp, SWT.SHADOW_ETCHED_IN);
	clickGrp.setText("Click");
	createGroup(clickGrp, cbcrPanel.rxMouseDown(), xkcdLookup);
}
 
Example 18
Source Project: nebula   Source File: BackgroundPrintTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void testEquals() {
	Print background = new BackgroundPrint(new PrintStub(0), new RGB(0, 0,
			0));
	assertEquals(background, new BackgroundPrint(new PrintStub(0), new RGB(
			0, 0, 0)));
	assertFalse(background.equals(new BackgroundPrint(new PrintStub(1),
			new RGB(0, 0, 0))));
	assertFalse(background.equals(new BackgroundPrint(new PrintStub(0),
			new RGB(1, 1, 1))));
}
 
Example 19
Source Project: tlaplus   Source File: CoverageInformationItem.java    License: MIT License 5 votes vote down vote up
Color colorItem(TreeSet<Long> counts, final Representation rep) {
	int hue = ModuleCoverageInformation.getHue(rep.getValue(this, Grouping.INDIVIDUAL), counts);
	String key = Integer.toString(hue);
	if (!JFaceResources.getColorRegistry().hasValueFor(key)) {
		JFaceResources.getColorRegistry().put(key, new RGB(hue, .25f, 1f));
	}
	final Color color = JFaceResources.getColorRegistry().get(key);

	Color[] colors = new Color[2];
	colors[Grouping.INDIVIDUAL.ordinal()] = color;
	colors[Grouping.COMBINED.ordinal()] = color;
	representations.put(rep, colors);
	
	if (hasSiblings()) {
		// Aggregated color (might be identical to color).
		hue = ModuleCoverageInformation.getHue(rep.getValue(this, Grouping.COMBINED), counts);
		key = Integer.toString(hue);
		if (!JFaceResources.getColorRegistry().hasValueFor(key)) {
			JFaceResources.getColorRegistry().put(key, new RGB(hue, .25f, 1f));
		}
		Color aggregate = JFaceResources.getColorRegistry().get(key);

		colors = new Color[2];
		colors[Grouping.INDIVIDUAL.ordinal()] = color;
		colors[Grouping.COMBINED.ordinal()] = aggregate;
		representations.put(rep, colors);
		return aggregate;
	}
	
	return color;
}
 
Example 20
@Override
public Color getColor(String key) {

	if (key == null)
		return null;

	RGB rgb = fKeyTable.get(key);
	return getColor(rgb);
}
 
Example 21
Source Project: neoscada   Source File: ChartFactoryImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public String convertToString ( EDataType eDataType, Object instanceValue )
{
    switch ( eDataType.getClassifierID () )
    {
        case ChartPackage.PROFILE_SWITCHER_TYPE:
            return convertProfileSwitcherTypeToString ( eDataType, instanceValue );
        case ChartPackage.RGB:
            return convertRGBToString ( eDataType, instanceValue );
        default:
            throw new IllegalArgumentException ( "The datatype '" + eDataType.getName () + "' is not a valid classifier" ); //$NON-NLS-1$ //$NON-NLS-2$
    }
}
 
Example 22
public void bindColor(String key, RGB rgb) {
	Object value= fKeyTable.get(key);
	if (value != null)
		throw new UnsupportedOperationException();

	fKeyTable.put(key, rgb);
}
 
Example 23
Source Project: goclipse   Source File: TextStylingPreference.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public static TextStyling getFromStore(IPreferencesAccess prefsHelper, String colorKey) {
	RGB rgb = getRgb(prefsHelper, getColorKey(colorKey));
	boolean isEnabled = getBoolean(prefsHelper, getEnabledKey(colorKey));
	boolean isBold = getBoolean(prefsHelper, getBoldKey(colorKey));
	boolean isItalic = getBoolean(prefsHelper, getItalicKey(colorKey));
	boolean isStrikethrough = getBoolean(prefsHelper, getStrikethroughKey(colorKey));
	boolean isUnderline = getBoolean(prefsHelper, getUnderlineKey(colorKey));
	
	return new TextStyling(isEnabled, rgb, isBold, isItalic, isStrikethrough, isUnderline);
}
 
Example 24
/**
 * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int,
 *      int)
 */
protected void drawCompositeImage(int width, int height) {

	// draw the thin color bar underneath
	if (rgb != null) {
		ImageData colorBar = new ImageData(width, height / 5, 1,
		
			new PaletteData(new RGB[] {rgb}));
		drawImage(colorBar, 0, height - height / 5);
		
	}
	// draw the base image
	drawImage(basicImgData, 0, 0);
}
 
Example 25
Source Project: slr-toolkit   Source File: SeriesPageBubble.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void mouseUp(MouseEvent e) {
	if(e.getSource() == labelShowColor && list_y.getItemCount() > 0 && btnRadioButtonCustom.getSelection()) {
		RGB rgb = PageSupport.openAndGetColor(this.getParent(), labelShowColor);
		int index = list_y.getSelectionIndex();
		termDataY.get(index).setRGB(rgb);
	}
}
 
Example 26
private RGB convertToRGB( String color )
{
	int[] rgbValues = ColorUtil.getRGBs( color );
	if ( rgbValues == null )
	{
		return null;
	}
	else
	{
		return new RGB( rgbValues[0], rgbValues[1], rgbValues[2] );
	}
}
 
Example 27
/**
 * @param foregroundColor The foregroundColor to set.
 */
public void setForegroundColor(RGB foregroundColor) {
    if (isRealModification(_foregroundColor, foregroundColor)) {
        RGB oldVal = _foregroundColor;
        _foregroundColor = foregroundColor;
        firePropertyChange(FOREGROUNDCOLOR, oldVal, foregroundColor);
    }
}
 
Example 28
Source Project: mat-calcite-plugin   Source File: CommentScanner.java    License: Apache License 2.0 5 votes vote down vote up
public CommentScanner() {
	List<IRule> rules = new ArrayList<IRule>();

	Token commentToken = new Token(new TextAttribute(new Color(
			Display.getCurrent(), new RGB(63, 127, 95))));
	rules.add(new EndOfLineRule("--", commentToken));
	rules.add(new EndOfLineRule("//", commentToken));
	rules.add(new MultiLineRule("/*", "*/", commentToken));

	setRules(rules.toArray(new IRule[rules.size()]));
}
 
Example 29
Source Project: gradle-and-eclipse-rcp   Source File: ColorPicker.java    License: Apache License 2.0 5 votes vote down vote up
/** Converts an RGB value to YCrCb. */
public static RGB toYCbCr(double r, double g, double b) {
	int y = limitRound(0.299 * r + 0.587 * g + 0.114 * b);
	int cb = limitRound(128 - 0.168736 * r - 0.331264 * g + 0.5 * b);
	int cr = limitRound(128 + 0.5 * r - 0.418688 * g - 0.081312 * b);
	return new RGB(y, cb, cr);
}
 
Example 30
Source Project: RepDev   Source File: SyntaxHighlighter.java    License: GNU General Public License v3.0 5 votes vote down vote up
public EStyle(RGB frgb, RGB bgrgb, int style) {
	if (frgb != null)
		fcolor = new Color(Display.getCurrent(), frgb);
	if (bgrgb != null)
		bgcolor = new Color(Display.getCurrent(), bgrgb);
	this.style = style;
}