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.
9 package eu
.etaxonomy
.taxeditor
.model
;
11 import org
.eclipse
.swt
.graphics
.GC
;
12 import org
.eclipse
.swt
.widgets
.Control
;
16 * @created Mar 30, 2010
18 public class TextHelper
{
20 /** Constant <code>ELLIPSIS="..."</code> */
21 public static final String ELLIPSIS
= "...";
26 * @param textValue a {@link java.lang.String} object.
27 * @param control a {@link org.eclipse.swt.widgets.Control} object.
28 * @see org.eclipse.jface.dialogs.Dialog#shortenText(String, Control)
29 * @return a {@link java.lang.String} object.
31 public static String
shortenText(String textValue
, Control control
) {
32 if (textValue
== null) {
35 GC gc
= new GC(control
);
36 int maxWidth
= control
.getBounds().width
;
37 int maxExtent
= gc
.textExtent(textValue
).x
;
38 if (maxExtent
< maxWidth
) {
42 int length
= textValue
.length();
43 int charsToClip
= Math
.round(0.95f
*length
* (1 - ((float)maxWidth
/maxExtent
)));
45 int end
= length
- charsToClip
;
47 String s1
= textValue
.substring(0, end
);
48 String s
= s1
+ ELLIPSIS
;
49 int l
= gc
.textExtent(s
).x
;
61 public static String
deproxyClassName(Class clazz
){
62 String name
= clazz
.getSimpleName();
63 if (name
.indexOf("_$$")>-1){
64 return name
.substring(0, name
.indexOf("_$$"));