Java 类org.eclipse.jface.text.IPainter 实例源码
项目:tm4e
文件:TMPresentationReconciler.java
/**
* 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) {
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) {
List<IPainter> painters = ClassHelper.getFieldValue(paintManager, "fPainters", PaintManager.class);
if (painters != null) {
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) {
e.printStackTrace();
}
}
}
项目:bts
文件:EgyTextEditorPart.java
/**
* Sets the sentence translation.
*
* @param sentence the new sentence translation
*/
private AnnotationModelEvent setSentenceTranslation(BTSSenctence sentence, boolean postSelection) {
// TODO: allow for multiple sentence translations to be highlighted simultaneously
// i.e. create method setSentenceTranslation(List<BTSSentence>) which gets passed
// a Collection containing all sentences detected within a BTSTextSelectionEvent
final AnnotationModelEvent ev = new AnnotationModelEvent(annotationModel);
if (sentence != null && !sentence.equals(selectedSentence)) {
selectedSentence = sentence;
if (selectedSentence.getTranslation() == null) {
Command command = AddCommand.create(editingDomain, selectedSentence,
BtsCorpusModelPackage.BTS_SENCTENCE__TRANSLATION,
BtsmodelFactory.eINSTANCE
.createBTSTranslations());
editingDomain.getCommandStack().execute(command);
}
sentenceTranslate_Editor.setEnabled(userMayEdit);
sentenceTranslate_Editor.load(selectedSentence.getTranslation(),
editingDomain, false);
BTSModelAnnotation am = modelAnnotationMap.get(sentence.get_id());
if (am != null)
{
if (!am.equals(highlightedSentenceAnnotation) || !am.getType().endsWith(".highlighted")) {
// highlight current translation
am.setHighlighted(true);
ev.annotationChanged(am);
// remove previous highlight
if (highlightedSentenceAnnotation != null) {
highlightedSentenceAnnotation.setHighlighted(false);
ev.annotationChanged(highlightedSentenceAnnotation);
}
highlightedSentenceAnnotation = am;
}
if (!postSelection) {
// make sure annotation is visible in text editor
Position pos = annotationModel.getPosition(am);
if (pos != null)
embeddedEditor.getViewer().revealRange(pos.getOffset(), pos.length);
// In order to limit workload, only repaint text editor (including highlight of line(s)
// containing this sentence) if method call seems to come from selection listener
// in EgyTextTranslationPart. This is indicated by postSelection being false.
// (if postSelection is true, repaint has most likely already been invoked in processSelection)
sync.asyncExec(new Runnable() {
public void run() {
// TODO this can be improved in order to reduce work load repainting large texts
if (painter == null || embeddedEditor.getViewer().getTextWidget().isDisposed()) return;
painter.modelChanged(ev);
painter.paint(IPainter.INTERNAL);
ruler.update();
ruler.relayout();
oruler.update();
embeddedEditor.getViewer().getTextWidget().redraw();
}
});
return null;
}
}
if (postSelection)
selectionService.setSelection(sentence);
return ev;
}
return null;
}
项目:bts
文件:EgyTextEditorPart.java
@Inject
@Optional
void eventReceivedRelatedObjectsFilterSet(
@UIEventTopic("event_anno_filters/*") final BTSRelatingObjectsFilterEvent event) {
if (event != null) {
Map<String, Boolean> filters = event.getFilters();
//painter.removeAllAnnotationTypes();
for (Entry<String, Boolean> e : filters.entrySet()) {
String typeId = e.getKey();
String strategyId = null;
if (getAnnotationStrategySet().contains(typeId))
{
strategyId = typeId;
}
else{
if (typeId.startsWith(BTSConstants.COMMENT))
{
strategyId = BTSConstants.COMMENT;
}else if (typeId.startsWith(CorpusUtils.SUBTEXT_TYPE))
{
strategyId = CorpusUtils.SUBTEXT_TYPE;
}else if (typeId.startsWith(BTSConstants.ANNOTATION + "." +CorpusUtils.ANNOTATION_RUBRUM_TYPE))
{
strategyId = BTSConstants.ANNOTATION + "." +CorpusUtils.ANNOTATION_RUBRUM_TYPE;
}else if (typeId.startsWith(BTSConstants.ANNOTATION))
{
strategyId = BTSConstants.ANNOTATION;
}
else
{
strategyId = BTSConstants.ANNOTATION;
}
}
// update editor painter and ruler annotation types
for (String suffix : ANNO_TYPES_SUFFIXES) {
if (e.getValue()) {
painter.addAnnotationType(typeId+suffix,
strategyId+suffix);
painter.setAnnotationTypeColor(typeId +suffix, getBackgroundColorTypePath(strategyId));
oruler.addAnnotationType(typeId+suffix);
} else {
painter.removeAnnotationType(typeId+suffix);
oruler.removeAnnotationType(typeId+suffix);
}
}
painter.paint(IPainter.INTERNAL);
}
}
}
项目:Pydev
文件:ScriptConsoleViewerWrapper.java
public void addPainter(IPainter painter) {
viewer.addPainter(painter);
}
项目:Pydev
文件:ScriptConsoleViewerWrapper.java
public void removePainter(IPainter painter) {
viewer.removePainter(painter);
}