Project

General

Profile

Download (2.33 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.ui.element;
11

    
12
import org.eclipse.jface.resource.FontDescriptor;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.graphics.Color;
15
import org.eclipse.swt.graphics.Font;
16
import org.eclipse.swt.widgets.Label;
17
import org.eclipse.ui.forms.widgets.TableWrapData;
18

    
19
import eu.etaxonomy.cdm.common.CdmUtils;
20

    
21
/**
22
 * <p>LabelElement class.</p>
23
 *
24
 * @author n.hoffmann
25
 * @created Jun 1, 2010
26
 * @version 1.0
27
 */
28
public class LabelElement extends AbstractCdmFormElement implements ISelectable{
29

    
30
	private Label label;
31

    
32
	/**
33
	 * <p>Constructor for LabelElement.</p>
34
	 *
35
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
36
	 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
37
	 * @param text a {@link java.lang.String} object.
38
	 */
39
	public LabelElement(CdmFormFactory formFactory, ICdmFormElement formElement, String text) {
40
		super(formFactory, formElement);
41

    
42
		label = formFactory.createLabel(getLayoutComposite(), text, SWT.WRAP);
43
		label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
44
		addControl(label);
45
	}
46

    
47
	/**
48
	 * <p>setText</p>
49
	 *
50
	 * @param text a {@link java.lang.String} object.
51
	 */
52
	public void setText(String text) {
53
	    String pattern = "(.*[^&])&([^&].*)";
54
        if(text.matches(pattern)){
55
	        text = text.replaceAll(pattern, "$1&&$2");
56
	    }
57
		label.setText(CdmUtils.Nz(text));
58
	}
59

    
60
	public void setLayout(TableWrapData layoutConstants){
61
		label.setLayoutData(layoutConstants);
62
	}
63

    
64

    
65

    
66
	public void setForeground(Color color){
67
		label.setForeground(color);
68
	}
69

    
70
	public void setVisible(boolean setVisible){
71
		label.setVisible(setVisible);
72
	}
73

    
74
	public boolean isDisposed(){
75
	    return label.isDisposed();
76
	}
77

    
78
	public void setBold(){
79
	    FontDescriptor boldDescriptor = FontDescriptor.createFrom(label.getFont()).setStyle(SWT.BOLD);
80
	    Font boldFont = boldDescriptor.createFont(label.getDisplay());
81
	    label.setFont( boldFont );
82
	}
83

    
84

    
85
    @Override
86
    public void setSelected(boolean selected) {
87
        this.label.setBackground(selected ? SELECTED : getPersistentBackground());
88

    
89
    }
90

    
91

    
92
}
(31-31/53)