Java Code Examples for org.eclipse.swt.graphics.TextLayout#getLocation()

The following examples show how to use org.eclipse.swt.graphics.TextLayout#getLocation() . 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: XGridCellRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
protected void drawInnerTag(GC gc, TextLayout layout) {
	String displayStr = layout.getText();
	List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans();
	Rectangle bounds = getBounds();
	for (InnerTagBean innerTagBean : innerTagBeans) {
		String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean));
		int start = displayStr.indexOf(placeHolder);
		if (start == -1) {
			continue;
		}			
		if (gc != null) {
			Point p = layout.getLocation(start, false);
			int x = bounds.x + p.x + leftMargin;
			x += SEGMENT_LINE_SPACING;

			Point tagSize = tagRender.calculateTagSize(innerTagBean);
			int lineIdx = layout.getLineIndex(start);
			Rectangle r = layout.getLineBounds(lineIdx);
			int y = bounds.y + p.y + topMargin + r.height / 2 - tagSize.y /2;				
			tagRender.draw(gc, innerTagBean, x, y - layout.getAscent());
		}
	}
}
 
Example 2
Source File: GridCopyEnable.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
void handleVerticalScroll(Event event) {
	GridVisibleRange visibleR = gridTable.getVisibleRange();
	GridItem[] items = visibleR.getItems();
	boolean itemFlg = false;
	for (GridItem item : items) {
		if (focusItem == item) {
			itemFlg = true;
		}
	}
	boolean columnFlg = false;
	GridColumn[] columns = visibleR.getColumns();
	if (columns.length - 1 >= focusColIndex) {
		columnFlg = true;
	}
	if (!itemFlg || !columnFlg) {
		defaultCaret.setVisible(false);
		return;
	}
	defaultCaret.setVisible(true);

	GridColumn col = gridTable.getColumn(focusColIndex);
	GridCellRenderer gcr = col.getCellRenderer();
	int colIndex = gcr.getColumn();
	if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
		return;
	}
	XGridCellRenderer cellRender = (XGridCellRenderer) gcr;

	Rectangle cellBounds = focusItem.getBounds(colIndex);
	GC gc = new GC(Display.getDefault());
	TextLayout layout = null;
	try {
		layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
		if (layout == null) {
			gc.dispose();
			return;
		}
		Point point = layout.getLocation(caretOffset, false);
		coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
		coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
		defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
	} finally {
		if (layout != null) {
			layout.dispose();
		}
		if (gc != null) {
			gc.dispose();
		}
	}
}
 
Example 3
Source File: GridCopyEnable.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
void handleVerticalScroll(Event event) {
	GridVisibleRange visibleR = gridTable.getVisibleRange();
	GridItem[] items = visibleR.getItems();
	boolean itemFlg = false;
	for (GridItem item : items) {
		if (focusItem == item) {
			itemFlg = true;
		}
	}
	boolean columnFlg = false;
	GridColumn[] columns = visibleR.getColumns();
	if (columns.length - 1 >= focusColIndex) {
		columnFlg = true;
	}
	if (!itemFlg || !columnFlg) {
		defaultCaret.setVisible(false);
		return;
	}
	defaultCaret.setVisible(true);

	GridColumn col = gridTable.getColumn(focusColIndex);
	GridCellRenderer gcr = col.getCellRenderer();
	int colIndex = gcr.getColumn();
	if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
		return;
	}
	XGridCellRenderer cellRender = (XGridCellRenderer) gcr;

	Rectangle cellBounds = focusItem.getBounds(colIndex);
	GC gc = new GC(Display.getDefault());
	TextLayout layout = null;
	try {
		layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
		if (layout == null) {
			gc.dispose();
			return;
		}
		Point point = layout.getLocation(caretOffset, false);
		coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
		coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
		defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
	} finally {
		if (layout != null) {
			layout.dispose();
		}
		if (gc != null) {
			gc.dispose();
		}
	}
}