org.eclipse.jface.text.IPainter Java Examples

The following examples show how to use org.eclipse.jface.text.IPainter. 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: AnnotationEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronizes all annotations with the eclipse annotation painter.
 */
public void syncAnnotationTypes() {

  mPainter.removeAllAnnotationTypes();
  getSourceViewer().getTextWidget().setLineSpacing(0);
  
  for (Type displayType : mShowAnnotationsMenu.getSelectedTypes()) {
    showAnnotationType(displayType, true);
  }

  if (!mShowAnnotationsMenu.getSelectedTypes().contains(getAnnotationMode())) {
    showAnnotationType(getAnnotationMode(), true);
  }

  mPainter.paint(IPainter.CONFIGURATION);
}
 
Example #2
Source File: TMPresentationReconciler.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initialize foreground, background color, current line highlight from the
 * current theme if needed.
 *
 */
private void applyThemeEditorIfNeeded() {
	if (!initializeViewerColors) {
		StyledText styledText = viewer.getTextWidget();
		((ITheme) tokenProvider).initializeViewerColors(styledText);
		initializeViewerColors = true;
	}
	if (updateTextDecorations) {
		return;
	}
	try {
		// Ugly code to update "current line highlight" :
		// - get the PaintManager from the ITextViewer with reflection.
		// - get the list of IPainter of PaintManager with reflection
		// - loop for IPainter to retrieve CursorLinePainter which manages "current line
		// highlight".
		PaintManager paintManager = ClassHelper.getFieldValue(viewer, "fPaintManager", TextViewer.class);
		if (paintManager == null) {
			return;
		}
		List<IPainter> painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class);
		if (painters == null) {
			return;
		}
		for (IPainter painter : painters) {
			if (painter instanceof CursorLinePainter) {
				// Update current line highlight
				Color background = tokenProvider.getEditorCurrentLineHighlight();
				if (background != null) {
					((CursorLinePainter) painter).setHighlightColor(background);
				}
				updateTextDecorations = true;
			}
		}
	} catch (Exception e) {
		TMUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TMUIPlugin.PLUGIN_ID, e.getMessage(), e));
	}
}
 
Example #3
Source File: IndentGuidesModel.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the given document as the indents' model input and updates
 * the model accordingly.
 * 
 * @param document the models's new input document, <code>null</code> if none
 * @param painter the painter to be notified about model changes, <code>null</code> if none
 */
public void applyToDocument(IDocument document, IPainter painter, StyledText widget) {
    deactivate();
    textWidget       = widget;
    documentPainter  = painter;
    listenedDocument = document;
    listenedDocument.addDocumentListener(documentListener);
    requestUpdate();
}
 
Example #4
Source File: PairedBracketsPainter.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void paint(int reason) {

    IDocument document= fSourceViewer.getDocument();
    if (document == null) {
        deactivate(false);
        return;
    }

    Point selection= fSourceViewer.getSelectedRange();
    if (selection.y > 0) {
        deactivate(true);
        return;
    }

    IRegion pair= fMatcher.match(document, selection.x);
    if (pair == null) {
        deactivate(true);
        return;
    }

    if (fIsActive) {

        if (IPainter.CONFIGURATION == reason) {

            // redraw current highlighting
            handleDrawRequest(null);

        } else if (pair.getOffset() != fPairPosition.getOffset() ||
                pair.getLength() != fPairPosition.getLength() ||
                fMatcher.getAnchor() != fAnchor || fMatcher.getMatchFlags() != fMatchFlags) 
        {

            // otherwise only do something if position is different

            // remove old highlighting
            handleDrawRequest(null);
            // update position
            updatePos(pair);
            // apply new highlighting
            handleDrawRequest(null);

        }
    } else {
        fIsActive = true;
        updatePos(pair);
        fTextWidget.addPaintListener(this);
        fPaintPositionManager.managePosition(fPairPosition);
        handleDrawRequest(null);
    }
}
 
Example #5
Source File: IndentGuidesModel.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Schedules the update of indent guides model to be run. The job is added to a 
 * queue of waiting jobs, and will be run when it arrives at the beginning 
 * of the queue.
 */    
protected void requestUpdate() {
    Job job = new Job(Messages.UpdateIndentGuides) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IDocument document = listenedDocument;
            if (document != null) {
                try {
                    final int[] tabSizeNah = new int[1];
                    tabSizeNah[0] = -1;
                    Display.getDefault().syncExec(new Runnable() {
                        @Override
                        public void run() {
                        	if (!textWidget.isDisposed()){
                        		tabSizeNah[0] = textWidget.getTabs(); //#^(@!! gui thread expected
                        	}
                        }
                    });
                    if (tabSizeNah[0] == -1) { // Widget is disposed
                    	return Status.OK_STATUS;
                    }
                    CharSequence chars = document.get();
                    assumeIndents(IndentsParser.buildDescriptors(chars, tabSizeNah[0], eolPrefix));
                } catch (Exception e) {
                    LogHelper.logError(e);
                }
                
                if (documentPainter != null) {
                    Display.getDefault().asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            IPainter painter = documentPainter; 
                            if (painter != null) 
                                painter.paint(IPainter.CONFIGURATION);
                        }
                    });
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}
 
Example #6
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void addPainter(IPainter painter) {
    viewer.addPainter(painter);
}
 
Example #7
Source File: ScriptConsoleViewerWrapper.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void removePainter(IPainter painter) {
    viewer.removePainter(painter);
}