2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.model
;
12 import org
.eclipse
.swt
.graphics
.GC
;
13 import org
.eclipse
.swt
.widgets
.Control
;
16 * <p>TextHelper class.</p>
19 * @created Mar 30, 2010
22 public class TextHelper
{
24 /** Constant <code>ELLIPSIS="..."</code> */
25 public static final String ELLIPSIS
= "...";
30 * @param textValue a {@link java.lang.String} object.
31 * @param control a {@link org.eclipse.swt.widgets.Control} object.
32 * @see org.eclipse.jface.dialogs.Dialog#shortenText(String, Control)
33 * @return a {@link java.lang.String} object.
35 public static String
shortenText(String textValue
, Control control
) {
36 if (textValue
== null) {
39 GC gc
= new GC(control
);
40 int maxWidth
= control
.getBounds().width
;
41 int maxExtent
= gc
.textExtent(textValue
).x
;
42 if (maxExtent
< maxWidth
) {
46 int length
= textValue
.length();
47 int charsToClip
= Math
.round(0.95f
*length
* (1 - ((float)maxWidth
/maxExtent
)));
49 int end
= length
- charsToClip
;
51 String s1
= textValue
.substring(0, end
);
52 String s
= s1
+ ELLIPSIS
;
53 int l
= gc
.textExtent(s
).x
;
65 public static String
deproxyClassName(Class clazz
){
66 String name
= clazz
.getSimpleName();
67 if (name
.indexOf("_$$")>-1){
68 return name
.substring(0, name
.indexOf("_$$"));