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

The following examples show how to use org.eclipse.swt.custom.StyledText#getLineHeight() . 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: RenameRefactoringPopup.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: InputPageUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a signature preview viewer in a parent composite with a 1-column GridLayout.
 * 
 * @param parent the parent 
 * @return the preview viewer
 * @since 3.9
 */
public static JavaSourceViewer createSignaturePreview(Composite parent) {
	IPreferenceStore store= JavaPlugin.getDefault().getCombinedPreferenceStore();
	JavaSourceViewer signaturePreview= new JavaSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.WRAP, store);
	signaturePreview.configure(new JavaSourceViewerConfiguration(JavaPlugin.getDefault().getJavaTextTools().getColorManager(), store, null, null));
	StyledText textWidget= signaturePreview.getTextWidget();
	textWidget.setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
	textWidget.setAlwaysShowScrollBars(false);
	signaturePreview.adaptBackgroundColor(parent);
	signaturePreview.setDocument(new Document());
	signaturePreview.setEditable(false);

	GridData gdata= new GridData(GridData.FILL_BOTH);
	gdata.widthHint= new PixelConverter(textWidget).convertWidthInCharsToPixels(50);
	gdata.heightHint= textWidget.getLineHeight() * 2;
	textWidget.setLayoutData(gdata);
	
	return signaturePreview;
}
 
Example 3
Source File: JDTQuickMenuCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Point computeWordStart() {
	ITextSelection selection= (ITextSelection)fEditor.getSelectionProvider().getSelection();
	IRegion textRegion= JavaWordFinder.findWord(fEditor.getViewer().getDocument(), selection.getOffset());
	if (textRegion == null)
		return null;

	IRegion widgetRegion= modelRange2WidgetRange(textRegion);
	if (widgetRegion == null)
		return null;

	int start= widgetRegion.getOffset();

	StyledText styledText= fEditor.getViewer().getTextWidget();
	Point result= styledText.getLocationAtOffset(start);
	result.y+= styledText.getLineHeight(start);

	if (!styledText.getClientArea().contains(result))
		return null;
	return result;
}
 
Example 4
Source File: StyledTextContentAdapter.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public Rectangle getInsertionBounds(Control control) {
	StyledText text = (StyledText) control;
	Point caretOrigin = text.getCaret().getLocation();
	
	return new Rectangle(caretOrigin.x + text.getClientArea().x,
			caretOrigin.y + text.getClientArea().y + 3, 1,
			text.getLineHeight());
}
 
Example 5
Source File: JavaPreview.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getHeightOfAllLines(StyledText styledText) {
	int height= 0;
	int lineCount= styledText.getLineCount();
	for (int i= 0; i < lineCount; i++)
		height= height + styledText.getLineHeight(styledText.getOffsetAtLine(i));
	return height;
}
 
Example 6
Source File: RecenterHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Recenter the widget:
 *    - cycle through center/top/bottom
 *    - with ^U arg, position arg lines from top
 *    - with ^U, center regardless of cycle
 *    - only scroll within the current view area 
 * 
 * @param widget our StyledText widget
 * @param withArg true if called with some variant of ^U
 * @return the next recenter state in sequence
 */
private CS recenter(StyledText widget, boolean withArg) {
	int topLine = -1;
	int caretLine= widget.getLineAtOffset(widget.getCaretOffset());
	int areaLines = (widget.getClientArea().height / widget.getLineHeight()); 
	if (withArg) {
		int newLine = caretLine - argLines;
		// ensure we never scroll out of the currently displayed area
		if (argLines < 0) {
			topLine = Math.min(newLine - areaLines, caretLine);
		} else {
			topLine = Math.max(caretLine - areaLines, newLine);
		}
	} else {
		switch (this) {
			case B:
				// ensure we never scroll out of the currently displayed area
				topLine = Math.min((caretLine - areaLines + (scrollMargin > 0 ? scrollMargin : 1)), caretLine);
				break;
			case T:
				// ensure we never scroll out of the currently displayed area
				topLine =  Math.max((caretLine - scrollMargin), (caretLine - areaLines + 1));
				break;
			case C:
			default:
				topLine =  caretLine - (areaLines / 2); 
		}
	}
	widget.setTopIndex(Math.max(0, topLine));
	return next;
}
 
Example 7
Source File: XdsConsoleViewer.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public void setCurrentLinkRange(int offset, int length, boolean scrollToMakeItVisible) {
    try {
        boolean redraw = false;

        StyledText st = getTextWidget();
        
        if (markedOffset != offset || markedLength != length) {
            markedOffset = offset;
            markedLength = length;
            redraw = true;
        }
        
        if (scrollToMakeItVisible) {
            redraw = true;
            
            int topIdx = st.getTopIndex();
            int btmIdx = topIdx + st.getSize().y / st.getLineHeight();

            int mTop = st.getLineAtOffset(offset);
            int mBtm = st.getLineAtOffset(offset + length);

            int newTop = topIdx;
            if (mTop < topIdx) {
                newTop = mTop;
            } else if (mBtm > btmIdx) {
                newTop = topIdx + (mBtm - btmIdx);
                if (newTop < mTop) {
                    newTop = mTop;
                }
            }
            
            if (newTop != topIdx) {
                st.setTopIndex(newTop);
            }
        }

        if (redraw) {
            st.redraw();
        }
    } catch (Exception e) {}

}
 
Example 8
Source File: LineBackgroundPainter.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private Rectangle getLineRectangle(Position position)
{
	if (position == null)
	{
		return null;
	}

	// if the position that is about to be drawn was deleted then we can't
	if (position.isDeleted())
	{
		return null;
	}

	int widgetOffset = 0;
	if (fViewer instanceof ITextViewerExtension5)
	{

		ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
		widgetOffset = extension.modelOffset2WidgetOffset(position.getOffset());
		if (widgetOffset == -1)
		{
			return null;
		}
	}
	else
	{

		IRegion visible = fViewer.getVisibleRegion();
		widgetOffset = position.getOffset() - visible.getOffset();
		if (widgetOffset < 0 || visible.getLength() < widgetOffset)
		{
			return null;
		}
	}

	StyledText textWidget = fViewer.getTextWidget();
	// check for https://bugs.eclipse.org/bugs/show_bug.cgi?id=64898
	// this is a guard against the symptoms but not the actual solution
	if (0 <= widgetOffset && widgetOffset <= textWidget.getCharCount())
	{
		Point upperLeft = textWidget.getLocationAtOffset(widgetOffset);
		int width = textWidget.getClientArea().width + textWidget.getHorizontalPixel();
		int height = textWidget.getLineHeight(widgetOffset);
		return new Rectangle(0, upperLeft.y, width, height);
	}

	return null;
}