Project

General

Profile

Download (3.04 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.ui.forms;
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
/**
16
 * <p>BrowserElement class.</p>
17
 *
18
 * @author n.hoffmann
19
 * @version $Id: $
20
 */
21
public class BrowserElement extends AbstractCdmFormElement implements ControlListener{
22

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

    
45
		layoutBrowser();
46
		
47
		showBrowser();
48
		browser.addControlListener(this);
49
		
50
		this.setImageUri(imageUri);
51
	}
52

    
53
	/**
54
	 * 
55
	 */
56
	private void layoutBrowser() {
57
		TableWrapData layoutData = CdmFormFactory.FILL();
58
		layoutData.heightHint = 1000;
59
		
60
		browser.setLayoutData(layoutData);
61
	}
62

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

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

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

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

    
130
	/** {@inheritDoc} */
131
	public void setSelected(boolean selected) {
132
		
133
	}
134

    
135
}
(5-5/35)