use of org.eclipse.jface.text.ITextViewerExtension5 in project webtools.sourceediting by eclipse.
the class HighlighterHyperlinkPresenter method highlightRegion.
private void highlightRegion(IRegion region) {
if (region.equals(fActiveRegion))
return;
repairRepresentation();
StyledText text = fTextViewer.getTextWidget();
if (text == null || text.isDisposed())
return;
// Underline
int offset = 0;
int length = 0;
if (fTextViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
IRegion widgetRange = extension.modelRange2WidgetRange(region);
if (widgetRange == null)
return;
offset = widgetRange.getOffset();
length = widgetRange.getLength();
} else {
offset = region.getOffset() - fTextViewer.getVisibleRegion().getOffset();
length = region.getLength();
}
// needs to clean background due to StructuredTextEditor's highlighter
text.redrawRange(offset, length, true);
// Invalidate region ==> apply text presentation
fActiveRegion = region;
if (fTextViewer instanceof ITextViewerExtension2)
((ITextViewerExtension2) fTextViewer).invalidateTextPresentation(region.getOffset(), region.getLength());
else
fTextViewer.invalidateTextPresentation();
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project tdq-studio-se by Talend.
the class MouseClickListener method highlightRegion.
private void highlightRegion(ISourceViewer viewer, IRegion region) {
if (region.equals(fActiveRegion))
return;
repairRepresentation();
StyledText text = viewer.getTextWidget();
if (text == null || text.isDisposed())
return;
// highlight region
int offset = 0;
int length = 0;
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
IRegion widgetRange = extension.modelRange2WidgetRange(region);
if (widgetRange == null)
return;
offset = widgetRange.getOffset();
length = widgetRange.getLength();
} else {
offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
length = region.getLength();
}
StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
Color foregroundColor = fColor;
Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
text.setStyleRange(styleRange);
// underline
text.redrawRange(offset, length, true);
fActiveRegion = region;
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project tdq-studio-se by Talend.
the class MouseClickListener method getCurrentTextOffset.
private int getCurrentTextOffset(ISourceViewer viewer) {
try {
StyledText text = viewer.getTextWidget();
if (text == null || text.isDisposed())
return -1;
Display display = text.getDisplay();
Point absolutePosition = display.getCursorLocation();
Point relativePosition = text.toControl(absolutePosition);
int widgetOffset = text.getOffsetAtLocation(relativePosition);
if (viewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
return extension.widgetOffset2ModelOffset(widgetOffset);
} else {
return widgetOffset + viewer.getVisibleRegion().getOffset();
}
} catch (IllegalArgumentException e) {
return -1;
}
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project tdq-studio-se by Talend.
the class MouseClickListener method paintControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
*/
public void paintControl(PaintEvent event) {
if (fActiveRegion == null)
return;
if (sourceViewer == null)
return;
StyledText text = sourceViewer.getTextWidget();
if (text == null || text.isDisposed())
return;
int offset = 0;
int length = 0;
if (sourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
if (widgetRange == null)
return;
offset = widgetRange.getOffset();
length = widgetRange.getLength();
} else {
IRegion region = sourceViewer.getVisibleRegion();
if (!includes(region, fActiveRegion))
return;
offset = fActiveRegion.getOffset() - region.getOffset();
length = fActiveRegion.getLength();
}
// support for bidi
Point minLocation = getMinimumLocation(text, offset, length);
Point maxLocation = getMaximumLocation(text, offset, length);
int x1 = minLocation.x;
int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
int y = minLocation.y + text.getLineHeight() - 1;
GC gc = event.gc;
if (fColor != null && !fColor.isDisposed())
gc.setForeground(fColor);
gc.drawLine(x1, y, x2, y);
}
use of org.eclipse.jface.text.ITextViewerExtension5 in project xtext-eclipse by eclipse.
the class RenameRefactoringPopup method computePopupLocation.
protected Point computePopupLocation() {
if (popup == null || popup.isDisposed())
return null;
LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition();
if (position == null)
return null;
ISourceViewer viewer = editor.getInternalSourceViewer();
ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer;
int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset);
StyledText textWidget = viewer.getTextWidget();
Point pos = textWidget.getLocationAtOffset(widgetOffset);
Point pSize = getExtent();
pSize.y += HAH + 1;
pos.x -= HAO;
pos.y += textWidget.getLineHeight(widgetOffset);
Point dPos = textWidget.toDisplay(pos);
Rectangle displayBounds = textWidget.getDisplay().getClientArea();
Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize);
Geometry.moveInside(dPopupRect, displayBounds);
return new Point(dPopupRect.x, dPopupRect.y);
}
Aggregations