51681507807b4d4fe95159b3dd2a678b6ac92f7e
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.model
;
13 import org
.eclipse
.swt
.graphics
.GC
;
14 import org
.eclipse
.swt
.widgets
.Control
;
17 * <p>TextHelper class.</p>
20 * @created Mar 30, 2010
23 public class TextHelper
{
25 /** Constant <code>ELLIPSIS="..."</code> */
26 public static final String ELLIPSIS
= "...";
31 * @param textValue a {@link java.lang.String} object.
32 * @param control a {@link org.eclipse.swt.widgets.Control} object.
33 * @see org.eclipse.jface.dialogs.Dialog#shortenText(String, Control)
34 * @return a {@link java.lang.String} object.
36 public static String
shortenText(String textValue
, Control control
) {
37 if (textValue
== null) {
40 GC gc
= new GC(control
);
41 int maxWidth
= control
.getBounds().width
;
42 int maxExtent
= gc
.textExtent(textValue
).x
;
43 if (maxExtent
< maxWidth
) {
47 int length
= textValue
.length();
48 int charsToClip
= Math
.round(0.95f
*length
* (1 - ((float)maxWidth
/maxExtent
)));
50 int end
= length
- charsToClip
;
52 String s1
= textValue
.substring(0, end
);
53 String s
= s1
+ ELLIPSIS
;
54 int l
= gc
.textExtent(s
).x
;