1 |
c883ceaa
|
n.hoffmann
|
/**
|
2 |
|
|
*
|
3 |
|
|
*/
|
4 |
78222507
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.ui.element;
|
5 |
c883ceaa
|
n.hoffmann
|
|
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 |
6504f35c
|
Patric Plitzner
|
|
16 |
78222507
|
n.hoffmann
|
|
17 |
c883ceaa
|
n.hoffmann
|
/**
|
18 |
3be6ef3e
|
n.hoffmann
|
* <p>BrowserElement class.</p>
|
19 |
c883ceaa
|
n.hoffmann
|
*
|
20 |
3be6ef3e
|
n.hoffmann
|
* @author n.hoffmann
|
21 |
|
|
* @version $Id: $
|
22 |
c883ceaa
|
n.hoffmann
|
*/
|
23 |
|
|
public class BrowserElement extends AbstractCdmFormElement implements ControlListener{
|
24 |
|
|
|
25 |
|
|
private Browser browser;
|
26 |
|
|
|
27 |
|
|
private String imageUriString;
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
3be6ef3e
|
n.hoffmann
|
* <p>Constructor for BrowserElement.</p>
|
31 |
|
|
*
|
32 |
|
|
* @param style a int.
|
33 |
78222507
|
n.hoffmann
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
34 |
|
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
35 |
3be6ef3e
|
n.hoffmann
|
* @param imageUri a {@link java.net.URI} object.
|
36 |
c883ceaa
|
n.hoffmann
|
*/
|
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 |
cd074e7b
|
n.hoffmann
|
addControl(browser);
|
43 |
c883ceaa
|
n.hoffmann
|
|
44 |
23783f7a
|
n.hoffmann
|
getLayoutComposite().setLayoutData(LayoutConstants.FILL());
|
45 |
c883ceaa
|
n.hoffmann
|
|
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 |
23783f7a
|
n.hoffmann
|
TableWrapData layoutData = LayoutConstants.FILL();
|
60 |
c883ceaa
|
n.hoffmann
|
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 |
3be6ef3e
|
n.hoffmann
|
/**
|
79 |
|
|
* <p>calculateWidth</p>
|
80 |
|
|
*
|
81 |
|
|
* @return a int.
|
82 |
c883ceaa
|
n.hoffmann
|
*/
|
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 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
92 |
c883ceaa
|
n.hoffmann
|
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 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
100 |
c883ceaa
|
n.hoffmann
|
public void controlResized(ControlEvent e) {
|
101 |
|
|
showBrowser();
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
/**
|
105 |
3be6ef3e
|
n.hoffmann
|
* <p>setImageUri</p>
|
106 |
|
|
*
|
107 |
c883ceaa
|
n.hoffmann
|
* @param imageUri the imageUri to set
|
108 |
|
|
*/
|
109 |
|
|
public void setImageUri(URI imageUri) {
|
110 |
|
|
setImageUriString(imageUri != null ? imageUri.toString() : "");
|
111 |
|
|
}
|
112 |
|
|
|
113 |
3be6ef3e
|
n.hoffmann
|
/**
|
114 |
|
|
* <p>Setter for the field <code>imageUriString</code>.</p>
|
115 |
|
|
*
|
116 |
|
|
* @param imageUriString a {@link java.lang.String} object.
|
117 |
|
|
*/
|
118 |
c883ceaa
|
n.hoffmann
|
public void setImageUriString(String imageUriString){
|
119 |
|
|
this.imageUriString = imageUriString;
|
120 |
|
|
showBrowser();
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
/**
|
124 |
3be6ef3e
|
n.hoffmann
|
* <p>Getter for the field <code>imageUriString</code>.</p>
|
125 |
|
|
*
|
126 |
c883ceaa
|
n.hoffmann
|
* @return the imageUri
|
127 |
|
|
*/
|
128 |
|
|
public String getImageUriString() {
|
129 |
|
|
return imageUriString;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
}
|