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
|
|
16
|
|
17
|
/**
|
18
|
* <p>BrowserElement class.</p>
|
19
|
*
|
20
|
* @author n.hoffmann
|
21
|
* @version $Id: $
|
22
|
*/
|
23
|
public class BrowserElement extends AbstractCdmFormElement implements ControlListener{
|
24
|
|
25
|
private Browser browser;
|
26
|
|
27
|
private String imageUriString;
|
28
|
|
29
|
/**
|
30
|
* <p>Constructor for BrowserElement.</p>
|
31
|
*
|
32
|
* @param style a int.
|
33
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
34
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
35
|
* @param imageUri a {@link java.net.URI} object.
|
36
|
*/
|
37
|
protected BrowserElement(CdmFormFactory formFactory, ICdmFormElement parentElement, URI imageUri, int style) {
|
38
|
super(formFactory, parentElement);
|
39
|
formFactory.createLabel(getLayoutComposite(), "");
|
40
|
|
41
|
browser = new Browser(getLayoutComposite(), SWT.NONE);
|
42
|
addControl(browser);
|
43
|
|
44
|
getLayoutComposite().setLayoutData(LayoutConstants.FILL());
|
45
|
|
46
|
|
47
|
layoutBrowser();
|
48
|
|
49
|
showBrowser();
|
50
|
browser.addControlListener(this);
|
51
|
|
52
|
this.setImageUri(imageUri);
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
*
|
57
|
*/
|
58
|
private void layoutBrowser() {
|
59
|
TableWrapData layoutData = LayoutConstants.FILL();
|
60
|
layoutData.heightHint = 1000;
|
61
|
|
62
|
browser.setLayoutData(layoutData);
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
*
|
67
|
*/
|
68
|
private void showBrowser() {
|
69
|
|
70
|
String html = "";
|
71
|
html = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>";
|
72
|
html += "<img width=\"" + calculateWidth() + "\" src=\"" + getImageUriString() + "\" />";
|
73
|
html += "</BODY></HTML>";
|
74
|
|
75
|
browser.setText(html);
|
76
|
}
|
77
|
|
78
|
/**
|
79
|
* <p>calculateWidth</p>
|
80
|
*
|
81
|
* @return a int.
|
82
|
*/
|
83
|
public int calculateWidth() {
|
84
|
Rectangle boundaries = browser.getBounds();
|
85
|
return boundaries.width;
|
86
|
}
|
87
|
|
88
|
/* (non-Javadoc)
|
89
|
* @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent)
|
90
|
*/
|
91
|
/** {@inheritDoc} */
|
92
|
public void controlMoved(ControlEvent e) {
|
93
|
showBrowser();
|
94
|
}
|
95
|
|
96
|
/* (non-Javadoc)
|
97
|
* @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent)
|
98
|
*/
|
99
|
/** {@inheritDoc} */
|
100
|
public void controlResized(ControlEvent e) {
|
101
|
showBrowser();
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* <p>setImageUri</p>
|
106
|
*
|
107
|
* @param imageUri the imageUri to set
|
108
|
*/
|
109
|
public void setImageUri(URI imageUri) {
|
110
|
setImageUriString(imageUri != null ? imageUri.toString() : "");
|
111
|
}
|
112
|
|
113
|
/**
|
114
|
* <p>Setter for the field <code>imageUriString</code>.</p>
|
115
|
*
|
116
|
* @param imageUriString a {@link java.lang.String} object.
|
117
|
*/
|
118
|
public void setImageUriString(String imageUriString){
|
119
|
this.imageUriString = imageUriString;
|
120
|
showBrowser();
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* <p>Getter for the field <code>imageUriString</code>.</p>
|
125
|
*
|
126
|
* @return the imageUri
|
127
|
*/
|
128
|
public String getImageUriString() {
|
129
|
return imageUriString;
|
130
|
}
|
131
|
|
132
|
}
|