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