Java Code Examples for org.eclipse.jface.resource.JFaceResources#getColorRegistry()

The following examples show how to use org.eclipse.jface.resource.JFaceResources#getColorRegistry() . 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: DefaultEObjectHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion,
		XtextBrowserInformationControlInput previous) {
	String html = getHoverInfoAsHtml(element);
	if (html != null) {
		StringBuffer buffer = new StringBuffer(html);
		ColorRegistry registry = JFaceResources.getColorRegistry();
		RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
		RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
		if (fgRGB != null && bgRGB != null) {
			HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
		} else {
			HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
		}
		HTMLPrinter.addPageEpilog(buffer);
		html = buffer.toString();
		return new XtextBrowserInformationControlInput(previous, element, html, labelProvider);
	}
	return null;
}
 
Example 2
Source File: RenameRefactoringPopup.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createContent(Composite parent) {
	Display display = parent.getDisplay();
	ColorRegistry registry = JFaceResources.getColorRegistry();
	Color foreground= registry.get("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
	if (foreground == null) {
		foreground = display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
	}
	Color background= registry.get("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
	if (background == null) {
		background = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
	}
	StyledText hint = new StyledText(popup, SWT.READ_ONLY | SWT.SINGLE);
	String enterKeyName = getEnterBinding();
	String hintTemplate = "Enter new name, press {0} to refactor";
	hint.setText(Messages.format(hintTemplate, enterKeyName));
	hint.setForeground(foreground);
	hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$
	hint.setEnabled(false); // text must not be selectable
	addViewMenu(parent);
	recursiveSetBackgroundColor(parent, background);
}
 
Example 3
Source File: StylerFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void applyStyles(TextStyle textStyle) {
	ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
	if (fontDescriptor != null) {
		textStyle.font = fontDescriptor.createFont(Display.getCurrent());
	}
	if (foregroundColorName != null) {
		textStyle.foreground = colorRegistry.get(foregroundColorName);
	}
	if (backgroundColorName != null) {
		textStyle.background = colorRegistry.get(backgroundColorName);
	}
}
 
Example 4
Source File: XbaseHoverProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected XtextBrowserInformationControlInput getHoverInfo(EObject element, IRegion hoverRegion,
		XtextBrowserInformationControlInput previous) {
	//TODO remove this check when the typesystem works without a java project
	if (isValidationDisabled(element))
		return null;
	EObject objectToView = getObjectToView(element);
	if(objectToView == null || objectToView.eIsProxy())
		return null;
	String html = getHoverInfoAsHtml(element, objectToView, hoverRegion);
	if (html != null) {
		StringBuffer buffer = new StringBuffer(html);
		ColorRegistry registry = JFaceResources.getColorRegistry();
		RGB fgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
		RGB bgRGB = registry.getRGB("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
		if (fgRGB != null && bgRGB != null) {
			HTMLPrinter.insertPageProlog(buffer, 0, fgRGB, bgRGB, getStyleSheet());
		} else {
			HTMLPrinter.insertPageProlog(buffer, 0, getStyleSheet());
		}
		HTMLPrinter.addPageEpilog(buffer);
		html = buffer.toString();
		IJavaElement javaElement = null;
		if (objectToView != element && objectToView instanceof JvmIdentifiableElement) {
			javaElement = javaElementFinder.findElementFor((JvmIdentifiableElement) objectToView);
		}
		return new XbaseInformationControlInput(previous, objectToView, javaElement, html, labelProvider);
	}
	return null;
}
 
Example 5
Source File: DemoSelectableControlListViewer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static Color getRegisteredColor(String name, int r, int g, int b) {
  if (_COLOR_REGISTRY == null) {
    _COLOR_REGISTRY = JFaceResources.getColorRegistry();
  }
  if (!_COLOR_REGISTRY.hasValueFor(name)) {
    _COLOR_REGISTRY.put(name, new RGB(r, g, b));
  }
  return _COLOR_REGISTRY.get(name);
}
 
Example 6
Source File: DemoSelectableControlList.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static Color getRegisteredColor(String name, int r, int g, int b) {
  if (_COLOR_REGISTRY == null) {
    _COLOR_REGISTRY = JFaceResources.getColorRegistry();
  }
  if (!_COLOR_REGISTRY.hasValueFor(name)) {
    _COLOR_REGISTRY.put(name, new RGB(r, g, b));
  }
  return _COLOR_REGISTRY.get(name);
}
 
Example 7
Source File: SWTUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void run()
{
	ColorRegistry cm = JFaceResources.getColorRegistry();
	RGB errorRGB = new RGB(255, 255, 180);
	cm.put("error", errorRGB); //$NON-NLS-1$
	backgroundErrorColor = cm.get("error"); //$NON-NLS-1$
}
 
Example 8
Source File: SyntaxHighlighter.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
protected void initialize(String[] keywords) {
    ColorRegistry registry = JFaceResources.getColorRegistry();

    IToken keyword = new Token(new TextAttribute(registry.get(KEYWORD_COLOR), null, SWT.BOLD));
    IToken string = new Token(new TextAttribute(registry.get(STRING_COLOR)));
    IToken number = new Token(new TextAttribute(registry.get(NUMBER_COLOR)));
    IToken annotation = new Token(new TextAttribute(registry.get(ANNOTATION_COLOR)));
    IToken defaultToken = new Token(new TextAttribute(registry.get(DEFAULT_COLOR)));

    List<IRule> rules = new ArrayList<IRule>();

    // strings
    rules.add(new SingleLineRule("\"", "\"", string, '\\'));

    // annotations
    rules.add(new MultiLineRule("[", "]", annotation));

    // numbers
    rules.add(new NumberRule(number));

    // keywords and normal (default) text
    WordRule wordRule = new WordRule(new WordDetector(), defaultToken);
    for (int i = 0; i < keywords.length; i++) {
        wordRule.addWord(keywords[i], keyword);
    }
    rules.add(wordRule);

    setRules(rules.toArray(new IRule[rules.size()]));
}