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

The following examples show how to use org.eclipse.swt.custom.StyledText#getBackground() . 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: ThemeableEditorExtension.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void overrideRulerColors()
{
	IThemeableEditor editor = this.fEditor.get();

	// default to bg color of surrounding composite
	Color bg = null;
	// Use editor background color if we can
	if (editor != null)
	{
		ISourceViewer sv = editor.getISourceViewer();
		if (sv != null)
		{
			StyledText text = sv.getTextWidget();
			if (text != null)
			{
				bg = text.getBackground();
				// copy the color because for some reason it gets disposed
				bg = ThemePlugin.getDefault().getColorManager().getColor(bg.getRGB());
			}
		}

		// force the colors for all the ruler columns (specifically so we force the folding bg to match).
		CompositeRuler ruler = (CompositeRuler) editor.getIVerticalRuler();
		Iterator<IVerticalRulerColumn> iter = ruler.getDecoratorIterator();
		while (iter.hasNext())
		{
			IVerticalRulerColumn column = iter.next();
			column.getControl().setBackground(bg);
		}
	}

	if (fLineColumn != null)
	{
		fLineColumn.setBackground(bg);
	}
}
 
Example 3
Source File: LineBackgroundPainter.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void drawCurrentLine(LineBackgroundEvent event, final IRegion lineRegion)
{
	final StyledText textWidget = fViewer.getTextWidget();
	final int offset = event.lineOffset;
	final RGBa lineHighlight = getCurrentTheme().getLineHighlight();
	event.lineBackground = getColorManager().getColor(lineHighlight.toRGB());

	// In this case, we should be overriding the bg of the style ranges for the line too!
	if (textWidget.isDisposed())
	{
		return;
	}
	// FIXME Only change bg colors of visible ranges!
	int replaceLength = 160;
	if (lineRegion != null)
	{
		replaceLength = Math.min(replaceLength, lineRegion.getLength());
	}

	// be safe about offsets
	int charCount = textWidget.getCharCount();
	if (offset + replaceLength > charCount)
	{
		replaceLength = charCount - offset;
		if (replaceLength < 0)
		{
			// Just playing safe here
			replaceLength = 0;
		}
	}
	final StyleRange[] ranges = textWidget.getStyleRanges(offset, replaceLength, true);
	if (ranges == null || ranges.length == 0)
	{
		return;
	}
	Color background = textWidget.getBackground();
	final int[] positions = new int[ranges.length << 1];
	int x = 0;
	boolean apply = false;
	for (StyleRange range : ranges)
	{
		if (range.background != null)
		{
			if (!range.background.equals(background))
			{
				positions[x] = range.start;
				positions[x + 1] = range.length;
				x += 2;
				continue;
			}
			apply = true;
		}
		range.background = null;
		positions[x] = range.start;
		positions[x + 1] = range.length;
		x += 2;
	}

	if (apply)
	{
		textWidget.setStyleRanges(offset, replaceLength, positions, ranges);
	}
}
 
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;
}
 
Example 5
Source File: ScreenFlasher.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
private void getColors(StyledText widget) {
	background = widget.getBackground();
	if (background != null) {
		flash = Flasher.invertColor(background);
	}
}