Project

General

Profile

Download (3.06 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.ui.element;
5

    
6
import java.net.URI;
7

    
8
import org.eclipse.swt.SWT;
9
import org.eclipse.swt.browser.Browser;
10
import org.eclipse.swt.events.ControlEvent;
11
import org.eclipse.swt.events.ControlListener;
12
import org.eclipse.swt.graphics.Rectangle;
13
import org.eclipse.ui.forms.widgets.TableWrapData;
14

    
15
import eu.etaxonomy.taxeditor.ui.section.campanula.compatibility.ICdmFormElement;
16

    
17

    
18
/**
19
 * <p>BrowserElement class.</p>
20
 *
21
 * @author n.hoffmann
22
 * @version $Id: $
23
 */
24
public class BrowserElement extends AbstractCdmFormElement implements ControlListener{
25

    
26
	private Browser browser;
27
	
28
	private String imageUriString;
29
	
30
	/**
31
	 * <p>Constructor for BrowserElement.</p>
32
	 *
33
	 * @param style a int.
34
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
35
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
36
	 * @param imageUri a {@link java.net.URI} object.
37
	 */
38
	protected BrowserElement(CdmFormFactory formFactory, ICdmFormElement parentElement, URI imageUri, int style) {
39
		super(formFactory, parentElement);
40
		formFactory.createLabel(getLayoutComposite(), "");
41
		
42
		browser = new Browser(getLayoutComposite(), SWT.NONE);
43
		addControl(browser);
44
		
45
		getLayoutComposite().setLayoutData(LayoutConstants.FILL());
46
		
47

    
48
		layoutBrowser();
49
		
50
		showBrowser();
51
		browser.addControlListener(this);
52
		
53
		this.setImageUri(imageUri);
54
	}
55

    
56
	/**
57
	 * 
58
	 */
59
	private void layoutBrowser() {
60
		TableWrapData layoutData = LayoutConstants.FILL();
61
		layoutData.heightHint = 1000;
62
		
63
		browser.setLayoutData(layoutData);
64
	}
65

    
66
	/**
67
	 * 
68
	 */
69
	private void showBrowser() {
70
		
71
		String html = "";
72
		html = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>";
73
		html += "<img width=\"" + calculateWidth() + "\" src=\"" + getImageUriString() + "\" />";
74
		html += "</BODY></HTML>";
75
		
76
		browser.setText(html);
77
	}
78
	
79
	/**
80
	 * <p>calculateWidth</p>
81
	 *
82
	 * @return a int.
83
	 */
84
	public int calculateWidth() {	
85
		Rectangle boundaries = browser.getBounds();
86
		return boundaries.width;
87
	}
88
	
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
91
	 */
92
	/** {@inheritDoc} */
93
	public void controlMoved(ControlEvent e) {
94
		showBrowser();
95
	}
96

    
97
	/* (non-Javadoc)
98
	 * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
99
	 */
100
	/** {@inheritDoc} */
101
	public void controlResized(ControlEvent e) {
102
		showBrowser();
103
	}
104

    
105
	/**
106
	 * <p>setImageUri</p>
107
	 *
108
	 * @param imageUri the imageUri to set
109
	 */
110
	public void setImageUri(URI imageUri) {
111
		setImageUriString(imageUri != null ? imageUri.toString() : "");
112
	}
113
	
114
	/**
115
	 * <p>Setter for the field <code>imageUriString</code>.</p>
116
	 *
117
	 * @param imageUriString a {@link java.lang.String} object.
118
	 */
119
	public void setImageUriString(String imageUriString){
120
		this.imageUriString = imageUriString;
121
		showBrowser();
122
	}
123

    
124
	/**
125
	 * <p>Getter for the field <code>imageUriString</code>.</p>
126
	 *
127
	 * @return the imageUri
128
	 */
129
	public String getImageUriString() {
130
		return imageUriString;
131
	}
132

    
133
}
(5-5/35)