/******************************************************************************* * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.snippets; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.TextLayout; import org.eclipse.swt.widgets.*; public class OffsetTest { public static void main(String[] args) { Display display = new Display(); final TextLayout layout = new TextLayout(display); layout.setText("My text"); layout.setWidth(200); layout.setSegments(new int[] { layout.getText().length() }); layout.setSegmentsChars(new char[] { '*' }); int[] trailing = new int[1]; int length = layout.getText().length(); //Point point = layout.getLocation(length - 1, true); System.out.println("Text\t\t= " + layout.getText()); System.out.println("Text length\t= " + length); System.out.println("Expected offset\t= " + (length - 1) + "; trailing = 1"); //System.out.println("Actual offset\t= " + layout.getOffset(point, trailing) // + "; trailing = " + trailing[0]); System.out.println("Actual offset\t= " + layout.getOffset(new Point( layout.getBounds().width - layout.getBounds().x, 0), trailing) + "; trailing = " + trailing[0]); layout.dispose(); display.dispose(); } }