Java Code Examples for org.eclipse.swt.custom.StyledText#getForeground()

The following examples show how to use org.eclipse.swt.custom.StyledText#getForeground() . 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: MinimapOverviewRuler.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void doubleBufferPaint(GC dest) {
    if (fTextViewer != null) {
        StyledText textWidget = fTextViewer.getTextWidget();
        //Calling setBackground/setForeground leads to a repaint on some Linux variants (ubuntu 12), so
        //we must only call it if it actually changed to prevent a repaint.
        //View: https://www.brainwy.com/tracker/LiClipse/120
        Color background = textWidget.getBackground();
        if (lastBackground == null || !lastBackground.equals(background)) {
            fCanvas.setBackground(background);
            lastBackground = background;
        }

        Color foreground = textWidget.getForeground();
        if (lastForeground == null || !lastForeground.equals(foreground)) {
            fCanvas.setForeground(foreground);
            lastForeground = foreground;
        }

    }
    super.doubleBufferPaint(dest);
}
 
Example 2
Source File: TestSyntaxHighlighting.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testJSXHighlighting() throws CoreException {
	IFile file = project.getFile("test.jsx");
	file.create(new ByteArrayInputStream("var n = 4;\n".getBytes()), true, null);
	ITextEditor editor = (ITextEditor)IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file);
	StyledText widget = (StyledText) editor.getAdapter(Control.class);
	Color defaultTextColor = widget.getForeground();
	assertTrue("Missing syntax highlighting", new DisplayHelper() {
		@Override protected boolean condition() {
			return Arrays.stream(widget.getStyleRanges()).anyMatch(range -> range.foreground != null && !defaultTextColor.equals(range.foreground));
		}
	}.waitForCondition(widget.getDisplay(), 2000));
}
 
Example 3
Source File: PyAbstractIndentGuidePreferencesProvider.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Color getColor(StyledText styledText) {
    if (useEditorForegroundColor) {
        return styledText.getForeground();
    }
    ColorCache colorCache = PydevPlugin.getColorCache();
    return colorCache.getColor(PyDevEditorPreferences.VERTICAL_INDENT_COLOR);
}
 
Example 4
Source File: JavaSourceViewer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void configure(SourceViewerConfiguration configuration) {

	/*
	 * Prevent access to colors disposed in unconfigure(), see:
	 *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641
	 *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177
	 */
	StyledText textWidget= getTextWidget();
	if (textWidget != null && !textWidget.isDisposed()) {
		Color foregroundColor= textWidget.getForeground();
		if (foregroundColor != null && foregroundColor.isDisposed())
			textWidget.setForeground(null);
		Color backgroundColor= textWidget.getBackground();
		if (backgroundColor != null && backgroundColor.isDisposed())
			textWidget.setBackground(null);
	}

	super.configure(configuration);
	if (configuration instanceof JavaSourceViewerConfiguration) {
		JavaSourceViewerConfiguration javaSVCconfiguration= (JavaSourceViewerConfiguration)configuration;
		fOutlinePresenter= javaSVCconfiguration.getOutlinePresenter(this, false);
		if (fOutlinePresenter != null)
			fOutlinePresenter.install(this);

		fStructurePresenter= javaSVCconfiguration.getOutlinePresenter(this, true);
		if (fStructurePresenter != null)
			fStructurePresenter.install(this);

		fHierarchyPresenter= javaSVCconfiguration.getHierarchyPresenter(this, true);
		if (fHierarchyPresenter != null)
			fHierarchyPresenter.install(this);

	}

	if (fPreferenceStore != null) {
		fPreferenceStore.addPropertyChangeListener(this);
		initializeViewerColors();
	}

	fIsConfigured= true;
}