Java Code Examples for org.eclipse.swt.graphics.GC#getCharWidth()
The following examples show how to use
org.eclipse.swt.graphics.GC#getCharWidth() .
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: TextUtils.java From nebula with Eclipse Public License 2.0 | 6 votes |
private static String getShortStringTruncatedInTheBeginning(GC gc, String text, int width) { char[] chars = text.toCharArray(); int calcWidth = gc.stringExtent("...").x; int index = chars.length - 1; while (calcWidth < width && index >= 0) { int step = gc.getCharWidth(chars[index]); calcWidth += step; if (calcWidth >= width) { break; } index--; } if (index <= 0) { return text; } StringBuilder sb = new StringBuilder(chars.length - index + 4); sb.append("...").append(text.substring(index)); return sb.toString(); }
Example 2
Source File: TextUtils.java From nebula with Eclipse Public License 2.0 | 6 votes |
private static String getShortStringTruncatedInTheEnd(GC gc, String text, int width) { char[] chars = text.toCharArray(); int calcWidth = gc.stringExtent("...").x; int index = 0; int length = chars.length; while (calcWidth < width && index < length) { int step = gc.getCharWidth(chars[index]); calcWidth += step; if (calcWidth >= width) { break; } index++; } if (index == length - 1) { return text; } StringBuilder sb = new StringBuilder(index + 4); if (index > 4) { sb.append(text.substring(0, index - 4)); } else { sb.append(text.substring(0, 1)); } sb.append("..."); return sb.toString(); }
Example 3
Source File: TextUtils.java From nebula with Eclipse Public License 2.0 | 5 votes |
private static String getShortStringTruncatedInTheMiddle(GC gc, String text, int width) { char[] chars = text.toCharArray(); int length = chars.length; int left = 0; int right = length - 1; int calcWidth = gc.stringExtent("...").x; while (left < right) { int step = gc.getCharWidth(chars[left]); calcWidth += step; if (calcWidth >= width) { break; } left++; step = gc.getCharWidth(chars[right]); calcWidth += step; if (calcWidth >= width) { break; } right--; } if (left >= right) { return text; } StringBuilder builder = new StringBuilder(left + length - right + 4); if (left == 0 || right == length - 1) { builder.append(chars[0]).append("...").append(chars[length - 1]); } else { int leftLen = left == 1 ? left : left - 1; builder.append(chars, 0, leftLen).append("...").append(chars, right + 1, length - right - 1); } return builder.toString(); }
Example 4
Source File: TimeGraphScale.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Standard constructor * * @param parent * The parent composite object * @param colors * The color scheme to use * @param style * The style to add to the view, can be {@link SWT#TOP} or * {@link SWT#BOTTOM} * @since 3.3 */ public TimeGraphScale(Composite parent, TimeGraphColorScheme colors, int style) { super(parent, colors, SWT.NO_BACKGROUND | SWT.NO_FOCUS | SWT.DOUBLE_BUFFERED); TmfSignalManager.register(this); addMouseListener(this); addMouseMoveListener(this); TimeDraw.updateTimeZone(); addDisposeListener((e) -> { TmfSignalManager.deregister(TimeGraphScale.this); }); GC gc = new GC(parent.getDisplay()); fDigitWidth = gc.getCharWidth('0'); gc.dispose(); fAlign = (style & SWT.BOTTOM) == 0 ? SWT.TOP : SWT.BOTTOM; }